interplane.Get Omega
Read in your language

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

branch main Branches Tags History

omega-mv / om / tls / test / aesgcm / gen_wycheproof.py

41 lines · 1660 bytes Raw Blame History
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
5import hashlib
6import json
7import os
8import subprocess
9import sys
10
11root = sys.argv[1]
12rel = "testvectors_v1/aes_gcm_test.json"
13path = os.path.join(root, rel)
14raw = open(path, "rb").read()
15doc = json.loads(raw)
16commit = subprocess.run(["git", "-C", root, "rev-parse", "HEAD"], capture_output=True,
17 text=True, check=True).stdout.strip()
18
19
20def h(s):
21 return s.lower() if s else "-"
22
23
24out = sys.stdout
25out.write("# Wycheproof %s (%s, %d tests)\n" % (rel, doc["algorithm"], doc["numberOfTests"]))
26out.write("# Source: https://github.com/C2SP/wycheproof commit %s\n" % commit)
27out.write("# sha256 %s\n" % hashlib.sha256(raw).hexdigest())
28out.write("# License: Apache-2.0 (see wycheproof-LICENSE beside this file)\n")
29out.write("# Format: W TCID V|I KEY IV AAD MSG CT TAG (result valid -> V, invalid -> I)\n")
30n = 0
31for 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
40if n != doc["numberOfTests"]:
41 sys.exit("count %d != numberOfTests %d" % (n, doc["numberOfTests"]))