diff options
-rw-r--r-- | internal/speed/speed.go | 16 | ||||
-rw-r--r-- | internal/speed/speed_test.go | 8 |
2 files changed, 20 insertions, 4 deletions
diff --git a/internal/speed/speed.go b/internal/speed/speed.go index 950bbda..47fe8c9 100644 --- a/internal/speed/speed.go +++ b/internal/speed/speed.go @@ -23,7 +23,7 @@ import ( const adLen = 24 // gocryptfs uses fixed-size 4 kiB blocks -const blockSize = 4096 +const gocryptfsBlockSize = 4096 // Run - run the speed the test and print the results. func Run() { @@ -83,6 +83,11 @@ func randBytes(n int) []byte { // bEncrypt benchmarks the encryption speed of cipher "c" func bEncrypt(b *testing.B, c cipher.AEAD) { + bEncryptBlockSize(b, c, gocryptfsBlockSize) +} + +// bEncryptBlockSize benchmarks the encryption speed of cipher "c" at block size "blockSize" +func bEncryptBlockSize(b *testing.B, c cipher.AEAD, blockSize int) { authData := randBytes(adLen) iv := randBytes(c.NonceSize()) in := make([]byte, blockSize) @@ -97,13 +102,12 @@ func bEncrypt(b *testing.B, c cipher.AEAD) { // Encrypt and append to nonce c.Seal(dst, iv, in, authData) } - } func bDecrypt(b *testing.B, c cipher.AEAD) { authData := randBytes(adLen) iv := randBytes(c.NonceSize()) - plain := randBytes(blockSize) + plain := randBytes(gocryptfsBlockSize) ciphertext := c.Seal(iv, iv, plain, authData) b.SetBytes(int64(len(plain))) @@ -129,6 +133,10 @@ func bStupidGCM(b *testing.B) { // bGoGCM benchmarks Go stdlib GCM func bGoGCM(b *testing.B) { + bGoGCMBlockSize(b, gocryptfsBlockSize) +} + +func bGoGCMBlockSize(b *testing.B, blockSize int) { gAES, err := aes.NewCipher(randBytes(32)) if err != nil { b.Fatal(err) @@ -137,7 +145,7 @@ func bGoGCM(b *testing.B) { if err != nil { b.Fatal(err) } - bEncrypt(b, gGCM) + bEncryptBlockSize(b, gGCM, blockSize) } // bAESSIV benchmarks AES-SIV from github.com/aperturerobotics/jacobsa-crypto/siv diff --git a/internal/speed/speed_test.go b/internal/speed/speed_test.go index 5f3001b..39ef918 100644 --- a/internal/speed/speed_test.go +++ b/internal/speed/speed_test.go @@ -3,6 +3,7 @@ package speed import ( "crypto/aes" "crypto/cipher" + "fmt" "testing" "golang.org/x/crypto/chacha20poly1305" @@ -38,6 +39,13 @@ func BenchmarkGoGCM(b *testing.B) { bGoGCM(b) } +func BenchmarkGoGCMBlockSize(b *testing.B) { + for blockSize := 1024; blockSize <= 1024*1024; blockSize *= 2 { + name := fmt.Sprintf("%d", blockSize) + b.Run(name, func(b *testing.B) { bGoGCMBlockSize(b, blockSize) }) + } +} + func BenchmarkGoGCMDecrypt(b *testing.B) { gAES, err := aes.NewCipher(randBytes(32)) if err != nil { |