forked from codahale/chacha20
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shootout_test.go
44 lines (35 loc) · 840 Bytes
/
shootout_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package chacha20_test
import (
"crypto/aes"
"crypto/cipher"
"crypto/rc4"
"testing"
"github.com/codahale/chacha20"
)
const benchSize = 1024 * 1024
func benchmarkStream(b *testing.B, c cipher.Stream) {
b.SetBytes(benchSize)
input := make([]byte, benchSize)
output := make([]byte, benchSize)
for i := 0; i < b.N; i++ {
c.XORKeyStream(output, input)
}
}
func BenchmarkChaCha20(b *testing.B) {
key := make([]byte, chacha20.KeySize)
nonce := make([]byte, chacha20.NonceSize)
c, _ := chacha20.New(key, nonce)
benchmarkStream(b, c)
}
func BenchmarkAESCTR(b *testing.B) {
key := make([]byte, 32)
a, _ := aes.NewCipher(key)
iv := make([]byte, aes.BlockSize)
c := cipher.NewCTR(a, iv)
benchmarkStream(b, c)
}
func BenchmarkRC4(b *testing.B) {
key := make([]byte, 32)
c, _ := rc4.NewCipher(key)
benchmarkStream(b, c)
}