File: lms_parse.py

package info (click to toggle)
openssl 3.6.0-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 148,104 kB
  • sloc: ansic: 612,658; perl: 248,939; asm: 6,332; sh: 1,755; pascal: 997; python: 648; makefile: 551; lisp: 35; ruby: 16; cpp: 10; sed: 6
file content (79 lines) | stat: -rw-r--r-- 3,073 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/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)