A cryptographically secure pseudorandom number generator (CSPRNG) or cryptographic pseudorandom number generator (CPRNG) is a pseudorandom number generator (PRNG) with properties that make it suitable for use in cryptography. It is also referred to as a cryptographic random number generator (CRNG).
Background
Most cryptographic applications require random numbers, for example:
key generation initialization vectors nonces salts in certain signature schemes, including ECDSA and RSASSA-PSS token generation The "quality" of the randomness required for these applications varies. For example, creating a nonce in some protocols needs only uniqueness. On the other hand, the generation of a master key requires a higher quality, such as more entropy. And in the case of one-time pads, the information-theoretic guarantee of perfect secrecy only holds if the key material comes from a true random source with high entropy, and thus just any kind of pseudorandom number generator is insufficient. Ideally, the generation of random numbers in CSPRNGs uses entropy obtained from a high-quality source, generally the operating system's randomness API. However, unexpected correlations have been found in several such ostensibly independent processes. From an information-theoretic point of view, the amount of randomness, the entropy that can be generated, is equal to the entropy provided by the system. But sometimes, in practical situations, numbers are needed with more randomness than the available entropy can provide. Also, the processes to extract randomness from a running system are slow in actual practice. In such instances, a CSPRNG can sometimes be used. A CSPRNG can "stretch" the available entropy over more bits.
Requirements The requirements of an ordinary PRNG are also satisfied by a cryptographically secure PRNG, but the reverse is not true. CSPRNG requirements fall into two groups:
They pass statistical randomness tests: Every CSPRNG should satisfy the next-bit test. That is, given the first k bits of a random sequence, there is no polynomial-time algorithm that can predict the (k+1)th bit with probability of success non-negligibly better than 50%. Andrew Yao proved in 1982 that a generator passing the next-bit test will pass all other polynomial-time statistical tests for randomness. In other words, no polynomial-time algorithm would be able to distinguish the output of the RNG from true randomness. Instead of polynomial-time complexity, another metric considered in practice is the absolute number of operations required for a distinguisher to tell the output from true randomness. From the number of operations one can also define a security level (bits of security) for a particular CSPRNG against distinguishing attacks. They hold up well under serious attack, even when part of their initial or running state becomes available to an attacker: Every CSPRNG should withstand "state compromise extension attacks". In the event that part or all of its state has been revealed (or guessed correctly), it should be impossible to reconstruct the stream of random numbers prior to the revelation. Additionally, if there is an entropy input while running, it should be infeasible to use knowledge of the input's state to predict future conditions of the CSPRNG state. For instance, if the PRNG under consideration produces output by computing bits of pi in sequence, starting from some unknown point in the binary expansion, it may well satisfy the next-bit test and thus be statistically random, as pi is conjectured to be a normal number. However, this algorithm is not cryptographically secure; an attacker who determines which bit of pi is currently in use (i.e. the state of the algorithm) will be able to calculate all preceding bits as well. Most PRNGs are not suitable for use as CSPRNGs and will fail on both counts:
While most PRNGs' outputs appear random to assorted statistical tests, they do not resist determined reverse engineering. Specialized statistical tests may be found specially tuned to such a PRNG that shows the random numbers not to be truly random. At the same time, because CSPRNGs are designed to resist all statistical tests (and are believed to be secure on this front until such a test has been found), a CSPRNG can replace any true random number generator in any non-cryptographic application as well. For most PRNGs, when their state has been revealed, all past random numbers can be retrodicted, allowing an attacker to read all past messages, as well as future ones. CSPRNGs are designed explicitly to resist this type of cryptanalysis.
Definitions In the asymptotic setting, a family of deterministic polynomial time computable functions Gk:{𝟶,𝟷}k→{𝟶,𝟷}p(k) for some polynomial p, is a pseudorandom number generator (PRNG, or PRG in some references), if it stretches the length of its input (p(k)>k for any k), and if its output is computationally indistinguishable from true randomness, i.e. for any probabilistic polynomial time algorithm A, which outputs 1 or 0 as a distinguisher,
|Prx←{𝟶,𝟷}k[A(G(x))=1]−Prr←{𝟶,𝟷}p(k)[A(r)=1]|<μ(k) for some negligible function μ. (The notation x←X means that x is chosen uniformly at random from the set X.) There is an equivalent characterization: For any function family Gk:{𝟶,𝟷}k→{𝟶,𝟷}p(k), G is a PRNG if and only if the next output bit of G cannot be predicted by a polynomial time algorithm. A forward-secure PRNG with block length t(k) is a PRNG Gk:{𝟶,𝟷}k→{𝟶,𝟷}k×{𝟶,𝟷}t(k), where the input string si with length k is the current state at period i, and the output (si+1, yi) consists of the next state si+1 and the pseudorandom output block yi of period i, that withstands state compromise extensions in the following sense. If the initial state s1 is chosen uniformly at random from {𝟶,𝟷}k, then for any i, the sequence (y1,y2,…,yi,si+1) must be computationally indistinguishable from (r1,r2,…,ri,si+1), in which the ri are chosen uniformly at random from {𝟶,𝟷}t(k). Any PRNG G:{𝟶,𝟷}k→{𝟶,𝟷}p(k) can be turned into a forward secure PRNG with block length p(k)−k by splitting its output into the next state and the actual output. This is done by setting G(s)=G𝟶(s)‖G𝟷(s), in which |G𝟶(s)|=|s|=k and |G𝟷(s)|=p(k)−k; then G is a forward secure PRNG with G𝟶 as the next state and G𝟷 as the pseudorandom output block of the current period.
Entropy extraction
… excerpt ends here. Continue reading the full article.