PRNG State and Reseeding
You'll learn why even cryptographically secure PRNGs need fresh entropy injections over time to stay unpredictable.
Why PRNGs Need Reseeding
A CSPRNG (like we learned in lesson 288) starts with an initial entropy "seed" and uses complex algorithms to generate seemingly random output. But here's the catch: the PRNG maintains an internal state — essentially a set of values it manipulates to produce the next random number.
Think of it like a water fountain with a large tank. The initial seed fills the tank (entropy), and the fountain flows beautifully. But if you just keep drawing water without refilling, eventually patterns emerge or someone could predict what's left. Reseeding is periodically adding fresh water from an unpredictable source.
The Problem Without Reseeding
Over time, several risks emerge:
- State compromise: If an attacker learns the internal state (through memory dumps, side channels, or bugs), they can predict all future outputs
- Entropy exhaustion: Long-running systems might generate millions of keys — the initial entropy gets "stretched thin"
- Cryptanalysis advances: Theoretical weaknesses might let attackers narrow down possible states
How Reseeding Works
Modern systems periodically inject fresh entropy from hardware RNGs or OS entropy pools back into the CSPRNG state. This might happen:
- After generating a certain number of bytes
- At regular time intervals
- When new entropy becomes available from system events
The reseeding process mixes new unpredictable data into the internal state, making it computationally infeasible to predict future outputs even if the old state was compromised.
Key Takeaway: Even the best CSPRNGs must periodically reseed from true entropy sources to maintain forward security and long-term unpredictability — relying solely on an initial seed is dangerous for long-running systems.