summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorJakob Unterwurzacher2021-09-14 18:47:07 +0200
committerJakob Unterwurzacher2021-09-14 18:58:04 +0200
commit61e37b2439f0b8a7c16458e73cb57c7428fe61f2 (patch)
treea8ab52aea36d1e62bf681cf66d39448108925dec /internal
parent52b044498529c4abd1d2044eabd709047e1194b5 (diff)
stupidgcm: add CpuHasAES()
Makes the code clearer, and will be used in the next commit.
Diffstat (limited to 'internal')
-rw-r--r--internal/stupidgcm/prefer.go27
1 files changed, 18 insertions, 9 deletions
diff --git a/internal/stupidgcm/prefer.go b/internal/stupidgcm/prefer.go
index ffbaf58..bb613c3 100644
--- a/internal/stupidgcm/prefer.go
+++ b/internal/stupidgcm/prefer.go
@@ -21,17 +21,11 @@ func PreferOpenSSLAES256GCM() bool {
if BuiltWithoutOpenssl {
return false
}
- // Safe to call on other architectures - will just read false.
- if cpu.X86.HasAES || cpu.ARM64.HasAES {
- // Go stdlib is probably faster
+ // If the CPU has AES acceleration, Go stdlib is faster
+ if CpuHasAES() {
return false
}
- // On the Apple M1, Go stdlib is faster than OpenSSL, despite cpu.ARM64.HasAES
- // reading false: https://github.com/rfjakob/gocryptfs/issues/556#issuecomment-848079309
- if runtime.GOOS == "darwin" && runtime.GOARCH == "arm64" {
- return false
- }
- // OpenSSL is probably faster
+ // Otherwise OpenSSL is probably faster
return true
}
@@ -49,3 +43,18 @@ func PreferOpenSSLXchacha20poly1305() bool {
// On arm64 and arm, OpenSSL is faster. Probably everwhere else too.
return true
}
+
+// CpuHasAES tells you if the CPU we are running has AES acceleration that is
+// usable by the Go crypto library.
+func CpuHasAES() bool {
+ // Safe to call on other architectures - will just read false.
+ if cpu.X86.HasAES || cpu.ARM64.HasAES {
+ return true
+ }
+ // On the Apple M1, the CPU has AES acceleration, despite cpu.ARM64.HasAES
+ // reading false: https://github.com/rfjakob/gocryptfs/issues/556#issuecomment-848079309
+ if runtime.GOOS == "darwin" && runtime.GOARCH == "arm64" {
+ return true
+ }
+ return false
+}