fix(random): remixture TRNG on rand_below retry; Linux getrandom - #65
Conversation
|
Follow-up commit: Pairs with Coldcard firmware change to pass |
|
Friendly bump — related entropy hardening across libngu#65 and Coldcard firmware#697 (TRNG remix on reject, Linux getrandom, full SE hash reseed). Happy to split or retarget if you want a different shape. |
|
rebase, will merge |
CHIP_TRNG_32 on Linux mapped to glibc random(), which is not a TRNG and is typically unseeded in simulator / Linux libngu builds. Every consumer (drbg_seed_from_chip -> my_random_bytes, including the rejection retry in _rand_below) therefore derives from a deterministic sequence on Linux. Map CHIP_TRNG_32 to getrandom(2) instead, failing hard on error. Co-authored-by: Cursor <cursoragent@cursor.com> Signed-off-by: SashaMIT <sash@ela.city>
59f3dd3 to
bb6d30a
Compare
|
Rebased onto current master (e9d5e80). Note: your my_random_bytes() refactor of the _rand_below retry already covers the re-mixture half of this PR, so I've rescoped to the still-live half: CHIP_TRNG_32 on Linux mapped to unseeded glibc random(), which makes drbg_seed_from_chip deterministic on Linux/sim builds. Now maps to getrandom(2), hard-failing on error. |
Summary
Two related entropy hygiene fixes in
ngu/random.c:_rand_below/uniform: After the first sample, rejection retries previously remixed onlymy_yasmarang()and never calledCHIP_TRNG_32()again. Retries now remixture TRNG each iteration.CHIP_TRNG_32: Was mapped to glibcrandom()with nosrandom/getrandom. Now usesgetrandom(2)(fails hard on error, same pattern as the duplicate-TRNG check inmy_random_bytes).Impact
ngu.random.uniformconsumers (Coldcard firmware uses this for Key Teleport / PIN scramble / web2fa digits, etc.).Test plan
makefile.unix/ MicroPython unix portuniformstill returns< mxrandom()Elacity CodeRED Amber review (portal #51, #53). Coordinating with Coinkite on firmware-side siblings separately.