Skip to content

Commit 1319ba6

Browse files
zeripathjolheiser
andauthored
Use minio/sha256-simd for accelerated SHA256 (#23052)
minio/sha256-simd provides additional acceleration for SHA256 using AVX512, SHA Extensions for x86 and ARM64 for ARM. It provides a drop-in replacement for crypto/sha256 and if the extensions are not available it falls back to standard crypto/sha256. --------- Signed-off-by: Andrew Thornton <[email protected]> Co-authored-by: John Olheiser <[email protected]>
1 parent eb5a557 commit 1319ba6

File tree

24 files changed

+33
-24
lines changed

24 files changed

+33
-24
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ require (
7676
github.com/mholt/archiver/v3 v3.5.1
7777
github.com/microcosm-cc/bluemonday v1.0.21
7878
github.com/minio/minio-go/v7 v7.0.46
79+
github.com/minio/sha256-simd v1.0.0
7980
github.com/msteinert/pam v1.1.0
8081
github.com/nektos/act v0.0.0
8182
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
@@ -220,7 +221,6 @@ require (
220221
github.com/mholt/acmez v1.0.4 // indirect
221222
github.com/miekg/dns v1.1.50 // indirect
222223
github.com/minio/md5-simd v1.1.2 // indirect
223-
github.com/minio/sha256-simd v1.0.0 // indirect
224224
github.com/mitchellh/copystructure v1.2.0 // indirect
225225
github.com/mitchellh/mapstructure v1.5.0 // indirect
226226
github.com/mitchellh/reflectwalk v1.0.2 // indirect

models/auth/oauth2.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ package auth
55

66
import (
77
"context"
8-
"crypto/sha256"
98
"encoding/base32"
109
"encoding/base64"
1110
"fmt"
@@ -18,6 +17,7 @@ import (
1817
"code.gitea.io/gitea/modules/util"
1918

2019
uuid "github.com/google/uuid"
20+
"github.com/minio/sha256-simd"
2121
"golang.org/x/crypto/bcrypt"
2222
"xorm.io/builder"
2323
"xorm.io/xorm"

models/auth/twofactor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ package auth
55

66
import (
77
"crypto/md5"
8-
"crypto/sha256"
98
"crypto/subtle"
109
"encoding/base32"
1110
"encoding/base64"
@@ -18,6 +17,7 @@ import (
1817
"code.gitea.io/gitea/modules/timeutil"
1918
"code.gitea.io/gitea/modules/util"
2019

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

models/migrations/base/hash.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
package base
55

66
import (
7-
"crypto/sha256"
87
"encoding/hex"
98

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

models/migrations/v1_14/v166.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
package v1_14 //nolint
55

66
import (
7-
"crypto/sha256"
87
"encoding/hex"
98

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
package hash
55

66
import (
7-
"crypto/sha256"
87
"encoding/hex"
98
"strings"
109

1110
"code.gitea.io/gitea/modules/log"
1211

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

modules/avatar/hash.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
package avatar
55

66
import (
7-
"crypto/sha256"
87
"encoding/hex"
98
"strconv"
9+
10+
"github.com/minio/sha256-simd"
1011
)
1112

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

modules/avatar/identicon/identicon.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
package identicon
88

99
import (
10-
"crypto/sha256"
1110
"fmt"
1211
"image"
1312
"image/color"
13+
14+
"github.com/minio/sha256-simd"
1415
)
1516

1617
const minImageSize = 16

modules/base/tool.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package base
66
import (
77
"crypto/md5"
88
"crypto/sha1"
9-
"crypto/sha256"
109
"encoding/base64"
1110
"encoding/hex"
1211
"errors"
@@ -26,6 +25,7 @@ import (
2625
"code.gitea.io/gitea/modules/util"
2726

2827
"github.com/dustin/go-humanize"
28+
"github.com/minio/sha256-simd"
2929
)
3030

3131
// EncodeMD5 encodes string to md5 hex value.

modules/context/context.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package context
66

77
import (
88
"context"
9-
"crypto/sha256"
109
"encoding/hex"
1110
"errors"
1211
"fmt"
@@ -40,6 +39,7 @@ import (
4039
"gitea.com/go-chi/cache"
4140
"gitea.com/go-chi/session"
4241
chi "github.com/go-chi/chi/v5"
42+
"github.com/minio/sha256-simd"
4343
"github.com/unrolled/render"
4444
"golang.org/x/crypto/pbkdf2"
4545
)

modules/git/last_commit_cache.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
package git
55

66
import (
7-
"crypto/sha256"
87
"fmt"
98

109
"code.gitea.io/gitea/modules/log"
1110
"code.gitea.io/gitea/modules/setting"
11+
12+
"github.com/minio/sha256-simd"
1213
)
1314

1415
// Cache represents a caching interface

modules/lfs/content_store.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
package lfs
55

66
import (
7-
"crypto/sha256"
87
"encoding/hex"
98
"errors"
109
"hash"
@@ -13,6 +12,8 @@ import (
1312

1413
"code.gitea.io/gitea/modules/log"
1514
"code.gitea.io/gitea/modules/storage"
15+
16+
"github.com/minio/sha256-simd"
1617
)
1718

1819
var (

modules/lfs/pointer.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
package lfs
55

66
import (
7-
"crypto/sha256"
87
"encoding/hex"
98
"errors"
109
"fmt"
@@ -15,6 +14,8 @@ import (
1514
"strings"
1615

1716
"code.gitea.io/gitea/modules/log"
17+
18+
"github.com/minio/sha256-simd"
1819
)
1920

2021
const (

modules/secret/secret.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ import (
77
"crypto/aes"
88
"crypto/cipher"
99
"crypto/rand"
10-
"crypto/sha256"
1110
"encoding/base64"
1211
"encoding/hex"
1312
"errors"
1413
"io"
14+
15+
"github.com/minio/sha256-simd"
1516
)
1617

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

modules/util/keypair_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ import (
77
"crypto"
88
"crypto/rand"
99
"crypto/rsa"
10-
"crypto/sha256"
1110
"crypto/x509"
1211
"encoding/pem"
1312
"regexp"
1413
"testing"
1514

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

routers/api/packages/chef/auth.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"crypto"
88
"crypto/rsa"
99
"crypto/sha1"
10-
"crypto/sha256"
1110
"crypto/x509"
1211
"encoding/base64"
1312
"encoding/pem"
@@ -25,6 +24,8 @@ import (
2524
chef_module "code.gitea.io/gitea/modules/packages/chef"
2625
"code.gitea.io/gitea/modules/util"
2726
"code.gitea.io/gitea/services/auth"
27+
28+
"github.com/minio/sha256-simd"
2829
)
2930

3031
const (

routers/api/packages/maven/maven.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package maven
66
import (
77
"crypto/md5"
88
"crypto/sha1"
9-
"crypto/sha256"
109
"crypto/sha512"
1110
"encoding/hex"
1211
"encoding/xml"
@@ -27,6 +26,8 @@ import (
2726
maven_module "code.gitea.io/gitea/modules/packages/maven"
2827
"code.gitea.io/gitea/routers/api/packages/helper"
2928
packages_service "code.gitea.io/gitea/services/packages"
29+
30+
"github.com/minio/sha256-simd"
3031
)
3132

3233
const (

services/auth/source/oauth2/jwtsigningkey.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"crypto/elliptic"
1010
"crypto/rand"
1111
"crypto/rsa"
12-
"crypto/sha256"
1312
"crypto/x509"
1413
"encoding/base64"
1514
"encoding/pem"
@@ -25,6 +24,7 @@ import (
2524
"code.gitea.io/gitea/modules/util"
2625

2726
"github.com/golang-jwt/jwt/v4"
27+
"github.com/minio/sha256-simd"
2828
ini "gopkg.in/ini.v1"
2929
)
3030

services/lfs/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ package lfs
55

66
import (
77
stdCtx "context"
8-
"crypto/sha256"
98
"encoding/base64"
109
"encoding/hex"
1110
"errors"
@@ -32,6 +31,7 @@ import (
3231
"code.gitea.io/gitea/modules/storage"
3332

3433
"github.com/golang-jwt/jwt/v4"
34+
"github.com/minio/sha256-simd"
3535
)
3636

3737
// requestContext contain variables from the HTTP request.

services/mailer/token/token.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ package token
66
import (
77
"context"
88
crypto_hmac "crypto/hmac"
9-
"crypto/sha256"
109
"encoding/base32"
1110
"fmt"
1211
"time"
1312

1413
user_model "code.gitea.io/gitea/models/user"
1514
"code.gitea.io/gitea/modules/util"
15+
16+
"github.com/minio/sha256-simd"
1617
)
1718

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

services/webhook/deliver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"context"
88
"crypto/hmac"
99
"crypto/sha1"
10-
"crypto/sha256"
1110
"crypto/tls"
1211
"encoding/hex"
1312
"fmt"
@@ -29,6 +28,7 @@ import (
2928
webhook_module "code.gitea.io/gitea/modules/webhook"
3029

3130
"github.com/gobwas/glob"
31+
"github.com/minio/sha256-simd"
3232
)
3333

3434
// Deliver deliver hook task

tests/integration/api_packages_chef_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"crypto/rand"
1212
"crypto/rsa"
1313
"crypto/sha1"
14-
"crypto/sha256"
1514
"crypto/x509"
1615
"encoding/base64"
1716
"encoding/pem"
@@ -34,6 +33,7 @@ import (
3433
chef_router "code.gitea.io/gitea/routers/api/packages/chef"
3534
"code.gitea.io/gitea/tests"
3635

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

tests/integration/api_packages_container_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ package integration
55

66
import (
77
"bytes"
8-
"crypto/sha256"
98
"encoding/base64"
109
"fmt"
1110
"net/http"
@@ -24,6 +23,7 @@ import (
2423
api "code.gitea.io/gitea/modules/structs"
2524
"code.gitea.io/gitea/tests"
2625

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

tests/integration/api_packages_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ package integration
55

66
import (
77
"bytes"
8-
"crypto/sha256"
98
"fmt"
109
"net/http"
1110
"strings"
@@ -24,6 +23,7 @@ import (
2423
packages_cleanup_service "code.gitea.io/gitea/services/packages/cleanup"
2524
"code.gitea.io/gitea/tests"
2625

26+
"github.com/minio/sha256-simd"
2727
"github.com/stretchr/testify/assert"
2828
)
2929

0 commit comments

Comments
 (0)