Cryptographically secure pseudorandom number generator
A cryptographically secure pseudorandom number generator or cryptographic pseudorandom number generator is a pseudorandom number generator with properties that make it suitable for use in cryptography. It is also loosely known as a cryptographic random number generator .
Most cryptographic applications require random numbers, for example:
- key generation
- nonces
- salts in certain signature schemes, including ECDSA, RSASSA-PSS
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 any kind of pseudo-random 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, more random numbers are needed than there is entropy available. 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: first, that they pass statistical randomness tests; and secondly, that they hold up well under serious attack, even when part of their initial or running state becomes available to an attacker.- 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 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.
- Every CSPRNG should withstand "state compromise extensions". In the event that part or all of its state has been revealed, 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.
CSPRNGs are designed explicitly to resist this type of cryptanalysis.
Definitions
In the asymptotic setting, a family of deterministic polynomial time computable functions for some polynomial, is a pseudorandom number generator, if it stretches the length of its input, and if its output is computationally indistinguishable from true randomness, i.e. for any probabilistic polynomial time algorithm, which outputs 1 or 0 as a distinguisher,for some negligible function.
There is an equivalent characterization: For any function family, is a PRNG if and only if the next output bit of cannot be predicted by a polynomial time algorithm.
A forward-secure PRNG with block length is a PRNG, where the input string with length is the current state at period, and the output consists of the next state and the pseudorandom output block of period, such that it withstands state compromise extensions in the following sense. If the initial state is chosen uniformly at random from, then for any, the sequence must be computationally indistinguishable from, in which the are chosen uniformly at random from.
Any PRNG can be turned into a forward secure PRNG with block length by splitting its output into the next state and the actual output. This is done by setting, in which and ; then is a forward secure PRNG with as the next state and as the pseudorandom output block of the current period.
Entropy extraction
Santha and Vazirani proved that several bit streams with weak randomness can be combined to produce a higher-quality quasi-random bit stream.Even earlier, John von Neumann proved that a simple algorithm can remove a considerable amount of the bias in any bit stream which should be applied to each bit stream before using any variation of the Santha–Vazirani design.
Designs
In the discussion below, CSPRNG designs are divided into three classes:- those based on cryptographic primitives such as ciphers and cryptographic hashes,
- those based upon mathematical problems thought to be hard, and
- special-purpose designs.
Designs based on cryptographic primitives
- A secure block cipher can be converted into a CSPRNG by running it in counter mode. This is done by choosing a random key and encrypting a 0, then encrypting a 1, then encrypting a 2, etc. The counter can also be started at an arbitrary number other than zero. Assuming an n-bit block cipher the output can be distinguished from random data after around 2n/2 blocks since, following the birthday problem, colliding blocks should become likely at that point, whereas a block cipher in CTR mode will never output identical blocks. For 64-bit block ciphers this limits the safe output size to a few gigabytes, with 128-bit blocks the limitation is large enough not to impact typical applications. However, when used alone it does not meet all of the criteria of a CSPRNG since it is not strong against "state compromise extensions": with knowledge of the state you can predict all past output.
- A cryptographically secure hash of a counter might also act as a good CSPRNG in some cases. In this case, it is also necessary that the initial value of this counter is random and secret. However, there has been little study of these algorithms for use in this manner, and at least some authors warn against this use.
- Most stream ciphers work by generating a pseudorandom stream of bits that are combined with the plaintext; running the cipher on a counter will return a new pseudorandom stream, possibly with a longer period. The cipher can only be secure if the original stream is a good CSPRNG, although this is not necessarily the case. Again, the initial state must be kept secret.
Number-theoretic designs
- The Blum Blum Shub algorithm has a security proof based on the difficulty of the quadratic residuosity problem. Since the only known way to solve that problem is to factor the modulus, it is generally regarded that the difficulty of integer factorization provides a conditional security proof for the Blum Blum Shub algorithm. However the algorithm is very inefficient and therefore impractical unless extreme security is needed.
- The Blum–Micali algorithm has an unconditional security proof based on the difficulty of the discrete logarithm problem but is also very inefficient.
- Daniel Brown of Certicom has written a 2006 security proof for Dual_EC_DRBG, based on the assumed hardness of the Decisional Diffie–Hellman assumption, the x-logarithm problem, and the truncated point problem. The 2006 proof explicitly assumes a lower outlen than in the Dual_EC_DRBG standard, and that the P and Q in the Dual_EC_DRBG standard are replaced with non-backdoored values.
Special designs
- the Yarrow algorithm which attempts to evaluate the entropic quality of its inputs. Yarrow is used in macOS.
- the ChaCha20 algorithm replaced RC4 in OpenBSD, NetBSD, and FreeBSD.
- ChaCha20 also replaced SHA-1 in Linux in version 4.8.
- the Fortuna algorithm, the successor to Yarrow, which does not attempt to evaluate the entropic quality of its inputs. Fortuna is used in FreeBSD.
- the function CryptGenRandom provided in Microsoft's Cryptographic Application Programming Interface
- ISAAC based on a variant of the RC4 cipher
- Evolutionary algorithm based on the NIST Statistical Test Suite.
- arc4random
- AES-CTR DRBG is often used as a random number generator in systems that use AES encryption.
- ANSI X9.17 standard, which has been adopted as a FIPS standard as well. It takes as input a TDEA key bundle k and a 64-bit random seed s. Each time a random number is required it:
- * Obtains the current date/time D to the maximum resolution possible.
- * Computes a temporary value
- * Computes the random value, where ⊕ denotes bitwise exclusive or.
- * Updates the seed
Standards
- NIST SP 800-90A:
- NIST SP 800-90A Rev.1: This is essentially NIST SP 800-90A with Dual_EC_DRBG removed, and is the withdrawn standard's replacement.
- ANSI X9.17-1985 Appendix C
- ANSI X9.31-1998 Appendix A.2.4
- ANSI X9.62-1998 Annex A.4, obsoleted by ANSI X9.62-2005, Annex D
There are also standards for statistical testing of new CSPRNG designs:
- A Statistical Test Suite for Random and Pseudorandom Number Generators, .
NSA kleptographic backdoor in the Dual_EC_DRBG PRNG