-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathudpheader_test.go
76 lines (59 loc) · 1.25 KB
/
udpheader_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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package udpheader
import (
"crypto/aes"
"crypto/cipher"
"crypto/rand"
"crypto/sha1"
"io"
"testing"
"golang.org/x/crypto/hkdf"
"lukechampine.com/blake3"
)
var (
key = make([]byte, 32)
plaintext = make([]byte, aes.BlockSize)
c cipher.Block
)
func init() {
rand.Read(key)
rand.Read(plaintext)
var err error
c, err = aes.NewCipher(key)
if err != nil {
panic(err)
}
}
func BenchmarkGenSaltHkdfSha1(b *testing.B) {
salt := make([]byte, 32)
subkey := make([]byte, 32)
for b.Loop() {
rand.Read(salt)
r := hkdf.New(sha1.New, key, salt, []byte("ss-subkey"))
if _, err := io.ReadFull(r, subkey); err != nil {
b.Fatal(err)
}
}
}
func BenchmarkGenSaltBlake3(b *testing.B) {
keyMaterial := make([]byte, 64)
copy(keyMaterial, key)
subkey := make([]byte, 32)
for b.Loop() {
rand.Read(keyMaterial[32:])
blake3.DeriveKey(subkey, "shadowsocks 2022 session subkey", keyMaterial)
}
}
func BenchmarkAesEcbHeaderEncryption(b *testing.B) {
ciphertext := make([]byte, 16)
for b.Loop() {
c.Encrypt(ciphertext, plaintext)
}
}
func BenchmarkAesEcbHeaderDecryption(b *testing.B) {
ciphertext := make([]byte, 16)
c.Encrypt(ciphertext, plaintext)
decrypted := make([]byte, 16)
for b.Loop() {
c.Decrypt(decrypted, ciphertext)
}
}