github.com/tunabay/go-bitarray@v1.3.1/bitarray_sha512_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_SHA512_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.SHA512()
    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("SHA512ShortMsg")
    30  	test("SHA512LongMsg")
    31  }
    32  
    33  func TestBitArray_SHA384_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.SHA384()
    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("SHA384ShortMsg")
    51  	test("SHA384LongMsg")
    52  }
    53  
    54  func TestBitArray_SHA512_256_cavp(t *testing.T) {
    55  	test := func(name string) {
    56  		tcs, err := cavpTestCases(name)
    57  		if err != nil {
    58  			t.Fatalf("failed to load test cases: %s: %s", name, err)
    59  		}
    60  		for i, tc := range tcs {
    61  			got := tc.ba.SHA512_256()
    62  			if !bytes.Equal(got[:], tc.md) {
    63  				t.Errorf("unexpected hash: %s: #%d", name, i)
    64  				t.Logf("mlen: %d", tc.ba.Len())
    65  				t.Logf(" msg: %#b", tc.ba)
    66  				t.Logf(" got: %X", got)
    67  				t.Logf("want: %X", tc.md)
    68  			}
    69  		}
    70  	}
    71  	test("SHA512_256ShortMsg")
    72  	test("SHA512_256LongMsg")
    73  }
    74  
    75  func TestBitArray_SHA512_224_cavp(t *testing.T) {
    76  	test := func(name string) {
    77  		tcs, err := cavpTestCases(name)
    78  		if err != nil {
    79  			t.Fatalf("failed to load test cases: %s: %s", name, err)
    80  		}
    81  		for i, tc := range tcs {
    82  			got := tc.ba.SHA512_224()
    83  			if !bytes.Equal(got[:], tc.md) {
    84  				t.Errorf("unexpected hash: %s: #%d", name, i)
    85  				t.Logf("mlen: %d", tc.ba.Len())
    86  				t.Logf(" msg: %#b", tc.ba)
    87  				t.Logf(" got: %X", got)
    88  				t.Logf("want: %X", tc.md)
    89  			}
    90  		}
    91  	}
    92  	test("SHA512_224ShortMsg")
    93  	test("SHA512_224LongMsg")
    94  }