aboutsummaryrefslogtreecommitdiff
path: root/openssl_benchmark/openssl_test.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2016-05-04 19:09:14 +0200
committerJakob Unterwurzacher2016-05-04 19:56:07 +0200
commit39f3a24484ffc343d2d5225d5c419082aabb9baa (patch)
tree04b9d7aa98ef3e18f05b00efe39e5288baeed5c4 /openssl_benchmark/openssl_test.go
parentc92190bf07d27a4c7fbecba5778d11c77c52574e (diff)
stupidgcm: completely replace spacemonkeygo/openssl
Diffstat (limited to 'openssl_benchmark/openssl_test.go')
-rw-r--r--openssl_benchmark/openssl_test.go163
1 files changed, 0 insertions, 163 deletions
diff --git a/openssl_benchmark/openssl_test.go b/openssl_benchmark/openssl_test.go
deleted file mode 100644
index 1530f9b..0000000
--- a/openssl_benchmark/openssl_test.go
+++ /dev/null
@@ -1,163 +0,0 @@
-package benchmark
-
-// Benchmark go built-int GCM against spacemonkey openssl bindings
-//
-// Note: This is deprecated in favor of the benchmarks integrated in cryptfs.
-//
-// Run benchmark:
-// go test -bench=.
-
-import (
- "bytes"
- "crypto/aes"
- "crypto/cipher"
- "fmt"
- "os"
- "testing"
-
- "github.com/spacemonkeygo/openssl"
-
- "github.com/rfjakob/gocryptfs/internal/cryptocore"
-)
-
-func TestMain(m *testing.M) {
-
- fmt.Printf("Benchmarking AES-GCM-%d with 4kB block size\n", cryptocore.KeyLen*8)
-
- r := m.Run()
- os.Exit(r)
-}
-
-func BenchmarkGoEnc4K(b *testing.B) {
- buf := make([]byte, 1024*4)
- b.SetBytes(int64(len(buf)))
-
- var key [cryptocore.KeyLen]byte
- var nonce [12]byte
- aes, _ := aes.NewCipher(key[:])
- aesgcm, _ := cipher.NewGCM(aes)
- var out []byte
- // This would be fileID + blockNo
- aData := make([]byte, 24)
- b.ResetTimer()
- for i := 0; i < b.N; i++ {
- out = aesgcm.Seal(out[:0], nonce[:], buf, aData)
- }
-}
-
-func BenchmarkGoDec4K(b *testing.B) {
- buf := make([]byte, 1024*4)
- b.SetBytes(int64(len(buf)))
-
- var key [cryptocore.KeyLen]byte
- var nonce [12]byte
- aes, _ := aes.NewCipher(key[:])
- aesgcm, _ := cipher.NewGCM(aes)
- var out []byte
- out = aesgcm.Seal(out[:0], nonce[:], buf, nil)
-
- b.ResetTimer()
- for i := 0; i < b.N; i++ {
- _, err := aesgcm.Open(buf[:0], nonce[:], out, nil)
- if err != nil {
- b.Errorf("Open: %v", err)
- }
- }
-}
-
-func BenchmarkOpensslEnc4K(b *testing.B) {
- buf := make([]byte, 1024*4)
- b.SetBytes(int64(len(buf)))
-
- var key [cryptocore.KeyLen]byte
- var nonce [12]byte
-
- // This would be fileID + blockNo
- aData := make([]byte, 24)
-
- var ciphertext bytes.Buffer
- var part []byte
-
- b.ResetTimer()
- for i := 0; i < b.N; i++ {
- ciphertext.Reset()
- ectx, err := openssl.NewGCMEncryptionCipherCtx(cryptocore.KeyLen*8, nil, key[:], nonce[:])
- if err != nil {
- b.FailNow()
- }
- err = ectx.ExtraData(aData)
- if err != nil {
- b.FailNow()
- }
- part, err = ectx.EncryptUpdate(buf)
- if err != nil {
- b.FailNow()
- }
- ciphertext.Write(part)
- part, err = ectx.EncryptFinal()
- if err != nil {
- b.FailNow()
- }
- ciphertext.Write(part)
- part, err = ectx.GetTag()
- if err != nil {
- b.FailNow()
- }
- ciphertext.Write(part)
- }
-}
-
-func BenchmarkOpensslDec4K(b *testing.B) {
- buf := makeOpensslCiphertext()
- b.SetBytes(int64(1024 * 4))
-
- tag := buf[4096:]
- buf = buf[0:4096]
-
- var key [cryptocore.KeyLen]byte
- var nonce [12]byte
-
- var plaintext bytes.Buffer
- var part []byte
-
- b.ResetTimer()
- for i := 0; i < b.N; i++ {
- plaintext.Reset()
- dctx, err := openssl.NewGCMDecryptionCipherCtx(cryptocore.KeyLen*8, nil, key[:], nonce[:])
- if err != nil {
- b.FailNow()
- }
- part, err = dctx.DecryptUpdate(buf)
- if err != nil {
- b.FailNow()
- }
- plaintext.Write(part)
- err = dctx.SetTag(tag)
- if err != nil {
- b.FailNow()
- }
- part, err = dctx.DecryptFinal()
- if err != nil {
- b.FailNow()
- }
- plaintext.Write(part)
- }
-}
-
-func makeOpensslCiphertext() []byte {
- buf := make([]byte, 1024*4)
- var key [cryptocore.KeyLen]byte
- var nonce [12]byte
- var ciphertext bytes.Buffer
- var part []byte
-
- ectx, _ := openssl.NewGCMEncryptionCipherCtx(cryptocore.KeyLen*8, nil, key[:], nonce[:])
- part, _ = ectx.EncryptUpdate(buf)
- ciphertext.Write(part)
- part, _ = ectx.EncryptFinal()
- ciphertext.Write(part)
- part, _ = ectx.GetTag()
- ciphertext.Write(part)
-
- return ciphertext.Bytes()
-}