github.com/tunabay/go-bitarray@v1.3.1/bitarray_sha256_test.go (about)

     1  // Copyright (c) 2021 Hirotsuna Mizuno. All rights reserved.
     2  // Use of this source code is governed by the MIT license that can be found in
     3  // the LICENSE file.
     4  
     5  package bitarray_test
     6  
     7  import (
     8  	"bytes"
     9  	"testing"
    10  )
    11  
    12  func TestBitArray_SHA256_cavp(t *testing.T) {
    13  	test := func(name string) {
    14  		tcs, err := cavpTestCases(name)
    15  		if err != nil {
    16  			t.Fatalf("failed to load test cases: %s: %s", name, err)
    17  		}
    18  		for i, tc := range tcs {
    19  			got := tc.ba.SHA256()
    20  			if !bytes.Equal(got[:], tc.md) {
    21  				t.Errorf("unexpected hash: %s: #%d", name, i)
    22  				t.Logf("mlen: %d", tc.ba.Len())
    23  				t.Logf(" msg: %#b", tc.ba)
    24  				t.Logf(" got: %X", got)
    25  				t.Logf("want: %X", tc.md)
    26  			}
    27  		}
    28  	}
    29  	test("SHA256ShortMsg")
    30  	test("SHA256LongMsg")
    31  }
    32  
    33  func TestBitArray_SHA224_cavp(t *testing.T) {
    34  	test := func(name string) {
    35  		tcs, err := cavpTestCases(name)
    36  		if err != nil {
    37  			t.Fatalf("failed to load test cases: %s: %s", name, err)
    38  		}
    39  		for i, tc := range tcs {
    40  			got := tc.ba.SHA224()
    41  			if !bytes.Equal(got[:], tc.md) {
    42  				t.Errorf("unexpected hash: %s: #%d", name, i)
    43  				t.Logf("mlen: %d", tc.ba.Len())
    44  				t.Logf(" msg: %#b", tc.ba)
    45  				t.Logf(" got: %X", got)
    46  				t.Logf("want: %X", tc.md)
    47  			}
    48  		}
    49  	}
    50  	test("SHA224ShortMsg")
    51  	test("SHA224LongMsg")
    52  }