1 // GoGOST -- Pure Go GOST cryptographic functions library
2 // Copyright (C) 2015-2019 Sergey Matveev <stargrave@stargrave.org>
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
27 func TestMACVectors(t *testing.T) {
29 copy(key[:], []byte("This is message\xFF length\x0032 bytes"))
30 c := NewCipher(key, SboxDefault)
32 m, err := c.NewMAC(8, iv)
38 if bytes.Compare(m.Sum(nil), []byte{0xbd, 0x5d, 0x3b, 0x5b, 0x2b, 0x7b, 0x57, 0xaf}) != 0 {
43 m.Write([]byte("abc"))
44 if bytes.Compare(m.Sum(nil), []byte{0x28, 0x66, 0x1e, 0x40, 0x80, 0x5b, 0x1f, 0xf9}) != 0 {
49 for i := 0; i < 128; i++ {
52 if bytes.Compare(m.Sum(nil), []byte{0x1a, 0x06, 0xd1, 0xba, 0xd7, 0x45, 0x80, 0xef}) != 0 {
57 for i := 0; i < 13; i++ {
60 if bytes.Compare(m.Sum(nil), []byte{0x91, 0x7e, 0xe1, 0xf1, 0xa6, 0x68, 0xfb, 0xd3}) != 0 {
65 func TestMACRandom(t *testing.T) {
68 c := NewCipher(key, SboxDefault)
69 f := func(ivRaw []byte, data []byte) bool {
75 copy(iv[:], ivRaw[:8])
77 m, err := c.NewMAC(8, iv)
85 for _, b := range data {
94 return bytes.Compare(tag1, tag2) == 0
96 if err := quick.Check(f, nil); err != nil {
101 func TestMACInterface(t *testing.T) {
104 c := NewCipher(key, SboxDefault)
105 m, _ := c.NewMAC(8, iv)
109 func BenchmarkMAC(b *testing.B) {
110 var key [KeySize]byte
111 var iv [BlockSize]byte
114 b1 := make([]byte, BlockSize)
115 b2 := make([]byte, BlockSize)
118 c := NewCipher(key, SboxDefault)
119 mac, _ := c.NewMAC(BlockSize, iv)
121 for i := 0; i < b.N; i++ {