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