Repository navigation
Expand file tree
/
Copy pathstats
More file actions
executable file
·99 lines (89 loc) · 3.38 KB
/
Copy pathstats
File metadata and controls
executable file
·99 lines (89 loc) · 3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/env bash
# Standalone statistical sanity analysis. This is evidence against gross
# implementation mistakes, not evidence of cryptographic security.
set -u
root="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
if [ "${1-}" = --ziggurat ]; then shift; exec "$root/experiments/stats-ziggurat" "$@"; fi
lua_cli="${RANDOM_STATS_LUA_CLI:-$root/luajit/random}"
zig_options=()
[ "$(uname -s)" != Linux ] || zig_options=(--variant gnu)
c_cli="${RANDOM_STATS_ZIG_CLI:-$("$root/build-support/product-path" zig "${zig_options[@]}")/bin/randomz}"
rust_cli="${RANDOM_STATS_RUST_CLI:-$("$root/build-support/product-path" rust)/bin/randomr}"
lean_cli="${RANDOM_STATS_LEAN_CLI:-$("$root/build-support/product-path" lean)/bin/randoml}"
usage() {
cat <<'EOF'
Usage: ./stats [--all | --lua | --c | --rust | --lean | --roc | --cli PATH | --ziggurat [N]]
Runs raw-stream and distribution sanity checks without writing sample data to
disk. Default: all available implementations, including Roc on Linux.
--ziggurat compares three experimental samplers across four shapes (default 96M).
Environment:
RANDOM_STATS_BYTES=N raw bytes per stream (default 4194304)
RANDOM_STATS_SAMPLES=N values per distribution (default 50000)
RANDOM_STATS_SKIP_TRUE=1 omit the nondeterministic OS-CSPRNG sample
FAST=1 use 262144 bytes / 10000 distribution values
RANDOM_STATS_SKIP_BUILD=1 use explicitly selected installed products (Nix checks)
RANDOM_STATS_{LUA,ZIG,RUST,LEAN,ROC}_CLI explicit CLI paths
EOF
}
targets=()
case "${1:---all}" in
--all)
targets=("LuaJIT oracle:$lua_cli" "Zig core / C FFI:$c_cli" "Rust core / CLI:$rust_cli" "Lean core / native CLI:$lean_cli") ;;
--lua)
targets=("LuaJIT oracle:$lua_cli") ;;
--c)
targets=("Zig core / C FFI:$c_cli") ;;
--rust)
targets=("Rust core / CLI:$rust_cli") ;;
--lean)
targets=("Lean core / native CLI:$lean_cli") ;;
--roc)
targets=() ;;
--cli)
if [ "$#" -ne 2 ]; then usage >&2; exit 2; fi
targets=("selected CLI:$2") ;;
-h|--help)
usage; exit 0 ;;
*)
usage >&2; exit 2 ;;
esac
if [ "${1:---all}" = --roc ] ||
{ [ "${1:---all}" = --all ] && [ "$(uname -s)" = Linux ]; }; then
if [ "${RANDOM_STATS_SKIP_BUILD:-0}" != 1 ]; then "$root/build" --impl roc >&2 || exit 1; fi
roc_cli="${RANDOM_STATS_ROC_CLI:-$("$root/build-support/product-path" roc)/bin/randomroc}"
targets+=("Roc core / C FFI:$roc_cli")
fi
if [ "${RANDOM_STATS_SKIP_BUILD:-0}" != 1 ]; then
if [ "${1:---all}" = "--all" ] || [ "${1:---all}" = "--c" ]; then
"$root/build" --impl zig "${zig_options[@]}" >&2 || exit 1
fi
if [ "${1:---all}" = "--all" ] || [ "${1:---all}" = "--lean" ]; then
"$root/build" --impl lean >&2 || exit 1
fi
if [ "${1:---all}" = "--all" ] || [ "${1:---all}" = "--rust" ]; then
"$root/build" --impl rust >&2 || exit 1
fi
fi
failed=0
for entry in "${targets[@]}"; do
label="${entry%%:*}"
cli="${entry#*:}"
if [ ! -x "$cli" ]; then
echo "stats: executable not found: $cli" >&2
failed=$((failed + 1))
continue
fi
echo ""
echo "=== $label ($cli) ==="
luajit "$root/tests/stats.lua" "$cli"
rc=$?
if [ "$rc" -ne 0 ]; then failed=$((failed + 1)); fi
done
if [ "$failed" -ne 0 ]; then
echo "" >&2
echo "Statistical sanity analysis FAILED for $failed target(s)" >&2
exit "$failed"
fi
echo ""
echo "Statistical sanity analysis PASSED for ${#targets[@]} target(s)"
echo "This detects gross bias/shape regressions; it does not certify CSPRNG security."