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 / reuse / run.sh
| 1 | #!/bin/sh |
| 2 | # SPDX-License-Identifier: Apache-2.0 |
| 3 | # run.sh: OMEGA-CRYPTO-REUSE-1 gates 1 and 2 (issue #639). Orchestration only; the checks are |
| 4 | # in driver.om. Usage: sh om/tls/test/reuse/run.sh OMC (run from the repository root) |
| 5 | # Builds om2 + om/tls/chacha.om + om/tls/aesgcm.om + om/tls/gcmsiv.om + driver.om, expects all 27 |
| 6 | # checks to pass on vectors.txt, then requires every mutant to be caught: the mutant must build |
| 7 | # (rc 0, empty stderr), exit 1, report F > 0 failed checks and print exactly F "MISMATCH check" or |
| 8 | # "BAD input" lines. A mutant that fails to build, traps or crashes is INVALID and fails the gate. |
| 9 | set -u |
| 10 | OMC=${1:?usage: sh om/tls/test/reuse/run.sh OMC} |
| 11 | D=om/tls/test/reuse |
| 12 | B=build/tls/reuse |
| 13 | mkdir -p "$B" |
| 14 | fail() { echo "REUSE FAIL: $*"; exit 1; } |
| 15 | |
| 16 | build() { # $1 driver source, $2 output |
| 17 | { printf 'om2\n'; cat om/tls/chacha.om om/tls/aesgcm.om om/tls/gcmsiv.om "$1"; } > "$2.unit" |
| 18 | "$OMC" < "$2.unit" > "$2" 2> "$2.err"; rc=$? |
| 19 | [ "$rc" -eq 0 ] && [ ! -s "$2.err" ] || return 1 |
| 20 | chmod +x "$2" |
| 21 | } |
| 22 | |
| 23 | build "$D/driver.om" "$B/driver" || fail "driver build: $(cat "$B/driver.err")" |
| 24 | out=$("$B/driver" < "$D/vectors.txt"); rc=$? |
| 25 | [ "$rc" -eq 0 ] || fail "base exit $rc: $out" |
| 26 | [ "$out" = "reuse driver: 27 checks, 0 failed" ] || fail "base output: $out" |
| 27 | |
| 28 | caught() { # $1 binary, $2 vectors, $3 name, $4 expected failed count or "any" |
| 29 | o=$("$1" < "$2"); r=$? |
| 30 | [ "$r" -eq 1 ] || fail "mutant $3: exit $r (want 1, INVALID if trap/crash): $o" |
| 31 | f=$(printf '%s\n' "$o" | sed -n 's/^reuse driver: 27 checks, \([0-9]*\) failed$/\1/p') |
| 32 | [ -n "$f" ] && [ "$f" -gt 0 ] || fail "mutant $3: no failure summary: $o" |
| 33 | m=$(printf '%s\n' "$o" | grep -c -e '^MISMATCH check ' -e '^BAD input$') |
| 34 | [ "$m" -eq "$f" ] || fail "mutant $3: $m mismatch lines for $f failed" |
| 35 | [ "$4" = any ] || [ "$f" -eq "$4" ] || fail "mutant $3: $f failed (want $4)" |
| 36 | echo "caught $3: $f failed" |
| 37 | } |
| 38 | |
| 39 | n=0 |
| 40 | mut() { # $1 name, $2 site (must occur exactly once), $3 replacement |
| 41 | c=$(grep -cxF "$2" "$D/driver.om") |
| 42 | [ "$c" -eq 1 ] || fail "mutant $1: site found $c times" |
| 43 | awk -v s="$2" -v r="$3" '$0 == s { print r; next } { print }' "$D/driver.om" > "$B/m.om" |
| 44 | build "$B/m.om" "$B/m" || fail "mutant $1 INVALID: build failed: $(cat "$B/m.err")" |
| 45 | caught "$B/m" "$D/vectors.txt" "$1" any |
| 46 | n=$((n + 1)) |
| 47 | } |
| 48 | |
| 49 | mut tags-in-detector 'dchk kreuse w OC1 OC2 OP1 OP2 RLEN add b 2' 'dchk kreuse w OC1 OC2 OP1 OP2 SLEN add b 2' |
| 50 | mut detector-always-reuse 'ret not ne acc 0' 'ret true' |
| 51 | mut nonce-not-distinct 'put w last xor get w last 1' 'put w last xor get w last 0' |
| 52 | mut tamper-not-applied 'put w add OT 5 xor get w add OT 5 1' 'put w add OT 5 xor get w add OT 5 0' |
| 53 | mut siv-as-other-mode 'r1 = dseal 2 w ON1 nl OC1' 'r1 = dseal 1 w ON1 nl OC1' |
| 54 | |
| 55 | # expectation mutant: one digit of X wrong -> checks 1, 5, 13 fail and nothing else |
| 56 | sed 's/^X 6/X 7/' "$D/vectors.txt" > "$B/vx.txt" |
| 57 | cmp -s "$B/vx.txt" "$D/vectors.txt" && fail "vector mutant not applied" |
| 58 | caught "$B/driver" "$B/vx.txt" wrong-expected-xor 3 |
| 59 | n=$((n + 1)) |
| 60 | |
| 61 | echo "REUSE PASS checks=27 mutants=$n/$n" |