]> source.dussan.org Git - gitea.git/commitdiff
Use minio/sha256-simd for accelerated SHA256 (#23052)
authorzeripath <art27@cantab.net>
Wed, 22 Feb 2023 19:21:46 +0000 (19:21 +0000)
committerGitHub <noreply@github.com>
Wed, 22 Feb 2023 19:21:46 +0000 (14:21 -0500)
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 <art27@cantab.net>
Co-authored-by: John Olheiser <john.olheiser@gmail.com>
24 files changed:
go.mod
models/auth/oauth2.go
models/auth/twofactor.go
models/migrations/base/hash.go
models/migrations/v1_14/v166.go
modules/auth/password/hash/pbkdf2.go
modules/avatar/hash.go
modules/avatar/identicon/identicon.go
modules/base/tool.go
modules/context/context.go
modules/git/last_commit_cache.go
modules/lfs/content_store.go
modules/lfs/pointer.go
modules/secret/secret.go
modules/util/keypair_test.go
routers/api/packages/chef/auth.go
routers/api/packages/maven/maven.go
services/auth/source/oauth2/jwtsigningkey.go
services/lfs/server.go
services/mailer/token/token.go
services/webhook/deliver.go
tests/integration/api_packages_chef_test.go
tests/integration/api_packages_container_test.go
tests/integration/api_packages_test.go

diff --git a/go.mod b/go.mod
index 343a70da25a02a2e2ccddb2434f1780fa908aa5e..f003d444b403da249490c545e3086f9e19af1e3f 100644 (file)
--- a/go.mod
+++ b/go.mod
@@ -76,6 +76,7 @@ require (
        github.com/mholt/archiver/v3 v3.5.1
        github.com/microcosm-cc/bluemonday v1.0.21
        github.com/minio/minio-go/v7 v7.0.46
+       github.com/minio/sha256-simd v1.0.0
        github.com/msteinert/pam v1.1.0
        github.com/nektos/act v0.0.0
        github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
@@ -220,7 +221,6 @@ require (
        github.com/mholt/acmez v1.0.4 // indirect
        github.com/miekg/dns v1.1.50 // indirect
        github.com/minio/md5-simd v1.1.2 // indirect
-       github.com/minio/sha256-simd v1.0.0 // indirect
        github.com/mitchellh/copystructure v1.2.0 // indirect
        github.com/mitchellh/mapstructure v1.5.0 // indirect
        github.com/mitchellh/reflectwalk v1.0.2 // indirect
index 09d4bfc4ea35ef8b5089c257ddc3228c88cfcfc2..bda0668c45f559a9004faba134d19aa9dd4351a8 100644 (file)
@@ -5,7 +5,6 @@ package auth
 
 import (
        "context"
-       "crypto/sha256"
        "encoding/base32"
        "encoding/base64"
        "fmt"
@@ -18,6 +17,7 @@ import (
        "code.gitea.io/gitea/modules/util"
 
        uuid "github.com/google/uuid"
+       "github.com/minio/sha256-simd"
        "golang.org/x/crypto/bcrypt"
        "xorm.io/builder"
        "xorm.io/xorm"
index 5b3a9d011a099c300183471c8ff72cd76397f193..751a281f7e8b9abf505c5df4f713b5cbb08a72bc 100644 (file)
@@ -5,7 +5,6 @@ package auth
 
 import (
        "crypto/md5"
-       "crypto/sha256"
        "crypto/subtle"
        "encoding/base32"
        "encoding/base64"
@@ -18,6 +17,7 @@ import (
        "code.gitea.io/gitea/modules/timeutil"
        "code.gitea.io/gitea/modules/util"
 
+       "github.com/minio/sha256-simd"
        "github.com/pquerna/otp/totp"
        "golang.org/x/crypto/pbkdf2"
 )
index 00fd1efd4a3ba40fbffdcecc538650320b69b04f..0debec272b3f320f4ef53d1dbd3023bdc7cf99aa 100644 (file)
@@ -4,9 +4,9 @@
 package base
 
 import (
-       "crypto/sha256"
        "encoding/hex"
 
+       "github.com/minio/sha256-simd"
        "golang.org/x/crypto/pbkdf2"
 )
 
index f797930d6d5bc02502df840f1ce51ecf3cac6fa0..de7626076a95dcc2b980e165a8591976278f6911 100644 (file)
@@ -4,9 +4,9 @@
 package v1_14 //nolint
 
 import (
-       "crypto/sha256"
        "encoding/hex"
 
+       "github.com/minio/sha256-simd"
        "golang.org/x/crypto/argon2"
        "golang.org/x/crypto/bcrypt"
        "golang.org/x/crypto/pbkdf2"
index 27382fedb8cb0f89edbf070f42d7eae9238f6a02..9ff6d162fcc394efb2068dd89a55d81409f08ba2 100644 (file)
@@ -4,12 +4,12 @@
 package hash
 
 import (
-       "crypto/sha256"
        "encoding/hex"
        "strings"
 
        "code.gitea.io/gitea/modules/log"
 
+       "github.com/minio/sha256-simd"
        "golang.org/x/crypto/pbkdf2"
 )
 
index 50db9c1943a30841168fb0a2616033c9f1686ba6..4fc28a7739f0bb2078d76e0cadc049a6fcf5ce27 100644 (file)
@@ -4,9 +4,10 @@
 package avatar
 
 import (
-       "crypto/sha256"
        "encoding/hex"
        "strconv"
+
+       "github.com/minio/sha256-simd"
 )
 
 // HashAvatar will generate a unique string, which ensures that when there's a
index 63926d5f1908610d262de65f52856054f4c20e5a..9b7a2faf05b509436f91fb1379ba855b9845b0b1 100644 (file)
@@ -7,10 +7,11 @@
 package identicon
 
 import (
-       "crypto/sha256"
        "fmt"
        "image"
        "image/color"
+
+       "github.com/minio/sha256-simd"
 )
 
 const minImageSize = 16
index 994e58ac3cd3eaa7e76edb3d4e001a34aa7f4b3c..94f19576b48d7ca327e06a2f2e1835a1d07c8459 100644 (file)
@@ -6,7 +6,6 @@ package base
 import (
        "crypto/md5"
        "crypto/sha1"
-       "crypto/sha256"
        "encoding/base64"
        "encoding/hex"
        "errors"
@@ -26,6 +25,7 @@ import (
        "code.gitea.io/gitea/modules/util"
 
        "github.com/dustin/go-humanize"
+       "github.com/minio/sha256-simd"
 )
 
 // EncodeMD5 encodes string to md5 hex value.
index a2088217ff387703ae966e0c8861db5ebf2261e4..0c8d7411ed5db3ae9bbcc2312f5c6be3b2d4fb10 100644 (file)
@@ -6,7 +6,6 @@ package context
 
 import (
        "context"
-       "crypto/sha256"
        "encoding/hex"
        "errors"
        "fmt"
@@ -40,6 +39,7 @@ import (
        "gitea.com/go-chi/cache"
        "gitea.com/go-chi/session"
        chi "github.com/go-chi/chi/v5"
+       "github.com/minio/sha256-simd"
        "github.com/unrolled/render"
        "golang.org/x/crypto/pbkdf2"
 )
index ec8f1cce62fcc4562149368bdfe5aba51e1d29b3..984561b2c67295bc2e1bf3e6bdaba03eae2fc686 100644 (file)
@@ -4,11 +4,12 @@
 package git
 
 import (
-       "crypto/sha256"
        "fmt"
 
        "code.gitea.io/gitea/modules/log"
        "code.gitea.io/gitea/modules/setting"
+
+       "github.com/minio/sha256-simd"
 )
 
 // Cache represents a caching interface
index 94277a6b8eb3b2434e53f889f75d9caf614ba172..a4ae21bfd65c6c79e12d6d29f8e421978f00d112 100644 (file)
@@ -4,7 +4,6 @@
 package lfs
 
 import (
-       "crypto/sha256"
        "encoding/hex"
        "errors"
        "hash"
@@ -13,6 +12,8 @@ import (
 
        "code.gitea.io/gitea/modules/log"
        "code.gitea.io/gitea/modules/storage"
+
+       "github.com/minio/sha256-simd"
 )
 
 var (
index b5e13d56a3b365a0909a7ab15f967a73273e0aeb..f7f225bf1c1e7f640732e626fbefccf483099823 100644 (file)
@@ -4,7 +4,6 @@
 package lfs
 
 import (
-       "crypto/sha256"
        "encoding/hex"
        "errors"
        "fmt"
@@ -15,6 +14,8 @@ import (
        "strings"
 
        "code.gitea.io/gitea/modules/log"
+
+       "github.com/minio/sha256-simd"
 )
 
 const (
index b84d1cfea877ee0a8947531fa4eeb00980787408..628ae505a5c0b8d44e654af2ac1d43079a00066c 100644 (file)
@@ -7,11 +7,12 @@ import (
        "crypto/aes"
        "crypto/cipher"
        "crypto/rand"
-       "crypto/sha256"
        "encoding/base64"
        "encoding/hex"
        "errors"
        "io"
+
+       "github.com/minio/sha256-simd"
 )
 
 // AesEncrypt encrypts text and given key with AES.
index c6f68c845a47a90f1bc3b286349f64b98cfb4292..c9925f7988103fe978fb8010d4666b799c14d209 100644 (file)
@@ -7,12 +7,12 @@ import (
        "crypto"
        "crypto/rand"
        "crypto/rsa"
-       "crypto/sha256"
        "crypto/x509"
        "encoding/pem"
        "regexp"
        "testing"
 
+       "github.com/minio/sha256-simd"
        "github.com/stretchr/testify/assert"
 )
 
index 69f7b763ab66ca747514c20c45946982f7e8743f..1ea453f1f4d137eafaf358fe0ef735538d3d7139 100644 (file)
@@ -7,7 +7,6 @@ import (
        "crypto"
        "crypto/rsa"
        "crypto/sha1"
-       "crypto/sha256"
        "crypto/x509"
        "encoding/base64"
        "encoding/pem"
@@ -25,6 +24,8 @@ import (
        chef_module "code.gitea.io/gitea/modules/packages/chef"
        "code.gitea.io/gitea/modules/util"
        "code.gitea.io/gitea/services/auth"
+
+       "github.com/minio/sha256-simd"
 )
 
 const (
index d0c9983cbf1f20b0d58d6f64479b3f8b831a4659..a3a23ecfa8dc902e86d6f21a89575fd76d479de7 100644 (file)
@@ -6,7 +6,6 @@ package maven
 import (
        "crypto/md5"
        "crypto/sha1"
-       "crypto/sha256"
        "crypto/sha512"
        "encoding/hex"
        "encoding/xml"
@@ -27,6 +26,8 @@ import (
        maven_module "code.gitea.io/gitea/modules/packages/maven"
        "code.gitea.io/gitea/routers/api/packages/helper"
        packages_service "code.gitea.io/gitea/services/packages"
+
+       "github.com/minio/sha256-simd"
 )
 
 const (
index 93c15743798c2a3e32640576ba5831e3f2e3d62e..94feddbf6b6a57af6e27bc9719f51fd803e2fd05 100644 (file)
@@ -9,7 +9,6 @@ import (
        "crypto/elliptic"
        "crypto/rand"
        "crypto/rsa"
-       "crypto/sha256"
        "crypto/x509"
        "encoding/base64"
        "encoding/pem"
@@ -25,6 +24,7 @@ import (
        "code.gitea.io/gitea/modules/util"
 
        "github.com/golang-jwt/jwt/v4"
+       "github.com/minio/sha256-simd"
        ini "gopkg.in/ini.v1"
 )
 
index 320c8e728116df952a4898e68f819b7619bab5d4..217d45124e391f183228c25cad743c9637f01e68 100644 (file)
@@ -5,7 +5,6 @@ package lfs
 
 import (
        stdCtx "context"
-       "crypto/sha256"
        "encoding/base64"
        "encoding/hex"
        "errors"
@@ -32,6 +31,7 @@ import (
        "code.gitea.io/gitea/modules/storage"
 
        "github.com/golang-jwt/jwt/v4"
+       "github.com/minio/sha256-simd"
 )
 
 // requestContext contain variables from the HTTP request.
index 8a5a762d6b5fd3623f16dec8c9eaf2ae94043a23..aa7b56718863b6ece55938aca2a5e251cd36bc73 100644 (file)
@@ -6,13 +6,14 @@ package token
 import (
        "context"
        crypto_hmac "crypto/hmac"
-       "crypto/sha256"
        "encoding/base32"
        "fmt"
        "time"
 
        user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/util"
+
+       "github.com/minio/sha256-simd"
 )
 
 // A token is a verifiable container describing an action.
index effbe45e569102f0cd0ed2d16247f8aca1dcc152..e389b1f9fe670221f48fd47edb836b5ce3baef9d 100644 (file)
@@ -7,7 +7,6 @@ import (
        "context"
        "crypto/hmac"
        "crypto/sha1"
-       "crypto/sha256"
        "crypto/tls"
        "encoding/hex"
        "fmt"
@@ -29,6 +28,7 @@ import (
        webhook_module "code.gitea.io/gitea/modules/webhook"
 
        "github.com/gobwas/glob"
+       "github.com/minio/sha256-simd"
 )
 
 // Deliver deliver hook task
index 14baddca9428072c8b028d4805055c0e7c44e924..0ee43e17418606fd884570d58b48b11c29d210db 100644 (file)
@@ -11,7 +11,6 @@ import (
        "crypto/rand"
        "crypto/rsa"
        "crypto/sha1"
-       "crypto/sha256"
        "crypto/x509"
        "encoding/base64"
        "encoding/pem"
@@ -34,6 +33,7 @@ import (
        chef_router "code.gitea.io/gitea/routers/api/packages/chef"
        "code.gitea.io/gitea/tests"
 
+       "github.com/minio/sha256-simd"
        "github.com/stretchr/testify/assert"
 )
 
index 3d9319f37001c9bbc3ee90328dce7690bed39950..bbab820ecbbc1e1b2becbfde68fc25ea1a03f435 100644 (file)
@@ -5,7 +5,6 @@ package integration
 
 import (
        "bytes"
-       "crypto/sha256"
        "encoding/base64"
        "fmt"
        "net/http"
@@ -24,6 +23,7 @@ import (
        api "code.gitea.io/gitea/modules/structs"
        "code.gitea.io/gitea/tests"
 
+       "github.com/minio/sha256-simd"
        oci "github.com/opencontainers/image-spec/specs-go/v1"
        "github.com/stretchr/testify/assert"
 )
index 39852e212c387c439eb519e7d6495deb3e6addb0..4a16cec015b8b93353665ba1152c4b4af502c8e4 100644 (file)
@@ -5,7 +5,6 @@ package integration
 
 import (
        "bytes"
-       "crypto/sha256"
        "fmt"
        "net/http"
        "strings"
@@ -24,6 +23,7 @@ import (
        packages_cleanup_service "code.gitea.io/gitea/services/packages/cleanup"
        "code.gitea.io/gitea/tests"
 
+       "github.com/minio/sha256-simd"
        "github.com/stretchr/testify/assert"
 )