A topic in the Open Knowledge Graph — a free, open map of 15,290 topics and the order to learn them in.

Random Number Generation in Cryptography

Graduate Depth 97 in the knowledge graph I know this Set as goal
2topics build on this
515prerequisites beneath it
See this on the map →
Symmetric Encryption and Block CiphersHash Functions and Collision ResistancePseudorandom Generators
csprng entropy prng dev-urandom dual-ec-drbg

Core Idea

Cryptographic security depends critically on high-quality randomness for key generation, nonces, IVs, and padding. A cryptographically secure pseudorandom number generator (CSPRNG) expands a short truly random seed into a long pseudorandom stream that is computationally indistinguishable from true randomness. Entropy — genuine physical unpredictability — must be harvested from hardware sources (timing jitter, thermal noise, etc.) and cannot be created algorithmically. Weak or predictable randomness has caused catastrophic real-world failures: the Debian OpenSSL bug (2008) reduced key entropy to 15 bits, and Dual_EC_DRBG contained an NSA backdoor. Using the OS-provided CSPRNG (/dev/urandom, CryptGenRandom) is the correct practice.

Explainer

Every cryptographic operation that generates keys, nonces, IVs, or random padding depends on a source of randomness that an adversary cannot predict. If an attacker can predict or narrow down the random values used in key generation, they can break the system regardless of how strong the algorithms are. Entropy — genuine physical unpredictability — is the foundation of cryptographic randomness, and it cannot be manufactured by computation. A deterministic algorithm, no matter how complex, produces a predictable output from a predictable input. Randomness must ultimately come from physical processes: hardware timing jitter, thermal noise, radioactive decay, or user input timing.

A cryptographically secure pseudorandom number generator (CSPRNG) bridges the gap between the small amount of entropy available from hardware sources and the large amount of randomness that cryptographic operations consume. It takes a short truly random seed (128-256 bits of entropy) and expands it into an arbitrarily long stream that is computationally indistinguishable from true randomness — no polynomial-time algorithm can tell the CSPRNG's output from a truly random string. Modern CSPRNGs (like ChaCha20-based designs in Linux) also provide forward secrecy: even if the internal state is compromised at some point, past outputs remain unpredictable, and the generator recovers security as new entropy is mixed in.

The critical principle is that a CSPRNG cannot create entropy; it can only expand it. If the seed has 30 bits of entropy (e.g., seeded with a timestamp), the output has 30 bits of entropy — the CSPRNG merely obscures which 30-bit value was used. Real-world catastrophes confirm this. The Debian OpenSSL bug (2006-2008) accidentally reduced entropy to the process ID (~15 bits), making every key generated on affected systems guessable from a set of ~32,768 possibilities. A developer who seeds a PRNG with time.time() provides perhaps 25-30 bits of entropy to an attacker who can estimate when the key was generated. These failures are invisible: the output looks random, passes statistical tests, and appears to work perfectly — until an attacker exploits the predictability.

The correct practice is simple: use your operating system's CSPRNG. On Linux, /dev/urandom (or the getrandom() system call) provides a CSPRNG seeded from hardware entropy sources, continuously reseeded, and maintained by security experts. On Windows, BCryptGenRandom serves the same role. These implementations handle entropy collection, pool management, and reseeding automatically. Rolling your own is almost always wrong — the Dual_EC_DRBG scandal (a NIST-standardized PRNG with a probable NSA backdoor exploiting the relationship between two elliptic curve points) showed that even standards bodies can get it wrong, but OS implementations receive the most scrutiny and the fastest patches. For application developers, the rule is absolute: never implement your own random number generation for cryptographic purposes.

Practice Questions 5 questions

Prerequisite Chain

Understanding ZeroThe Number ZeroCounting to FiveCounting to 10Counting to 20Counting a Set of Objects Up to 20Cardinality: The Last Number CountedMatching Numerals to QuantitiesSubitizing Small QuantitiesAddition Within 10Number Bonds to 10Addition Within 20Doubles and Near DoublesDoubles Facts Within 10Near Doubles Facts Within 20Mental Math Strategies for AdditionMental Math: Adding and Subtracting TensAddition Within 100Repeated Addition as MultiplicationMultiplication as Equal GroupsMultiplication: ArraysBasic Multiplication Facts (0s, 1s, 2s, 5s, 10s)Multiplication Facts Within 100Division as Equal SharingDivision as Grouping (Measurement Division)Division: Grouping (Repeated Subtraction) ModelDivision: Fair Sharing ModelDivision as Equal SharingDivision as GroupingBasic Division FactsDivision Facts Within 100Multiplication and Division Fact FamiliesRelationship Between Multiplication and DivisionDivision Facts as Inverse of MultiplicationRemainders and Quotients in DivisionDivision Word ProblemsMulti-Step Word ProblemsSolving Multi-Step Word ProblemsMultiplication Word ProblemsDivision Word ProblemsIntroduction to Long DivisionFactors and MultiplesPrime and Composite NumbersEquivalent FractionsRelating Fractions and DecimalsDecimal Place ValueIntegers and the Number LineComparing and Ordering IntegersAbsolute ValueAdding IntegersSubtracting IntegersMultiplying IntegersIntroduction to ExponentsOrder of OperationsInteger Order of OperationsVariable ExpressionsThe Distributive PropertyVariables and Expressions ReviewIntroduction to PolynomialsAdding and Subtracting PolynomialsMultiplying PolynomialsFactorialPermutationsCombinationsCounting Principles: Addition and Multiplication RulesIntroduction to Graph TheoryPropositional Logic FoundationsLogical EquivalencesBoolean AlgebraBoolean Type and Truth ValuesComparison Operators and Boolean TestsLogical Operators and Boolean AlgebraBoolean Algebra and Fundamental LawsLogic Gates FundamentalsImplementing Boolean Functions with GatesKarnaugh Map SimplificationCombinational Circuit DesignFlip-Flops and LatchesFinite State Machines (FSMs)Deterministic Finite Automata (DFA)Nondeterministic Finite Automata (NFA)Two-Way Finite AutomataNFA to DFA Conversion (Subset Construction)DFA Properties and Minimization AlgorithmsRegular Languages: Definition and CharacterizationContext-Free Grammars (CFGs)Pushdown Automata (PDA)Equivalence of CFGs and Pushdown AutomataClosure Properties of Context-Free LanguagesLimitations of Context-Free LanguagesPumping Lemma for Context-Free LanguagesTuring MachinesVariants of Turing Machines and EquivalenceNondeterministic Time Complexity and NPThe P vs. NP ProblemComplexity Class P: Polynomial TimeHash Functions and Collision ResistanceRandom Number Generation in Cryptography

Longest path: 98 steps · 515 total prerequisite topics

Prerequisites (2)

Leads To (1)