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/x25519/run.sh # 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 / x25519 / run.sh` 153 lines ยท 6108 bytes Raw Blame History 1 #!/bin/sh 2 # SPDX-License-Identifier: Apache-2.0 3 # Test suite for om/tls/x25519.om. Usage: sh om/tls/test/x25519/run.sh PATH_TO_PINNED_OMC 4 # Builds om2 + x25519.om + driver.om into build/tls/x25519/, runs the RFC 7748 and Wycheproof vector 5 # files, a negative control, an expectation mutant and five library mutants (each must be detected: 6 # exit 1 with MISMATCH lines), and a low/high Hamming weight timing pair (informational). 7 # Environment: X25519_ITER1M=1 also runs the RFC 7748 1,000,000-iteration test (177 s measured on 8 # the DGX Spark GB10 host, 2026-10-26, under nice 19); 9 # X25519_BENCH_N (default 200) calls per timing scalar. 10 # Exit 0 only when every check passes; the final line is 11 # X25519 PASS vectors=N (wycheproof=W) mutants=M/M or X25519 FAIL ... 12 set -eu 13 omc=${1:?usage: run.sh OMC} 14 here=$(cd "$(dirname "$0")" && pwd) 15 root=$(cd "$here/../../../.." && pwd) 16 lib="$root/om/tls/x25519.om" 17 out="$root/build/tls/x25519" 18 rm -rf "$out" 19 mkdir -p "$out" 20 fail=0 21 vectors=0 22 wyche=0 23 mut=0 24 mutok=0 25 nice="nice -n 19 ionice -c3" 26 27 build() { # build SRC_X25519 OUT_BINARY 28 { echo om2; cat "$1" "$here/driver.om"; } > "$2.unit.om" 29 if ! $nice "$omc" < "$2.unit.om" > "$2" 2> "$2.err" || [ -s "$2.err" ]; then 30 echo "FAIL build $2: $(cat "$2.err")" 31 rm -f "$2" 32 return 1 33 fi 34 chmod +x "$2" 35 } 36 37 # calls LOG: the checked-call count from the driver's summary line 38 calls() { awk '/^cases / { print $4 }' "$1"; } 39 40 # run BINARY FILE LABEL: the driver must exit 0 with no mismatch 41 run() { 42 if $nice "$1" < "$2" > "$out/$3.log" 2>&1; then 43 echo "PASS $3: $(tail -n 1 "$out/$3.log")" 44 else 45 echo "FAIL $3 (exit $?):" 46 cat "$out/$3.log" 47 fail=1 48 fi 49 } 50 51 # mutant BINARY FILE LABEL: the driver must finish normally and report a mismatch: exit status 52 # exactly 1, at least one MISMATCH line, and its summary line. Any other outcome (0, 65 bad 53 # input, 100+N trap, a signal) fails the run, so a mutant that crashes is not counted as detected. 54 mutant() { 55 mut=$((mut + 1)) 56 rc=0 57 $nice "$1" < "$2" > "$out/$3.log" 2>&1 || rc=$? 58 nm=$(grep -c '^MISMATCH ' "$out/$3.log" || true) 59 if [ "$rc" -eq 1 ] && [ "$nm" -gt 0 ] && grep -q '^cases .* mismatches [1-9]' "$out/$3.log"; then 60 echo "PASS $3 detected: $nm mismatches, $(tail -n 1 "$out/$3.log")" 61 mutok=$((mutok + 1)) 62 else 63 echo "FAIL $3: exit $rc, $nm MISMATCH lines (need exit 1 and at least one): $(tail -n 1 "$out/$3.log")" 64 fail=1 65 fi 66 } 67 68 # libmut LABEL SED_SCRIPT VECTORS: a library mutant built from a sed edit of x25519.om 69 libmut() { 70 sed "$2" "$lib" > "$out/$1.om" 71 if cmp -s "$lib" "$out/$1.om"; then 72 mut=$((mut + 1)) 73 echo "FAIL $1: sed did not change the source" 74 fail=1 75 elif build "$out/$1.om" "$out/$1"; then 76 mutant "$out/$1" "$3" "$1" 77 else 78 mut=$((mut + 1)) 79 fail=1 80 fi 81 } 82 83 if ! build "$lib" "$out/driver"; then 84 echo "X25519 FAIL build" 85 exit 1 86 fi 87 echo "omc $(sha256sum "$omc" | cut -d' ' -f1)" 88 echo "x25519.om $(sha256sum "$lib" | cut -d' ' -f1)" 89 echo "driver $(sha256sum "$out/driver" | cut -d' ' -f1)" 90 91 for v in rfc7748 wycheproof; do 92 run "$out/driver" "$here/vectors/$v.txt" "$v" 93 n=$(calls "$out/$v.log") 94 vectors=$((vectors + ${n:-0})) 95 [ "$v" = wycheproof ] && wyche=${n:-0} 96 done 97 if [ "${X25519_ITER1M:-0}" = 1 ]; then 98 t0=$(date +%s) 99 run "$out/driver" "$here/vectors/rfc7748-iter1m.txt" rfc7748-iter1m 100 t1=$(date +%s) 101 echo "TIME rfc7748-iter1m: $((t1 - t0)) s wall" 102 n=$(calls "$out/rfc7748-iter1m.log") 103 vectors=$((vectors + ${n:-0})) 104 else 105 echo "NOTE rfc7748-iter1m not run (opt-in: X25519_ITER1M=1)" 106 fi 107 108 # negative control: one input byte of the first RFC 7748 section 5.2 vector flipped (u byte 0 e6 -> e7) 109 sed 's/^\(X 0 `a546e36b`[0-9a-f]* \)e6db/\1e7db/' "$here/vectors/rfc7748.txt" > "$out/neg-u.txt" 110 if cmp -s "$here/vectors/rfc7748.txt" "$out/neg-u.txt"; then 111 echo "FAIL negative-control: sed did not change the vectors" 112 fail=1 113 else 114 mutant "$out/driver" "$out/neg-u.txt" negative-control 115 fi 116 117 # expectation mutant: the first ZeroSharedSecret line expected to return 0 instead of 1 118 awk 'BEGIN { done = 0 } !done && /^X 1 / { sub(/^X 1 /, "X 0 "); done = 1 } { print }' \ 119 "$here/vectors/wycheproof.txt" > "$out/mut-expect.txt" 120 mutant "$out/driver" "$out/mut-expect.txt" mutant-expectation 121 122 # library mutants 123 libmut mut-a24 's/^const XCA24 ulong 121665$/const XCA24 ulong 121666/' "$here/vectors/rfc7748.txt" 124 libmut mut-step 's/^x25519_fsub w XCTD XCX3 XCZ3$/x25519_fadd w XCTD XCX3 XCZ3/' "$here/vectors/rfc7748.txt" 125 libmut mut-clamp 's/^put e 31 or and get e 31 127 64$/put e 31 and get e 31 127/' "$here/vectors/wycheproof.txt" 126 libmut mut-zero 's/^z = xor shr or z sub 0 z 63 1$/z = shr or z sub 0 z 63/' "$here/vectors/wycheproof.txt" 127 libmut mut-canon 's/^c = ulong 19$/c = ulong 0/' "$here/vectors/wycheproof.txt" 128 129 # timing sanity (informational, not a proof of constant time): clamped low and high Hamming weight 130 # scalars, after one discarded warm-up series (CPU clock ramp), interleaved low high high low so 131 # drift falls on both; sums per weight 132 n=${X25519_BENCH_N:-200} 133 u=`e6db6867583030db3594c1a424b15f7c726624ec26b3353b10a903a6d0ab1c4c` 134 lo=`0000000000000000000000000000000000000000000000000000000000000040` 135 hi=ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 136 printf 'T %s %s %s\n' "$n" "$hi" "$u" "$n" "$lo" "$u" "$n" "$hi" "$u" "$n" "$hi" "$u" "$n" "$lo" "$u" \ 137 > "$out/timing.txt" 138 $nice "$out/driver" < "$out/timing.txt" > "$out/timing.log" 2>&1 || true 139 tlo=$(awk '/^TIME line [25] / { s += $7; c++ } END { if (c == 2) print s }' "$out/timing.log") 140 thi=$(awk '/^TIME line [34] / { s += $7; c++ } END { if (c == 2) print s }' "$out/timing.log") 141 if [ -n "$tlo" ] && [ -n "$thi" ]; then 142 echo "TIME low-weight scalar (clamped weight 1): $((2 * n)) calls, $tlo ns, $((tlo / (2 * n))) ns per call" 143 echo "TIME high-weight scalar (clamped weight 252): $((2 * n)) calls, $thi ns, $((thi / (2 * n))) ns per call" 144 else 145 echo "FAIL timing: $(cat "$out/timing.log")" 146 fail=1 147 fi 148 149 if [ "$fail" -ne 0 ] || [ "$mutok" -ne "$mut" ]; then 150 echo "X25519 FAIL vectors=$vectors (wycheproof=$wyche) mutants=$mutok/$mut" 151 exit 1 152 fi 153 echo "X25519 PASS vectors=$vectors (wycheproof=$wyche) mutants=$mutok/$mut"