omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / om / tls / test / aesgcm / gen_wycheproof.py
| 1 | # SPDX-License-Identifier: Apache-2.0 |
| 2 | # Test tooling only (no primitive here): converts Wycheproof testvectors_v1/aes_gcm_test.json into |
| 3 | # driver records "W TCID V|I KEY IV AAD MSG CT TAG" (hex, "-" for empty), with a provenance header. |
| 4 | # Usage: python3 gen_wycheproof.py WYCHEPROOF_DIR > vectors/wycheproof_aes_gcm.txt |
| 5 | import hashlib |
| 6 | import json |
| 7 | import os |
| 8 | import subprocess |
| 9 | import sys |
| 10 | |
| 11 | root = sys.argv[1] |
| 12 | rel = "testvectors_v1/aes_gcm_test.json" |
| 13 | path = os.path.join(root, rel) |
| 14 | raw = open(path, "rb").read() |
| 15 | doc = json.loads(raw) |
| 16 | commit = subprocess.run(["git", "-C", root, "rev-parse", "HEAD"], capture_output=True, |
| 17 | text=True, check=True).stdout.strip() |
| 18 | |
| 19 | |
| 20 | def h(s): |
| 21 | return s.lower() if s else "-" |
| 22 | |
| 23 | |
| 24 | out = sys.stdout |
| 25 | out.write("# Wycheproof %s (%s, %d tests)\n" % (rel, doc["algorithm"], doc["numberOfTests"])) |
| 26 | out.write("# Source: https://github.com/C2SP/wycheproof commit %s\n" % commit) |
| 27 | out.write("# sha256 %s\n" % hashlib.sha256(raw).hexdigest()) |
| 28 | out.write("# License: Apache-2.0 (see wycheproof-LICENSE beside this file)\n") |
| 29 | out.write("# Format: W TCID V|I KEY IV AAD MSG CT TAG (result valid -> V, invalid -> I)\n") |
| 30 | n = 0 |
| 31 | for g in doc["testGroups"]: |
| 32 | for t in g["tests"]: |
| 33 | r = t["result"] |
| 34 | if r not in ("valid", "invalid"): |
| 35 | sys.exit("unexpected result %r in tcId %d" % (r, t["tcId"])) |
| 36 | out.write("W %d %s %s %s %s %s %s %s\n" % ( |
| 37 | t["tcId"], "V" if r == "valid" else "I", h(t["key"]), h(t["iv"]), h(t["aad"]), |
| 38 | h(t["msg"]), h(t["ct"]), h(t["tag"]))) |
| 39 | n += 1 |
| 40 | if n != doc["numberOfTests"]: |
| 41 | sys.exit("count %d != numberOfTests %d" % (n, doc["numberOfTests"])) |