github.com/shrimpyuk/bor@v0.2.15-0.20220224151350-fb4ec6020bae/crypto/blake2b/blake2b_f_test.go (about)

     1  package blake2b
     2  
     3  import (
     4  	"fmt"
     5  	"reflect"
     6  	"testing"
     7  )
     8  
     9  func TestF(t *testing.T) {
    10  	for i, test := range testVectorsF {
    11  		t.Run(fmt.Sprintf("test vector %v", i), func(t *testing.T) {
    12  			//toEthereumTestCase(test)
    13  
    14  			h := test.hIn
    15  			F(&h, test.m, test.c, test.f, test.rounds)
    16  
    17  			if !reflect.DeepEqual(test.hOut, h) {
    18  				t.Errorf("Unexpected result\nExpected: [%#x]\nActual:   [%#x]\n", test.hOut, h)
    19  			}
    20  		})
    21  	}
    22  }
    23  
    24  type testVector struct {
    25  	hIn    [8]uint64
    26  	m      [16]uint64
    27  	c      [2]uint64
    28  	f      bool
    29  	rounds uint32
    30  	hOut   [8]uint64
    31  }
    32  
    33  // https://tools.ietf.org/html/rfc7693#appendix-A
    34  var testVectorsF = []testVector{
    35  	{
    36  		hIn: [8]uint64{
    37  			0x6a09e667f2bdc948, 0xbb67ae8584caa73b,
    38  			0x3c6ef372fe94f82b, 0xa54ff53a5f1d36f1,
    39  			0x510e527fade682d1, 0x9b05688c2b3e6c1f,
    40  			0x1f83d9abfb41bd6b, 0x5be0cd19137e2179,
    41  		},
    42  		m: [16]uint64{
    43  			0x0000000000636261, 0x0000000000000000, 0x0000000000000000,
    44  			0x0000000000000000, 0x0000000000000000, 0x0000000000000000,
    45  			0x0000000000000000, 0x0000000000000000, 0x0000000000000000,
    46  			0x0000000000000000, 0x0000000000000000, 0x0000000000000000,
    47  			0x0000000000000000, 0x0000000000000000, 0x0000000000000000,
    48  			0x0000000000000000,
    49  		},
    50  		c:      [2]uint64{3, 0},
    51  		f:      true,
    52  		rounds: 12,
    53  		hOut: [8]uint64{
    54  			0x0D4D1C983FA580BA, 0xE9F6129FB697276A, 0xB7C45A68142F214C,
    55  			0xD1A2FFDB6FBB124B, 0x2D79AB2A39C5877D, 0x95CC3345DED552C2,
    56  			0x5A92F1DBA88AD318, 0x239900D4ED8623B9,
    57  		},
    58  	},
    59  }