]> Cypherpunks.ru repositories - gogost.git/blobdiff - src/cypherpunks.ru/gogost/internal/gost34112012/hash_test.go
FailNow() must be used instead of just marking Fail()
[gogost.git] / src / cypherpunks.ru / gogost / internal / gost34112012 / hash_test.go
index 1e056c6d1c0828d2c4b627c38fd4fda1903d2ae0..b9422b7105ea96b5e9e804668a17a9530e4c506b 100644 (file)
@@ -1,5 +1,5 @@
 // GoGOST -- Pure Go GOST cryptographic functions library
-// Copyright (C) 2015-2018 Sergey Matveev <stargrave@stargrave.org>
+// Copyright (C) 2015-2019 Sergey Matveev <stargrave@stargrave.org>
 //
 // This program is free software: you can redistribute it and/or modify
 // it under the terms of the GNU General Public License as published by
@@ -55,7 +55,7 @@ func TestVectors(t *testing.T) {
                0xe2, 0xa4, 0x81, 0x33, 0x2b, 0x08, 0xef, 0x7f,
                0x41, 0x79, 0x78, 0x91, 0xc1, 0x64, 0x6f, 0x48,
        }) != 0 {
-               t.Fail()
+               t.FailNow()
        }
        h256.Write(m)
        if bytes.Compare(h256.Sum(nil), []byte{
@@ -64,10 +64,12 @@ func TestVectors(t *testing.T) {
                0x5d, 0xd0, 0x51, 0x02, 0x6b, 0xb1, 0x49, 0xa4,
                0x52, 0xfd, 0x84, 0xe5, 0xe5, 0x7b, 0x55, 0x00,
        }) != 0 {
-               t.Fail()
+               t.FailNow()
        }
 
        // Second vector
+       // It is CP1251-encoded "Се ветри, Стрибожи внуци, веютъ с моря
+       // стрелами на храбрыя плъкы Игоревы" string
        h512.Reset()
        h256.Reset()
        m = []byte{
@@ -92,7 +94,7 @@ func TestVectors(t *testing.T) {
                0x3f, 0x0c, 0xb9, 0xdd, 0xdc, 0x2b, 0x64, 0x60,
                0x14, 0x3b, 0x03, 0xda, 0xba, 0xc9, 0xfb, 0x28,
        }) != 0 {
-               t.Fail()
+               t.FailNow()
        }
        h256.Write(m)
        if bytes.Compare(h256.Sum(nil), []byte{
@@ -101,7 +103,39 @@ func TestVectors(t *testing.T) {
                0xc0, 0xca, 0xc6, 0x28, 0xfc, 0x66, 0x9a, 0x74,
                0x1d, 0x50, 0x06, 0x3c, 0x55, 0x7e, 0x8f, 0x50,
        }) != 0 {
-               t.Fail()
+               t.FailNow()
+       }
+
+       // Test vector from https://habr.com/ru/post/450024/
+       h256.Reset()
+       m = []byte{
+               0xd0, 0xcf, 0x11, 0xe0, 0xa1, 0xb1, 0x1a, 0xe1,
+               0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+               0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+               0x3e, 0x00, 0x03, 0x00, 0xfe, 0xff, 0x09, 0x00,
+               0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+               0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
+               0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+               0x00, 0x10, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00,
+               0x01, 0x00, 0x00, 0x00, 0xfe, 0xff, 0xff, 0xff,
+               0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+               0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+               0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+               0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+               0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+               0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+               0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+               0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+               0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+       }
+       h256.Write(m)
+       if bytes.Compare(h256.Sum(nil), []byte{
+               0xc7, 0x66, 0x08, 0x55, 0x40, 0xca, 0xaa, 0x89,
+               0x53, 0xbf, 0xcf, 0x7a, 0x1b, 0xa2, 0x20, 0x61,
+               0x9c, 0xee, 0x50, 0xd6, 0x5d, 0xc2, 0x42, 0xf8,
+               0x2f, 0x23, 0xba, 0x4b, 0x18, 0x0b, 0x18, 0xe0,
+       }) != 0 {
+               t.FailNow()
        }
 }
 
@@ -122,7 +156,7 @@ func TestBlocksized(t *testing.T) {
                0x6f, 0xa8, 0xa1, 0x55, 0xdc, 0xb3, 0xeb, 0x82,
                0x2d, 0x92, 0x58, 0x08, 0xf7, 0xc7, 0xe3, 0x45,
        }) != 0 {
-               t.Fail()
+               t.FailNow()
        }
 }
 
@@ -131,17 +165,17 @@ func TestBehaviour(t *testing.T) {
        // Sum does not change the state
        hsh1 := h.Sum(nil)
        if bytes.Compare(h.Sum(nil), hsh1) != 0 {
-               t.Fail()
+               t.FailNow()
        }
        // No data equals to no state changing
        h.Write([]byte{})
        if bytes.Compare(h.Sum(nil), hsh1) != 0 {
-               t.Fail()
+               t.FailNow()
        }
        // Just to be sure
        h.Write([]byte{})
        if bytes.Compare(h.Sum(nil), hsh1) != 0 {
-               t.Fail()
+               t.FailNow()
        }
 }