]> Cypherpunks.ru repositories - gogost.git/blobdiff - src/cypherpunks.ru/gogost/gost28147/mac_test.go
FailNow() must be used instead of just marking Fail()
[gogost.git] / src / cypherpunks.ru / gogost / gost28147 / mac_test.go
index 0aea54c958642e4180de5f2551597d0882f65a48..9f85665b7e3fd8af776994262e3e988e2ac07695 100644 (file)
@@ -25,24 +25,23 @@ import (
 )
 
 func TestMACVectors(t *testing.T) {
-       var key [KeySize]byte
-       copy(key[:], []byte("This is message\xFF length\x0032 bytes"))
+       key := []byte("This is message\xFF length\x0032 bytes")
        c := NewCipher(key, SboxDefault)
        var iv [8]byte
-       m, err := c.NewMAC(8, iv)
+       m, err := c.NewMAC(8, iv[:])
        if err != nil {
-               t.Fail()
+               t.FailNow()
        }
 
        m.Write([]byte("a"))
        if bytes.Compare(m.Sum(nil), []byte{0xbd, 0x5d, 0x3b, 0x5b, 0x2b, 0x7b, 0x57, 0xaf}) != 0 {
-               t.Fail()
+               t.FailNow()
        }
 
        m.Reset()
        m.Write([]byte("abc"))
        if bytes.Compare(m.Sum(nil), []byte{0x28, 0x66, 0x1e, 0x40, 0x80, 0x5b, 0x1f, 0xf9}) != 0 {
-               t.Fail()
+               t.FailNow()
        }
 
        m.Reset()
@@ -50,7 +49,7 @@ func TestMACVectors(t *testing.T) {
                m.Write([]byte("U"))
        }
        if bytes.Compare(m.Sum(nil), []byte{0x1a, 0x06, 0xd1, 0xba, 0xd7, 0x45, 0x80, 0xef}) != 0 {
-               t.Fail()
+               t.FailNow()
        }
 
        m.Reset()
@@ -58,25 +57,21 @@ func TestMACVectors(t *testing.T) {
                m.Write([]byte("x"))
        }
        if bytes.Compare(m.Sum(nil), []byte{0x91, 0x7e, 0xe1, 0xf1, 0xa6, 0x68, 0xfb, 0xd3}) != 0 {
-               t.Fail()
+               t.FailNow()
        }
 }
 
 func TestMACRandom(t *testing.T) {
        var key [KeySize]byte
        rand.Read(key[:])
-       c := NewCipher(key, SboxDefault)
-       f := func(ivRaw []byte, data []byte) bool {
+       c := NewCipher(key[:], SboxDefault)
+       f := func(iv [BlockSize]byte, data []byte) bool {
                if len(data) == 0 {
                        return true
                }
-               var iv [8]byte
-               if len(ivRaw) >= 8 {
-                       copy(iv[:], ivRaw[:8])
-               }
-               m, err := c.NewMAC(8, iv)
+               m, err := c.NewMAC(8, iv[:])
                if err != nil {
-                       t.Fail()
+                       return false
                }
 
                var tag1 []byte
@@ -99,23 +94,23 @@ func TestMACRandom(t *testing.T) {
 }
 
 func TestMACInterface(t *testing.T) {
-       var key [32]byte
+       var key [KeySize]byte
        var iv [8]byte
-       c := NewCipher(key, SboxDefault)
-       m, _ := c.NewMAC(8, iv)
+       c := NewCipher(key[:], SboxDefault)
+       m, _ := c.NewMAC(8, iv[:])
        var _ hash.Hash = m
 }
 
 func BenchmarkMAC(b *testing.B) {
-       var key [KeySize]byte
-       var iv [BlockSize]byte
-       rand.Read(key[:])
-       rand.Read(iv[:])
+       key := make([]byte, KeySize)
+       iv := make([]byte, BlockSize)
+       rand.Read(key)
+       rand.Read(iv)
        b1 := make([]byte, BlockSize)
        b2 := make([]byte, BlockSize)
        rand.Read(b1)
        rand.Read(b2)
-       c := NewCipher(key, SboxDefault)
+       c := NewCipher(key[:], SboxDefault)
        mac, _ := c.NewMAC(BlockSize, iv)
        b.ResetTimer()
        for i := 0; i < b.N; i++ {