-
Notifications
You must be signed in to change notification settings - Fork 258
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Go GCM is faster than OpenSSL if the CPU has AES instructions and you are running Go 1.6+. See #23 for details.
- Loading branch information
Showing
5 changed files
with
70 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// +build !go1.6 | ||
// = go 1.5 or lower | ||
|
||
package stupidgcm | ||
|
||
func PreferOpenSSL() bool { | ||
// OpenSSL is always faster than Go GCM on old Go versions. | ||
return true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// +build go1.6 | ||
// = go 1.6 or higher | ||
|
||
package stupidgcm | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"regexp" | ||
"runtime" | ||
) | ||
|
||
// PreferOpenSSL tells us if OpenSSL is faster than Go GCM on this machine. | ||
// Go GCM is fastern 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. | ||
func PreferOpenSSL() bool { | ||
runtime.G | ||
ci, err := ioutil.ReadFile("/proc/cpuinfo") | ||
if err != nil { | ||
fmt.Println(err) | ||
return true | ||
} | ||
match, err := regexp.Match("(?m)^flags.*\baes\b", ci) | ||
if err != nil { | ||
fmt.Println(err) | ||
return true | ||
} | ||
return match | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters