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/entropy.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 / entropy.sh` 53 lines ยท 3297 bytes Raw Blame History 1 #!/bin/sh 2 # SPDX-License-Identifier: Apache-2.0 3 # NIST SP 800-90B entropy assessment of the bytes fips.om draws (Linux getrandom), with the NIST 4 # reference tool usnistgov/SP800-90B_EntropyAssessment (pinned commit below, built separately). 5 # What this grades: the Linux kernel's getrandom output, which the kernel has already conditioned 6 # (ChaCha20 CRNG). It is not an Omega noise source, and it does not replace an Entropy Source 7 # Validation (ESV): that would need a kernel/platform entropy certificate. 8 # usage: sh om/tls/test/fips/entropy.sh OMC EA_CPP_DIR [OUTDIR] 9 # EA_CPP_DIR holds ea_non_iid, ea_iid and ea_restart built from SP800-90B_EntropyAssessment 10 # `87c104d0ed4cbc96103e7b8b38d6f2c7e0a6b289` (cpp/, `make`). 11 # 1. entropy.om writes 1,000,000 samples (one process) -> samples.bin 12 # 2. 1000 restarts: 1000 separate processes of 1000 samples each -> restart.bin (row dataset) 13 # 3. ea_non_iid and ea_iid on samples.bin (8 bits per sample) 14 # 4. ea_restart -n with the non-IID H_I and ea_restart -i with the IID H_I on restart.bin 15 # Final line: ENTROPY PASS non_iid=H iid=H iid_tests=passed restart_iid=H restart_non_iid=H, or 16 # ENTROPY FAIL / ENTROPY NOT_RUN (tool missing). 17 set -eu 18 omc=${1:?usage: entropy.sh OMC EA_CPP_DIR [OUTDIR]} 19 ea=${2:?usage: entropy.sh OMC EA_CPP_DIR [OUTDIR]} 20 here=$(cd "$(dirname "$0")" && pwd) 21 lib=$(cd "$here/../.." && pwd) 22 root=$(cd "$lib/../.." && pwd) 23 out=${3:-"$root/build/tls/entropy"} 24 nice="nice -n 19 ionice -c3" 25 for t in ea_non_iid ea_iid ea_restart; do 26 [ -x "$ea/$t" ] || { echo "ENTROPY NOT_RUN: $ea/$t missing"; exit 3; } 27 done 28 mkdir -p "$out" 29 $nice sh "$lib/build.sh" "$omc" "$here/entropy.om" "$out/entropy" 2> "$out/build.err" || { echo "ENTROPY FAIL build: $(cat "$out/build.err")"; exit 1; } 30 cd "$out" 31 $nice ./entropy `1000000` > samples.bin 32 : > restart.bin 33 i=0 34 while [ "$i" -lt 1000 ]; do ./entropy 1000 >> restart.bin; i=$((i + 1)); done 35 [ "$(wc -c < samples.bin)" -eq `1000000` ] && [ "$(wc -c < restart.bin)" -eq `1000000` ] || { echo "ENTROPY FAIL: sample counts"; exit 1; } 36 sha256sum samples.bin restart.bin 37 $nice "$ea/ea_non_iid" -v samples.bin 8 > non_iid.txt 2>&1 38 $nice "$ea/ea_iid" -v samples.bin 8 > iid.txt 2>&1 39 hn=$(awk -F': ' '/^min\(H_original, 8 X H_bitstring\)/ { print $2 }' non_iid.txt) 40 hi=$(awk -F': ' '/^min\(H_original, 8 X H_bitstring\)/ { print $2 }' iid.txt) 41 grep -q '^\*\* Passed IID permutation tests' iid.txt && it=passed || it=failed 42 [ -n "$hn" ] && [ -n "$hi" ] || { echo "ENTROPY FAIL: no estimate (non_iid=$hn iid=$hi)"; exit 1; } 43 $nice "$ea/ea_restart" -n -v restart.bin 8 "$hn" > restart_non_iid.txt 2>&1 && rn=0 || rn=$? 44 $nice "$ea/ea_restart" -i -v restart.bin 8 "$hi" > restart_iid.txt 2>&1 && ri=0 || ri=$? 45 rhn=$(awk -F': ' '/^min\(H_r, H_c, H_I\)/ { print $2 }' restart_non_iid.txt) 46 rhi=$(awk -F': ' '/^min\(H_r, H_c, H_I\)/ { print $2 }' restart_iid.txt) 47 if [ "$rn" -eq 0 ] && [ "$ri" -eq 0 ] && [ "$it" = passed ] && [ -n "$rhn" ] && [ -n "$rhi" ] \ 48 && grep -q 'Restart Sanity Check Passed' restart_non_iid.txt && grep -q 'Restart Sanity Check Passed' restart_iid.txt; then 49 echo "ENTROPY PASS non_iid=$hn iid=$hi iid_tests=$it restart_iid=$rhi restart_non_iid=$rhn" 50 exit 0 51 fi 52 echo "ENTROPY FAIL non_iid=$hn iid=$hi iid_tests=$it restart_iid=$rhi (rc $ri) restart_non_iid=$rhn (rc $rn)" 53 exit 1