Skip to content

Add More Entropy Sources and Checks for Random Generation - #145

Merged
odudex merged 4 commits into
masterfrom
more-entropy-sources-and-checks
Aug 18, 2026
Merged

Add More Entropy Sources and Checks for Random Generation#145
odudex merged 4 commits into
masterfrom
more-entropy-sources-and-checks

Conversation

@odudex

@odudex odudex commented Aug 18, 2026

Copy link
Copy Markdown
Owner

feat(entropy) — Entropy checks. Dice pairs a histogram estimate against a 128/256-bit target with consecutive-difference pattern check; camera gates snapshots at 5.0 bits/pixel. Both are explicitly labelled estimates of the observed distribution, not cryptographic entropy. A uniform-but-cyclic dice sequence passes the entropy check and is caught only by the pattern check.

fix(crypto) — Enable the SAR ADC entropy source around RNG reads, Although ESP-IDF's random.rst claims the opposite for chips without RF. Bracketing inside crypto_random_bytes() covers every consumer

fix(crypto) — Make crypto_random_bytes failures detectable. It returned void, so failure was structurally invisible — pin.c and nvs_secure.c fill an uninitialized key[32] and burn it straight into eFuse. Now returns a status under KERN_WARN_UNUSED_RESULT, so the compiler rejects any caller that ignores it, plus an all-zero health check for a dead RNG.

feat(crypto) — Auxiliary entropy pool fed by touch timing and camera sensor noise, folded into crypto_random_bytes by hashing so it can only ever add. Extraction ratchets the pool; stirring stays a rotate-XOR because it runs on every camera frame.

odudex added 4 commits August 18, 2026 18:14
…apture

Estimates describe the observed distribution, not cryptographic entropy, so dice pairs the histogram estimate with consecutive-difference pattern check and the camera folds the hardware RNG into the frame digest - hashed rather than XOR-ed, so an RNG that could observe the frame still cannot steer the result. Dice deliberately stays reproducible: the user must be able to verify that derivation off-device.
The void return left failure structurally invisible: pin.c and nvs_secure.c fill an uninitialized key[32] and burn it straight into eFuse, so a silent no-op would permanently provision a key made of stack garbage. Returning a status under KERN_WARN_UNUSED_RESULT makes the compiler reject any caller that ignores it. The all-zero health check catches a dead RNG, which is otherwise indistinguishable from a valid draw at the call sites that matter most.
Defense in depth behind the hardware RNG, fed by touch timing and camera sensor noise. Folding it in by hashing rather than XOR means it can only add: a worthless or attacker-known pool leaves the output exactly as strong as the RNG alone, so this is never a reason to skip the SAR ADC source. The all-zero health check stays ahead of the mix, since hashing first would make a dead RNG undetectable. Extraction ratchets the pool so a later compromise cannot recover the state behind bytes already handed out; stirring stays a rotate-XOR because it runs on every camera frame.
@odudex
odudex merged commit 68be355 into master Aug 18, 2026
15 checks passed
@odudex
odudex deleted the more-entropy-sources-and-checks branch August 27, 2026 17:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant