Docsity

Pseudorandomness and Cryptography, Lecture notes of Mathematics

Toggle sidebar
bg1
1Edited and expanded by Richard Xu in Spring 2020.
2Even lawyers grapple with this question, with a
recent example being the debate of whether fantasy
football is a game of chance or of skill.
3In fact such a function must exist in some sense since
in the entire history of the world, presumably no
sequence of 100fair coin tosses has ever repeated.
3
Pseudorandomness
Reading: Katz-Lindell Section 3.3, Boneh-Shoup Chapter 31
The nature of randomness has troubled philosophers, scientists,
statisticians and laypeople for many years.2Over the years people
have given different answers to the question of what does it mean for
data to be random, and what is the nature of probability. The move-
ments of the planets initially looked random and arbitrary, but then
early astronomers managed to find order and make some predictions
on them. Similarly, we have made great advances in predicting the
weather and will probably continue to do so.
So, while these days it seems as if the event of whether or not it will
rain a week from today is random, we could imagine that in the future
we will be able to predict the weather accurately. Even the canonical
notion of a random experiment -tossing a coin - might not be as ran-
dom as youโ€™d think: the second toss will have the same result as the
first one with about a 51% chance. (Though see also this experiment.)
It is conceivable that at some point someone would discover some
function ๐นthat, given the first 100 coin tosses by any given person, can
predict the value of the 101๐‘ ๐‘ก.3
In all these examples, the physics underlying the event, whether itโ€™s
the planetsโ€™ movement, the weather, or coin tosses, did not change but
only our powers to predict them. So to a large extent, randomness is a
function of the observer, or in other words
If a quantity is hard to compute, it might as well be
random.
Much of cryptography is about trying to make this intuition more
formal, and harnessing it to build secure systems. The basic object we
want is the following:
Compiled on 11.17.2021 22:35
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14

Partial preview of the text

Download Pseudorandomness and Cryptography and more Lecture notes Mathematics in PDF only on Docsity!

(^1) Edited and expanded by Richard Xu in Spring 2020.

(^2) Even lawyers grapple with this question, with a recent example being the debate of whether fantasy football is a game of chance or of skill.

(^3) In fact such a function must exist in some sense since in the entire history of the world, presumably no sequence of 100 fair coin tosses has ever repeated.

Pseudorandomness

Reading: Katz-Lindell Section 3.3, Boneh-Shoup Chapter 3^1 The nature of randomness has troubled philosophers, scientists, statisticians and laypeople for many years.^2 Over the years people have given different answers to the question of what does it mean for data to be random, and what is the nature of probability. The move- ments of the planets initially looked random and arbitrary, but then early astronomers managed to find order and make some predictions on them. Similarly, we have made great advances in predicting the weather and will probably continue to do so. So, while these days it seems as if the event of whether or not it will rain a week from today is random , we could imagine that in the future we will be able to predict the weather accurately. Even the canonical notion of a random experiment -tossing a coin - might not be as ran- dom as youโ€™d think: the second toss will have the same result as the first one with about a 51% chance. (Though see also this experiment.) It is conceivable that at some point someone would discover some function ๐น that, given the first 100 coin tosses by any given person, can predict the value of the 101๐‘ ๐‘ก.^3 In all these examples, the physics underlying the event, whether itโ€™s the planetsโ€™ movement, the weather, or coin tosses, did not change but only our powers to predict them. So to a large extent, randomness is a function of the observer , or in other words If a quantity is hard to compute, it might as well be random.

Much of cryptography is about trying to make this intuition more formal, and harnessing it to build secure systems. The basic object we want is the following:

Compiled on 11.17.2021 22:

92 an intensive introduction to cryptography

Definition 3.1 โ€” Pseudorandom generator (concrete). A function ๐บ โˆถ {0, 1}๐‘›^ โ†’ {0, 1}โ„“^ is a (๐‘‡ , ๐œ–) pseudorandom generator if ๐บ(๐‘ˆ๐‘›) โ‰ˆ๐‘‡ ,๐œ– ๐‘ˆโ„“ where ๐‘ˆ๐‘ก denotes the uniform distribution on {0, 1}๐‘ก.

That is, ๐บ is a (๐‘‡ , ๐œ–) pseudorandom generator if no circuit of at most ๐‘‡ gates can distinguish with bias better than ๐œ– between the output of ๐บ (on a random input) and a uniformly random string of the same length. Spelling this out fully, this means that for every function ๐ท โˆถ {0, 1}โ„“^ โ†’ {0, 1} computable using at most ๐‘‡ operations,

โˆฃ Pr ๐‘ฅโ†๐‘…{0,1}๐‘› [๐ท(๐บ(๐‘ฅ)) = 1] โˆ’ Pr ๐‘ฆโ†๐‘…{0,1}โ„“

[๐ท(๐‘ฆ) = 1]โˆฃ < ๐œ–.

As we did for the case of encryption, we will typically use asymp- totic terms to describe cryptographic pseudorandom generator. We say that ๐บ is simply a pseudorandom generator if it is efficiently com- putable and it is (๐‘(๐‘›), 1/๐‘(๐‘›))-pseudorandom generator for every polynomial ๐‘(โ‹…). In other words, we define pseudorandom generators as follows:

Definition 3.2 โ€” Pseudorandom generator. Let ๐บ โˆถ {0, 1}โˆ—^ โ†’ {0, 1}โˆ—^ be some function computable in polynomial time. We say that ๐บ is a pseudorandom generator with length function โ„“ โˆถ โ„• โ†’ โ„• (where โ„“(๐‘›) > ๐‘›) if

  • For every ๐‘ฅ โˆˆ {0, 1}โˆ—, |๐บ(๐‘ฅ)| = โ„“(|๐‘ฅ|).
  • For every polynomial ๐‘(โ‹…) and sufficiently large ๐‘›, if ๐ท โˆถ {0, 1}โ„“(๐‘›)^ โ†’ {0, 1} is computable by at most ๐‘(๐‘›) operations, then

|Pr[๐ท(๐บ(๐‘ˆ๐‘›)) = 1] โˆ’ Pr[๐ท(๐‘ˆโ„“) = 1]| < (^) ๐‘(๐‘›)^1 (3.1)

Another way to say it, is that a polynomial-time computable func- tion ๐บ mapping ๐‘› bits strings to โ„“(๐‘›) > ๐‘› bit strings is a pseudo- random generator if the two distributions ๐บ(๐‘ˆ๐‘›) and ๐‘ˆโ„“(๐‘›) are compu- tationally indistinguishable.

P This definition (as is often the case in cryptography) is a bit long, but the concept of a pseudorandom gen- erator is central to cryptography, and so you should take your time and make sure you understand it. In- tuitively, a function ๐บ is a pseudorandom generator if (1) it expands its input (mapping ๐‘› bits to ๐‘› + 1 or more) and (2) we cannot distinguish between the out-

94 an intensive introduction to cryptography

(^5) Because we use a small input to grow a large pseu- dorandom string, the input to a pseudorandom generator is often known as its seed.

As was the case for the cipher conjecture, and any other conjecture, there are two natural questions regarding the PRG conjecture: why should we believe it and why should we care. Fortunately, the answer to the first question is simple: it is known that the cipher conjecture implies the PRG conjecture, and hence if we believe the former we should believe the latter. (The proof is highly non-trivial and we may not get to see it in this course.) As for the second question, we will see that the PRG conjecture implies a great number of useful crypto- graphic tools, including the cipher conjecture (i.e., the two conjectures are in fact equivalent). We start by showing that once we can get to an output that is one bit longer than the input, we can in fact obtain any polynomial number of bits.

Theorem 3.4 โ€” Length Extension for PRGโ€™s. Suppose that the PRG con- jecture is true. Then for every polynomial ๐‘ก(๐‘›), there exists a pseu- dorandom generator mapping ๐‘› bits to ๐‘ก(๐‘›) bits.

Figure 3.2 : Length extension for pseudorandom generators

Proof. The proof of this theorem is very similar to the length extension theorem for ciphers, and in fact this theorem can be used to give an alternative proof for the former theorem. The construction is illustrated in Fig. 3.2. We are given a pseu- dorandom generator ๐บโ€ฒ^ mapping ๐‘› bits into ๐‘› + 1 bits and need to construct a pseudorandom generator ๐บ mapping ๐‘› bits to ๐‘ก = ๐‘ก(๐‘›) bits for some polynomial ๐‘ก(โ‹…). The idea is that we maintain a state of ๐‘› bits, which are originally our input seed^5 ๐‘  0 , and at the ๐‘–๐‘กโ„Ž^ step we use ๐บโ€ฒ to map ๐‘ ๐‘–โˆ’1 to the ๐‘› + 1-long bit string (๐‘ ๐‘–, ๐‘ฆ๐‘–), output ๐‘ฆ๐‘– and keep ๐‘ ๐‘– as our new state. To prove the security of this construction we need to show that the distribution ๐บ(๐‘ˆ๐‘›) = (๐‘ฆ 1 , โ€ฆ , ๐‘ฆ๐‘ก) is computationally indistinguishable from the uniform distribution ๐‘ˆ๐‘ก. As usual, we will use the hybrid argument. For ๐‘– โˆˆ {0, โ€ฆ , ๐‘ก} we define ๐ป๐‘– to be the dis- tribution where the first ๐‘– bits chosen uniformly at random, whereas the last ๐‘ก โˆ’ ๐‘– bits are computed as above. Namely, we choose ๐‘ ๐‘– at ran-

pseudorandomness 95

dom in {0, 1}๐‘›^ and continue the computation of ๐‘ฆ๐‘–+1, โ€ฆ , ๐‘ฆ๐‘ก from the state ๐‘ ๐‘–. Clearly ๐ป 0 = ๐บ(๐‘ˆ๐‘›) and ๐ป๐‘ก = ๐‘ˆ๐‘ก and hence by the triangle inequality it suffices to prove that ๐ป๐‘– โ‰ˆ ๐ป๐‘–+1 for all ๐‘– โˆˆ {0, โ€ฆ , ๐‘ก โˆ’ 1}. We illustrate these two hybrids in Fig. 3.3.

Figure 3.3 : Hybrids ๐ป๐‘– and ๐ป๐‘–+1โ€” dotted boxes refer to values that are chosen independently and uniformly at random

Now suppose otherwise that there exists some adversary ๐ธ๐‘ฃ๐‘’ such that |๐”ผ[๐ธ๐‘ฃ๐‘’(๐ป๐‘–)] โˆ’ ๐”ผ[๐ธ๐‘ฃ๐‘’(๐ป๐‘–+1)]| โ‰ฅ ๐œ– for some non-negligible ๐œ–. From ๐ธ๐‘ฃ๐‘’, we will design an adversary ๐ธ๐‘ฃ๐‘’โ€ฒ^ breaking the security of the pseudorandom generator ๐บโ€ฒ^ (see Fig. 3.4).

Figure 3.4 : Building an adversary ๐ธ๐‘ฃ๐‘’โ€ฒ^ for ๐บโ€ฒ^ from an adversary ๐ธ๐‘ฃ๐‘’ distinguishing ๐ป๐‘– and ๐ป๐‘–+1. The boxes marked with questions marks are those that are random or pseudorandom depending on whether we are in ๐ป๐‘– or ๐ป๐‘–+1. Everything inside the dashed red lines is simulated by ๐ธ๐‘ฃ๐‘’โ€ฒ^ that gets as input the ๐‘› + 1-bit string (๐‘ ๐‘–+1, ๐‘ฆ๐‘–+1).

On input a string ๐‘ฆ of length ๐‘› + 1, ๐ธ๐‘ฃ๐‘’โ€ฒ^ will interpret ๐‘ฆ as (๐‘ ๐‘–+1, ๐‘ฆ๐‘–+1) where ๐‘ ๐‘–+1 โˆˆ {0, 1}๐‘›. She then chooses ๐‘ฆ 1 , โ€ฆ , ๐‘ฆ๐‘– randomly and compute ๐‘ฆ๐‘–+2, โ€ฆ , ๐‘ฆ๐‘ก as in our pseudorandom generatorโ€™s construc- tion. ๐ธ๐‘ฃ๐‘’โ€ฒ^ will then feed (๐‘ฆ 1 , โ€ฆ , ๐‘ฆ๐‘ก) to ๐ธ๐‘ฃ๐‘’ and output whatever ๐ธ๐‘ฃ๐‘’

pseudorandomness 97

cuit can predict the next bit of the output of ๐บ given the previous bits significantly better than guessing.

We now show that the condition for a function ๐บ to be unpre- dictable is equivalent to the condition for it to be a secure PRG. Please make sure you follow the proof, because it is an important theorem, and because it is another example of a canonical cryptographic proof.

Lemma 3.7 Let ๐บ โˆถ {0, 1}โˆ—^ โ†’ {0, 1}โˆ—^ be a function with length function โ„“(๐‘›), then ๐บ is a secure PRG iff it is unpredictable.

Proof. For the forward direction, suppose for contradiction that there exists some ๐‘– and some circuit ๐‘ƒ can predict ๐‘ฆ๐‘– given ๐‘ฆ 1 , โ€ฆ , ๐‘ฆ๐‘–โˆ’1 with probability ๐‘ โ‰ฅ 12 + ๐œ–(๐‘›) for non-negligible ๐œ–. Consider the adversary ๐ธ๐‘ฃ๐‘’ that, given a string ๐‘ฆ, runs the circuit ๐‘ƒ on ๐‘ฆ 1 , โ€ฆ , ๐‘ฆ๐‘–โˆ’1, checks if the output is equal to ๐‘ฆ๐‘– and if so output 1. If ๐‘ฆ = ๐บ(๐‘ฅ) for a uniform ๐‘ฅ, then ๐‘ƒ succeeds with probability ๐‘. If ๐‘ฆ is uniformly random, then we can imagine that the bit ๐‘ฆ๐‘– is generated after ๐‘ƒ finished its calculation. The bit ๐‘ฆ๐‘– is 0 or 1 with equal probability, so ๐‘ƒ succeeds with probability 12. Since ๐ธ๐‘ฃ๐‘’ outputs 1 when ๐‘ƒ succeeds,

|Pr[๐ธ๐‘ฃ๐‘’(๐บ(๐‘ˆ๐‘›)) = 1] โˆ’ Pr[๐ธ๐‘ฃ๐‘’(๐‘ˆโ„“) = 1]| = |๐‘ โˆ’

a contradiction. For the backward direction, let ๐บ be an unpredictable function. Let ๐ป๐‘– be the distribution where the first ๐‘– bits come from ๐บ(๐‘ˆ๐‘›) while the last โ„“ โˆ’ ๐‘– bits are all random. Notice that ๐ป 0 = ๐‘ˆโ„“ and ๐ปโ„“ = ๐บ(๐‘ˆ๐‘›), so it suffices to show that ๐ป๐‘–โˆ’1 โ‰ˆ ๐ป๐‘– for all ๐‘–. Suppose ๐ป๐‘–โˆ’1 โ‰‰ ๐ป๐‘– for some ๐‘–, i.e. there exists some ๐ธ๐‘ฃ๐‘’ and non- negligible ๐œ– such that

Pr[๐ธ๐‘ฃ๐‘’(๐ป๐‘–) = 1] โˆ’ Pr[๐ธ๐‘ฃ๐‘’(๐ป๐‘–โˆ’1) = 1] > ๐œ–(๐‘›).

Consider the program ๐‘ƒ that, on input (๐‘ฆ 1 , โ€ฆ , ๐‘ฆ๐‘–โˆ’1), picks the bits ๐‘ฆ๐‘–ฬ‚, โ€ฆ ,ฬ‚ ๐‘ฆโ„“ uniformly at random. Then, ๐‘ƒ calls ๐ธ๐‘ฃ๐‘’ on the generated input. If ๐ธ๐‘ฃ๐‘’ outputs 1 then ๐‘ƒ outputs ๐‘ฆ๐‘–ฬ‚, and otherwise it outputs 1 โˆ’ฬ‚ ๐‘ฆ๐‘–. The string (๐‘ฆ 1 , โ€ฆ , ๐‘ฆ๐‘–โˆ’1,ฬ‚ ๐‘ฆ๐‘–, โ€ฆ ,ฬ‚ ๐‘ฆโ„“) has the same distribution as ๐ป๐‘–โˆ’1. However, conditioned on ๐‘ฆ๐‘–ฬ‚ = ๐‘ฆ๐‘–, the string has distribution equal to ๐ป๐‘–. Let ๐‘ be the probability that ๐ธ๐‘ฃ๐‘’ outputs 1 if ๐‘ฆ๐‘–ฬ‚ = ๐‘ฆ๐‘– and ๐‘ž be the same probability when ๐‘ฆฬ‚๐‘– โ‰  ๐‘ฆ๐‘–, then we get

๐‘ โˆ’

2 (๐‘ + ๐‘ž) =^ Pr[๐ธ๐‘ฃ๐‘’(๐ป๐‘–) = 1] โˆ’^ Pr[๐ธ๐‘ฃ๐‘’(๐ป๐‘–โˆ’1) = 1] > ๐œ–(๐‘›).

Therefore, the probability ๐‘ƒ outputs the correct value is equal to 12 ๐‘ + 1 2 (1 โˆ’ ๐‘ž) =^ 1 2 + ๐œ–(๐‘›), a contradiction. โ– 

98 an intensive introduction to cryptography

The definition of unpredictability is useful because many of our candidates for pseudorandom generators appeal to the unpredictabil- ity definition in their proofs. For example, the Blum-Blum-Shub gen- erator we will see later in the chapter is proved to be unpredictable if the โ€œquadratic residuosity problemโ€ is hard. It is also nice to know that our intuition at the beginning of the chapter can be formalized.

3.1 STREAM CIPHERS

We now show a connection between pseudorandom generators and encryption schemes:

Theorem 3.8 โ€” PRG conjecture implies Cipher conjectures. If the PRG conjecture is true then so is the cipher conjecture.

It turns out that the converse direction is also true, and hence these two conjectures are equivalent. We will probably not show the (quite non-trivial) proof of this fact in this course. (We might show a weaker version though.)

Proof. Recall that the one time pad is a perfectly secure cipher but its only problem was that to encrypt an ๐‘› + 1 long message it needed an ๐‘› + 1 long bit key. Now using a pseudorandom generator, we can map an ๐‘›-bit long key into an ๐‘› + 1-bit long string that looks random enough that we could use it as a key for the one-time pad. That is, our cipher will look as follows:

and

Just like in the one time pad, ๐ท๐‘˜(๐ธ๐‘˜(๐‘š)) = ๐บ(๐‘˜) โŠ• ๐บ(๐‘˜) โŠ• ๐‘š = ๐‘š. Moreover, the encryption and decryption algorithms are clearly efficient. We will prove security of this encryption by showing the stronger claim that ๐ธ๐‘ˆ๐‘› (๐‘š) โ‰ˆ ๐‘ˆ๐‘›+1 for any ๐‘š. Notice that ๐‘ˆ๐‘›+1 = ๐‘ˆ๐‘›+1 โŠ• ๐‘š, as we showed in the security of the one-time pad. Suppose that for some non-negligible ๐œ– = ๐œ–(๐‘›) > 0 there is an efficient adversary ๐ธ๐‘ฃ๐‘’โ€ฒ^ such that

|๐”ผ[๐ธ๐‘ฃ๐‘’โ€ฒ(๐บ(๐‘ˆ๐‘›) โŠ• ๐‘š)] โˆ’ ๐”ผ[๐ธ๐‘ฃ๐‘’โ€ฒ(๐‘ˆ๐‘›+1 โŠ• ๐‘š)]| โ‰ฅ ๐œ–.

Then the adversary ๐ธ๐‘ฃ๐‘’ defined as ๐ธ๐‘ฃ๐‘’(๐‘ฆ) = ๐ธ๐‘ฃ๐‘’โ€ฒ(๐‘ฆ โŠ• ๐‘š) would be also efficient. Furthermore, if ๐‘ฆ is pseudorandom then ๐ธ๐‘ฃ๐‘’(๐‘ฆ) = ๐ธ๐‘ฃ๐‘’โ€ฒ(๐บ(๐‘ˆ๐‘›) โŠ• ๐‘š) and if ๐‘ฆ is uniformly random then ๐ธ๐‘ฃ๐‘’(๐‘ฆ) =

100 an intensive introduction to cryptography

(^6) CRC are often used to generate a โ€œcontrol digitโ€ to detect mistypes of credit card or social security card number. This has very different goals than its use for pseudorandom generators, though there are some common intuitions behind the two usages.

3.2 WHAT DO PSEUDORANDOM GENERATORS ACTUALLY LOOK LIKE?

So far we have made the conjectures that objects such as ciphers and pseudorandom generators exist , without giving any hint as to how they would actually look like. (Though we have examples such as the Caesar cipher, Vigenere, and Enigma of what secure ciphers donโ€™t look like.) As mentioned above, we do not know how to prove that any particular function is a pseudorandom generator. However, there are quite simple candidates (i.e., functions that are conjectured to be secure pseudorandom generators), though care must be taken in constructing them. We now consider candidates for functions that maps ๐‘› bits to ๐‘› + 1 bits (or more generally ๐‘› + ๐‘ for some constant ๐‘ ) and look at least somewhat โ€œrandomishโ€. As these constructions are typically used as a basic component for obtaining a longer length PRG via the length extension theorem (Theorem 3.4), we will think of these pseudorandom generators as mapping a string ๐‘  โˆˆ {0, 1}๐‘› representing the current state into a string ๐‘ โ€™ โˆˆ {0, 1}๐‘›^ representing the new state as well as a string ๐‘ โˆˆ {0, 1}๐‘^ representing the current output. See also Section 6.1 in Katz-Lindell and (for greater depth) Sections 3.6-3.9 in the Boneh-Shoup book.

3.2.1 Attempt 0: The counter generator To get started, letโ€™s look at an example of an obviously bogus pseudo- random generator. We define the โ€œcounter pseudorandom generatorโ€ ๐บ โˆถ {0, 1}๐‘›^ โ†’ {0, 1}๐‘›+1^ as follows. ๐บ(๐‘ ) = (๐‘ โ€ฒ, ๐‘) where ๐‘ โ€ฒ^ = ๐‘  + 1 mod 2 ๐‘›^ (treating ๐‘  and ๐‘ โ€ฒ^ as numbers in {0, โ€ฆ , 2๐‘›^ โˆ’ 1}) and ๐‘ is the least significant digit of ๐‘ โ€ฒ. Itโ€™s a great exercise to work out why this is not a secure pseudorandom generator.

P You should really pause here and make sure you see why the โ€œcounter pseudorandom generatorโ€ is not a secure pseudorandom generator. Show that this is true even if we replace the least significant digit by the ๐‘˜-th digit for every 0 โ‰ค ๐‘˜ < ๐‘›.

3.2.2 Attempt 1: The linear checksum / linear feedback shift register (LFSR) LFSR can be thought of as the โ€œmotherโ€ (or maybe more like the sick great-uncle) of all pseudorandom generators. One of the simplest ways to generate a โ€œrandomishโ€ extra digit given an ๐‘› digit number is to use a checksum - some linear combination of the digits, with a canonical example being the cyclic redundancy check or CRC.^6 This motivates the notion of a linear feedback shift register generator (LFSR):

pseudorandomness 101

(^7) A ring is a set of elements where addition and multiplication are defined and obey the natural rules of associativity and commutativity (though without necessarily having a multiplicative inverse for every element). For every integer ๐‘ž we define โ„ค๐‘ž (known as the ring of integers modulo ๐‘ž) to be the set {0, โ€ฆ , ๐‘ž โˆ’ 1} where addition and multiplication is done modulo ๐‘ž.

(^8) Despite the name, the algorithm goes at least as far back as the Chinese Jiuzhang Suanshu manuscript, circa 150 B.C.

if the current state is ๐‘  โˆˆ {0, 1}๐‘›^ then the output is ๐‘“(๐‘ ) where ๐‘“ is a linear function (modulo 2) and the new state is obtained by right shifting the previous state and putting ๐‘“(๐‘ ) at the leftmost location. That is, ๐‘ โ€ฒ 1 = ๐‘“(๐‘ ) and ๐‘ โ€ฒ๐‘– = ๐‘ ๐‘–โˆ’1 for ๐‘– โˆˆ {2, โ€ฆ , ๐‘›}. LFSRโ€™s have several good properties- if the function ๐‘“(โ‹…) is chosen properly then they can have very long periods (i.e., it can take an ex- ponential number of steps until the state repeats itself), though that also holds for the simple โ€œcounterโ€ generator we saw above. They also have the property that every individual bit is equal to 0 or 1 with probability exactly half (the counter generator also shares this prop- erty). A more interesting property is that (if the function is selected prop- erly) every two coordinates are independent from one another. That is, there is some super-polynomial function ๐‘ก(๐‘›) (in fact ๐‘ก(๐‘›) can be exponential in ๐‘›) such that if โ„“ โ‰  โ„“โ€ฒ^ โˆˆ {0, โ€ฆ , ๐‘ก(๐‘›)}, then if we look at the two random variables corresponding to the โ„“-th and โ„“โ€ฒ-th output of the generator (where randomness is the initial state) then they are distributed like two independent random coins. (This is non-trivial to show, and depends on the choice of ๐‘“ - it is a challenging but useful exercise to work this out.) The counter generator fails badly at this condition: the least significant bits between two consecutive states always flip. There is a more general notion of a linear generator where the new state can be any invertible linear transformation of the previous state. That is, we interpret the state ๐‘  as an element of โ„ค๐‘ก๐‘ž for some integers ๐‘ž, ๐‘ก,^7 and let ๐‘ โ€™ = ๐น (๐‘ ) and the output ๐‘ = ๐บ(๐‘ ) where ๐น โˆถ โ„ค๐‘ก๐‘ž โ†’ โ„ค๐‘ก๐‘ž and ๐บ โˆถ โ„ค๐‘ก๐‘ž โ†’ โ„ค๐‘ž are invertible linear transformations (modulo ๐‘ž). This includes as a special case the linear congruential generator where ๐‘ก = 1 and the map ๐น (๐‘ ) corresponds to taking ๐‘Ž๐‘  (mod ๐‘ž) where ๐‘Ž is number co-prime to ๐‘ž. All these generators are unfortunately insecure due to the great bane of cryptography- the Gaussian elimination algorithm which stu- dents typically encounter in any linear algebra class.^8

Theorem 3.10 โ€” The unfortunate theorem for cryptography. There is a poly- nomial time algorithm to solve ๐‘š linear equations in ๐‘› variables (or to certify no solution exists) over any ring.

Despite its seeming simplicity and ubiquity, Gaussian elimination (and some generalizations and related algorithms such as Euclidโ€™s extended g.c.d algorithm and the LLL lattice reduction algorithm) has been used time and again to break candidate cryptographic con- structions. In particular, if we look at the first ๐‘› outputs of a linear generator ๐‘ 1 , โ€ฆ , ๐‘๐‘› then we can write linear equations in the unknown

pseudorandomness 103

Easy Hard Convex Non-convex Linear Non-linear (degree โ‰ฅ 2) Noiseless Noisy Local Global Shallow Deep Low degree High degree

Many cryptographic constructions can be thought of as trying to transform an easy problem into a hard one by moving from the left to the right column of this table. The discrete logarithm problem is the discrete version of the con- tinuous real logarithm problem. The learning with errors problem can be thought of as the noisy version of the linear equations problem (or the discrete version of least squares minimization). When con- structing block ciphers we often have mixing transformation to ensure that the dependency structure between different bits is global , S-boxes to ensure non-linearity , and many rounds to ensure deep structure and large algebraic degree. This also works in the other direction. Many algorithmic and ma- chine learning advances work by embedding a discrete problem in a continuous convex one. Some attacks on cryptographic objects can be thought of as trying to recover some of the structure (e.g., by embed- ding modular arithmetic in the real line or โ€œlinearizingโ€ non linear equations).

3.2.4 Attempt 2: Linear Congruential Generators with dropped bits One approach that is widely used in implementations of pseudoran- dom generators is to take a linear generator such as the linear congru- ential generators described above, and use for the output a โ€œchoppedโ€ version of the linear function and drop some of the least significant bits. The operation of dropping these bits is non-linear and hence the attack above does not immediately apply. Nevertheless, it turns out this attack can be generalized to handle this case, and hence even with dropped bits Linear Congruential Generators are completely insecure and should be used (if at all) only in applications such as simulations where there is no adversary. Section 3.7.1 in the Boneh-Shoup book describes one attack against such generators that uses the notion of lattice algorithms that we will encounter later in this course in very different contexts.

104 an intensive introduction to cryptography

(^10) Actually modern computers will be able to break this generator via brute force, but if the length and number of the constants were doubled (or perhaps quadrupled) this should be sufficiently secure, though longer to write down.

3.3 SUCCESSFUL EXAMPLES

Letโ€™s now describe some successful (at least per current knowledge) pseudorandom generators:

3.3.1 Case Study 1: Subset Sum Generator Here is an extremely simple generator that is yet still secure^10 as far as we know.

_# seed is a list of 40 zero/one values

output is a 48 bit integer_

def subset_sum_gen(seed): modulo = 0x constants = [ 0x3D6EA1, 0x1E2795, 0xC802C6, 0xBF742A, 0x45FF31, 0x53A9D4, 0x927F9F, 0x70E09D, 0x56F00A, 0x78B494, 0x9122E7, 0xAFB10C, 0x18C2C8, 0x8FF050, 0x0239A3, 0x02E4E0, 0x779B76, 0x1C4FC2, 0x7C5150, 0x81E05E, 0x154647, 0xB80E68, 0xA042E5, 0xE20269, 0xD3B7F3, 0xCC5FB9, 0x0BFC55, 0x847AE0, 0x8CFDF8, 0xE304B7, 0x869ACE, 0xB4CDAB, 0xC8E31F, 0x00EDC7, 0xC50541, 0x0D6DDD, 0x695A2F, 0xA81062, 0x0123CA, 0xC6C5C3 ]

_# return the modular sum of the constants

corresponding to ones in the seed_

return reduce( lambda x,y: (x+y) % modulo, map( lambda a,b: a*b, constants,seed))

The seed to this generator is an array seed of 40 bits, with 40 hard- wired constants each 48 bits long (these constants were generated at random, but are fixed once and for all, and are not kept secret and hence are not considered part of the secret random seed). The output is simply 40 โˆ‘ ๐‘–=

seed[๐‘–]constants[๐‘–] (mod 248 )

and hence expands the 40 bit input into a 48 bit output. This generator is loosely motivated by the โ€œsubset sumโ€ computa- tional problem, which is NP hard. However, since NP hardness is a worst case notion of complexity, it does not imply security for pseudo- random generators, which requires hardness of an average case variant. To get some intuition for its security, we can work out why (given that it seems to be linear) we cannot break it by simply using Gaussian elimination.

106 an intensive introduction to cryptography

(^11) I typically do not include references in these lecture notes, and leave them to the texts, but I make here an exception because Itsik Mantin was a close friend of mine in grad school.

ized to zero, although to save on initial seed size, typically RC4 uses some โ€œpseudorandomโ€ way to generate P from a shorter seed as well. RC4 has extremely efficient software implementations and hence has been widely implemented. However, it has several issues with its security. In particular it was shown by Mantin^11 and Shamir that the second bit of RC4 is not random, even if the initialization vector was random. This and other issues led to a practical attack on the 802.11b WiFi protocol, see Section 9.9 in Boneh-Shoup. The initial response to those attacks was to suggest to drop the first 1024 bytes of the output, but by now the attacks have been sufficiently extended that RC4 is simply not considered a secure cipher anymore. The ciphers Salsa and ChaCha, designed by Dan Bernstein, have a similar design to RC4, and are considered secure and deployed in several standard protocols such as TLS, SSH and QUIC, see Section 3.6 in Boneh-Shoup.

3.3.3 Case Study 3: Blum, Blum and Shub B.B.S., which stands for the authors Blum, Blum and Shub, is a simple generator constructed from a potentially hard problem in number theory. Let ๐‘ = ๐‘ƒ โ‹… ๐‘„, where ๐‘ƒ , ๐‘„ are primes. (We will generally use ๐‘ƒ , ๐‘„ of size roughly ๐‘›, where ๐‘› is our security parameter, and so use capital letters to emphasize that the magnitude of these numbers is exponential in the security parameter.) We define QR ๐‘ to be the set of quadratic residues modulo ๐‘ , which are the numbers that have a modular square root. Formally,

QR ๐‘ = {๐‘‹^2 mod ๐‘ โˆฃ gcd(๐‘‹, ๐‘ ) = 1}. This definition extends the concept of โ€œperfect squaresโ€ when we are working with standard integers. Notice that each number in ๐‘Œ โˆˆ QR ๐‘ has at least one square root (number ๐‘‹ such that ๐‘Œ = ๐‘‹^2 mod ๐‘ ). We will see later in the course that if ๐‘ = ๐‘ƒ โ‹… ๐‘„ for primes ๐‘ƒ , ๐‘„ then each ๐‘Œ โˆˆ QR ๐‘ has exactly 4 square roots. The B.B.S. genera- tor chooses ๐‘ = ๐‘ƒ โ‹… ๐‘„, where ๐‘ƒ , ๐‘„ are prime and ๐‘ƒ , ๐‘„ โ‰ก 3 (mod 4). The second condition guarantees that for each ๐‘Œ โˆˆ QR ๐‘ , exactly one of its square roots fall in QR ๐‘ , and hence the map ๐‘‹ โ†ฆ ๐‘‹^2 mod ๐‘ is one-to-one and onto map from QR ๐‘ to itself. It is defined as follows:

def BBS(X): return (X * X % N, N % 2)

In other words, on input ๐‘‹, BBS (๐‘‹) outputs ๐‘‹^2 mod ๐‘ and the least significant bit of ๐‘‹. We can think of BBS as a map BBS โˆถ ๐‘„๐‘…๐‘ โ†’ QR ๐‘ ร— {0, 1} and so it maps a domain into a larger domain. We can also extend it to output ๐‘ก additional bits, by repeatedly squaring the

pseudorandomness 107

(^12) There is a whole (highly recommended) book by Alon and Spencer devoted to this method.

input, letting ๐‘‹ 0 = ๐‘‹, ๐‘‹๐‘–+1 = ๐‘‹๐‘–^2 mod ๐‘ , for ๐‘– = 0, โ€ฆ , ๐‘ก โˆ’ 1, and outputting ๐‘‹๐‘ก together with the least significant bits of ๐‘‹ 0 , โ€ฆ , ๐‘‹๐‘กโˆ’1. It turns out that assuming that there is no polynomial-time algorithm (where โ€œpolynomial-timeโ€ means polynomial in the number of bits to represent ๐‘ , i.e., polynomial in log ๐‘ ) to factor randomly chosen integers ๐‘ = ๐‘ƒ โ‹… ๐‘„, for every ๐‘ก that is polynomial in the number of bits in ๐‘ , the output of the ๐‘ก-step BBS generator will be computationally indistinguishable from ๐‘ˆ๐‘„๐‘…๐‘ ร— ๐‘ˆ๐‘ก where ๐‘ˆ๐‘„๐‘…๐‘ denotes the uniform distribution over QR ๐‘. The number theory required to show takes a while to develop. However, it is interesting and I recommend the reader to search up this particular generator, see for example this survey by Junod.

3.4 NON-CONSTRUCTIVE EXISTENCE OF PSEUDORANDOM GEN- ERATORS

We now show that, if we donโ€™t insist on constructivity of pseudoran- dom generators, then there exists pseudorandom generators with output that are exponentially larger than the input length.

Lemma 3.12 โ€” Existence of inefficient pseudorandom generators. There is some absolute constant ๐ถ such that for every ๐œ–, ๐‘‡ , if โ„“ > ๐ถ(log ๐‘‡ + log(1/๐œ–)) and ๐‘š โ‰ค ๐‘‡ , then there is an (๐‘‡ , ๐œ–) pseudorandom generator ๐บ โˆถ {0, 1}โ„“^ โ†’ {0, 1}๐‘š.

Proof Idea: The proof uses an extremely useful technique known as the โ€œprob- abilistic methodโ€ which is not too hard mathematically but can be confusing at first.^12 The idea is to give a โ€œnon constructiveโ€ proof of existence of the pseudorandom generator ๐บ by showing that if ๐บ was chosen at random, then the probability that it would be a valid (๐‘‡ , ๐œ–) pseudorandom generator is positive. In particular this means that there exists a single ๐บ that is a valid (๐‘‡ , ๐œ–) pseudorandom generator. The probabilistic method is just a proof technique to demonstrate the existence of such a function. Ultimately, our goal is to show the ex- istence of a deterministic function ๐บ that satisfies the conditions of a (๐‘‡ , ๐œ–) PRG. โ‹†

The above discussion might be rather abstract at this point, but would become clearer after seeing the proof.

Proof of Lemma 3.12. Let ๐œ–, ๐‘‡ , โ„“, ๐‘š be as in the lemmaโ€™s statement. We need to show that there exists a function ๐บ โˆถ {0, 1}โ„“^ โ†’ {0, 1}๐‘š^ that โ€œfoolsโ€ every ๐‘‡ line program ๐‘ƒ in the sense of (3.1). We will show that this follows from the following claim:

pseudorandomness 109

๐‘ƒ โˆถ {0, 1}๐‘š^ โ†’ {0, 1}, if ๐ฟ > 2๐ถ(log^ ๐‘‡ +log(1/๐œ–))^ (which by setting ๐ถ > 4, we can ensure is larger than 10๐‘‡ 2 /๐œ–^2 ) then the probability that

โˆฃ ๐ฟ^1

๐ฟโˆ’ โˆ‘ ๐‘–=

๐‘ƒ (๐‘ฆ๐‘–) โˆ’ Pr ๐‘ โ†๐‘…{0,1}๐‘š

[๐‘ƒ (๐‘ ) = 1]โˆฃ > ๐œ– (3.3)

is at most 2 โˆ’๐‘‡^2. ( ?? ) follows directly from the Chernoff bound. If we let for every ๐‘– โˆˆ [๐ฟ] the random variable ๐‘‹๐‘– denote ๐‘ƒ (๐‘ฆ๐‘–), then since ๐‘ฆ 0 , โ€ฆ , ๐‘ฆ๐ฟโˆ’1 is chosen independently at random, these are inde- pendently and identically distributed random variables with mean ๐”ผ๐‘ฆโ†๐‘…{0,1}๐‘š [๐‘ƒ (๐‘ฆ)] = Pr๐‘ฆโ†๐‘…{0,1}๐‘š [๐‘ƒ (๐‘ฆ) = 1] and hence the probability that they deviate from their expectation by ๐œ– is at most 2 โ‹… 2โˆ’๐œ–^2 ๐ฟ/2. โ–