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.
This commit is contained in:
Jakob Unterwurzacher 2020-02-15 17:21:30 +01:00
parent 9aeb2a3df6
commit d5ce340c02
9 changed files with 29 additions and 212 deletions

View File

@ -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 {

View File

@ -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:

View File

@ -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:

View File

@ -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
}

View File

@ -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
}

View File

@ -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")
}

View File

@ -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()
}
}

View File

@ -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 {

View File

@ -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
}