aboutsummaryrefslogtreecommitdiff
path: root/libgo/go/crypto/cipher/benchmark_test.go
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2019-01-18 19:04:36 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2019-01-18 19:04:36 +0000
commit4f4a855d82a889cebcfca150a7a43909bcb6a346 (patch)
treef12bae0781920fa34669fe30b6f4615a86d9fb80 /libgo/go/crypto/cipher/benchmark_test.go
parent225220d668dafb8262db7012bced688acbe63b33 (diff)
downloadgcc-4f4a855d82a889cebcfca150a7a43909bcb6a346.zip
gcc-4f4a855d82a889cebcfca150a7a43909bcb6a346.tar.gz
gcc-4f4a855d82a889cebcfca150a7a43909bcb6a346.tar.bz2
libgo: update to Go1.12beta2
Reviewed-on: https://go-review.googlesource.com/c/158019 gotools/: * Makefile.am (go_cmd_vet_files): Update for Go1.12beta2 release. (GOTOOLS_TEST_TIMEOUT): Increase to 600. (check-runtime): Export LD_LIBRARY_PATH before computing GOARCH and GOOS. (check-vet): Copy golang.org/x/tools into check-vet-dir. * Makefile.in: Regenerate. gcc/testsuite/: * go.go-torture/execute/names-1.go: Stop using debug/xcoff, which is no longer externally visible. From-SVN: r268084
Diffstat (limited to 'libgo/go/crypto/cipher/benchmark_test.go')
-rw-r--r--libgo/go/crypto/cipher/benchmark_test.go67
1 files changed, 23 insertions, 44 deletions
diff --git a/libgo/go/crypto/cipher/benchmark_test.go b/libgo/go/crypto/cipher/benchmark_test.go
index 1a3f1bd..90d0cd7 100644
--- a/libgo/go/crypto/cipher/benchmark_test.go
+++ b/libgo/go/crypto/cipher/benchmark_test.go
@@ -81,70 +81,49 @@ func BenchmarkAESGCMOpen8K(b *testing.B) {
benchmarkAESGCMOpen(b, make([]byte, 8*1024))
}
-// If we test exactly 1K blocks, we would generate exact multiples of
-// the cipher's block size, and the cipher stream fragments would
-// always be wordsize aligned, whereas non-aligned is a more typical
-// use-case.
-const almost1K = 1024 - 5
-
-func BenchmarkAESCFBEncrypt1K(b *testing.B) {
- buf := make([]byte, almost1K)
+func benchmarkAESStream(b *testing.B, mode func(cipher.Block, []byte) cipher.Stream, buf []byte) {
b.SetBytes(int64(len(buf)))
var key [16]byte
var iv [16]byte
aes, _ := aes.NewCipher(key[:])
- ctr := cipher.NewCFBEncrypter(aes, iv[:])
+ stream := mode(aes, iv[:])
b.ResetTimer()
for i := 0; i < b.N; i++ {
- ctr.XORKeyStream(buf, buf)
+ stream.XORKeyStream(buf, buf)
}
}
-func BenchmarkAESCFBDecrypt1K(b *testing.B) {
- buf := make([]byte, almost1K)
- b.SetBytes(int64(len(buf)))
-
- var key [16]byte
- var iv [16]byte
- aes, _ := aes.NewCipher(key[:])
- ctr := cipher.NewCFBDecrypter(aes, iv[:])
+// If we test exactly 1K blocks, we would generate exact multiples of
+// the cipher's block size, and the cipher stream fragments would
+// always be wordsize aligned, whereas non-aligned is a more typical
+// use-case.
+const almost1K = 1024 - 5
+const almost8K = 8*1024 - 5
- b.ResetTimer()
- for i := 0; i < b.N; i++ {
- ctr.XORKeyStream(buf, buf)
- }
+func BenchmarkAESCFBEncrypt1K(b *testing.B) {
+ benchmarkAESStream(b, cipher.NewCFBEncrypter, make([]byte, almost1K))
}
-func BenchmarkAESOFB1K(b *testing.B) {
- buf := make([]byte, almost1K)
- b.SetBytes(int64(len(buf)))
+func BenchmarkAESCFBDecrypt1K(b *testing.B) {
+ benchmarkAESStream(b, cipher.NewCFBDecrypter, make([]byte, almost1K))
+}
- var key [16]byte
- var iv [16]byte
- aes, _ := aes.NewCipher(key[:])
- ctr := cipher.NewOFB(aes, iv[:])
+func BenchmarkAESCFBDecrypt8K(b *testing.B) {
+ benchmarkAESStream(b, cipher.NewCFBDecrypter, make([]byte, almost8K))
+}
- b.ResetTimer()
- for i := 0; i < b.N; i++ {
- ctr.XORKeyStream(buf, buf)
- }
+func BenchmarkAESOFB1K(b *testing.B) {
+ benchmarkAESStream(b, cipher.NewOFB, make([]byte, almost1K))
}
func BenchmarkAESCTR1K(b *testing.B) {
- buf := make([]byte, almost1K)
- b.SetBytes(int64(len(buf)))
-
- var key [16]byte
- var iv [16]byte
- aes, _ := aes.NewCipher(key[:])
- ctr := cipher.NewCTR(aes, iv[:])
+ benchmarkAESStream(b, cipher.NewCTR, make([]byte, almost1K))
+}
- b.ResetTimer()
- for i := 0; i < b.N; i++ {
- ctr.XORKeyStream(buf, buf)
- }
+func BenchmarkAESCTR8K(b *testing.B) {
+ benchmarkAESStream(b, cipher.NewCTR, make([]byte, almost8K))
}
func BenchmarkAESCBCEncrypt1K(b *testing.B) {