@@ -4,24 +4,43 @@ package openssl_test
4
4
5
5
import (
6
6
"bytes"
7
- "hash "
7
+ "crypto "
8
8
"testing"
9
9
10
10
"github.com/golang-fips/openssl/v2"
11
11
)
12
12
13
13
type tls1prfTest struct {
14
- hash func () hash .Hash
14
+ hash crypto .Hash
15
15
secret []byte
16
16
label []byte
17
17
seed []byte
18
18
out []byte
19
19
}
20
20
21
21
var tls1prfTests = []tls1prfTest {
22
+ // TLS 1.0/1.1 test generated with OpenSSL and cross-validated
23
+ // with Windows CNG.
24
+ {
25
+ crypto .MD5SHA1 ,
26
+ []byte {
27
+ 0x9b , 0xbe , 0x43 , 0x6b , 0xa9 , 0x40 , 0xf0 , 0x17 ,
28
+ 0xb1 , 0x76 , 0x52 , 0x84 , 0x9a , 0x71 , 0xdb , 0x35 ,
29
+ },
30
+ []byte {
31
+ 0x74 , 0x65 , 0x73 , 0x74 , 0x20 , 0x6c , 0x61 , 0x62 ,
32
+ 0x65 , 0x6c },
33
+ []byte {
34
+ 0xa0 , 0xba , 0x9f , 0x93 , 0x6c , 0xda , 0x31 , 0x18 ,
35
+ 0x27 , 0xa6 , 0xf7 , 0x96 , 0xff , 0xd5 , 0x19 , 0x8c ,
36
+ },
37
+ []byte {
38
+ 0x66 , 0x17 , 0x40 , 0xe6 , 0xf9 , 0x8b , 0xc9 , 0x01 ,
39
+ },
40
+ },
22
41
// Tests from https://mailarchive.ietf.org/arch/msg/tls/fzVCzk-z3FShgGJ6DOXqM1ydxms/
23
42
{
24
- openssl . NewSHA256 ,
43
+ crypto . SHA256 ,
25
44
[]byte {
26
45
0x9b , 0xbe , 0x43 , 0x6b , 0xa9 , 0x40 , 0xf0 , 0x17 ,
27
46
0xb1 , 0x76 , 0x52 , 0x84 , 0x9a , 0x71 , 0xdb , 0x35 ,
@@ -50,7 +69,7 @@ var tls1prfTests = []tls1prfTest{
50
69
},
51
70
},
52
71
{
53
- openssl . NewSHA384 ,
72
+ crypto . SHA384 ,
54
73
[]byte {
55
74
0xb8 , 0x0b , 0x73 , 0x3d , 0x6c , 0xee , 0xfc , 0xdc ,
56
75
0x71 , 0x56 , 0x6e , 0xa4 , 0x8e , 0x55 , 0x67 , 0xdf ,
@@ -85,7 +104,7 @@ var tls1prfTests = []tls1prfTest{
85
104
},
86
105
},
87
106
{
88
- openssl . NewSHA512 ,
107
+ crypto . SHA512 ,
89
108
[]byte {
90
109
0xb0 , 0x32 , 0x35 , 0x23 , 0xc1 , 0x85 , 0x35 , 0x99 ,
91
110
0x58 , 0x4d , 0x88 , 0x56 , 0x8b , 0xbb , 0x05 , 0xeb ,
@@ -132,13 +151,19 @@ func TestTLS1PRF(t *testing.T) {
132
151
if ! openssl .SupportsTLS1PRF () {
133
152
t .Skip ("TLS 1.2 PRF is not supported" )
134
153
}
135
- for i , tt := range tls1prfTests {
136
- out , err := openssl .TLS1PRF (tt .secret , tt .label , tt .seed , len (tt .out ), tt .hash )
137
- if err != nil {
138
- t .Errorf ("test %d: error deriving TLS 1.2 PRF: %v." , i , err )
139
- }
140
- if ! bytes .Equal (out , tt .out ) {
141
- t .Errorf ("test %d: incorrect key output: have %v, need %v." , i , out , tt .out )
142
- }
154
+ for _ , tt := range tls1prfTests {
155
+ tt := tt
156
+ t .Run (tt .hash .String (), func (t * testing.T ) {
157
+ if ! openssl .SupportsHash (tt .hash ) {
158
+ t .Skip ("skipping: hash not supported" )
159
+ }
160
+ out , err := openssl .TLS1PRF (tt .secret , tt .label , tt .seed , len (tt .out ), cryptoToHash (tt .hash ))
161
+ if err != nil {
162
+ t .Fatalf ("error deriving TLS 1.2 PRF: %v." , err )
163
+ }
164
+ if ! bytes .Equal (out , tt .out ) {
165
+ t .Errorf ("incorrect key output: have %v, need %v." , out , tt .out )
166
+ }
167
+ })
143
168
}
144
169
}
0 commit comments