-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsiv_test.go
59 lines (50 loc) · 1.12 KB
/
siv_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
package xchacha20blake2b
import (
"bytes"
"crypto/rand"
"testing"
)
func TestXChaCha20Blake2bSIV(t *testing.T) {
key := make([]byte, KeySize)
rand.Read(key)
cphr, err := New(key)
if err != nil {
t.Error(err)
}
msg := make([]byte, 64)
rand.Read(msg)
aad := make([]byte, 16)
rand.Read(aad)
ct := cphr.Seal(nil, nil, msg, aad)
pt, err := cphr.Open(nil, nil, ct, aad)
if err != nil {
t.Error(err)
}
if !bytes.Equal(msg, pt) {
t.Error("plaintexts do not match")
}
_, err = cphr.Open(nil, nil, ct, nil)
if err == nil {
t.Error("incorrect additional data does not invalidate decryption")
}
ct[0] ^= 1
_, err = cphr.Open(nil, nil, ct, aad)
if err == nil {
t.Error("flipping a bit in the ciphertext does not break decryption")
}
ct[0] ^= 1
ct[len(pt)+1] ^= 1
_, err = cphr.Open(nil, nil, ct, aad)
if err == nil {
t.Error("flipping a bit in the MAC does not break decryption")
}
ct[len(pt)+1] ^= 1
cphr2, err := New(make([]byte, KeySize))
if err != nil {
t.Error(err)
}
_, err = cphr2.Open(nil, nil, ct, aad)
if err == nil {
t.Error("ciphertext can be decrypted with incorrect password")
}
}