diff options
| author | Jakob Unterwurzacher | 2020-04-13 22:34:07 +0200 | 
|---|---|---|
| committer | Jakob Unterwurzacher | 2020-04-13 22:34:07 +0200 | 
| commit | 8f5c2a613d37d8f58aee5b2405098da5c99aaca2 (patch) | |
| tree | b3d53b14e02ac5eabd12fe4079673ee37629cf1d /internal/stupidgcm | |
| parent | 73436d9419d9ef60b0104a73ffae156d9f871261 (diff) | |
Prefer Go stdlib aes-gcm on arm64 with aes instructions
We used to prefer openssl in this situation, which
used to make sense, but now Go gained an optimized
assembly implementation for aes-gcm on arm64 with
aes instructions:
  root@q1:~/go/src/github.com/rfjakob/gocryptfs# ./gocryptfs -speed
  gocryptfs v1.7.1-46-g73436d9; go-fuse v1.0.1-0.20190319092520-161a16484456; 2020-04-13 go1.14.2 linux/arm64
  AES-GCM-256-OpenSSL      212.30 MB/s    (selected in auto mode)
  AES-GCM-256-Go           452.30 MB/s
  AES-SIV-512-Go           100.25 MB/s
  XChaCha20-Poly1305-Go    137.35 MB/s
https://github.com/rfjakob/gocryptfs/issues/452
Diffstat (limited to 'internal/stupidgcm')
| -rw-r--r-- | internal/stupidgcm/prefer.go | 12 | 
1 files changed, 7 insertions, 5 deletions
| diff --git a/internal/stupidgcm/prefer.go b/internal/stupidgcm/prefer.go index a08d154..c067d09 100644 --- a/internal/stupidgcm/prefer.go +++ b/internal/stupidgcm/prefer.go @@ -6,11 +6,11 @@ import (  // PreferOpenSSL tells us if OpenSSL is faster than Go GCM on this machine.  // -// Go GCM is only faster if the CPU: +// Go GCM is only faster if the CPU either:  // -// 1) Is X86 -// 2) Has AES instructions -// 3) Go is v1.6 or higher +// 1) Is X86_64 && has AES instructions && Go is v1.6  or higher +// 2) Is ARM64  && has AES instructions && Go is v1.11 or higher +//    (commit https://github.com/golang/go/commit/4f1f503373cda7160392be94e3849b0c9b9ebbda)  //  // See https://github.com/rfjakob/gocryptfs/wiki/CPU-Benchmarks  // for benchmarks. @@ -19,8 +19,10 @@ func PreferOpenSSL() bool {  		return false  	}  	// Safe to call on other architectures - will just read false. -	if cpu.X86.HasAES { +	if cpu.X86.HasAES || cpu.ARM64.HasAES { +		// Go stdlib is probably faster  		return false  	} +	// Openssl is probably faster  	return true  } | 
