@@ -23,7 +23,7 @@ import (
23
23
const adLen = 24
24
24
25
25
// gocryptfs uses fixed-size 4 kiB blocks
26
- const blockSize = 4096
26
+ const gocryptfsBlockSize = 4096
27
27
28
28
// Run - run the speed the test and print the results.
29
29
func Run () {
@@ -83,6 +83,11 @@ func randBytes(n int) []byte {
83
83
84
84
// bEncrypt benchmarks the encryption speed of cipher "c"
85
85
func bEncrypt (b * testing.B , c cipher.AEAD ) {
86
+ bEncryptBlockSize (b , c , gocryptfsBlockSize )
87
+ }
88
+
89
+ // bEncryptBlockSize benchmarks the encryption speed of cipher "c" at block size "blockSize"
90
+ func bEncryptBlockSize (b * testing.B , c cipher.AEAD , blockSize int ) {
86
91
authData := randBytes (adLen )
87
92
iv := randBytes (c .NonceSize ())
88
93
in := make ([]byte , blockSize )
@@ -97,13 +102,12 @@ func bEncrypt(b *testing.B, c cipher.AEAD) {
97
102
// Encrypt and append to nonce
98
103
c .Seal (dst , iv , in , authData )
99
104
}
100
-
101
105
}
102
106
103
107
func bDecrypt (b * testing.B , c cipher.AEAD ) {
104
108
authData := randBytes (adLen )
105
109
iv := randBytes (c .NonceSize ())
106
- plain := randBytes (blockSize )
110
+ plain := randBytes (gocryptfsBlockSize )
107
111
ciphertext := c .Seal (iv , iv , plain , authData )
108
112
109
113
b .SetBytes (int64 (len (plain )))
@@ -129,6 +133,10 @@ func bStupidGCM(b *testing.B) {
129
133
130
134
// bGoGCM benchmarks Go stdlib GCM
131
135
func bGoGCM (b * testing.B ) {
136
+ bGoGCMBlockSize (b , gocryptfsBlockSize )
137
+ }
138
+
139
+ func bGoGCMBlockSize (b * testing.B , blockSize int ) {
132
140
gAES , err := aes .NewCipher (randBytes (32 ))
133
141
if err != nil {
134
142
b .Fatal (err )
@@ -137,7 +145,7 @@ func bGoGCM(b *testing.B) {
137
145
if err != nil {
138
146
b .Fatal (err )
139
147
}
140
- bEncrypt (b , gGCM )
148
+ bEncryptBlockSize (b , gGCM , blockSize )
141
149
}
142
150
143
151
// bAESSIV benchmarks AES-SIV from github.com/aperturerobotics/jacobsa-crypto/siv
0 commit comments