Bitcoin Forum
November 20, 2026, 09:18:30 AM *
News: Latest Bitcoin Core release: 32.1 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: [Tool] How (Fake) Whitening Functions Disguise Weak PRNGs & TRNGs  (Read 6 times)
mixoftix (OP)
Full Member
***
Online Online

Activity: 145
Merit: 195

[Curiousity Lab]


View Profile WWW
Today at 08:48:46 AM
 #1

Disclaimer: Educational and diagnostic tool only—passing statistical p-value thresholds never proves cryptographic min-entropy.



I just published an updated edition of my client-side workshop of NIST SP 800-22 RNG Test Suite:
https://mixoftix.net/workshops/nist_sp_800_22.asp

The Core Problem: When a TRNG Silently Becomes a PRNG
In hardware True Random Number Generators (TRNGs), a conditioning or "whitening" stage is normally meant to remove minor physical bias from an analog noise source without masking a dead or degraded entropy core. However, when a hardware module uses an aggressive stream-cipher or PRNG-style whitening filter—or deliberately hides a weak entropy source behind a deterministic mixer—it effectively converts a broken TRNG into a standard PRNG:

  • Loss of True Unpredictability: Even commercial or corporate TRNG modules can silently lose their physical entropy quality if a stuck oscillator, thermal drift, or clock-coupling flaw is masked by heavy post-processing.
  • Why Statistical Tests Fail to Catch It: Standard batteries like NIST SP 800-22 only measure distributional uniformity (p-values). A shallow 32-bit mixer seeded with near-zero entropy will pass every statistical check while remaining completely deterministic.
  • What a Flawed TRNG Brings Us: In cryptographic key or seed generation, a whitened-over hardware failure gives the user full confidence ("all NIST tests passed!") while shrinking the actual search space down to a small internal state or predictable counter—opening the door to state-recovery and private-key reconstruction attacks.

The Other Side of the Problem: When a Weak PRNG Looks Cryptographically Safe
Software Pseudo-Random Number Generators (PRNGs)—such as JavaScript's Math.random(), Linear Congruential Generators (LCGs), or Xorshift—are deterministic math formulas built for speed and simulation, not secrecy. When developers use them for key generation or wrap them in an extra whitening pass, they create a dangerous illusion:

  • Deterministic State Collapse: Even if a PRNG outputs millions of balanced bits, its entire sequence is locked to a small internal seed or state (such as 32-bit, 64-bit, or 128-bit XorShift128+). Once an attacker observes a handful of outputs or narrows down the seed timestamp, every past and future bit can be reconstructed.
  • Why Statistical Tests Fail to Catch It: Modern PRNGs are specifically engineered to pass statistical batteries like NIST SP 800-22. Passing every p-value threshold only proves the algorithm distributes 0s and 1s evenly—not that its internal state is resistant to algebraic or solver-based state recovery.
  • What a Flawed PRNG Brings Us: In browser wallets or custom key generators, relying on non-cryptographic PRNGs (even when disguised behind extra hashing or whitening) produces valid-looking Bitcoin addresses whose private keys can be brute-forced or mathematically solved—the exact class of flaw behind several real-world wallet drains.


How This Tool Demonstrates the Flaw (Two-Stage Pipeline)
To make this visible, I separated the workshop into two distinct stages:

  • Stage 1 — Raw Entropy Input: Generate or paste raw sequences in Binary (0/1), Dice (1–6) (using unbiased odd/even parity mapping), or Hex (0–9A–F), or load a binary/text file.
  • Stage 2 — Whitening / Conditioning Layer: Pass that exact raw sequence through 11 selectable filters—ranging from No Whitening (Raw Entropy) and failure modes (Low Entropy, Periodic Pattern, Biased Hidden) to 32-bit toy mixers (Fake AES-CTR, Fake ChaCha, XOR Shift, Hash-Counter PRNG).
  • Full 15-Test NIST Battery: Evaluates Monobit Frequency, Block Frequency, Runs, Longest Run, 32×32 GF(2) Matrix Rank, Mixed-Radix FFT, Template Matching, Maurer's Universal, Berlekamp–Massey Linear Complexity, Serial, Approximate Entropy, Cumulative Sums, and Random Excursions.

Try It Yourself — Three Experiments to Run:

1. Exposing a Broken TRNG Masked by a Fake Whitener
  • Select Very Poor entropy (a monotonic millisecond timer × wrapping 10-bit counter) and generate 1,000,000 bits.
  • Evaluate with = No Whitening (Raw Entropy) — the raw hardware flaw is immediately exposed across multiple tests.
  • Switch Whitening to * Fake AES-CTR or * Fake ChaCha and re-evaluate — every p ≥ 0.01 test turns green, illustrating how a whitening filter can disguise a broken TRNG as a healthy one.

2. Testing Native JS Simple Mode (Math.random()) — General-Purpose PRNG
  • Select Simple entropy (which calls JavaScript's native Math.random()), leave Whitening on = No Whitening (Raw Entropy), and generate 1,000,000 bits.
  • Per ECMAScript and MDN specifications, Math.random() is explicitly not cryptographically secure (modern browsers implement it with XorShift128+, whose internal state can be solved from a handful of outputs).
  • Yet when you run the NIST suite, Math.random() routinely passes every single test—proving why web wallets that fall back to Math.random() (or weak polyfills) look "statistically random" while generating predictable Bitcoin private keys.

3. Testing Native JS Crypto Mode (crypto.getRandomValues()) — Web Crypto CSPRNG
  • Select Crypto entropy (which calls the Web Crypto API's window.crypto.getRandomValues()), keep = No Whitening, and evaluate 1,000,000 bits across several fresh generations.
  • Even though crypto.getRandomValues() is the browser's intended interface for security-sensitive randomness, watch two things happen: first, at NIST's α = 0.01 threshold, individual tests will occasionally dip below p = 0.01 (~14% chance of at least one test flagging across 15 tests on a single run); second, in a browser-based JS wallet, your key generation is still completely blind to the underlying OS entropy pool, browser runtime, and injected scripts/extensions.
  • This is why relying on a browser JS environment for generating serious Bitcoin key-pairs—rather than verifiable, air-gapped physical entropy—carries structural trust risks that no statistical test suite can rule out.

Feedback, test vectors, and technical critiques from the board are welcome.

#Personal_TRNG for concrete secure wallets..
https://github.com/mixoftix/personal_trng_firmware
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!