2020-02-15 17:21:30 +01:00
|
|
|
package stupidgcm
|
|
|
|
|
|
|
|
import (
|
2021-05-26 09:20:22 +02:00
|
|
|
"runtime"
|
|
|
|
|
2020-02-15 17:21:30 +01:00
|
|
|
"golang.org/x/sys/cpu"
|
|
|
|
)
|
|
|
|
|
|
|
|
// PreferOpenSSL tells us if OpenSSL is faster than Go GCM on this machine.
|
|
|
|
//
|
2020-04-13 22:34:07 +02:00
|
|
|
// Go GCM is only faster if the CPU either:
|
2020-02-15 17:21:30 +01:00
|
|
|
//
|
2020-04-13 22:34:07 +02:00
|
|
|
// 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)
|
2020-02-15 17:21:30 +01:00
|
|
|
//
|
2021-08-30 11:31:01 +02:00
|
|
|
// See https://github.com/rfjakob/gocryptfs/wiki/CPU-Benchmarks
|
2020-02-15 17:21:30 +01:00
|
|
|
// for benchmarks.
|
|
|
|
func PreferOpenSSL() bool {
|
|
|
|
if BuiltWithoutOpenssl {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
// Safe to call on other architectures - will just read false.
|
2020-04-13 22:34:07 +02:00
|
|
|
if cpu.X86.HasAES || cpu.ARM64.HasAES {
|
|
|
|
// Go stdlib is probably faster
|
2020-02-15 17:21:30 +01:00
|
|
|
return false
|
|
|
|
}
|
2021-05-26 09:20:22 +02:00
|
|
|
// On the Apple M1, Go stdlib is faster than OpenSSL, despite cpu.ARM64.HasAES
|
2021-08-30 11:31:01 +02:00
|
|
|
// reading false: https://github.com/rfjakob/gocryptfs/issues/556#issuecomment-848079309
|
2021-05-26 09:20:22 +02:00
|
|
|
if runtime.GOOS == "darwin" && runtime.GOARCH == "arm64" {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
// OpenSSL is probably faster
|
2020-02-15 17:21:30 +01:00
|
|
|
return true
|
|
|
|
}
|