github.com/core-coin/go-core/v2@v2.1.9/crypto/blake2b/blake2b_f_test.go (about) 1 // Copyright 2019 by the Authors 2 // This file is part of the go-core library. 3 // 4 // The go-core library is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Lesser 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. 8 // 9 // The go-core library 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 Lesser General Public License for more details. 13 // 14 // You should have received a copy of the GNU Lesser General Public License 15 // along with the go-core library. If not, see <http://www.gnu.org/licenses/>. 16 17 package blake2b 18 19 import ( 20 "fmt" 21 "reflect" 22 "testing" 23 ) 24 25 func TestF(t *testing.T) { 26 for i, test := range testVectorsF { 27 t.Run(fmt.Sprintf("test vector %v", i), func(t *testing.T) { 28 //toCoreTestCase(test) 29 30 h := test.hIn 31 F(&h, test.m, test.c, test.f, test.rounds) 32 33 if !reflect.DeepEqual(test.hOut, h) { 34 t.Errorf("Unexpected result\nExpected: [%#x]\nActual: [%#x]\n", test.hOut, h) 35 } 36 }) 37 } 38 } 39 40 type testVector struct { 41 hIn [8]uint64 42 m [16]uint64 43 c [2]uint64 44 f bool 45 rounds uint32 46 hOut [8]uint64 47 } 48 49 // https://tools.ietf.org/html/rfc7693#appendix-A 50 var testVectorsF = []testVector{ 51 { 52 hIn: [8]uint64{ 53 0x6a09e667f2bdc948, 0xbb67ae8584caa73b, 54 0x3c6ef372fe94f82b, 0xa54ff53a5f1d36f1, 55 0x510e527fade682d1, 0x9b05688c2b3e6c1f, 56 0x1f83d9abfb41bd6b, 0x5be0cd19137e2179, 57 }, 58 m: [16]uint64{ 59 0x0000000000636261, 0x0000000000000000, 0x0000000000000000, 60 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 61 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 62 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 63 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 64 0x0000000000000000, 65 }, 66 c: [2]uint64{3, 0}, 67 f: true, 68 rounds: 12, 69 hOut: [8]uint64{ 70 0x0D4D1C983FA580BA, 0xE9F6129FB697276A, 0xB7C45A68142F214C, 71 0xD1A2FFDB6FBB124B, 0x2D79AB2A39C5877D, 0x95CC3345DED552C2, 72 0x5A92F1DBA88AD318, 0x239900D4ED8623B9, 73 }, 74 }, 75 }