aboutsummaryrefslogtreecommitdiff
path: root/internal/stupidgcm/prefer.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2021-09-08 19:48:13 +0200
committerJakob Unterwurzacher2021-09-08 19:48:13 +0200
commit1a5866729387c09eca1cdc9737d1b02c74c25901 (patch)
treef4f3e067a23fad3f34f9b555ec8b27799bc7412c /internal/stupidgcm/prefer.go
parent85c2beccaf674c69b3e30b0d646f5c11d91ecb9b (diff)
stupidgcm: add PreferOpenSSL{AES256GCM,Xchacha20poly1305}
Add PreferOpenSSLXchacha20poly1305, rename PreferOpenSSL -> PreferOpenSSLAES256GCM.
Diffstat (limited to 'internal/stupidgcm/prefer.go')
-rw-r--r--internal/stupidgcm/prefer.go20
1 files changed, 18 insertions, 2 deletions
diff --git a/internal/stupidgcm/prefer.go b/internal/stupidgcm/prefer.go
index bacd56a..ffbaf58 100644
--- a/internal/stupidgcm/prefer.go
+++ b/internal/stupidgcm/prefer.go
@@ -6,7 +6,8 @@ import (
"golang.org/x/sys/cpu"
)
-// PreferOpenSSL tells us if OpenSSL is faster than Go GCM on this machine.
+// PreferOpenSSLAES256GCM tells us if OpenSSL AES-256-GCM is faster than Go stdlib
+// on this machine.
//
// Go GCM is only faster if the CPU either:
//
@@ -16,7 +17,7 @@ import (
//
// See https://github.com/rfjakob/gocryptfs/wiki/CPU-Benchmarks
// for benchmarks.
-func PreferOpenSSL() bool {
+func PreferOpenSSLAES256GCM() bool {
if BuiltWithoutOpenssl {
return false
}
@@ -33,3 +34,18 @@ func PreferOpenSSL() bool {
// OpenSSL is probably faster
return true
}
+
+// PreferOpenSSLXchacha20poly1305 returns true if OpenSSL Xchacha20poly1305 is
+// faster than Go stdlib on this machine.
+func PreferOpenSSLXchacha20poly1305() bool {
+ if BuiltWithoutOpenssl {
+ return false
+ }
+ // Go x/crypto has optimized assembly for amd64:
+ // https://github.com/golang/crypto/blob/master/chacha20poly1305/chacha20poly1305_amd64.s
+ if runtime.GOARCH == "amd64" {
+ return false
+ }
+ // On arm64 and arm, OpenSSL is faster. Probably everwhere else too.
+ return true
+}