Files
openssl/test/lms_parse.py
slontis e6c8110483 Add LMS evp_test using NIST ACVP test data.
This covers all LMS algorithm parameter sets.

The following changes were done to handle the tests:
 (1) Changed LMS to use OSSL_PKEY_PARAM_PUB_KEY instead of
OSSL_PKEY_PARAM_ENCODED_PUBLIC_KEY for import/export.
(There is no reason to have the encoded form for verify operations).
 (2) Fixed a bug for W=1 with truncated digests. The checksum was using
a value of 8-w, which was off by 1 for this case. A value was added to
the ots parameters that represents this value.
 (3) A check in evp_test for a NID was removed since LMS does not have
OIDS (HSS does).
 (4) the unused PROPERTIES param was removed from the LMS keymanager.

Reviewed-by: Viktor Dukhovni <viktor@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Paul Dale <ppzgs1@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/27885)
2025-07-10 19:04:37 +10:00

80 lines
3.0 KiB
Python

#!/usr/bin/env python
# Copyright 2025 The OpenSSL Project Authors. All Rights Reserved.
#
# Licensed under the Apache License 2.0 (the "License"). You may not use
# this file except in compliance with the License. You can obtain a copy
# in the file LICENSE in the source distribution or at
# https://www.openssl.org/source/license.html
# A python program written to parse (version 1.0) of the ACVP test vectors for
# LMS. The file that can be processed by this utility can be downloaded from
# https://raw.githubusercontent.com/usnistgov/ACVP-Server/refs/heads/master/gen-val/json-files/LMS-sigVer-1.0/internalProjection.json
# and output from this utility to
# test/recipes/30-test_evp_data/evppkey_lms.txt
#
# e.g. python3 mldsa_parse.py ~/Downloads/internalProjection.json > ./test/recipes/30-test_evp_data/evppkey_lms.txt
#
import json
import argparse
import datetime
def print_label(label, value):
print(label + " = " + value)
def print_hexlabel(label, tag, value):
print(label + " = hex" + tag + ":" + value)
def parse_lms_sig_ver(groups):
for grp in groups:
lmsmode = grp["lmsMode"]
lmotsmode = grp["lmOtsMode"]
name = lmsmode + "_" + str(grp["tgId"])
pubkey = grp["publicKey"]
if grp["testType"] != "AFT":
continue
print_label("Title", lmsmode + " " + lmotsmode)
print("");
print_label("PublicKeyRaw", name + ":" + "LMS" + ":" + pubkey)
for tst in grp['tests']:
testname = lmsmode + "_" + str(tst['tcId'])
print("");
if "reason" in tst:
print("# " + tst['reason'])
print_label("FIPSversion", ">=3.6.0")
print_label("Verify-Message-Public", "LMS:" + name)
print_label("Input", tst['message'])
print_label("Output", tst['signature'])
if not tst['testPassed']:
print_label("Result", "VERIFY_ERROR")
parser = argparse.ArgumentParser(description="")
parser.add_argument('filename', type=str)
args = parser.parse_args()
# Open and read the JSON file
with open(args.filename, 'r') as file:
data = json.load(file)
year = datetime.date.today().year
version = data['vsId']
revision = data['revision']
algorithm = data['algorithm']
print("# Copyright " + str(year) + " The OpenSSL Project Authors. All Rights Reserved.")
print("#")
print("# Licensed under the Apache License 2.0 (the \"License\"). You may not use")
print("# this file except in compliance with the License. You can obtain a copy")
print("# in the file LICENSE in the source distribution or at")
print("# https://www.openssl.org/source/license.html\n")
print("# ACVP test data for " + algorithm + " generated from")
print("# https://raw.githubusercontent.com/usnistgov/ACVP-Server/refs/heads/master/gen-val/json-files/LMS-sigVer-1.0/internalProjection.json")
print("# [version " + str(version) + " : revision " + str(revision) + "]")
print("")
if algorithm == "LMS":
parse_lms_sig_ver(data['testGroups'])
else:
print("Unsupported algorithm " + algorithm)