@@ -20,24 +20,33 @@ type acvpHeader struct {
20
20
IsSample bool `json:"isSample"`
21
21
}
22
22
23
- type acvpKeygenVector struct {
23
+ type acvpKeyGenPrompt struct {
24
24
acvpHeader
25
25
TestGroups []struct {
26
26
TgID int `json:"tgId"`
27
27
TestType string `json:"testType"`
28
28
ParameterSet string `json:"parameterSet"`
29
- Tests []keygenInput `json:"tests"`
29
+ Tests []keyGenInput `json:"tests"`
30
30
} `json:"testGroups"`
31
31
}
32
32
33
- type keygenInput struct {
34
- TcID int `json:"tcId"`
35
- Deferred bool `json:"deferred"`
36
- SkSeed hexBytes `json:"skSeed"`
37
- SkPrf hexBytes `json:"skPrf"`
38
- PkSeed hexBytes `json:"pkSeed"`
39
- Sk hexBytes `json:"sk"`
40
- Pk hexBytes `json:"pk"`
33
+ type keyGenInput struct {
34
+ TcID int `json:"tcId"`
35
+ SkSeed Hex `json:"skSeed"`
36
+ SkPrf Hex `json:"skPrf"`
37
+ PkSeed Hex `json:"pkSeed"`
38
+ }
39
+
40
+ type acvpKeyGenResult struct {
41
+ acvpHeader
42
+ TestGroups []struct {
43
+ TgID int `json:"tgId"`
44
+ Tests []struct {
45
+ TcID int `json:"tcId"`
46
+ Sk Hex `json:"sk"`
47
+ Pk Hex `json:"pk"`
48
+ } `json:"tests"`
49
+ } `json:"testGroups"`
41
50
}
42
51
43
52
type acvpSigGenPrompt struct {
@@ -52,20 +61,20 @@ type acvpSigGenPrompt struct {
52
61
}
53
62
54
63
type signInput struct {
55
- TcID int `json:"tcId"`
56
- Sk hexBytes `json:"sk"`
57
- MsgLen int `json:"messageLength"`
58
- Msg hexBytes `json:"message"`
59
- AddRand hexBytes `json:"additionalRandomness,omitempty"`
64
+ TcID int `json:"tcId"`
65
+ Sk Hex `json:"sk"`
66
+ MsgLen int `json:"messageLength"`
67
+ Msg Hex `json:"message"`
68
+ AddRand Hex `json:"additionalRandomness,omitempty"`
60
69
}
61
70
62
71
type acvpSigGenResult struct {
63
72
acvpHeader
64
73
TestGroups []struct {
65
74
TgID int `json:"tgId"`
66
75
Tests []struct {
67
- TcID int `json:"tcId"`
68
- Signature hexBytes `json:"signature"`
76
+ TcID int `json:"tcId"`
77
+ Signature Hex `json:"signature"`
69
78
} `json:"tests"`
70
79
} `json:"testGroups"`
71
80
}
@@ -81,12 +90,12 @@ type acvpVerifyInput struct {
81
90
}
82
91
83
92
type verifyInput struct {
84
- TcID int `json:"tcId"`
85
- Pk hexBytes `json:"pk"`
86
- MessageLength int `json:"messageLength"`
87
- Message hexBytes `json:"message"`
88
- Signature hexBytes `json:"signature"`
89
- Reason string `json:"reason"`
93
+ TcID int `json:"tcId"`
94
+ Pk Hex `json:"pk"`
95
+ MessageLength int `json:"messageLength"`
96
+ Message Hex `json:"message"`
97
+ Signature Hex `json:"signature"`
98
+ Reason string `json:"reason"`
90
99
}
91
100
92
101
type acvpVerifyResult struct {
@@ -107,23 +116,34 @@ func TestACVP(t *testing.T) {
107
116
}
108
117
109
118
func testKeygen (t * testing.T ) {
110
- // https://github.com/usnistgov/ACVP-Server/tree/v1.1.0.35/gen-val/json-files/SLH-DSA-keyGen-FIPS205
111
- inputs := new (acvpKeygenVector )
112
- readVector (t , "testdata/keygen.json.zip" , inputs )
119
+ // https://github.com/usnistgov/ACVP-Server/tree/v1.1.0.37/gen-val/json-files/SLH-DSA-keyGen-FIPS205
120
+ inputs := new (acvpKeyGenPrompt )
121
+ readVector (t , "testdata/keyGen_prompt.json.zip" , inputs )
122
+ outputs := new (acvpKeyGenResult )
123
+ readVector (t , "testdata/keyGen_results.json.zip" , outputs )
113
124
114
- for _ , group := range inputs .TestGroups {
125
+ for gi , group := range inputs .TestGroups {
115
126
t .Run (fmt .Sprintf ("TgID_%v" , group .TgID ), func (t * testing.T ) {
116
127
for ti := range group .Tests {
117
- t .Run (fmt .Sprintf ("TcID_%v" , group .Tests [ti ].TcID ), func (t * testing.T ) {
118
- acvpKeygen (t , group .ParameterSet , & group .Tests [ti ])
119
- })
128
+ test .CheckOk (
129
+ group .Tests [ti ].TcID == outputs .TestGroups [gi ].Tests [ti ].TcID ,
130
+ "mismatch of TcID" , t ,
131
+ )
132
+
133
+ t .Run (fmt .Sprintf ("TcID_%v" , group .Tests [ti ].TcID ),
134
+ func (t * testing.T ) {
135
+ acvpKeygen (t , group .ParameterSet , & group .Tests [ti ],
136
+ outputs .TestGroups [gi ].Tests [ti ].Sk ,
137
+ outputs .TestGroups [gi ].Tests [ti ].Pk ,
138
+ )
139
+ })
120
140
}
121
141
})
122
142
}
123
143
}
124
144
125
145
func testSign (t * testing.T ) {
126
- // https://github.com/usnistgov/ACVP-Server/tree/v1.1.0.35 /gen-val/json-files/SLH-DSA-sigGen-FIPS205
146
+ // https://github.com/usnistgov/ACVP-Server/tree/v1.1.0.37 /gen-val/json-files/SLH-DSA-sigGen-FIPS205
127
147
inputs := new (acvpSigGenPrompt )
128
148
readVector (t , "testdata/sigGen_prompt.json.zip" , inputs )
129
149
outputs := new (acvpSigGenResult )
@@ -139,20 +159,20 @@ func testSign(t *testing.T) {
139
159
"mismatch of TcID" , t ,
140
160
)
141
161
142
- t .Run (fmt .Sprintf ("TcID_%v" , group .Tests [ti ].TcID ), func ( t * testing. T ) {
143
- acvpSign (
144
- t , group .ParameterSet , & group .Tests [ti ],
145
- outputs .TestGroups [gi ].Tests [ti ].Signature ,
146
- group .Deterministic ,
147
- )
148
- })
162
+ t .Run (fmt .Sprintf ("TcID_%v" , group .Tests [ti ].TcID ),
163
+ func ( t * testing. T ) {
164
+ acvpSign ( t , group .ParameterSet , & group .Tests [ti ],
165
+ outputs .TestGroups [gi ].Tests [ti ].Signature ,
166
+ group .Deterministic ,
167
+ )
168
+ })
149
169
}
150
170
})
151
171
}
152
172
}
153
173
154
174
func testVerify (t * testing.T ) {
155
- // https://github.com/usnistgov/ACVP-Server/tree/v1.1.0.35 /gen-val/json-files/SLH-DSA-sigVer-FIPS205
175
+ // https://github.com/usnistgov/ACVP-Server/tree/v1.1.0.37 /gen-val/json-files/SLH-DSA-sigVer-FIPS205
156
176
inputs := new (acvpVerifyInput )
157
177
readVector (t , "testdata/verify_prompt.json.zip" , inputs )
158
178
outputs := new (acvpVerifyResult )
@@ -168,18 +188,18 @@ func testVerify(t *testing.T) {
168
188
"mismatch of TcID" , t ,
169
189
)
170
190
171
- t .Run (fmt .Sprintf ("TcID_%v" , group .Tests [ti ].TcID ), func ( t * testing. T ) {
172
- acvpVerify (
173
- t , group .ParameterSet , & group .Tests [ti ],
174
- outputs .TestGroups [gi ].Tests [ti ].TestPassed ,
175
- )
176
- })
191
+ t .Run (fmt .Sprintf ("TcID_%v" , group .Tests [ti ].TcID ),
192
+ func ( t * testing. T ) {
193
+ acvpVerify ( t , group .ParameterSet , & group .Tests [ti ],
194
+ outputs .TestGroups [gi ].Tests [ti ].TestPassed ,
195
+ )
196
+ })
177
197
}
178
198
})
179
199
}
180
200
}
181
201
182
- func acvpKeygen (t * testing.T , paramSet string , in * keygenInput ) {
202
+ func acvpKeygen (t * testing.T , paramSet string , in * keyGenInput , wantSk , wantPk [] byte ) {
183
203
id , err := ParamIDByName (paramSet )
184
204
test .CheckNoErr (t , err , "invalid param name" )
185
205
@@ -189,12 +209,12 @@ func acvpKeygen(t *testing.T, paramSet string, in *keygenInput) {
189
209
skGot , err := sk .MarshalBinary ()
190
210
test .CheckNoErr (t , err , "PrivateKey.MarshalBinary failed" )
191
211
192
- if ! bytes .Equal (skGot , in . Sk ) {
193
- test .ReportError (t , skGot , in . Sk )
212
+ if ! bytes .Equal (skGot , wantSk ) {
213
+ test .ReportError (t , skGot , wantSk )
194
214
}
195
215
196
216
skWant := & PrivateKey {ParamID : id }
197
- err = skWant .UnmarshalBinary (in . Sk )
217
+ err = skWant .UnmarshalBinary (wantSk )
198
218
test .CheckNoErr (t , err , "PrivateKey.UnmarshalBinary failed" )
199
219
200
220
if ! sk .Equal (skWant ) {
@@ -204,12 +224,12 @@ func acvpKeygen(t *testing.T, paramSet string, in *keygenInput) {
204
224
pkGot , err := pk .MarshalBinary ()
205
225
test .CheckNoErr (t , err , "PublicKey.MarshalBinary failed" )
206
226
207
- if ! bytes .Equal (pkGot , in . Pk ) {
208
- test .ReportError (t , pkGot , in . Pk )
227
+ if ! bytes .Equal (pkGot , wantPk ) {
228
+ test .ReportError (t , pkGot , wantPk )
209
229
}
210
230
211
231
pkWant := & PublicKey {ParamID : id }
212
- err = pkWant .UnmarshalBinary (in . Pk )
232
+ err = pkWant .UnmarshalBinary (wantPk )
213
233
test .CheckNoErr (t , err , "PublicKey.UnmarshalBinary failed" )
214
234
215
235
if ! pk .Equal (pkWant ) {
@@ -267,9 +287,9 @@ func acvpVerify(t *testing.T, paramSet string, in *verifyInput, want bool) {
267
287
}
268
288
}
269
289
270
- type hexBytes []byte
290
+ type Hex []byte
271
291
272
- func (b * hexBytes ) UnmarshalJSON (data []byte ) (err error ) {
292
+ func (b * Hex ) UnmarshalJSON (data []byte ) (err error ) {
273
293
var s string
274
294
err = json .Unmarshal (data , & s )
275
295
if err != nil {
0 commit comments