github.com/aigarnetwork/aigar@v0.0.0-20191115204914-d59a6eb70f8e/crypto/blake2b/blake2b_f_test.go (about)

     1  //  Copyright 2018 The go-ethereum Authors
     2  //  Copyright 2019 The go-aigar Authors
     3  //  This file is part of the go-aigar library.
     4  //
     5  //  The go-aigar library is free software: you can redistribute it and/or modify
     6  //  it under the terms of the GNU Lesser General Public License as published by
     7  //  the Free Software Foundation, either version 3 of the License, or
     8  //  (at your option) any later version.
     9  //
    10  //  The go-aigar library is distributed in the hope that it will be useful,
    11  //  but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    13  //  GNU Lesser General Public License for more details.
    14  //
    15  //  You should have received a copy of the GNU Lesser General Public License
    16  //  along with the go-aigar library. If not, see <http://www.gnu.org/licenses/>.
    17  
    18  package blake2b
    19  
    20  import (
    21  	"fmt"
    22  	"reflect"
    23  	"testing"
    24  )
    25  
    26  func TestF(t *testing.T) {
    27  	for i, test := range testVectorsF {
    28  		t.Run(fmt.Sprintf("test vector %v", i), func(t *testing.T) {
    29  			//toEthereumTestCase(test)
    30  
    31  			h := test.hIn
    32  			F(&h, test.m, test.c, test.f, test.rounds)
    33  
    34  			if !reflect.DeepEqual(test.hOut, h) {
    35  				t.Errorf("Unexpected result\nExpected: [%#x]\nActual:   [%#x]\n", test.hOut, h)
    36  			}
    37  		})
    38  	}
    39  }
    40  
    41  type testVector struct {
    42  	hIn    [8]uint64
    43  	m      [16]uint64
    44  	c      [2]uint64
    45  	f      bool
    46  	rounds uint32
    47  	hOut   [8]uint64
    48  }
    49  
    50  // https://tools.ietf.org/html/rfc7693#appendix-A
    51  var testVectorsF = []testVector{
    52  	{
    53  		hIn: [8]uint64{
    54  			0x6a09e667f2bdc948, 0xbb67ae8584caa73b,
    55  			0x3c6ef372fe94f82b, 0xa54ff53a5f1d36f1,
    56  			0x510e527fade682d1, 0x9b05688c2b3e6c1f,
    57  			0x1f83d9abfb41bd6b, 0x5be0cd19137e2179,
    58  		},
    59  		m: [16]uint64{
    60  			0x0000000000636261, 0x0000000000000000, 0x0000000000000000,
    61  			0x0000000000000000, 0x0000000000000000, 0x0000000000000000,
    62  			0x0000000000000000, 0x0000000000000000, 0x0000000000000000,
    63  			0x0000000000000000, 0x0000000000000000, 0x0000000000000000,
    64  			0x0000000000000000, 0x0000000000000000, 0x0000000000000000,
    65  			0x0000000000000000,
    66  		},
    67  		c:      [2]uint64{3, 0},
    68  		f:      true,
    69  		rounds: 12,
    70  		hOut: [8]uint64{
    71  			0x0D4D1C983FA580BA, 0xE9F6129FB697276A, 0xB7C45A68142F214C,
    72  			0xD1A2FFDB6FBB124B, 0x2D79AB2A39C5877D, 0x95CC3345DED552C2,
    73  			0x5A92F1DBA88AD318, 0x239900D4ED8623B9,
    74  		},
    75  	},
    76  }