Merge pull request #716 from Foundation-Devices/sft-7344-simulator-random-bytes
What changed, and why it matters
This commit fixes a weakness in the software simulator of the Passport hardware wallet. Previously, the simulator's random number generator was seeded with the system boot time, which could make simulated private keys or seeds guessable by someone who knew roughly when the simulator started. The change now reads randomness directly from the host computer's /dev/urandom. The commit message and documentation explicitly warn that the simulator is not a real hardware wallet and should never hold real funds.
No action needed for hardware wallet users. For developers using the simulator, ensure you are on a commit that includes this fix and continue to treat the simulator as unsafe for real funds or production seed generation. Consider auditing any other simulator-only code paths that may substitute weak entropy for hardware-backed randomness.
Security signals we found
Weak RNG seeding in simulator removed
Simulator entropy now sourced from /dev/urandom
Explicit short-read failure added to prevent silent fallback
Documentation warns simulator is not a hardware wallet and should not hold real funds
Evidence from the diff
The patch removes a simulator-only RNG initialization that seeded MicroPython’s urandom with ticks_ms() (boot time in milliseconds). It replaces randint-based byte generation with a direct read from /dev/urandom, plus a loud failure if the read is short. The documentation is updated to explain that the simulator lacks hardware entropy sources and is not safe for real funds. The fix only affects the Unix simulator build, not the firmware that runs on actual Passport hardware.
Changed components
simulator/sim_modules/passport/__init__.pysimulator/SIMULATOR.mdInspect captured patch +16 / −8
### simulator/SIMULATOR.md
@@ -26,6 +26,8 @@ The backend of the simulator is the standard MicroPython runtime with the Passpo
* **Secure Element** - The actual Passport hardware has an ATECC608A/B chip, but on the Unix Runtime, we replace that with a simple module that implements similar features. It is NOT secure at all and the functionality this module provides to the Unix Runtime is limited.
+* **Entropy** - The hardware mixes an avalanche noise source, the MCU TRNG and the Secure Element. The Simulator has none of those and reads `/dev/urandom` instead. That is fine for exercising the UI, but the Simulator is not a hardware wallet: **never put real funds in a wallet whose seed was generated here.**
+
* **SPI Flash** - The Simulator provides a memory buffer to simulate SPI flash.
* **Red/Blue LEDs** - The Secure Element can turn on either the blue or red LED. The simulator needs to be notified when the status of the LEDs changes. This is done through another Unix pipe.
### simulator/sim_modules/passport/__init__.py
@@ -5,8 +5,6 @@
#
import sys
-from urandom import randint, seed
-from utime import ticks_ms
IS_SIMULATOR = True
IS_COLOR = sys.argv[6] == 'color'
@@ -21,14 +19,22 @@ class Noise:
ALS = 8
ALL = AVALANCHE | MCU | SE | ALS
- def __init__(self):
- v = ticks_ms()
- # print('Initialize RNG with seed = {}'.format(v))
- seed(v)
-
def random_bytes(self, buf, _source):
+ # Read host entropy straight from the kernel. This used to be urandom
+ # seeded with ticks_ms(), which made anything the simulator generated
+ # reproducible from the boot time it happened at. The unix port does not
+ # define MICROPY_PY_URANDOM_SEED_INIT_FUNC, so dropping the explicit
+ # seed would have left a fixed default rather than fixing it.
+ with open('/dev/urandom', 'rb') as f:
+ data = f.read(len(buf))
+
+ # Fail loudly. Falling back to a seeded PRNG is the thing being fixed.
+ if len(data) != len(buf):
+ raise OSError('short read of host entropy: wanted {}, got {}'.format(
+ len(buf), len(data)))
+
for i in range(len(buf)):
- buf[i] = randint(0, 255)
+ buf[i] = data[i]
class Powermon:Why this scored 49/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.