Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/om/tls/test/ec/gen_fuzz.py # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / om / tls / test / ec / gen_fuzz.py` 60 lines ยท 2566 bytes Raw Blame History 1 #!/usr/bin/env python3 2 # SPDX-License-Identifier: Apache-2.0 3 # Test tooling only: deterministic malformed-input corpus for om/tls/test/ec/driver.om. Every line is 4 # a valid Wycheproof/CAVP case with its signature or public key damaged (byte flips, truncation, 5 # extension, random replacement, DER length/tag bytes changed), so the expected result is a 6 # refusal (EXP 1). The point is that untrusted input never traps: a trap ends the driver with 7 # exit 100+N and fails run.sh. 8 # Usage: python3 gen_fuzz.py VECTOR_DIR OUT_FILE COUNT SEED 9 import random 10 import sys 11 12 13 def main(): 14 vdir, outp, count, seed = sys.argv[1], sys.argv[2], int(sys.argv[3]), int(sys.argv[4]) 15 rnd = random.Random(seed) 16 base = [] 17 for name in ("wycheproof_secp256r1_sha256", "wycheproof_secp256r1_sha256_p1363", 18 "wycheproof_secp384r1_sha384", "wycheproof_secp384r1_sha384_p1363"): 19 for line in open("%s/%s.txt" % (vdir, name)): 20 f = line.split() 21 if line.startswith("#") or f[3] != "0": 22 continue 23 base.append(f) 24 out = ["# gen_fuzz.py seed %d count %d (all EXP 1)" % (seed, count)] 25 for i in range(count): 26 f = list(rnd.choice(base)) 27 sig = bytearray(bytes.fromhex(f[6])) 28 pub = bytearray(bytes.fromhex(f[5])) 29 op = rnd.randrange(8) 30 if op == 0: 31 sig[rnd.randrange(len(sig))] ^= 1 << rnd.randrange(8) 32 elif op == 1: 33 sig = sig[:rnd.randrange(len(sig))] 34 elif op == 2: 35 sig += bytes(rnd.randrange(256) for _ in range(rnd.randrange(1, 8))) 36 elif op == 3: 37 sig = bytearray(rnd.randrange(256) for _ in range(rnd.randrange(0, 120))) 38 elif op == 4: 39 # a DER length or tag byte (positions 0, 1, 2, 3 and the s header) set to a random value 40 pos = rnd.choice([0, 1, 2, 3, 4 + sig[3] if len(sig) > 3 and 4 + sig[3] < len(sig) else 0]) 41 old = sig[pos] 42 while sig[pos] == old: 43 sig[pos] = rnd.randrange(256) 44 elif op == 5: 45 pub[rnd.randrange(len(pub))] ^= 1 << rnd.randrange(8) 46 elif op == 6: 47 pub = pub[:rnd.randrange(len(pub))] 48 else: 49 pub = bytearray(rnd.randrange(256) for _ in range(rnd.choice([0, 1, 33, 49, 65, 97, 130]))) 50 f[0] = "f-%d-op%d" % (i, op) 51 f[3] = "1" 52 f[5] = pub.hex() or "-" 53 f[6] = sig.hex() or "-" 54 out.append(" ".join(f)) 55 with open(outp, "w") as fo: 56 fo.write("\n".join(out) + "\n") 57 58 59 if __name__ == "__main__": 60 main()