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 / sha256 / om2-evidence / s4 / harness.py

32 lines · 1478 bytes Raw Blame History
1#!/usr/bin/env python3
2# TEMPORARY harness (L838, oracle side, outside the delivered closure): feeds every row of the L836
3# fixture fixtures/sha256-vectors.txt to a program on stdin and compares its hex output with the
4# fixture digest. Generators as in fixtures/PROVENANCE.txt section 2.
5import sys, subprocess
6M = (1 << 64) - 1
7def gen(spec):
8 if spec == '-': return b''
9 k, *a = spec.split(':')
10 if k == 'file': return open('fx/msg/' + a[0].rsplit('/', 1)[1], 'rb').read()
11 if k == 'seq': return bytes(i % 251 for i in range(int(a[0])))
12 if k == 'rep': return bytes([int(a[0])]) * int(a[1])
13 if k == 'rnd':
14 s, n, out = int(a[0]), int(a[1]), bytearray()
15 while len(out) < n:
16 s = (s + 0x9E3779B97F4A7C15) & M; z = s
17 z = ((z ^ (z >> 30)) * 0xBF58476D1CE4E5B9) & M
18 z = ((z ^ (z >> 27)) * 0x94D049BB133111EB) & M
19 z ^= z >> 31; out += z.to_bytes(8, 'little')
20 return bytes(out[:n])
21 raise ValueError(spec)
22ok = bad = 0
23for line in open('fx/sha256-vectors.txt'):
24 if not line.strip() or line.startswith('#'): continue
25 name, spec, n, dig = line.split()
26 msg = gen(spec); assert len(msg) == int(n), name
27 r = subprocess.run(sys.argv[1:], input=msg, capture_output=True)
28 got = r.stdout.decode().strip()
29 if r.returncode == 0 and got == dig: ok += 1
30 else: bad += 1; print('FAIL', name, r.returncode, got)
31print(f'vectors pass={ok} fail={bad}')
32sys.exit(1 if bad else 0)