Skip to content

Commit a91ad61

Browse files
committed
Updating ACVP test vectors to v1.1.0.37
1 parent c74a2d3 commit a91ad61

8 files changed

+74
-54
lines changed

sign/slhdsa/acvp_test.go

+74-54
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,33 @@ type acvpHeader struct {
2020
IsSample bool `json:"isSample"`
2121
}
2222

23-
type acvpKeygenVector struct {
23+
type acvpKeyGenPrompt struct {
2424
acvpHeader
2525
TestGroups []struct {
2626
TgID int `json:"tgId"`
2727
TestType string `json:"testType"`
2828
ParameterSet string `json:"parameterSet"`
29-
Tests []keygenInput `json:"tests"`
29+
Tests []keyGenInput `json:"tests"`
3030
} `json:"testGroups"`
3131
}
3232

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"`
4150
}
4251

4352
type acvpSigGenPrompt struct {
@@ -52,20 +61,20 @@ type acvpSigGenPrompt struct {
5261
}
5362

5463
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"`
6069
}
6170

6271
type acvpSigGenResult struct {
6372
acvpHeader
6473
TestGroups []struct {
6574
TgID int `json:"tgId"`
6675
Tests []struct {
67-
TcID int `json:"tcId"`
68-
Signature hexBytes `json:"signature"`
76+
TcID int `json:"tcId"`
77+
Signature Hex `json:"signature"`
6978
} `json:"tests"`
7079
} `json:"testGroups"`
7180
}
@@ -81,12 +90,12 @@ type acvpVerifyInput struct {
8190
}
8291

8392
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"`
9099
}
91100

92101
type acvpVerifyResult struct {
@@ -107,23 +116,34 @@ func TestACVP(t *testing.T) {
107116
}
108117

109118
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)
113124

114-
for _, group := range inputs.TestGroups {
125+
for gi, group := range inputs.TestGroups {
115126
t.Run(fmt.Sprintf("TgID_%v", group.TgID), func(t *testing.T) {
116127
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+
})
120140
}
121141
})
122142
}
123143
}
124144

125145
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
127147
inputs := new(acvpSigGenPrompt)
128148
readVector(t, "testdata/sigGen_prompt.json.zip", inputs)
129149
outputs := new(acvpSigGenResult)
@@ -139,20 +159,20 @@ func testSign(t *testing.T) {
139159
"mismatch of TcID", t,
140160
)
141161

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+
})
149169
}
150170
})
151171
}
152172
}
153173

154174
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
156176
inputs := new(acvpVerifyInput)
157177
readVector(t, "testdata/verify_prompt.json.zip", inputs)
158178
outputs := new(acvpVerifyResult)
@@ -168,18 +188,18 @@ func testVerify(t *testing.T) {
168188
"mismatch of TcID", t,
169189
)
170190

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+
})
177197
}
178198
})
179199
}
180200
}
181201

182-
func acvpKeygen(t *testing.T, paramSet string, in *keygenInput) {
202+
func acvpKeygen(t *testing.T, paramSet string, in *keyGenInput, wantSk, wantPk []byte) {
183203
id, err := ParamIDByName(paramSet)
184204
test.CheckNoErr(t, err, "invalid param name")
185205

@@ -189,12 +209,12 @@ func acvpKeygen(t *testing.T, paramSet string, in *keygenInput) {
189209
skGot, err := sk.MarshalBinary()
190210
test.CheckNoErr(t, err, "PrivateKey.MarshalBinary failed")
191211

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)
194214
}
195215

196216
skWant := &PrivateKey{ParamID: id}
197-
err = skWant.UnmarshalBinary(in.Sk)
217+
err = skWant.UnmarshalBinary(wantSk)
198218
test.CheckNoErr(t, err, "PrivateKey.UnmarshalBinary failed")
199219

200220
if !sk.Equal(skWant) {
@@ -204,12 +224,12 @@ func acvpKeygen(t *testing.T, paramSet string, in *keygenInput) {
204224
pkGot, err := pk.MarshalBinary()
205225
test.CheckNoErr(t, err, "PublicKey.MarshalBinary failed")
206226

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)
209229
}
210230

211231
pkWant := &PublicKey{ParamID: id}
212-
err = pkWant.UnmarshalBinary(in.Pk)
232+
err = pkWant.UnmarshalBinary(wantPk)
213233
test.CheckNoErr(t, err, "PublicKey.UnmarshalBinary failed")
214234

215235
if !pk.Equal(pkWant) {
@@ -267,9 +287,9 @@ func acvpVerify(t *testing.T, paramSet string, in *verifyInput, want bool) {
267287
}
268288
}
269289

270-
type hexBytes []byte
290+
type Hex []byte
271291

272-
func (b *hexBytes) UnmarshalJSON(data []byte) (err error) {
292+
func (b *Hex) UnmarshalJSON(data []byte) (err error) {
273293
var s string
274294
err = json.Unmarshal(data, &s)
275295
if err != nil {
11.7 KB
Binary file not shown.
15.1 KB
Binary file not shown.

sign/slhdsa/testdata/keygen.json.zip

-6.11 KB
Binary file not shown.
415 KB
Binary file not shown.
3.07 MB
Binary file not shown.
1.87 MB
Binary file not shown.
241 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)