@@ -345,7 +345,12 @@ func mustPanic(t *testing.T, msg string, f func()) {
345
345
}
346
346
347
347
func BenchmarkEncrypt (b * testing.B ) {
348
- tt := encryptTests [0 ]
348
+ b .Run ("AES-128" , func (b * testing.B ) { benchmarkEncrypt (b , encryptTests [1 ]) })
349
+ b .Run ("AES-192" , func (b * testing.B ) { benchmarkEncrypt (b , encryptTests [2 ]) })
350
+ b .Run ("AES-256" , func (b * testing.B ) { benchmarkEncrypt (b , encryptTests [3 ]) })
351
+ }
352
+
353
+ func benchmarkEncrypt (b * testing.B , tt CryptTest ) {
349
354
c , err := NewCipher (tt .key )
350
355
if err != nil {
351
356
b .Fatal ("NewCipher:" , err )
@@ -359,7 +364,12 @@ func BenchmarkEncrypt(b *testing.B) {
359
364
}
360
365
361
366
func BenchmarkDecrypt (b * testing.B ) {
362
- tt := encryptTests [0 ]
367
+ b .Run ("AES-128" , func (b * testing.B ) { benchmarkDecrypt (b , encryptTests [1 ]) })
368
+ b .Run ("AES-192" , func (b * testing.B ) { benchmarkDecrypt (b , encryptTests [2 ]) })
369
+ b .Run ("AES-256" , func (b * testing.B ) { benchmarkDecrypt (b , encryptTests [3 ]) })
370
+ }
371
+
372
+ func benchmarkDecrypt (b * testing.B , tt CryptTest ) {
363
373
c , err := NewCipher (tt .key )
364
374
if err != nil {
365
375
b .Fatal ("NewCipher:" , err )
@@ -373,11 +383,30 @@ func BenchmarkDecrypt(b *testing.B) {
373
383
}
374
384
375
385
func BenchmarkExpand (b * testing.B ) {
376
- tt := encryptTests [0 ]
377
- n := len (tt .key ) + 28
378
- c := & aesCipher {make ([]uint32 , n ), make ([]uint32 , n )}
386
+ b .Run ("AES-128" , func (b * testing.B ) { benchmarkExpand (b , encryptTests [1 ]) })
387
+ b .Run ("AES-192" , func (b * testing.B ) { benchmarkExpand (b , encryptTests [2 ]) })
388
+ b .Run ("AES-256" , func (b * testing.B ) { benchmarkExpand (b , encryptTests [3 ]) })
389
+ }
390
+
391
+ func benchmarkExpand (b * testing.B , tt CryptTest ) {
392
+ c := & aesCipher {l : uint8 (len (tt .key ) + 28 )}
379
393
b .ResetTimer ()
380
394
for i := 0 ; i < b .N ; i ++ {
381
- expandKey (tt .key , c .enc , c .dec )
395
+ expandKey (tt .key , c .enc [:c .l ], c .dec [:c .l ])
396
+ }
397
+ }
398
+
399
+ func BenchmarkCreateCipher (b * testing.B ) {
400
+ b .Run ("AES-128" , func (b * testing.B ) { benchmarkCreateCipher (b , encryptTests [1 ]) })
401
+ b .Run ("AES-192" , func (b * testing.B ) { benchmarkCreateCipher (b , encryptTests [2 ]) })
402
+ b .Run ("AES-256" , func (b * testing.B ) { benchmarkCreateCipher (b , encryptTests [3 ]) })
403
+ }
404
+
405
+ func benchmarkCreateCipher (b * testing.B , tt CryptTest ) {
406
+ b .ReportAllocs ()
407
+ for i := 0 ; i < b .N ; i ++ {
408
+ if _ , err := NewCipher (tt .key ); err != nil {
409
+ b .Fatal (err )
410
+ }
382
411
}
383
412
}
0 commit comments