mirror of
https://github.com/itzmeanjan/ml-kem.git
synced 2026-01-08 23:27:54 -05:00
Add Python script for parsing NIST ACVP KATs for ML-KEM keygen to local KAT format
Signed-off-by: Anjan Roy <hello@itzmeanjan.in>
This commit is contained in:
43
kats/scripts/parse_ml_kem_keygen_acvp_kat.py
Normal file
43
kats/scripts/parse_ml_kem_keygen_acvp_kat.py
Normal file
@@ -0,0 +1,43 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
import json
|
||||
import sys
|
||||
import typing
|
||||
|
||||
ML_KEM_512_ACVP_KAT_FILE_NAME="ml_kem_512.acvp.kat"
|
||||
ML_KEM_768_ACVP_KAT_FILE_NAME="ml_kem_768.acvp.kat"
|
||||
ML_KEM_1024_ACVP_KAT_FILE_NAME="ml_kem_1024.acvp.kat"
|
||||
|
||||
def extract_and_write_ml_kem_keygen_kats(test_group: dict[str, typing.Any], write_to_file: str):
|
||||
assert test_group["testType"] == "AFT"
|
||||
|
||||
with open(write_to_file, "wt") as fd:
|
||||
for test in test_group["tests"]:
|
||||
fd.write(f'd = {test["d"]}\n')
|
||||
fd.write(f'z = {test["z"]}\n')
|
||||
fd.write(f'pk = {test["ek"]}\n')
|
||||
fd.write(f'sk = {test["dk"]}\n')
|
||||
|
||||
fd.write('\n')
|
||||
|
||||
fd.flush()
|
||||
|
||||
|
||||
def main():
|
||||
json_as_str = ''
|
||||
for line in sys.stdin:
|
||||
json_as_str += line
|
||||
|
||||
acvp_kats = json.loads(json_as_str)
|
||||
|
||||
ml_kem_512_param_set = acvp_kats["testGroups"][0]
|
||||
ml_kem_768_param_set = acvp_kats["testGroups"][1]
|
||||
ml_kem_1024_param_set = acvp_kats["testGroups"][2]
|
||||
|
||||
extract_and_write_ml_kem_keygen_kats(ml_kem_512_param_set, ML_KEM_512_ACVP_KAT_FILE_NAME)
|
||||
extract_and_write_ml_kem_keygen_kats(ml_kem_768_param_set, ML_KEM_768_ACVP_KAT_FILE_NAME)
|
||||
extract_and_write_ml_kem_keygen_kats(ml_kem_1024_param_set, ML_KEM_1024_ACVP_KAT_FILE_NAME)
|
||||
|
||||
|
||||
if __name__=='__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user