481 / 736RNG

Random Number Generator

Random-number generation

When a wallet creates a new secret, it needs numbers nobody else can guess. A random number generator helps supply them, but not every generator is suitable for protecting money.

A Random Number Generator, or RNG, is a device or program that produces numerical values. A wallet needs a cryptographically secure generator: knowing earlier results or the creation time must not let an attacker feasibly predict the new secret. This depends on the entropy source, the algorithm and how the application uses it. Here, entropy describes the uncertainty an attacker still has about the result.

Imagine a wallet deriving its secret from the current time alone. The result might look complicated, but someone who knows when you created it would have far fewer possibilities to try. RFC 4086 warns about precisely such predictable inputs. A generator suitable for games or simulations may therefore be unsuitable for keys. Even a good statistical distribution does not by itself establish security. [2]

Several parts usually work together. A source supplies uncertainty, its output is processed as needed, and a cryptographic deterministic generator produces further values from a secret internal state. Deterministic means that the same internal state and inputs produce the same result; that is why the state must remain secret. The application requests them through a system interface. There need not be a new physical measurement for every returned bit. NIST SP 800-90C describes combining generators under 90A with sources under 90B. [1]

With BIP39, the basis for wallet recovery is created before the first word appears: the generator produces 128 to 256 bits of initial entropy. A bit is a basic unit of information, a zero or a one; what matters is that an attacker cannot predict the resulting sequence. A checksum, a short value that helps detect some transcription errors, is added, and the whole is converted into recovery words. You can supplement them with a passphrase, an additional secret text. The PBKDF2 function derives a 512-bit seed from these inputs: the secret starting value used to derive the wallet’s keys. Neither a longer output nor a checksum adds missing randomness. That is why you should not choose your own recovery words. [6]

A device must detect faults such as a noise source starting to repeat the same value. NIST SP 800-90B therefore requires source checks at startup and during operation, and handling of detected failures. An error cannot simply be ignored while the output is still presented as verified randomness. These checks monitor the source; they do not guarantee the security of the entire wallet. [3]

A deterministic generator keeps internal state from which it calculates further results. NIST SP 800-90A describes instantiation, generation, adding fresh entropy (reseed), and termination. If the state leaks, merely calling the generator again may not restore security. Recovery needs an appropriate process and new entropy unknown to the attacker. It does not take previously exposed keys out of their hands. [7]

You do not need to program an RNG yourself. Look for documented generation and error handling in the particular wallet version. The words “hardware” or “offline” alone do not establish this. A review must cover the source, algorithm, initialization and application interface. Even a properly generated secret loses its protection if you later disclose its backup. [1] [2]

By default, Linux getrandom() waits for the urandom source to initialize; with GRND_NONBLOCK it can return EAGAIN instead. After initialization, a urandom request of no more than 256 bytes is guaranteed to return the full amount without signal interruption. Larger requests do not have that guarantee. The program must correctly check the return status and the number of bytes actually received. [4]

Web Crypto provides getRandomValues() to fill a supported integer array with cryptographically strong values. Above 65536 bytes it throws QuotaExceededError. For keys of supported algorithms, the specification recommends generateKey(); this is not a universal Bitcoin wallet generator. Even correct API use does not establish a page’s trustworthiness: its code may have access to the generated secret. [5]

For the clearest picture, read this entry together with Cryptographic Entropy, CSPRNG, Seed Generation, Brute Force Search Space. The reverse links also lead from CSPRNG, Deterministic RNG, True Random Number Generator, Seed Generation.

DOC · 001NIST SP 800-90C — RBG constructionsSpecification DOC · 002RFC 4086 — Unpredictability and weak inputsSpecification DOC · 003NIST SP 800-90B — Source health and failure handlingSpecification DOC · 004Linux getrandom(2) — Initialization and return behaviorDocumentation DOC · 005W3C Web Crypto — getRandomValues and key generationSpecification DOC · 006BIP39 — Initial entropy and mnemonic-to-seed derivationSpecification DOC · 007NIST SP 800-90A Rev. 1 — DRBG lifecycle and reseedingSpecification
Revised: Source-first · No investment advice