5b9e3ee8fb
Official vectors for the signature tests, fetched 2026-11-25 at the commits docs/02_signatures.md names: ACVP keyGen and sigGen at 2972def2, sigVer at a7f283cd (after the ModifyZ correction), Wycheproof at 20b25694, the composite-sigs repository at f0627ab, and RFC 8032 section 7.1. Files under about 1 MB are kept whole. The larger ones are reduced to their ML-DSA-65 groups and a few cases per group by make_subsets.py, which checks each original's sha256 and drops only whole cases and groups; RFC 8032's vectors are extracted from the RFC text by extract_rfc8032.py. SOURCES.md records the URL, commit, git blob, original sha256 and the selection of every file.
132 lines
4.6 KiB
Python
132 lines
4.6 KiB
Python
"""Reduce the large official vector files to the subsets kept in this folder.
|
|
|
|
Usage (each argument is the path to the ORIGINAL file, downloaded unchanged from the URL and
|
|
commit listed in SOURCES.md):
|
|
|
|
python -I make_subsets.py --acvp-siggen PATH --acvp-sigver PATH \
|
|
--wycheproof-mldsa-verify PATH --composite PATH --out DIR
|
|
|
|
The script refuses an original whose sha256 is not the pinned one, keeps every field of every
|
|
test case it selects unchanged (only whole test cases and whole groups are dropped), and writes
|
|
JSON with two-space indentation and LF line endings. Running it twice gives identical bytes.
|
|
"""
|
|
|
|
import argparse
|
|
import collections
|
|
import hashlib
|
|
import json
|
|
import os
|
|
|
|
PINNED = {
|
|
"acvp_siggen": "72dcaf5f69853ca267ccd16af9cb40949786aca0fcfbf05d1ebeba132b93af22",
|
|
"acvp_sigver": "47cdd6314c7f746d02421ffcba89d4dbc7bb875ac49e07a029fdfc26fba55437",
|
|
"wycheproof_mldsa_verify": "1ca235f61928421a173a171780beb00264ae9155dc33c52a11e1766cc7979034",
|
|
"composite": "a60f697f9fd94c3cd5e4501a40c4396d9a9ffc7cf0f8a1ddd87dedbb46a7abf0",
|
|
}
|
|
|
|
# ACVP sigGen: ML-DSA-65 only, no HashML-DSA (preHash) groups, the first N cases of each group.
|
|
SIGGEN_PER_GROUP = 3
|
|
# Wycheproof verify: per group, at most N cases for each (result, set of flags).
|
|
WYCHEPROOF_PER_KIND = 4
|
|
COMPOSITE_ENTRY = "id-MLDSA65-Ed25519-SHA512"
|
|
|
|
|
|
def load(path, key):
|
|
with open(path, "rb") as f:
|
|
raw = f.read()
|
|
got = hashlib.sha256(raw).hexdigest()
|
|
if got != PINNED[key]:
|
|
raise SystemExit(f"{path}: sha256 {got} is not the pinned {PINNED[key]}")
|
|
return json.loads(raw.decode("utf-8"))
|
|
|
|
|
|
def write(out_dir, name, obj):
|
|
path = os.path.join(out_dir, name)
|
|
with open(path, "w", encoding="utf-8", newline="\n") as f:
|
|
json.dump(obj, f, indent=2, ensure_ascii=False)
|
|
f.write("\n")
|
|
n = sum(len(g["tests"]) for g in obj["testGroups"]) if "testGroups" in obj else len(obj["tests"])
|
|
print(f"{name}: {n} cases")
|
|
|
|
|
|
def acvp_siggen(d):
|
|
groups = []
|
|
for g in d["testGroups"]:
|
|
if g["parameterSet"] != "ML-DSA-65" or g["preHash"] == "preHash":
|
|
continue
|
|
g = dict(g)
|
|
g["tests"] = sorted(g["tests"], key=lambda t: t["tcId"])[:SIGGEN_PER_GROUP]
|
|
groups.append(g)
|
|
d = dict(d)
|
|
d["testGroups"] = groups
|
|
return d
|
|
|
|
|
|
def acvp_sigver(d):
|
|
# One case for each (testPassed, reason) in each ML-DSA-65 non-preHash group.
|
|
groups = []
|
|
for g in d["testGroups"]:
|
|
if g["parameterSet"] != "ML-DSA-65" or g["preHash"] == "preHash":
|
|
continue
|
|
seen = set()
|
|
kept = []
|
|
for t in sorted(g["tests"], key=lambda t: t["tcId"]):
|
|
kind = (t["testPassed"], t.get("reason"))
|
|
if kind not in seen:
|
|
seen.add(kind)
|
|
kept.append(t)
|
|
g = dict(g)
|
|
g["tests"] = kept
|
|
groups.append(g)
|
|
d = dict(d)
|
|
d["testGroups"] = groups
|
|
return d
|
|
|
|
|
|
def wycheproof_verify(d):
|
|
groups = []
|
|
for g in d["testGroups"]:
|
|
count = collections.Counter()
|
|
kept = []
|
|
for t in sorted(g["tests"], key=lambda t: t["tcId"]):
|
|
kind = (t["result"], frozenset(t.get("flags", [])))
|
|
if count[kind] < WYCHEPROOF_PER_KIND:
|
|
count[kind] += 1
|
|
kept.append(t)
|
|
g = dict(g)
|
|
g["tests"] = kept
|
|
groups.append(g)
|
|
d = dict(d)
|
|
d["testGroups"] = groups
|
|
d["numberOfTests"] = sum(len(g["tests"]) for g in groups)
|
|
return d
|
|
|
|
|
|
def composite(d):
|
|
entries = [t for t in d["tests"] if t["tcId"] == COMPOSITE_ENTRY]
|
|
if len(entries) != 1:
|
|
raise SystemExit(f"expected exactly one {COMPOSITE_ENTRY} entry, found {len(entries)}")
|
|
return {"m": d["m"], "ctx": d["ctx"], "tests": entries}
|
|
|
|
|
|
def main():
|
|
p = argparse.ArgumentParser()
|
|
p.add_argument("--acvp-siggen", required=True)
|
|
p.add_argument("--acvp-sigver", required=True)
|
|
p.add_argument("--wycheproof-mldsa-verify", required=True)
|
|
p.add_argument("--composite", required=True)
|
|
p.add_argument("--out", required=True)
|
|
a = p.parse_args()
|
|
write(a.out, "acvp-ml-dsa-sigGen-FIPS204-internalProjection.subset.json",
|
|
acvp_siggen(load(a.acvp_siggen, "acvp_siggen")))
|
|
write(a.out, "acvp-ml-dsa-sigVer-FIPS204-internalProjection.subset.json",
|
|
acvp_sigver(load(a.acvp_sigver, "acvp_sigver")))
|
|
write(a.out, "wycheproof-mldsa_65_verify_test.subset.json",
|
|
wycheproof_verify(load(a.wycheproof_mldsa_verify, "wycheproof_mldsa_verify")))
|
|
write(a.out, "composite-sigs-testvectors-MLDSA65-Ed25519.subset.json",
|
|
composite(load(a.composite, "composite")))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|