ArticleslgStudy

computer science

Cryptographically secure pseudorandom number generator

Cryptographically secure pseudorandom number generator is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Cryptographically secure pseudorandom number generator rather than just read about it. In short: 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).

Key takeaways

  • Cryptographically secure pseudorandom number generator belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Cryptographically secure pseudorandom number generator to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Cryptographically secure pseudorandom number generator from memory before moving on to harder problems.

Reference excerpt

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.

Worked examples

Example 1 — a first encounter with Cryptographically secure pseudorandom number generator

Start with the simplest possible case. Write down what Cryptographically secure pseudorandom number generator claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Cryptographically secure pseudorandom number generator before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Cryptographically secure pseudorandom number generator ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Cryptographically secure pseudorandom number generator

In research
Cryptographically secure pseudorandom number generator appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Cryptographically secure pseudorandom number generator in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Cryptographically secure pseudorandom number generator is common in secondary-school and first-year university syllabi. It links to neighbouring topics Cryptographic algorithms, Cryptographic primitives, Cryptographically secure pseudorandom number generators, so understanding it makes those chapters shorter.
In everyday life
Look for Cryptographically secure pseudorandom number generator outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Cryptographically secure pseudorandom number generator” →

How to study Cryptographically secure pseudorandom number generator in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Cryptographically secure pseudorandom number generator means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Cryptographically secure pseudorandom number generator out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Cryptographically secure pseudorandom number generator in simple terms?

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).

Why does Cryptographically secure pseudorandom number generator matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Cryptographically secure pseudorandom number generator?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Cryptographically secure pseudorandom number generator.

Tags

  • Cryptographic algorithms
  • Cryptographic primitives
  • Cryptographically secure pseudorandom number generators

Keep exploring