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 / wycheproof / ledger-nc.sh

54 lines · 2488 bytes Raw Blame History
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.
10set -u
11wyc=${1:?usage: ledger-nc.sh WYCHEPROOF_DIR LOGDIR}
12logs=${2:?usage: ledger-nc.sh WYCHEPROOF_DIR LOGDIR}
13here=$(cd "$(dirname "$0")" && pwd)
14root=$(cd "$here/../../../.." && pwd)
15tmp=$(mktemp -d) || exit 1
16trap 'rm -rf "$tmp"' EXIT
17# first row with a suite, a label and a committed conversion
18row=$(awk -F'\t' '!/^#/ && $3 != "-" && $5 != "-" { print; exit }' "$here/ledger.tsv")
19json=$(printf '%s\n' "$row" | cut -f1)
20suite=$(printf '%s\n' "$row" | cut -f3)
21label=$(printf '%s\n' "$row" | cut -f4)
22vec=$(printf '%s\n' "$row" | cut -f5)
23[ -n "$json" ] || { echo "LEDGER-NC FAIL no run row in ledger.tsv"; exit 1; }
24sum=$(sha256sum "$wyc/testvectors_v1/$json" | cut -d' ' -f1)
25bad=0
26ctl() {
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}
50echo "LEDGER-NC row=$json suite=$suite label=$label vectors=$vec"
51for c in row fail header; do ctl "$c"; done
52if [ "$bad" -eq 0 ]; then echo "LEDGER-NC PASS"; exit 0; fi
53echo "LEDGER-NC FAIL"
54exit 1