Skip to content

Commit f79c9e8

Browse files
authoredFeb 25, 2024
Use crypto/sha256 (#29386)
Go 1.21 improved the performance of `crypto/sha256`. It's now similar to `minio/sha256-simd`, so we should just use the standard libs. https://go.dev/doc/go1.21#crypto/sha256 https://go-review.googlesource.com/c/go/+/408795 multiformats/go-multihash#173
1 parent ad0a34b commit f79c9e8

File tree

22 files changed

+22
-32
lines changed

22 files changed

+22
-32
lines changed
 

‎go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ require (
7878
github.com/mholt/archiver/v3 v3.5.1
7979
github.com/microcosm-cc/bluemonday v1.0.26
8080
github.com/minio/minio-go/v7 v7.0.66
81-
github.com/minio/sha256-simd v1.0.1
8281
github.com/msteinert/pam v1.2.0
8382
github.com/nektos/act v0.2.52
8483
github.com/niklasfasching/go-org v1.7.0
@@ -230,6 +229,7 @@ require (
230229
github.com/mholt/acmez v1.2.0 // indirect
231230
github.com/miekg/dns v1.1.58 // indirect
232231
github.com/minio/md5-simd v1.1.2 // indirect
232+
github.com/minio/sha256-simd v1.0.1 // indirect
233233
github.com/mitchellh/copystructure v1.2.0 // indirect
234234
github.com/mitchellh/mapstructure v1.5.0 // indirect
235235
github.com/mitchellh/reflectwalk v1.0.2 // indirect

‎models/auth/twofactor.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package auth
66
import (
77
"context"
88
"crypto/md5"
9+
"crypto/sha256"
910
"crypto/subtle"
1011
"encoding/base32"
1112
"encoding/base64"
@@ -18,7 +19,6 @@ import (
1819
"code.gitea.io/gitea/modules/timeutil"
1920
"code.gitea.io/gitea/modules/util"
2021

21-
"github.com/minio/sha256-simd"
2222
"github.com/pquerna/otp/totp"
2323
"golang.org/x/crypto/pbkdf2"
2424
)

‎models/migrations/base/hash.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
package base
55

66
import (
7+
"crypto/sha256"
78
"encoding/hex"
89

9-
"github.com/minio/sha256-simd"
1010
"golang.org/x/crypto/pbkdf2"
1111
)
1212

‎models/migrations/v1_14/v166.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
package v1_14 //nolint
55

66
import (
7+
"crypto/sha256"
78
"encoding/hex"
89

9-
"github.com/minio/sha256-simd"
1010
"golang.org/x/crypto/argon2"
1111
"golang.org/x/crypto/bcrypt"
1212
"golang.org/x/crypto/pbkdf2"

‎modules/auth/password/hash/pbkdf2.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
package hash
55

66
import (
7+
"crypto/sha256"
78
"encoding/hex"
89
"strings"
910

1011
"code.gitea.io/gitea/modules/log"
1112

12-
"github.com/minio/sha256-simd"
1313
"golang.org/x/crypto/pbkdf2"
1414
)
1515

‎modules/avatar/hash.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44
package avatar
55

66
import (
7+
"crypto/sha256"
78
"encoding/hex"
89
"strconv"
9-
10-
"github.com/minio/sha256-simd"
1110
)
1211

1312
// HashAvatar will generate a unique string, which ensures that when there's a

‎modules/avatar/identicon/identicon.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@
77
package identicon
88

99
import (
10+
"crypto/sha256"
1011
"fmt"
1112
"image"
1213
"image/color"
13-
14-
"github.com/minio/sha256-simd"
1514
)
1615

1716
const minImageSize = 16

‎modules/base/tool.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package base
55

66
import (
77
"crypto/sha1"
8+
"crypto/sha256"
89
"encoding/base64"
910
"encoding/hex"
1011
"errors"
@@ -22,7 +23,6 @@ import (
2223
"code.gitea.io/gitea/modules/setting"
2324

2425
"github.com/dustin/go-humanize"
25-
"github.com/minio/sha256-simd"
2626
)
2727

2828
// EncodeSha1 string to sha1 hex value.

‎modules/git/last_commit_cache.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44
package git
55

66
import (
7+
"crypto/sha256"
78
"fmt"
89

910
"code.gitea.io/gitea/modules/log"
1011
"code.gitea.io/gitea/modules/setting"
11-
12-
"github.com/minio/sha256-simd"
1312
)
1413

1514
// Cache represents a caching interface

‎modules/lfs/content_store.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package lfs
55

66
import (
7+
"crypto/sha256"
78
"encoding/hex"
89
"errors"
910
"hash"
@@ -12,8 +13,6 @@ import (
1213

1314
"code.gitea.io/gitea/modules/log"
1415
"code.gitea.io/gitea/modules/storage"
15-
16-
"github.com/minio/sha256-simd"
1716
)
1817

1918
var (

‎modules/lfs/pointer.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package lfs
55

66
import (
7+
"crypto/sha256"
78
"encoding/hex"
89
"errors"
910
"fmt"
@@ -12,8 +13,6 @@ import (
1213
"regexp"
1314
"strconv"
1415
"strings"
15-
16-
"github.com/minio/sha256-simd"
1716
)
1817

1918
const (

‎modules/secret/secret.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@ import (
77
"crypto/aes"
88
"crypto/cipher"
99
"crypto/rand"
10+
"crypto/sha256"
1011
"encoding/base64"
1112
"encoding/hex"
1213
"errors"
1314
"fmt"
1415
"io"
15-
16-
"github.com/minio/sha256-simd"
1716
)
1817

1918
// AesEncrypt encrypts text and given key with AES.

‎modules/util/keypair.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ import (
77
"crypto"
88
"crypto/rand"
99
"crypto/rsa"
10+
"crypto/sha256"
1011
"crypto/x509"
1112
"encoding/pem"
12-
13-
"github.com/minio/sha256-simd"
1413
)
1514

1615
// GenerateKeyPair generates a public and private keypair

‎modules/util/keypair_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ import (
77
"crypto"
88
"crypto/rand"
99
"crypto/rsa"
10+
"crypto/sha256"
1011
"crypto/x509"
1112
"encoding/pem"
1213
"regexp"
1314
"testing"
1415

15-
"github.com/minio/sha256-simd"
1616
"github.com/stretchr/testify/assert"
1717
)
1818

‎routers/api/packages/chef/auth.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"crypto"
99
"crypto/rsa"
1010
"crypto/sha1"
11+
"crypto/sha256"
1112
"crypto/x509"
1213
"encoding/base64"
1314
"encoding/pem"
@@ -26,8 +27,6 @@ import (
2627
chef_module "code.gitea.io/gitea/modules/packages/chef"
2728
"code.gitea.io/gitea/modules/util"
2829
"code.gitea.io/gitea/services/auth"
29-
30-
"github.com/minio/sha256-simd"
3130
)
3231

3332
const (

‎routers/api/packages/maven/maven.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package maven
66
import (
77
"crypto/md5"
88
"crypto/sha1"
9+
"crypto/sha256"
910
"crypto/sha512"
1011
"encoding/hex"
1112
"encoding/xml"
@@ -26,8 +27,6 @@ import (
2627
maven_module "code.gitea.io/gitea/modules/packages/maven"
2728
"code.gitea.io/gitea/routers/api/packages/helper"
2829
packages_service "code.gitea.io/gitea/services/packages"
29-
30-
"github.com/minio/sha256-simd"
3130
)
3231

3332
const (

‎services/lfs/server.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package lfs
55

66
import (
77
stdCtx "context"
8+
"crypto/sha256"
89
"encoding/base64"
910
"encoding/hex"
1011
"errors"
@@ -33,7 +34,6 @@ import (
3334
"code.gitea.io/gitea/modules/storage"
3435

3536
"github.com/golang-jwt/jwt/v5"
36-
"github.com/minio/sha256-simd"
3737
)
3838

3939
// requestContext contain variables from the HTTP request.

‎services/mailer/token/token.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@ package token
66
import (
77
"context"
88
crypto_hmac "crypto/hmac"
9+
"crypto/sha256"
910
"encoding/base32"
1011
"fmt"
1112
"time"
1213

1314
user_model "code.gitea.io/gitea/models/user"
1415
"code.gitea.io/gitea/modules/util"
15-
16-
"github.com/minio/sha256-simd"
1716
)
1817

1918
// A token is a verifiable container describing an action.

‎services/webhook/deliver.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"context"
88
"crypto/hmac"
99
"crypto/sha1"
10+
"crypto/sha256"
1011
"crypto/tls"
1112
"encoding/hex"
1213
"fmt"
@@ -29,7 +30,6 @@ import (
2930
webhook_module "code.gitea.io/gitea/modules/webhook"
3031

3132
"github.com/gobwas/glob"
32-
"github.com/minio/sha256-simd"
3333
)
3434

3535
// Deliver deliver hook task

‎tests/integration/api_packages_chef_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"crypto/rand"
1212
"crypto/rsa"
1313
"crypto/sha1"
14+
"crypto/sha256"
1415
"crypto/x509"
1516
"encoding/base64"
1617
"encoding/pem"
@@ -33,7 +34,6 @@ import (
3334
chef_router "code.gitea.io/gitea/routers/api/packages/chef"
3435
"code.gitea.io/gitea/tests"
3536

36-
"github.com/minio/sha256-simd"
3737
"github.com/stretchr/testify/assert"
3838
)
3939

‎tests/integration/api_packages_container_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package integration
55

66
import (
77
"bytes"
8+
"crypto/sha256"
89
"encoding/base64"
910
"fmt"
1011
"net/http"
@@ -24,7 +25,6 @@ import (
2425
"code.gitea.io/gitea/modules/test"
2526
"code.gitea.io/gitea/tests"
2627

27-
"github.com/minio/sha256-simd"
2828
oci "github.com/opencontainers/image-spec/specs-go/v1"
2929
"github.com/stretchr/testify/assert"
3030
)

‎tests/integration/api_packages_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package integration
55

66
import (
77
"bytes"
8+
"crypto/sha256"
89
"fmt"
910
"net/http"
1011
"strings"
@@ -24,7 +25,6 @@ import (
2425
packages_cleanup_service "code.gitea.io/gitea/services/packages/cleanup"
2526
"code.gitea.io/gitea/tests"
2627

27-
"github.com/minio/sha256-simd"
2828
"github.com/stretchr/testify/assert"
2929
)
3030

0 commit comments

Comments
 (0)