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 / reuse / run.sh

61 lines · 3031 bytes Raw Blame History
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.
9set -u
10OMC=${1:?usage: sh om/tls/test/reuse/run.sh OMC}
11D=om/tls/test/reuse
12B=build/tls/reuse
13mkdir -p "$B"
14fail() { echo "REUSE FAIL: $*"; exit 1; }
15
16build() { # $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
23build "$D/driver.om" "$B/driver" || fail "driver build: $(cat "$B/driver.err")"
24out=$("$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
28caught() { # $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
39n=0
40mut() { # $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
49mut 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'
50mut detector-always-reuse 'ret not ne acc 0' 'ret true'
51mut nonce-not-distinct 'put w last xor get w last 1' 'put w last xor get w last 0'
52mut 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'
53mut 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
56sed 's/^X 6/X 7/' "$D/vectors.txt" > "$B/vx.txt"
57cmp -s "$B/vx.txt" "$D/vectors.txt" && fail "vector mutant not applied"
58caught "$B/driver" "$B/vx.txt" wrong-expected-xor 3
59n=$((n + 1))
60
61echo "REUSE PASS checks=27 mutants=$n/$n"