summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cli_args.go2
-rw-r--r--cli_args_test.go2
-rw-r--r--internal/speed/speed.go4
-rw-r--r--internal/stupidgcm/prefer.go20
4 files changed, 22 insertions, 6 deletions
diff --git a/cli_args.go b/cli_args.go
index 0287741..7175006 100644
--- a/cli_args.go
+++ b/cli_args.go
@@ -253,7 +253,7 @@ func parseCliOpts(osArgs []string) (args argContainer) {
}
// "-openssl" needs some post-processing
if opensslAuto == "auto" {
- args.openssl = stupidgcm.PreferOpenSSL()
+ args.openssl = stupidgcm.PreferOpenSSLAES256GCM()
} else {
args.openssl, err = strconv.ParseBool(opensslAuto)
if err != nil {
diff --git a/cli_args_test.go b/cli_args_test.go
index 9bb9654..6c923f4 100644
--- a/cli_args_test.go
+++ b/cli_args_test.go
@@ -119,7 +119,7 @@ func TestParseCliOpts(t *testing.T) {
longnames: true,
raw64: true,
hkdf: true,
- openssl: stupidgcm.PreferOpenSSL(), // depends on CPU and build flags
+ openssl: stupidgcm.PreferOpenSSLAES256GCM(), // depends on CPU and build flags
scryptn: 16,
}
diff --git a/internal/speed/speed.go b/internal/speed/speed.go
index 2f818d0..d5aa696 100644
--- a/internal/speed/speed.go
+++ b/internal/speed/speed.go
@@ -32,8 +32,8 @@ func Run() {
f func(*testing.B)
preferred bool
}{
- {name: cryptocore.BackendOpenSSL.Name, f: bStupidGCM, preferred: stupidgcm.PreferOpenSSL()},
- {name: cryptocore.BackendGoGCM.Name, f: bGoGCM, preferred: !stupidgcm.PreferOpenSSL()},
+ {name: cryptocore.BackendOpenSSL.Name, f: bStupidGCM, preferred: stupidgcm.PreferOpenSSLAES256GCM()},
+ {name: cryptocore.BackendGoGCM.Name, f: bGoGCM, preferred: !stupidgcm.PreferOpenSSLAES256GCM()},
{name: cryptocore.BackendAESSIV.Name, f: bAESSIV, preferred: false},
{name: cryptocore.BackendXChaCha20Poly1305.Name, f: bXchacha20poly1305, preferred: false},
{name: cryptocore.BackendXChaCha20Poly1305OpenSSL.Name, f: bStupidXchacha, preferred: false},
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
+}