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 / seed / qualification / om2 / oracle / sha / randcheck.py

40 lines · 1420 bytes Raw Blame History
1#!/usr/bin/python3
2# SPDX-License-Identifier: Apache-2.0
3# ORACLE (outside the delivered closure), OM-2 qualification L836 (#748), phaseB/sha-f5d14cb2.
4# Second, independent oracle for sha_qual rand output: regenerates each message from its printed
5# (seed, index, length) with the same splitmix64 byte generator (fixtures/PROVENANCE.txt) and compares
6# the OM-2 digest printed by the driver with Python hashlib (OpenSSL).
7# Usage: randcheck.py < rand.out exit 0 iff every RAND line matches and at least one was read.
8import hashlib
9import sys
10
11M = (1 << 64) - 1
12
13
14def rnd(seed, n):
15 s = seed & M
16 out = bytearray()
17 while len(out) < n:
18 s = (s + 0x9E3779B97F4A7C15) & M
19 z = s
20 z = ((z ^ (z >> 30)) * 0xBF58476D1CE4E5B9) & M
21 z = ((z ^ (z >> 27)) * 0x94D049BB133111EB) & M
22 z ^= z >> 31
23 out += z.to_bytes(8, "little")
24 return bytes(out[:n])
25
26
27ok = bad = 0
28for line in sys.stdin:
29 f = line.split()
30 if not f or f[0] != "RAND":
31 continue
32 seed, i, n, dig = int(f[1]), int(f[2]), int(f[3]), f[4]
33 want = hashlib.sha256(rnd(seed ^ (i << 20) ^ 0x5EED, n)).hexdigest()
34 if want == dig:
35 ok += 1
36 else:
37 bad += 1
38 print(f"FAIL rand {seed} {i} len={n} got={dig} hashlib={want}")
39print(f"{'PASS' if bad == 0 and ok > 0 else 'FAIL'} randcheck hashlib matched={ok} mismatched={bad}")
40sys.exit(0 if bad == 0 and ok > 0 else 1)