Adapt openssl benchmark for 256 bit long keys

This commit is contained in:
Jakob Unterwurzacher 2015-10-07 22:05:32 +02:00
parent 878f64a5d7
commit 2f970e1aa6
1 changed files with 10 additions and 13 deletions

View File

@ -13,25 +13,22 @@ import (
"crypto/cipher" "crypto/cipher"
"github.com/spacemonkeygo/openssl" "github.com/spacemonkeygo/openssl"
"testing" "testing"
"github.com/rfjakob/gocryptfs/cryptfs"
) )
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
fmt.Printf("Benchmarking AES-GCM-128 with 4kB block size\n") fmt.Printf("Benchmarking AES-GCM-%d with 4kB block size\n", cryptfs.KEY_LEN*8)
r := m.Run() r := m.Run()
os.Exit(r) os.Exit(r)
} }
// This gets rid of the "testing: warning: no tests to run" message
func TestDummy(t *testing.T) {
}
func BenchmarkGoEnc4K(b *testing.B) { func BenchmarkGoEnc4K(b *testing.B) {
buf := make([]byte, 1024*4) buf := make([]byte, 1024*4)
b.SetBytes(int64(len(buf))) b.SetBytes(int64(len(buf)))
var key [16]byte var key [cryptfs.KEY_LEN]byte
var nonce [12]byte var nonce [12]byte
aes, _ := aes.NewCipher(key[:]) aes, _ := aes.NewCipher(key[:])
aesgcm, _ := cipher.NewGCM(aes) aesgcm, _ := cipher.NewGCM(aes)
@ -47,7 +44,7 @@ func BenchmarkGoDec4K(b *testing.B) {
buf := make([]byte, 1024*4) buf := make([]byte, 1024*4)
b.SetBytes(int64(len(buf))) b.SetBytes(int64(len(buf)))
var key [16]byte var key [cryptfs.KEY_LEN]byte
var nonce [12]byte var nonce [12]byte
aes, _ := aes.NewCipher(key[:]) aes, _ := aes.NewCipher(key[:])
aesgcm, _ := cipher.NewGCM(aes) aesgcm, _ := cipher.NewGCM(aes)
@ -67,7 +64,7 @@ func BenchmarkOpensslEnc4K(b *testing.B) {
buf := make([]byte, 1024*4) buf := make([]byte, 1024*4)
b.SetBytes(int64(len(buf))) b.SetBytes(int64(len(buf)))
var key [16]byte var key [cryptfs.KEY_LEN]byte
var nonce [12]byte var nonce [12]byte
var ciphertext bytes.Buffer var ciphertext bytes.Buffer
@ -76,7 +73,7 @@ func BenchmarkOpensslEnc4K(b *testing.B) {
b.ResetTimer() b.ResetTimer()
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
ciphertext.Reset() ciphertext.Reset()
ectx, err := openssl.NewGCMEncryptionCipherCtx(128, nil, key[:], nonce[:]) ectx, err := openssl.NewGCMEncryptionCipherCtx(cryptfs.KEY_LEN*8, nil, key[:], nonce[:])
if err != nil { if err != nil {
b.FailNow() b.FailNow()
} }
@ -105,7 +102,7 @@ func BenchmarkOpensslDec4K(b *testing.B) {
tag := buf[4096:] tag := buf[4096:]
buf = buf[0:4096] buf = buf[0:4096]
var key [16]byte var key [cryptfs.KEY_LEN]byte
var nonce [12]byte var nonce [12]byte
var plaintext bytes.Buffer var plaintext bytes.Buffer
@ -114,7 +111,7 @@ func BenchmarkOpensslDec4K(b *testing.B) {
b.ResetTimer() b.ResetTimer()
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
plaintext.Reset() plaintext.Reset()
dctx, err := openssl.NewGCMDecryptionCipherCtx(128, nil, key[:], nonce[:]) dctx, err := openssl.NewGCMDecryptionCipherCtx(cryptfs.KEY_LEN*8, nil, key[:], nonce[:])
if err != nil { if err != nil {
b.FailNow() b.FailNow()
} }
@ -137,12 +134,12 @@ func BenchmarkOpensslDec4K(b *testing.B) {
func makeOpensslCiphertext() []byte { func makeOpensslCiphertext() []byte {
buf := make([]byte, 1024*4) buf := make([]byte, 1024*4)
var key [16]byte var key [cryptfs.KEY_LEN]byte
var nonce [12]byte var nonce [12]byte
var ciphertext bytes.Buffer var ciphertext bytes.Buffer
var part []byte var part []byte
ectx, _ := openssl.NewGCMEncryptionCipherCtx(128, nil, key[:], nonce[:]) ectx, _ := openssl.NewGCMEncryptionCipherCtx(cryptfs.KEY_LEN*8, nil, key[:], nonce[:])
part, _ = ectx.EncryptUpdate(buf) part, _ = ectx.EncryptUpdate(buf)
ciphertext.Write(part) ciphertext.Write(part)
part, _ = ectx.EncryptFinal() part, _ = ectx.EncryptFinal()