1 // GoGOST -- Pure Go GOST cryptographic functions library
2 // Copyright (C) 2015-2021 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, version 3 of the License.
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with this program. If not, see <http://www.gnu.org/licenses/>.
26 func TestMACVectors(t *testing.T) {
27 key := []byte("This is message\xFF length\x0032 bytes")
28 c := NewCipher(key, SboxDefault)
30 m, err := c.NewMAC(8, iv[:])
35 t.Run("a", func(t *testing.T) {
37 if bytes.Compare(m.Sum(nil), []byte{0xbd, 0x5d, 0x3b, 0x5b, 0x2b, 0x7b, 0x57, 0xaf}) != 0 {
42 t.Run("abc", func(t *testing.T) {
44 m.Write([]byte("abc"))
45 if bytes.Compare(m.Sum(nil), []byte{0x28, 0x66, 0x1e, 0x40, 0x80, 0x5b, 0x1f, 0xf9}) != 0 {
50 t.Run("128U", func(t *testing.T) {
52 for i := 0; i < 128; i++ {
55 if bytes.Compare(m.Sum(nil), []byte{0x1a, 0x06, 0xd1, 0xba, 0xd7, 0x45, 0x80, 0xef}) != 0 {
60 t.Run("xxxxxxxxxxxxx", func(t *testing.T) {
62 for i := 0; i < 13; i++ {
65 if bytes.Compare(m.Sum(nil), []byte{0x91, 0x7e, 0xe1, 0xf1, 0xa6, 0x68, 0xfb, 0xd3}) != 0 {
71 func TestMACRandom(t *testing.T) {
74 c := NewCipher(key[:], SboxDefault)
75 f := func(iv [BlockSize]byte, data []byte) bool {
79 m, err := c.NewMAC(8, iv[:])
87 for _, b := range data {
96 return bytes.Compare(tag1, tag2) == 0
98 if err := quick.Check(f, nil); err != nil {
103 func TestMACInterface(t *testing.T) {
104 var key [KeySize]byte
106 c := NewCipher(key[:], SboxDefault)
107 m, _ := c.NewMAC(8, iv[:])
111 func BenchmarkMAC(b *testing.B) {
112 key := make([]byte, KeySize)
113 iv := make([]byte, BlockSize)
116 b1 := make([]byte, BlockSize)
117 b2 := make([]byte, BlockSize)
120 c := NewCipher(key[:], SboxDefault)
121 mac, _ := c.NewMAC(BlockSize, iv)
123 for i := 0; i < b.N; i++ {