diff options
author | Jakob Unterwurzacher | 2024-06-06 10:07:08 +0200 |
---|---|---|
committer | Jakob Unterwurzacher | 2024-06-06 10:07:08 +0200 |
commit | f06f27e7bc098e334024c365004f9303e79997d9 (patch) | |
tree | d6af7efa28dc945a982dee096019549e489360c8 /internal/stupidgcm/cipher_suites.go | |
parent | da873087dd7bcc54d96748a1f6e4e8ecf9e265e5 (diff) |
stupidgcm: detect AES-GCM acceleration like crypto/tls
Instead of just looking for AES, also look for PCLMULQDQ,
like crypto/tls does.
Fixes: https://github.com/rfjakob/gocryptfs/issues/822
Diffstat (limited to 'internal/stupidgcm/cipher_suites.go')
-rw-r--r-- | internal/stupidgcm/cipher_suites.go | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/internal/stupidgcm/cipher_suites.go b/internal/stupidgcm/cipher_suites.go new file mode 100644 index 0000000..fd032fd --- /dev/null +++ b/internal/stupidgcm/cipher_suites.go @@ -0,0 +1,28 @@ +package stupidgcm + +import ( + "runtime" + + "golang.org/x/sys/cpu" +) + +// ******** +// Carbon-copied from Go Stdlib +// https://github.com/golang/go/blob/45967bb18e04fa6dc62c2786c87ce120443c64f6/src/crypto/tls/cipher_suites.go#L367 +// ******** + +var ( + hasGCMAsmAMD64 = cpu.X86.HasAES && cpu.X86.HasPCLMULQDQ + hasGCMAsmARM64 = cpu.ARM64.HasAES && cpu.ARM64.HasPMULL + // Keep in sync with crypto/aes/cipher_s390x.go. + hasGCMAsmS390X = cpu.S390X.HasAES && cpu.S390X.HasAESCBC && cpu.S390X.HasAESCTR && + (cpu.S390X.HasGHASH || cpu.S390X.HasAESGCM) + + hasAESGCMHardwareSupport = runtime.GOARCH == "amd64" && hasGCMAsmAMD64 || + runtime.GOARCH == "arm64" && hasGCMAsmARM64 || + runtime.GOARCH == "s390x" && hasGCMAsmS390X +) + +// ******** +// End carbon-copy +// ******** |