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) {
28 key := []byte("This is message\xFF length\x0032 bytes")
29 c := NewCipher(key, SboxDefault)
31 m, err := c.NewMAC(8, iv[:])
37 if bytes.Compare(m.Sum(nil), []byte{0xbd, 0x5d, 0x3b, 0x5b, 0x2b, 0x7b, 0x57, 0xaf}) != 0 {
42 m.Write([]byte("abc"))
43 if bytes.Compare(m.Sum(nil), []byte{0x28, 0x66, 0x1e, 0x40, 0x80, 0x5b, 0x1f, 0xf9}) != 0 {
48 for i := 0; i < 128; i++ {
51 if bytes.Compare(m.Sum(nil), []byte{0x1a, 0x06, 0xd1, 0xba, 0xd7, 0x45, 0x80, 0xef}) != 0 {
56 for i := 0; i < 13; i++ {
59 if bytes.Compare(m.Sum(nil), []byte{0x91, 0x7e, 0xe1, 0xf1, 0xa6, 0x68, 0xfb, 0xd3}) != 0 {
64 func TestMACRandom(t *testing.T) {
67 c := NewCipher(key[:], SboxDefault)
68 f := func(iv [BlockSize]byte, data []byte) bool {
72 m, err := c.NewMAC(8, iv[:])
80 for _, b := range data {
89 return bytes.Compare(tag1, tag2) == 0
91 if err := quick.Check(f, nil); err != nil {
96 func TestMACInterface(t *testing.T) {
99 c := NewCipher(key[:], SboxDefault)
100 m, _ := c.NewMAC(8, iv[:])
104 func BenchmarkMAC(b *testing.B) {
105 key := make([]byte, KeySize)
106 iv := make([]byte, BlockSize)
109 b1 := make([]byte, BlockSize)
110 b2 := make([]byte, BlockSize)
113 c := NewCipher(key[:], SboxDefault)
114 mac, _ := c.NewMAC(BlockSize, iv)
116 for i := 0; i < b.N; i++ {