2.2 Stream Ciphers and Pseudorandom Generators
Section 2.1 showed that perfect secrecy costs one bit of key per bit of message, and the one-time pad meets that cost exactly. The way out is not a cleverer cipher but a weaker demand on the pad. The pad does not have to be random; it has to be indistinguishable from random for anyone who does not hold the seed that produced it. A short key is stretched into a long pad by a public deterministic algorithm, and the pad is then consumed exactly as in the one-time pad.
The construction is a stream cipher, the stretching algorithm is a pseudorandom generator, and everything about the cipher’s security reduces to a property of that algorithm. This section defines both objects, isolates the minimum the generator must satisfy, and explains why the generators that ship with programming languages do not satisfy it.
2.2.1 Making the one-time pad practical
Fix a message length
Both algorithms recompute the same pad from the same key, so correctness is again one line of XOR algebra:
With
Three facts shape everything that follows.
A stream cipher cannot have perfect secrecy. The key space has
A new definition of security is needed. Perfect secrecy asked for too much; the right notion will bound the advantage of an efficient attacker and allow a negligible failure probability. That definition is the work of the later sections of this chapter.
Security now rests entirely on
2.2.2 What a pseudorandom generator is
A generator concentrates randomness: it takes
Definition (pseudorandom generator)
A pseudorandom generator (PRG) is an efficient deterministic algorithm
The indistinguishability clause is the hard part, and it is made precise in Section 2.5. The two structural clauses already carry most of the intuition.
- Deterministic. Bob must reconstruct exactly the pad Alice used, and the channel carries nothing to help him. Any randomness inside
would either have to be transmitted, which defeats the purpose, or reproduced, which is impossible. All the randomness of the construction sits in the seed; itself is fixed, public, and has none. - Expanding.
is what makes the construction an improvement over the pad. A generator with would buy nothing, and one with would throw key material away.
Note what is not required. The definition does not ask that the seed be hard to recover, that the output avoid any particular pattern, or that any single statistic take its expected value. It asks one thing of the whole string: that no efficient test separate it from uniform.
2.2.3 A pad must not be predictable
Here is what “indistinguishable from random” has to rule out at a minimum. An SMTP message begins with the five characters From: and the space after them, six bytes that the sender cannot avoid and the attacker knows. XOR those six bytes into the first six bytes of the ciphertext and the attacker has recovered the first 48 bits of the pad, without touching the key. If 48 bits of pad determine the rest, one known header decrypts the entire message: the attacker predicts the pad forward, XORs it into the ciphertext, and reads the plaintext off.
The lesson generalizes to a single bit. An attacker who knows the first
Definition (predictable generator)
for some non-negligible
The
Theorem (predictability breaks the cipher)
If
Proof. The attacker XORs the known message prefix into the ciphertext and holds
Note the shape of the argument: the attacker never attacks
Quiz: A generator has the property that, for every seed, the XOR of all bits of its output is . Is it predictable?
Yes, at position
2.2.4 Negligible and non-negligible
Two words carry weight in the definitions so far. Efficient means polynomial time in the size of the objects involved, and that is all it will ever mean here. Non-negligible is defined differently by different communities: practitioners treat it as a property of a single number, and the formal definitions treat it as a property of a function. Both readings are worth having; the first gives the numbers to remember, the second is the official one.
In practice. Take
which is a coin flip, not a safety margin. A probability of
In theory. The scalar answer depends on the deployment it was computed for: change the key, change the amount of traffic, and the verdict can move. A definition should not hang on one deployment. In the rigorous view a generator is not one algorithm but a family
Definition (negligible, non-negligible)
Let
and
Unpacked: negligible means beating every inverse polynomial eventually, and all degrees at once.
| verdict | |
|---|---|
| negligible: exponential decay beats every inverse polynomial | |
| non-negligible: take | |
| non-negligible: the even |
The last two rows look wrong from the practitioner’s seat. At
One closure property does most of the work in the proofs that follow: a polynomial factor does not spoil negligibility. An efficient adversary can repeat an experiment polynomially many times, or attack polynomially many keys, and each such multiplication scales her edge by a polynomial; if
Two conventions for the rest of this tutorial. The parameter
2.2.5 Generators that look random and are not
Statistical quality is easy to fake, and the generators shipped with programming languages fake it well. Both examples below pass the elementary tests and neither can be used for a key.
Linear congruential generators. Pick integers
and the generator outputs a few bits of
The C library’s random(). The glibc implementation keeps a 31-word state and updates it by
a lagged Fibonacci recurrence. The new word
The general lesson is that a statistical test examines the output as a bag of bits, while an attacker examines the algorithm that produced it. The standard checks measure properties the generator happens to have: about as many zeros as ones, the pattern 00 in about a quarter of the positions, and the like; security has to hold against tests designed with the generator’s structure in mind. This is why Section 2.5 defines the security of a generator by quantifying over all efficient tests rather than listing a few, and why any generator not designed and analyzed for the purpose should be assumed predictable.