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 / wycheproof / ledger-nc.sh
| 1 | #!/bin/sh |
| 2 | # SPDX-License-Identifier: Apache-2.0 |
| 3 | # Negative controls for ledger.sh. Each control runs ledger.sh on a scratch copy of om/tls/test (and |
| 4 | # build/tls) with one planted defect, and must make it exit 1: |
| 5 | # row one ledger.tsv row deleted (a JSON file is no longer accounted for) |
| 6 | # fail "FAIL <label>" appended to the first run row's suite log |
| 7 | # header the JSON sha256 in that row's conversion header replaced by zeros |
| 8 | # Usage: sh om/tls/test/wycheproof/ledger-nc.sh WYCHEPROOF_DIR LOGDIR |
| 9 | # Prints "LEDGER-NC <name> rc=N detected|MISSED" per control, then LEDGER-NC PASS|FAIL; exit 0 or 1. |
| 10 | set -u |
| 11 | wyc=${1:?usage: ledger-nc.sh WYCHEPROOF_DIR LOGDIR} |
| 12 | logs=${2:?usage: ledger-nc.sh WYCHEPROOF_DIR LOGDIR} |
| 13 | here=$(cd "$(dirname "$0")" && pwd) |
| 14 | root=$(cd "$here/../../../.." && pwd) |
| 15 | tmp=$(mktemp -d) || exit 1 |
| 16 | trap 'rm -rf "$tmp"' EXIT |
| 17 | # first row with a suite, a label and a committed conversion |
| 18 | row=$(awk -F'\t' '!/^#/ && $3 != "-" && $5 != "-" { print; exit }' "$here/ledger.tsv") |
| 19 | json=$(printf '%s\n' "$row" | cut -f1) |
| 20 | suite=$(printf '%s\n' "$row" | cut -f3) |
| 21 | label=$(printf '%s\n' "$row" | cut -f4) |
| 22 | vec=$(printf '%s\n' "$row" | cut -f5) |
| 23 | [ -n "$json" ] || { echo "LEDGER-NC FAIL no run row in ledger.tsv"; exit 1; } |
| 24 | sum=$(sha256sum "$wyc/testvectors_v1/$json" | cut -d' ' -f1) |
| 25 | bad=0 |
| 26 | ctl() { |
| 27 | name=$1 |
| 28 | rm -rf "$tmp/t" |
| 29 | mkdir -p "$tmp/t/om/tls" "$tmp/t/build/tls" "$tmp/t/logs" |
| 30 | cp -R "$root/om/tls/test" "$tmp/t/om/tls/" |
| 31 | [ -d "$root/build/tls" ] && cp -R "$root/build/tls/." "$tmp/t/build/tls/" |
| 32 | cp -R "$logs/." "$tmp/t/logs/" 2>/dev/null |
| 33 | t=$tmp/t/om/tls/test |
| 34 | case $name in |
| 35 | row) grep -vF "$json " "$t/wycheproof/ledger.tsv" > "$tmp/x" && cp "$tmp/x" "$t/wycheproof/ledger.tsv" ;; |
| 36 | fail) echo "FAIL $label: planted by ledger-nc.sh" >> "$tmp/t/logs/$suite.log" ;; |
| 37 | header) grep -q "$sum" "$t/$vec" || { echo "LEDGER-NC header: $sum not in $vec"; bad=1; return; } |
| 38 | sed "s/$sum/0000000000000000000000000000000000000000000000000000000000000000/" "$t/$vec" > "$tmp/x" && |
| 39 | cp "$tmp/x" "$t/$vec" ;; |
| 40 | esac |
| 41 | sh "$t/wycheproof/ledger.sh" "$wyc" "$tmp/t/logs" > "$tmp/$name.out" 2>&1 |
| 42 | rc=$? |
| 43 | if [ "$rc" -eq 1 ]; then |
| 44 | echo "LEDGER-NC $name rc=$rc detected ($(tail -1 "$tmp/$name.out"))" |
| 45 | else |
| 46 | echo "LEDGER-NC $name rc=$rc MISSED ($(tail -1 "$tmp/$name.out"))" |
| 47 | bad=1 |
| 48 | fi |
| 49 | } |
| 50 | echo "LEDGER-NC row=$json suite=$suite label=$label vectors=$vec" |
| 51 | for c in row fail header; do ctl "$c"; done |
| 52 | if [ "$bad" -eq 0 ]; then echo "LEDGER-NC PASS"; exit 0; fi |
| 53 | echo "LEDGER-NC FAIL" |
| 54 | exit 1 |