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
|
// Written in 2015 by Dmitry Chestnykh.
package miscreant
import (
"bytes"
"testing"
)
func TestAEADAESCMACSIV(t *testing.T) {
v := loadAESSIVExamples("aes_siv.tjson")[0]
nonce := v.ad[0]
c, err := NewAEAD("AES-SIV", v.key, 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]
c, err := NewAEAD("AES-PMAC-SIV", v.key, 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)
}
}
|