forked from tunabay/go-bitarray
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bitarray_sha512_test.go
94 lines (88 loc) · 2.26 KB
/
bitarray_sha512_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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// 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_SHA512_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.SHA512()
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("SHA512ShortMsg")
test("SHA512LongMsg")
}
func TestBitArray_SHA384_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.SHA384()
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("SHA384ShortMsg")
test("SHA384LongMsg")
}
func TestBitArray_SHA512_256_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.SHA512_256()
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("SHA512_256ShortMsg")
test("SHA512_256LongMsg")
}
func TestBitArray_SHA512_224_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.SHA512_224()
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("SHA512_224ShortMsg")
test("SHA512_224LongMsg")
}