From 43f7a5cf5acd18a0b3d406de0896a5e2e07a171c Mon Sep 17 00:00:00 2001 From: SashaMIT Date: Tue, 4 Aug 2026 19:29:00 +0700 Subject: [PATCH] fix: feed full SE hash into ngu.random.reseed rng_seeding previously truncated sha256d(SE1||SE2) to 32 bits before reseed, which also only overwrote one yasmarang state word. Pass the full digest bytes (needs libngu reseed(bytes) from switck/libngu#65). Co-authored-by: Cursor --- shared/mk4.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/shared/mk4.py b/shared/mk4.py index 3a3e229d..0f4df9eb 100644 --- a/shared/mk4.py +++ b/shared/mk4.py @@ -38,15 +38,15 @@ def make_psram_fs(): def rng_seeding(): # seed our RNG with entropy from secure elements - import callgate, ngu, ustruct + import callgate, ngu a = callgate.read_rng(1) # SE1 b = callgate.read_rng(2) # SE2 - n = ngu.hash.sha256d(a+b) - n, = ustruct.unpack('I', n[0:4]) - - ngu.random.reseed(n) + # Pass full sha256d digest. Truncating to 32 bits left most SE entropy + # on the floor and libngu reseed(int) only overwrote one yasmarang word. + # Requires libngu reseed(bytes) support (switck/libngu#65). + ngu.random.reseed(ngu.hash.sha256d(a+b)) def init0():