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 / 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).
17set -eu
18omc=${1:?usage: entropy.sh OMC EA_CPP_DIR [OUTDIR]}
19ea=${2:?usage: entropy.sh OMC EA_CPP_DIR [OUTDIR]}
20here=$(cd "$(dirname "$0")" && pwd)
21lib=$(cd "$here/../.." && pwd)
22root=$(cd "$lib/../.." && pwd)
23out=${3:-"$root/build/tls/entropy"}
24nice="nice -n 19 ionice -c3"
25for t in ea_non_iid ea_iid ea_restart; do
26 [ -x "$ea/$t" ] || { echo "ENTROPY NOT_RUN: $ea/$t missing"; exit 3; }
27done
28mkdir -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; }
30cd "$out"
31$nice ./entropy 1000000 > samples.bin
32: > restart.bin
33i=0
34while [ "$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; }
36sha256sum 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
39hn=$(awk -F': ' '/^min\(H_original, 8 X H_bitstring\)/ { print $2 }' non_iid.txt)
40hi=$(awk -F': ' '/^min\(H_original, 8 X H_bitstring\)/ { print $2 }' iid.txt)
41grep -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=$?
45rhn=$(awk -F': ' '/^min\(H_r, H_c, H_I\)/ { print $2 }' restart_non_iid.txt)
46rhi=$(awk -F': ' '/^min\(H_r, H_c, H_I\)/ { print $2 }' restart_iid.txt)
47if [ "$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
51fi
52echo "ENTROPY FAIL non_iid=$hn iid=$hi iid_tests=$it restart_iid=$rhi (rc $ri) restart_non_iid=$rhn (rc $rn)"
53exit 1