Skip to content

Commit d493f9c

Browse files
committed
ACVP Client: Adjust to handle deterministic test cases better
Before the ACVP client would implement tests for the determinstic ML-DSA variant by passing an all-zero rnd to the the test harness. This felt a bit hacky. This commit changes it to handle the deterministic variant in the test harness directly by adding sigGenDeterministic, sigGenInternalDeterministic, sigGenPreHashDeterministic, and sigGenPreHashShake256Deterministic commands. To make simplify it slightly in the acvp_client, the rnd argument is moved to the end of each command. Signed-off-by: Matthias J. Kannwischer <[email protected]>
1 parent e67e2d3 commit d493f9c

File tree

2 files changed

+359
-42
lines changed

2 files changed

+359
-42
lines changed

test/acvp_client.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -167,31 +167,35 @@ def run_sigGen_test(tg, tc):
167167

168168
assert tg["testType"] == "AFT"
169169

170-
# TODO: probably we want to handle handle the deterministic case differently
171-
if tg["deterministic"] is True:
172-
tc["rnd"] = "0" * 64
170+
is_deterministic = tg["deterministic"] is True
173171

174172
if tg["preHash"] == "preHash":
175173
assert len(tc["context"]) <= 2 * 255
176174

177175
# Use specialized SHAKE256 function that computes hash internally
178176
if tc["hashAlg"] == "SHAKE-256":
177+
target = (
178+
"sigGenPreHashShake256Deterministic"
179+
if is_deterministic
180+
else "sigGenPreHashShake256"
181+
)
179182
acvp_call = exec_prefix + [
180183
acvp_bin,
181-
"sigGenPreHashShake256",
184+
target,
182185
f"message={tc['message']}",
183186
f"context={tc['context']}",
184-
f"rnd={tc['rnd']}",
185187
f"sk={tc['sk']}",
186188
]
187189
else:
188190
ph = compute_hash(tc["message"], tc["hashAlg"])
191+
target = (
192+
"sigGenPreHashDeterministic" if is_deterministic else "sigGenPreHash"
193+
)
189194
acvp_call = exec_prefix + [
190195
acvp_bin,
191-
"sigGenPreHash",
196+
target,
192197
f"ph={ph}",
193198
f"context={tc['context']}",
194-
f"rng={tc['rnd']}",
195199
f"sk={tc['sk']}",
196200
f"hashAlg={tc['hashAlg']}",
197201
]
@@ -200,11 +204,11 @@ def run_sigGen_test(tg, tc):
200204
assert len(tc["context"]) <= 2 * 255
201205
assert len(tc["message"]) <= 2 * 65536
202206

207+
target = "sigGenDeterministic" if is_deterministic else "sigGen"
203208
acvp_call = exec_prefix + [
204209
acvp_bin,
205-
"sigGen",
210+
target,
206211
f"message={tc['message']}",
207-
f"rnd={tc['rnd']}",
208212
f"sk={tc['sk']}",
209213
f"context={tc['context']}",
210214
]
@@ -219,15 +223,19 @@ def run_sigGen_test(tg, tc):
219223
assert len(tc["message"]) <= 2 * 65536
220224
msg = tc["message"]
221225

226+
target = "sigGenInternalDeterministic" if is_deterministic else "sigGenInternal"
222227
acvp_call = exec_prefix + [
223228
acvp_bin,
224-
"sigGenInternal",
229+
target,
225230
f"message={msg}",
226-
f"rnd={tc['rnd']}",
227231
f"sk={tc['sk']}",
228232
f"externalMu={externalMu}",
229233
]
230234

235+
# Append rnd argument for randomized (non-deterministic) variant
236+
if not is_deterministic:
237+
acvp_call.append(f"rnd={tc['rnd']}")
238+
231239
result = subprocess.run(acvp_call, encoding="utf-8", capture_output=True)
232240
if result.returncode != 0:
233241
err("FAIL!")

0 commit comments

Comments
 (0)