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/fips/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 / fips / run.sh` 146 lines ยท 7447 bytes Raw Blame History 1 #!/bin/sh 2 # SPDX-License-Identifier: Apache-2.0 3 # Test suite for om/tls/fips.om: self-tests, SP 800-90B health tests, approved-mode DRBG wiring, 4 # the X25519 pairwise consistency test and the module error state. Tested against the FIPS 140-3 / 5 # CAVP test methods, not NIST-validated. 6 # usage: sh om/tls/test/fips/run.sh OMC 7 # 1. driver.om on the real library: every self-test passes, health-test boundaries hold, the DRBG 8 # and PCT work, and the PCT failure latches the error state (tls_connect, tls_seal, tls_open 9 # refuse with TLS_ERR_SELFTEST); `driver drbgerr` latches through a DRBG in its error state; 10 # `driver ecgenerr` latches through a failed approved-mode ECDH key generation (tls_ecgen). 11 # 2. KAT mutants: one hex digit of each known answer changed; the driver must print 12 # "REFUSED detail N" for that self-test, pass the refusal checks and exit 3. 13 # 3. Code mutants in sha2.om, drbg.om (stuck V), x25519.om and aesgcm.om: the self-tests refuse. 14 # 4. Code mutants in fips.om and tls.om (health cut-offs, PCT compare, entropy draw, refusal lines, 15 # ECDH key draw and latch): 16 # the driver reports FAIL check lines and exits 1. 17 # Final line: FIPS PASS checks=C drbgerr=D ecgenerr=E kat-mutants=K/K code-mutants=M/M, or FIPS FAIL. 18 set -eu 19 omc=${1:?usage: run.sh OMC} 20 here=$(cd "$(dirname "$0")" && pwd) 21 lib=$(cd "$here/../.." && pwd) 22 root=$(cd "$lib/../.." && pwd) 23 out="$root/build/tls/fips" 24 rm -rf "$out"; mkdir -p "$out" 25 nice="nice -n 19 ionice -c3" 26 units="sha2 hkdf drbg x25519 sha3 mlkem chacha aesgcm ec ecdh rsa x509 rev fips tls" 27 bad=0; kmut=0; kok=0; cmut=0; cok=0; checks=0; derr=0; eerr=0 28 29 say() { printf '%s\n' "$*"; } 30 fail() { say "FAIL $*"; bad=1; } 31 32 say "omc sha256 $(sha256sum "$omc" | cut -d' ' -f1)" 33 for u in $units; do say "$u.om sha256 $(sha256sum "$lib/$u.om" | cut -d' ' -f1)"; done 34 35 # build NAME [UNIT MUTATED-FILE]: compose the library (one unit optionally replaced) + driver 36 build() { 37 d="$out/$1"; mkdir -p "$d" 38 for u in $units; do cp "$lib/$u.om" "$d/"; done 39 cp "$lib/build.sh" "$d/" 40 if [ $# -ge 3 ]; then cp "$3" "$d/$2.om"; fi 41 $nice sh "$d/build.sh" "$omc" "$here/driver.om" "$d/bin" 2> "$d.err" || { say "omc refused $1: $(cat "$d.err")"; return 1; } 42 } 43 44 # run NAME ARGS...: exit code in rc, output in $out/NAME.out 45 run() { 46 n=$1; shift 47 set +e 48 $nice "$out/$n/bin" "$@" < /dev/null > "$out/$n.out" 2>&1 49 rc=$? 50 set -e 51 } 52 53 summary() { awk '$1 == "fips" && $2 == "driver:" && $4 == "checks," && $6 == "failed" { print $3, $5 }' "$1" | tail -n 1; } 54 55 build real || { say "FIPS FAIL build"; exit 1; } 56 run real 57 s=$(summary "$out/real.out") 58 if [ "$rc" -eq 0 ] && [ "${s#* }" = 0 ]; then checks=${s% *}; say "PASS driver: $(tail -n 1 "$out/real.out")" 59 else fail "driver: exit $rc: $(tr '\n' ' ' < "$out/real.out")"; fi 60 run real drbgerr 61 cp "$out/real.out" "$out/drbgerr.out" 62 s=$(summary "$out/drbgerr.out") 63 if [ "$rc" -eq 0 ] && [ "${s#* }" = 0 ]; then derr=${s% *}; say "PASS driver drbgerr: $(tail -n 1 "$out/drbgerr.out")" 64 else fail "driver drbgerr: exit $rc: $(tr '\n' ' ' < "$out/drbgerr.out")"; fi 65 run real ecgenerr 66 cp "$out/real.out" "$out/ecgenerr.out" 67 s=$(summary "$out/ecgenerr.out") 68 if [ "$rc" -eq 0 ] && [ "${s#* }" = 0 ]; then eerr=${s% *}; say "PASS driver ecgenerr: $(tail -n 1 "$out/ecgenerr.out")" 69 else fail "driver ecgenerr: exit $rc: $(tr '\n' ' ' < "$out/ecgenerr.out")"; fi 70 71 # refused NAME DETAIL: the self-tests refused with that detail and every refusal check held 72 refused() { 73 if [ "$rc" -eq 3 ] && grep -qx "REFUSED detail $2" "$out/$1.out" && ! grep -q '^FAIL' "$out/$1.out"; then 74 return 0 75 fi 76 return 1 77 } 78 79 # katmut TEXT DETAIL: change the first hex digit of text TEXT in fips.om 80 katmut() { 81 kmut=$((kmut + 1)) 82 awk -v n="$1" '$1 == "text" && $2 == n { c = substr($3, 2, 1); r = (c == "0") ? "1" : "0"; $3 = "\"" r substr($3, 3) } { print }' "$lib/fips.om" > "$out/k-$1.om" 83 cmp -s "$lib/fips.om" "$out/k-$1.om" && { fail "kat $1: mutation did not apply"; return; } 84 build "k-$1" fips "$out/k-$1.om" || { fail "kat $1: did not compile"; return; } 85 run "k-$1" 86 if refused "k-$1" "$2"; then kok=$((kok + 1)); say "PASS kat-mutant $1: REFUSED detail $2, connect/seal/open refused" 87 else fail "kat-mutant $1: exit $rc: $(tr '\n' ' ' < "$out/k-$1.out")"; fi 88 } 89 90 katmut FKS256 1 91 katmut FKS384 2 92 katmut FKS512 3 93 katmut FKH256 4 94 katmut FKH384 5 95 katmut FKHO 6 96 katmut FKGC 7 97 katmut FKED 9 98 katmut FKR1S 10 99 katmut FKR2S 11 100 katmut FKCC 12 101 katmut FKXO 13 102 katmut FKDR 14 103 katmut FKTD 15 104 105 # codemut LABEL UNIT SED EXPECT: EXPECT is "detail N" (self-test refusal) or "check N" (driver FAIL 106 # line for check N, exit 1) 107 codemut() { 108 cmut=$((cmut + 1)) 109 sed "$3" "$lib/$2.om" > "$out/c-$1.om" 110 cmp -s "$lib/$2.om" "$out/c-$1.om" && { fail "code $1: sed changed nothing"; return; } 111 build "c-$1" "$2" "$out/c-$1.om" || { fail "code $1: did not compile"; return; } 112 run "c-$1" ${5:+"$5"} 113 case "$4" in 114 detail*) if refused "c-$1" "${4#detail }"; then cok=$((cok + 1)); say "PASS code-mutant $1: REFUSED ${4}"; return; fi ;; 115 check*) if [ "$rc" -eq 1 ] && grep -q "^FAIL check ${4#check } " "$out/c-$1.out"; then cok=$((cok + 1)); say "PASS code-mutant $1: FAIL ${4}"; return; fi ;; 116 esac 117 fail "code-mutant $1: expected $4: exit $rc: $(tr '\n' ' ' < "$out/c-$1.out")" 118 } 119 120 # library code under self-test 121 codemut sha256-k0 sha2 's/0x428a2f98/0x428a2f99/' "detail 1" 122 codemut drbg-stuck-v drbg '/^fn drbg_fill /,/^end$/ s/^drbg_next st x$/e = or e 0/' "detail 14" 123 codemut x25519-a24 x25519 's/^const XCA24 ulong 121665$/const XCA24 ulong 121666/' "detail 13" 124 codemut gcm-no-decrypt aesgcm '/^fn gcm_open1 /,/^ret 0$/ s/^gcm_ctr k s part buf 0 n$/n = n/' "detail 8" 125 # health tests, PCT, entropy draw, latch and refusal lines 126 codemut rct-cutoff fips 's/^const FHRCT1 ulong 7$/const FHRCT1 ulong 8/' "check 21" 127 codemut apt-cutoff fips 's/^const FHAPT1 ulong 34$/const FHAPT1 ulong 35/' "check 24" 128 codemut apt-window fips 's/^put FPST 7 rem add p 1 FHAPTW$/put FPST 7 rem add p 1 256/' "check 24" 129 codemut ht-unused fips '/^fn fips_draw /,/^ret 0$/ s/^fips_ht ulong get b i$/n = n/' "check 15" 130 codemut pct-nocompare fips '/^fn fips_pctx /,/^end$/ s/^d = or d xor ulong get o i ulong get pub i$/d = d/' "check 70" 131 codemut latch-keep fips '/^fn fips_fail /,/^ret code$/ s/^put FPST 0 2$/put FPST 0 1/' "check 60" 132 codemut pr-no-reseed fips '/^fn fips_drbgget /,/^ret 0$/ s/^r = drbg_reseed st e$/r = ulong 0/' "check 36" 133 codemut connect-hook tls '/^e = tls_fips c$/,/^end$/d' "check 62" 134 codemut seal-refuse tls '/^fn tls_seal /,/^for i ulong 5$/ s/^if eq fips_bad 1$/if eq fips_bad 2/' "check 65" 135 codemut open-refuse tls '/^fn tls_open /,/^for i ulong 5$/ s/^if eq fips_bad 1$/if eq fips_bad 2/' "check 66" 136 codemut wipe-drbg tls '/^fn tls_wipe /,/^end$/ {/^tls_zero c TLDRBG DRSZ$/d}' "check 58" 137 codemut rand-approved tls '/^fn tls_rand /,/^end$/ s/^if eq and get c TLFL 4 0$/if eq and get c TLFL 0 0/' "check 57" 138 codemut ecgen-getrandom tls '/^fn tls_ecgen /,/^ret 0$/ s/^r = tls_rand c part d 0 nb$/r = ulong 0\nif ne random d 0 nb 0 long nb\nr = TLERAND\nend/' "check 45" 139 codemut ecgen-nolatch tls '/^fn tls_ecgen /,/^ret 0$/ {/^r = fips_fail 21$/d}' "check 71" ecgenerr 140 141 if [ "$bad" -eq 0 ] && [ "$kok" -eq "$kmut" ] && [ "$cok" -eq "$cmut" ]; then 142 say "FIPS PASS checks=$checks drbgerr=$derr ecgenerr=$eerr kat-mutants=$kok/$kmut code-mutants=$cok/$cmut" 143 exit 0 144 fi 145 say "FIPS FAIL checks=$checks drbgerr=$derr ecgenerr=$eerr kat-mutants=$kok/$kmut code-mutants=$cok/$cmut" 146 exit 1