diff options
author | Jakob Unterwurzacher | 2020-02-15 17:21:30 +0100 |
---|---|---|
committer | Jakob Unterwurzacher | 2020-02-15 17:21:30 +0100 |
commit | d5ce340c02601992cc9dab1bd7d3c2d95d81155e (patch) | |
tree | e709cea1677b2d9dff80ce83d5086aaaebf03c49 | |
parent | 9aeb2a3df68539ad3a44283b9b94e1b28f011941 (diff) |
merge prefer_openssl package into stupidgcm
Now that I have discovered golang.org/x/sys/cpu and that Go
versions below 1.6 are uncommon, there was not much useful
code left in prefer_openssl.
Merge the remains into stupidgcm.
-rw-r--r-- | cli_args.go | 3 | ||||
-rw-r--r-- | internal/prefer_openssl/cpuinfo.pentium_g630.txt | 54 | ||||
-rw-r--r-- | internal/prefer_openssl/cpuinfo.xeon_e312xx.txt | 52 | ||||
-rw-r--r-- | internal/prefer_openssl/prefer.go | 31 | ||||
-rw-r--r-- | internal/prefer_openssl/prefer_go1.5.go | 18 | ||||
-rw-r--r-- | internal/prefer_openssl/prefer_go1.6.go | 29 | ||||
-rw-r--r-- | internal/prefer_openssl/prefer_test.go | 23 | ||||
-rw-r--r-- | internal/speed/speed.go | 5 | ||||
-rw-r--r-- | internal/stupidgcm/prefer.go | 26 |
9 files changed, 29 insertions, 212 deletions
diff --git a/cli_args.go b/cli_args.go index 8d0b7b5..0462fb4 100644 --- a/cli_args.go +++ b/cli_args.go @@ -17,7 +17,6 @@ import ( "github.com/hanwen/go-fuse/fuse" "github.com/rfjakob/gocryptfs/internal/configfile" "github.com/rfjakob/gocryptfs/internal/exitcodes" - "github.com/rfjakob/gocryptfs/internal/prefer_openssl" "github.com/rfjakob/gocryptfs/internal/stupidgcm" "github.com/rfjakob/gocryptfs/internal/tlog" ) @@ -232,7 +231,7 @@ func parseCliOpts() (args argContainer) { } // "-openssl" needs some post-processing if opensslAuto == "auto" { - args.openssl = prefer_openssl.PreferOpenSSL() + args.openssl = stupidgcm.PreferOpenSSL() } else { args.openssl, err = strconv.ParseBool(opensslAuto) if err != nil { diff --git a/internal/prefer_openssl/cpuinfo.pentium_g630.txt b/internal/prefer_openssl/cpuinfo.pentium_g630.txt deleted file mode 100644 index b6d7811..0000000 --- a/internal/prefer_openssl/cpuinfo.pentium_g630.txt +++ /dev/null @@ -1,54 +0,0 @@ -processor : 0 -vendor_id : GenuineIntel -cpu family : 6 -model : 42 -model name : Intel(R) Pentium(R) CPU G630 @ 2.70GHz -stepping : 7 -microcode : 0x29 -cpu MHz : 2700.000 -cache size : 3072 KB -physical id : 0 -siblings : 2 -core id : 0 -cpu cores : 2 -apicid : 0 -initial apicid : 0 -fpu : yes -fpu_exception : yes -cpuid level : 13 -wp : yes -flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm pcid sse4_1 sse4_2 popcnt tsc_deadline_timer xsave lahf_lm arat epb pln pts dtherm tpr_shadow vnmi flexpriority ept vpid xsaveopt -bugs : -bogomips : 5387.85 -clflush size : 64 -cache_alignment : 64 -address sizes : 36 bits physical, 48 bits virtual -power management: - -processor : 1 -vendor_id : GenuineIntel -cpu family : 6 -model : 42 -model name : Intel(R) Pentium(R) CPU G630 @ 2.70GHz -stepping : 7 -microcode : 0x29 -cpu MHz : 2700.000 -cache size : 3072 KB -physical id : 0 -siblings : 2 -core id : 1 -cpu cores : 2 -apicid : 2 -initial apicid : 2 -fpu : yes -fpu_exception : yes -cpuid level : 13 -wp : yes -flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm pcid sse4_1 sse4_2 popcnt tsc_deadline_timer xsave lahf_lm arat epb pln pts dtherm tpr_shadow vnmi flexpriority ept vpid xsaveopt -bugs : -bogomips : 5387.85 -clflush size : 64 -cache_alignment : 64 -address sizes : 36 bits physical, 48 bits virtual -power management: - diff --git a/internal/prefer_openssl/cpuinfo.xeon_e312xx.txt b/internal/prefer_openssl/cpuinfo.xeon_e312xx.txt deleted file mode 100644 index efad8c3..0000000 --- a/internal/prefer_openssl/cpuinfo.xeon_e312xx.txt +++ /dev/null @@ -1,52 +0,0 @@ -processor : 0 -vendor_id : GenuineIntel -cpu family : 6 -model : 42 -model name : Intel Xeon E312xx (Sandy Bridge) -stepping : 1 -microcode : 0x1 -cpu MHz : 3300.022 -cache size : 4096 KB -physical id : 0 -siblings : 1 -core id : 0 -cpu cores : 1 -apicid : 0 -initial apicid : 0 -fpu : yes -fpu_exception : yes -cpuid level : 13 -wp : yes -flags : fpu de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx rdtscp lm constant_tsc rep_good nopl eagerfpu pni pclmulqdq ssse3 cx16 sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx hypervisor lahf_lm xsaveopt -bogomips : 6600.04 -clflush size : 64 -cache_alignment : 64 -address sizes : 40 bits physical, 48 bits virtual -power management: - -processor : 1 -vendor_id : GenuineIntel -cpu family : 6 -model : 42 -model name : Intel Xeon E312xx (Sandy Bridge) -stepping : 1 -microcode : 0x1 -cpu MHz : 3300.022 -cache size : 4096 KB -physical id : 1 -siblings : 1 -core id : 0 -cpu cores : 1 -apicid : 1 -initial apicid : 1 -fpu : yes -fpu_exception : yes -cpuid level : 13 -wp : yes -flags : fpu de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx rdtscp lm constant_tsc rep_good nopl eagerfpu pni pclmulqdq ssse3 cx16 sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx hypervisor lahf_lm xsaveopt -bogomips : 6600.04 -clflush size : 64 -cache_alignment : 64 -address sizes : 40 bits physical, 48 bits virtual -power management: - diff --git a/internal/prefer_openssl/prefer.go b/internal/prefer_openssl/prefer.go deleted file mode 100644 index 74c26b7..0000000 --- a/internal/prefer_openssl/prefer.go +++ /dev/null @@ -1,31 +0,0 @@ -// Package prefer_openssl tries to determine if we should prefer openssl -// on the platform we are running on. -package prefer_openssl - -import ( - "io/ioutil" - "regexp" - - "github.com/rfjakob/gocryptfs/internal/tlog" -) - -// filePreferOpenSSL tells us if OpenSSL is faster than Go GCM on this machine. -// Go GCM is faster when the CPU has AES instructions and Go is v1.6 or higher. -// -// See https://github.com/rfjakob/gocryptfs/issues/23#issuecomment-218286502 -// for benchmarks. -// -// filePreferOpenSSL takes an explicit filename so it can be tested with saved -// cpuinfo files instead of /proc/cpuinfo. -func filePreferOpenSSL(file string) bool { - ci, err := ioutil.ReadFile(file) - if err != nil { - return true - } - haveAes, err := regexp.Match(`(?m)^flags.*\baes\b`, ci) - if err != nil { - tlog.Warn.Println(err) - return true - } - return !haveAes -} diff --git a/internal/prefer_openssl/prefer_go1.5.go b/internal/prefer_openssl/prefer_go1.5.go deleted file mode 100644 index b89e495..0000000 --- a/internal/prefer_openssl/prefer_go1.5.go +++ /dev/null @@ -1,18 +0,0 @@ -// +build !go1.6 !amd64 -// not go1.6+ OR not amd64 - -package prefer_openssl - -import ( - "github.com/rfjakob/gocryptfs/internal/stupidgcm" -) - -// PreferOpenSSL returns true if OpenSSL should be used. -func PreferOpenSSL() bool { - if stupidgcm.BuiltWithoutOpenssl { - return false - } - // OpenSSL is always faster than Go GCM on old Go versions or on anything - // other than amd64 - return true -} diff --git a/internal/prefer_openssl/prefer_go1.6.go b/internal/prefer_openssl/prefer_go1.6.go deleted file mode 100644 index e69da39..0000000 --- a/internal/prefer_openssl/prefer_go1.6.go +++ /dev/null @@ -1,29 +0,0 @@ -// +build go1.6,amd64 -// go1.6+ AND amd64 - -package prefer_openssl - -import ( - "runtime" - - "github.com/rfjakob/gocryptfs/internal/stupidgcm" -) - -// PreferOpenSSL tells us if OpenSSL is faster than Go GCM on this machine. -// Go GCM is faster when the CPU has AES instructions and Go is v1.6 or higher -// on amd64. -// -// See https://github.com/rfjakob/gocryptfs/issues/23#issuecomment-218286502 -// for benchmarks. -func PreferOpenSSL() bool { - if stupidgcm.BuiltWithoutOpenssl { - return false - } - if runtime.GOOS == "darwin" { - // OSX does not have /proc/cpuinfo, let's just assume the CPU has AES - // acceleration. Virtually all Macs that are running today have it I - // guess? - return false - } - return filePreferOpenSSL("/proc/cpuinfo") -} diff --git a/internal/prefer_openssl/prefer_test.go b/internal/prefer_openssl/prefer_test.go deleted file mode 100644 index 289a0a9..0000000 --- a/internal/prefer_openssl/prefer_test.go +++ /dev/null @@ -1,23 +0,0 @@ -package prefer_openssl - -import ( - "testing" -) - -func TestCurrentCPU(t *testing.T) { - t.Logf("PreferOpenSSL=%v", PreferOpenSSL()) -} - -// Has AES instructions -func TestXeonE312xx(t *testing.T) { - if filePreferOpenSSL("cpuinfo.xeon_e312xx.txt") { - t.Fail() - } -} - -// Pentium G do not have AES instructions -func TestPentiumG630(t *testing.T) { - if !filePreferOpenSSL("cpuinfo.pentium_g630.txt") { - t.Fail() - } -} diff --git a/internal/speed/speed.go b/internal/speed/speed.go index f020fca..43fea5d 100644 --- a/internal/speed/speed.go +++ b/internal/speed/speed.go @@ -12,7 +12,6 @@ import ( "log" "testing" - "github.com/rfjakob/gocryptfs/internal/prefer_openssl" "github.com/rfjakob/gocryptfs/internal/siv_aead" "github.com/rfjakob/gocryptfs/internal/stupidgcm" ) @@ -24,8 +23,8 @@ func Run() { f func(*testing.B) preferred bool }{ - {name: "AES-GCM-256-OpenSSL", f: bStupidGCM, preferred: prefer_openssl.PreferOpenSSL()}, - {name: "AES-GCM-256-Go", f: bGoGCM, preferred: !prefer_openssl.PreferOpenSSL()}, + {name: "AES-GCM-256-OpenSSL", f: bStupidGCM, preferred: stupidgcm.PreferOpenSSL()}, + {name: "AES-GCM-256-Go", f: bGoGCM, preferred: !stupidgcm.PreferOpenSSL()}, {name: "AES-SIV-512-Go", f: bAESSIV, preferred: false}, } for _, b := range bTable { diff --git a/internal/stupidgcm/prefer.go b/internal/stupidgcm/prefer.go new file mode 100644 index 0000000..a08d154 --- /dev/null +++ b/internal/stupidgcm/prefer.go @@ -0,0 +1,26 @@ +package stupidgcm + +import ( + "golang.org/x/sys/cpu" +) + +// PreferOpenSSL tells us if OpenSSL is faster than Go GCM on this machine. +// +// Go GCM is only faster if the CPU: +// +// 1) Is X86 +// 2) Has AES instructions +// 3) Go is v1.6 or higher +// +// 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. + if cpu.X86.HasAES { + return false + } + return true +} |