1
2
3
4
5 package fipstest
6
7 import (
8 "bytes"
9 "crypto/internal/fips140/aes"
10 "crypto/internal/fips140/aes/gcm"
11 "testing"
12 )
13
14 func TestCMAC(t *testing.T) {
15
16 key := "2B7E1516 28AED2A6 ABF71588 09CF4F3C"
17 tests := []struct {
18 in, out string
19 }{
20 {
21 "",
22 "BB1D6929 E9593728 7FA37D12 9B756746",
23 },
24 {
25 "6BC1BEE2 2E409F96 E93D7E11 7393172A",
26 "070A16B4 6B4D4144 F79BDD9D D04A287C",
27 },
28 {
29 "6BC1BEE2 2E409F96 E93D7E11 7393172A AE2D8A57",
30 "7D85449E A6EA19C8 23A7BF78 837DFADE",
31 },
32 }
33
34 b, err := aes.New(decodeHex(t, key))
35 if err != nil {
36 t.Fatal(err)
37 }
38 c := gcm.NewCMAC(b)
39 for i, test := range tests {
40 in := decodeHex(t, test.in)
41 out := decodeHex(t, test.out)
42 got := c.MAC(in)
43 if !bytes.Equal(got[:], out) {
44 t.Errorf("test %d: got %x, want %x", i, got, out)
45 }
46 }
47 }
48
View as plain text