2020-02-15 17:21:30 +01:00
|
|
|
package stupidgcm
|
|
|
|
|
|
|
|
import (
|
|
|
|
"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
|
|
|
//
|
|
|
|
// See https://github.com/rfjakob/gocryptfs/wiki/CPU-Benchmarks
|
|
|
|
// 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
|
|
|
|
}
|
2020-04-13 22:34:07 +02:00
|
|
|
// Openssl is probably faster
|
2020-02-15 17:21:30 +01:00
|
|
|
return true
|
|
|
|
}
|