-
Notifications
You must be signed in to change notification settings - Fork 4
/
sio_test.go
113 lines (107 loc) · 2.79 KB
/
sio_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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// Copyright (c) 2019 Andreas Auernhammer. All rights reserved.
// Use of this source code is governed by a license that can be
// found in the LICENSE file.
package sio
import (
mrand "math/rand"
)
type TestVector struct {
Algorithm Algorithm
BufSize int
Key []byte
Nonce []byte
AssociatedData []byte
Plaintext []byte
Ciphertext []byte
}
var TestVectors []TestVector = loadTestVectors("./test_vectors.json")
type SimpleTest struct {
Algorithm Algorithm
BufSize int
Key []byte
Nonce []byte
AssociatedData []byte
Plaintext []byte
}
var SimpleTests = []SimpleTest{
SimpleTest{ // 0
Algorithm: AES_128_GCM,
BufSize: BufSize,
Key: make([]byte, 128/8),
Nonce: make([]byte, 64/8),
AssociatedData: nil,
Plaintext: randomN(1 << 20),
},
SimpleTest{ // 1
Algorithm: AES_128_GCM,
BufSize: 1 + mrand.Intn(2*BufSize), // add 1 to ensure BufSize is not 0.
Key: random(128 / 8),
Nonce: random(64 / 8),
AssociatedData: randomN(256),
Plaintext: randomN(1 << 20),
},
SimpleTest{ // 2
Algorithm: AES_128_GCM,
BufSize: BufSize,
Key: random(128 / 8),
Nonce: random(64 / 8),
AssociatedData: randomN(256),
Plaintext: nil,
},
SimpleTest{ // 3
Algorithm: AES_128_GCM,
BufSize: BufSize,
Key: random(128 / 8),
Nonce: random(64 / 8),
AssociatedData: randomN(256),
Plaintext: random(1),
},
SimpleTest{ // 4
Algorithm: AES_128_GCM,
BufSize: BufSize,
Key: random(128 / 8),
Nonce: random(64 / 8),
AssociatedData: randomN(256),
Plaintext: random(BufSize - 1),
},
SimpleTest{ // 5
Algorithm: AES_128_GCM,
BufSize: BufSize,
Key: random(128 / 8),
Nonce: random(64 / 8),
AssociatedData: randomN(256),
Plaintext: random(BufSize),
},
SimpleTest{ // 6
Algorithm: AES_128_GCM,
BufSize: BufSize,
Key: random(128 / 8),
Nonce: random(64 / 8),
AssociatedData: randomN(256),
Plaintext: random(BufSize + 1),
},
SimpleTest{ // 7
Algorithm: AES_128_GCM,
BufSize: 1,
Key: random(128 / 8),
Nonce: random(64 / 8),
AssociatedData: randomN(256),
Plaintext: []byte{},
},
SimpleTest{ // 8
Algorithm: AES_128_GCM,
BufSize: 1,
Key: random(128 / 8),
Nonce: random(64 / 8),
AssociatedData: randomN(256),
Plaintext: randomN(1 << 20),
},
SimpleTest{ // 9
Algorithm: AES_128_GCM,
BufSize: 2*BufSize + 1,
Key: random(128 / 8),
Nonce: random(64 / 8),
AssociatedData: randomN(1 << 20),
Plaintext: randomN(1 << 20),
},
}