File: aead_test.go

package info (click to toggle)
golang-github-miscreant-miscreant.go 0.0~git20200214.26d3763-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, bullseye-backports, forky, sid, trixie
  • size: 216 kB
  • sloc: makefile: 3
file content (48 lines) | stat: -rw-r--r-- 1,141 bytes parent folder | download
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)
	}
}