Skip to content

Commit

Permalink
Update ACVP python script to handle new binary suffixes
Browse files Browse the repository at this point in the history
Signed-off-by: Thing-han, Lim <[email protected]>
  • Loading branch information
potsrevennil committed Nov 4, 2024
1 parent 6cbbd1c commit 45518b6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ quickcheck: buildall
$(MLKEM512_BUILD_DIR)/bin/test_mlkem512_$(OPT_SUFFIX)
$(MLKEM768_BUILD_DIR)/bin/test_mlkem768_$(OPT_SUFFIX)
$(MLKEM1024_BUILD_DIR)/bin/test_mlkem1024_$(OPT_SUFFIX)
python3 ./test/acvp_client.py
python3 ./test/acvp_client.py $(OPT_SUFFIX)
$(Q)echo " Functionality and ACVP tests passed!"

mlkem: \
Expand Down
46 changes: 33 additions & 13 deletions test/acvp_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,20 @@

import json
import subprocess
import sys

suffix = f"_{sys.argv[1]}" if len(sys.argv) > 1 else ""
acvp_dir = "test/acvp_data"
acvp_keygen_json = f"{acvp_dir}/acvp_keygen_internalProjection.json"
acvp_encapDecap_json = f"{acvp_dir}/acvp_encapDecap_internalProjection.json"

with open(acvp_keygen_json, 'r') as f:
with open(acvp_keygen_json, "r") as f:
acvp_keygen_data = json.load(f)

with open(acvp_encapDecap_json, 'r') as f:
with open(acvp_encapDecap_json, "r") as f:
acvp_encapDecap_data = json.load(f)


def get_acvp_binary(tg):
"""Convert JSON dict for ACVP test group to suitable ACVP binary."""
parameterSetToLevel = {
Expand All @@ -29,14 +32,22 @@ def get_acvp_binary(tg):
}
level = parameterSetToLevel[tg["parameterSet"]]
basedir = f"./test/build/mlkem{level}/bin"
acvp_bin = f"acvp_mlkem{level}"
acvp_bin = f"acvp_mlkem{level}{suffix}"
return f"{basedir}/{acvp_bin}"


def run_encapDecap_test(tg, tc):
print(f"Running encapDecap test case {tc['tcId']} ({tg['function']}) ... ", end='')
print(f"Running encapDecap test case {tc['tcId']} ({tg['function']}) ... ", end="")
if tg["function"] == "encapsulation":
acvp_bin = get_acvp_binary(tg)
acvp_call = [ acvp_bin, "encapDecap", "AFT", "encapsulation", f"ek={tc['ek']}", f"m={tc['m']}" ]
acvp_call = [
acvp_bin,
"encapDecap",
"AFT",
"encapsulation",
f"ek={tc['ek']}",
f"m={tc['m']}",
]
result = subprocess.run(acvp_call, encoding="utf-8", capture_output=True)
if result.returncode != 0:
print("FAIL!")
Expand All @@ -45,15 +56,22 @@ def run_encapDecap_test(tg, tc):
exit(1)
# Extract results and compare to expected data
for l in result.stdout.splitlines():
(k,v) = l.split("=")
(k, v) = l.split("=")
if v != tc[k]:
print("FAIL!")
print(f"Mismatching result for {k}: expected {tc[k]}, got {v}")
exit(1)
print("OK")
elif tg["function"] == "decapsulation":
acvp_bin = get_acvp_binary(tg)
acvp_call = [ acvp_bin, "encapDecap", "VAL", "decapsulation", f"dk={tg['dk']}", f"c={tc['c']}" ]
acvp_call = [
acvp_bin,
"encapDecap",
"VAL",
"decapsulation",
f"dk={tg['dk']}",
f"c={tc['c']}",
]
result = subprocess.run(acvp_call, encoding="utf-8", capture_output=True)
if result.returncode != 0:
print("FAIL!")
Expand All @@ -62,17 +80,18 @@ def run_encapDecap_test(tg, tc):
exit(1)
# Extract results and compare to expected data
for l in result.stdout.splitlines():
(k,v) = l.split("=")
(k, v) = l.split("=")
if v != tc[k]:
print("FAIL!")
print(f"Mismatching result for {k}: expected {tc[k]}, got {v}")
exit(1)
print("OK")


def run_keyGen_test(tg, tc):
print(f"Running keyGen test case {tc['tcId']} ... ", end='')
print(f"Running keyGen test case {tc['tcId']} ... ", end="")
acvp_bin = get_acvp_binary(tg)
acvp_call = [ acvp_bin, "keyGen", "AFT", f"z={tc['z']}", f"d={tc['d']}" ]
acvp_call = [acvp_bin, "keyGen", "AFT", f"z={tc['z']}", f"d={tc['d']}"]
result = subprocess.run(acvp_call, encoding="utf-8", capture_output=True)
if result.returncode != 0:
print("FAIL!")
Expand All @@ -81,17 +100,18 @@ def run_keyGen_test(tg, tc):
exit(1)
# Extract results and compare to expected data
for l in result.stdout.splitlines():
(k,v) = l.split("=")
(k, v) = l.split("=")
if v != tc[k]:
print("FAIL!")
print(f"Mismatching result for {k}: expected {tc[k]}, got {v}")
exit(1)
print("OK")


for tg in acvp_encapDecap_data["testGroups"]:
for tc in tg["tests"]:
run_encapDecap_test(tg,tc)
run_encapDecap_test(tg, tc)

for tg in acvp_keygen_data["testGroups"]:
for tc in tg["tests"]:
run_keyGen_test(tg,tc)
run_keyGen_test(tg, tc)

0 comments on commit 45518b6

Please sign in to comment.