-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsiv_test.go
63 lines (50 loc) · 1.44 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
60
61
62
63
package siv
import (
"bytes"
"testing"
"crypto/aes"
)
func Test_AEADAESCMACSIV(t *testing.T) {
v := loadAESSIVExamples("aes_siv.tjson")[0]
nonce := v.ad[0]
n := len(v.key)
macBlock, _ := aes.NewCipher(v.key[:n/2])
ctrBlock, _ := aes.NewCipher(v.key[n/2:])
c, err := NewCMAC(macBlock, ctrBlock, len(nonce))
if err != nil {
t.Fatal(err)
}
ct := c.Seal(nil, nonce, v.plaintext, nil)
if !bytes.Equal(v.ciphertext, ct) {
t.Errorf("Seal: expected: %x\ngot: %x", v.ciphertext, ct)
}
pt, err := c.Open(nil, nonce, ct, nil)
if err != nil {
t.Errorf("Open: %s", err)
}
if !bytes.Equal(v.plaintext, pt) {
t.Errorf("Open: expected: %x\ngot: %x", v.plaintext, pt)
}
}
func TestAEADAESPMACSIV(t *testing.T) {
v := loadAESSIVExamples("aes_pmac_siv.tjson")[0]
nonce := v.ad[0]
n := len(v.key)
macBlock, _ := aes.NewCipher(v.key[:n/2])
ctrBlock, _ := aes.NewCipher(v.key[n/2:])
c, err := NewPMAC(macBlock, ctrBlock, len(nonce))
if err != nil {
t.Fatal(err)
}
ct := c.Seal(nil, nonce, v.plaintext, nil)
if !bytes.Equal(v.ciphertext, ct) {
t.Errorf("Seal: expected: %x\ngot: %x", v.ciphertext, ct)
}
pt, err := c.Open(nil, nonce, ct, nil)
if err != nil {
t.Errorf("Open: %s", err)
}
if !bytes.Equal(v.plaintext, pt) {
t.Errorf("Open: expected: %x\ngot: %x", v.plaintext, pt)
}
}