Private-Key Encryption and Pseudorandomness

Computational security and how short keys encrypt long messages. The concrete (t, ε) and asymptotic approaches, security parameter, probabilistic polynomial-time adversaries, negligible functions and their closure, why both relaxations are necessary (brute force, guessing), proofs by reduction. Computationally secure encryption: syntax with 1ⁿ, indistinguishability against an eavesdropper (two equivalent forms), why messages must have equal length, and semantic security (bit- and function-prediction claims, the full definition, equivalence). Pseudorandom generators, their distance from uniform, and the brute-force distinguisher; the pseudorandom one-time pad and its reduction proof; variable output-length generators; stream ciphers in practice (RC4, LFSRs). Multiple encryptions: deterministic schemes fail, plus synchronized and IV-based modes. CPA security with the Midway story; CPA for one message implies many; bitwise extension to arbitrary lengths. Pseudorandom functions (oracle definition, the size of Func_n), the r ↦ ⟨r, F_k(r)⊕m⟩ scheme with its q/2ⁿ proof, strong pseudorandom permutations and block ciphers, and the modes ECB, CBC, OFB and CTR (CTR proof with overlap bound 2q²/2ⁿ, block-length lessons). CCA security, malleability, and why none of these schemes are CCA-secure. Exercises worked.

· 27 min read · 5,244 words

Corresponds to Katz & Lindell, Introduction to Modern Cryptography, Chapter 3.

Motivation: beating the one-time pad’s key bound

IntuitionGive up a little, gain everything

Perfect secrecy forces the key to be as long as all messages ever sent with it. Modern schemes are breakable in principle, but breaking them would take more than many lifetimes on the fastest computers. That is exactly Kerckhoffs’ other principle: practically, if not mathematically, indecipherable. We keep definitions and proofs, but weaken the definitions in two ways:

  1. security only against efficient adversaries;
  2. adversaries may succeed with some very small probability.

This currently requires assumptions: an unconditional proof that any scheme with messages longer than keys is secure would imply P ≠ NP.


The computational approach

Concrete versus asymptotic security

DefinitionConcrete security

A scheme is (t,ε)(t,\varepsilon)-secure if every adversary running for time at most tt breaks it with probability at most ε\varepsilon (for example, t=280t = 2^{80} cycles, ε=2−64\varepsilon = 2^{-64}).

ExampleHow big is big (Example 3.1)

Good private-key schemes with nn-bit keys are believed to be essentially optimal: success about t/2nt/2^n for time tt (brute force achieves this).

  • 2602^{60} cycles at 1 GHz is about 35 years, barely within reach with massive parallelism.
  • 2128/260=2682^{128}/2^{60} = 2^{68}, a 21-digit factor. The universe is about 2582^{58} seconds old.
  • An event once a century has probability about 2−302^{-30} per second; 2−602^{-60} per second is about once per 100 billion years.

WarningPitfalls of concrete claims

“No adversary running 5 years succeeds with probability above ε\varepsilon”: on what hardware? Does it account for Moore’s law? Generic or optimised attacks? It says nothing about 2 or 10 years. And theoretically, there is no threshold at which (t,ε)(t,\varepsilon) means “secure”.

DefinitionAsymptotic security

Schemes take a security parameter nn, known to the adversary and given in unary 1n1^n so that running time is polynomial in input length. Running times and success probabilities are functions of nn.

  • Efficient = probabilistic polynomial time (ppt). Adversaries may run much longer than honest parties, but still polynomially.

  • Small = negligible: smaller than every inverse polynomial eventually.

A scheme is secure if every ppt adversary succeeds with only negligible probability.

ExampleAsymptotic security only bites for large nn (Examples 3.2–3.4)

  • An attack taking n3n^3 minutes with success 240⋅2−n2^{40}\cdot2^{-n} is asymptotically negligible. Yet at n=40n = 40 it takes about 6 weeks and succeeds with certainty; at n=50n = 50, about 3 months with success about 1/10001/1000; at n=500n = 500, about 240 years with success 2−4602^{-460}.
  • Faster computers help defenders: honest cost 106n210^6n^2 cycles, attack 108n410^8n^4 cycles for success 220−n2^{20-n}. At 1 GHz with n=50n = 50: honest 2.5 s, the attack about a week for 2−302^{-30}. After everyone upgrades to 16 GHz, honest parties move to n=100n = 100 and still take only 0.625 s, while the same week-long attack now succeeds with only 2−802^{-80}.
  • Asymptotic to concrete: “time p(n)p(n) ⇒ success ≤p(n)/2n\le p(n)/2^n” with n=50n = 50 and p(n)=n2p(n) = n^2 gives (502,502/250)(50^2, 50^2/2^{50})-security.

The asymptotic approach is machine-independent (the Church–Turing thesis says all reasonable devices are polynomially related), but honest parties must still pick a concrete nn.

ImportantBoth relaxations are necessary

If ∣K∣<∣M∣\lvert\mathcal K\rvert < \lvert\mathcal M\rvert (many long messages, one short key), two attacks work against any scheme:

  • Brute force: decrypt with every key. A few known plaintext–ciphertext pairs pin down the key. Success about 1, time about ∣K∣\lvert\mathcal K\rvert.
  • Guessing: try one random key. Polynomial time, success about 1/∣K∣1/\lvert\mathcal K\rvert.

So we must bound time and forgive tiny success. Asymptotically, the key space Kn\mathcal K_n must grow super-polynomially in nn.

Efficient algorithms and negligible probabilities

DefinitionProbabilistic polynomial time

Runs within p(∣x∣)p(\lvert x\rvert) steps for some polynomial pp, with access to unbiased independent coin flips (equivalently, a random tape of length p(n)p(n)).

  • Why polynomial: the class is closed under composition. Otherwise nothing is special: results also hold for, say, nO(log⁡n)n^{O(\log n)}-time adversaries.
  • Why probabilistic: honest parties need randomness (keys), and adversaries should be as powerful as is realistic. Whether randomness helps is open (complexity results suggest it doesn’t); security against ppt implies security against deterministic adversaries.

WarningReal randomness is hard

Sources: hardware noise or radioactive decay, timing of keystrokes, mouse movement and disk accesses. These need post-processing to become uniform. Use a cryptographic generator: C’s random() and the current time are not random enough for keys.

DefinitionNegligible function (Def. 3.5)

ff is negligible if for every polynomial pp there is NN with f(n)<1/p(n)f(n) < 1/p(n) for all n>Nn > N. Equivalently, f(n)<n−cf(n) < n^{-c} eventually, for every cc. Write negl\mathrm{negl}.

ExampleNegligible functions differ wildly (Example 3.6)

2−n2^{-n}, 2−n2^{-\sqrt n} and n−log⁡nn^{-\log n} are all negligible. They drop below 10−610^{-6} at n=20n = 20, n=400n = 400 and n=32n = 32 respectively. Yet 2−n<n−log⁡n2^{-\sqrt n} < n^{-\log n} for all n>65536n > 65536 (where n=(log⁡n)2\sqrt n = (\log n)^2). Asymptotic order and practical size can disagree.

TheoremProposition 3.7 — Closure

negl1+negl2\mathrm{negl}_1 + \mathrm{negl}_2 and p(n)⋅negl(n)p(n)\cdot\mathrm{negl}(n) (for any polynomial pp) are negligible. So a negligible-probability event stays negligible over polynomially many repetitions (union bound). Negligible-probability breaks are not breaks: you are likelier to be hit by an asteroid, or lose the key to a disk failure.

Proofs by reduction

AlgorithmTemplate of a reduction proof

Assumption: problem XX is hard (every ppt algorithm solves it with negligible probability). Goal: construction Π\Pi is secure.

  1. Fix any ppt adversary A\mathcal A against Π\Pi, with success ε(n)\varepsilon(n).
  2. Build a ppt A′\mathcal A' that, given an instance xx of XX, simulates Π\Pi for A\mathcal A:
    • (a) A\mathcal A‘s view is (close to) identical to a real attack;
    • (b) A\mathcal A‘s success lets A′\mathcal A' solve xx with probability at least ε(n)/p(n)\varepsilon(n)/p(n).
  3. A non-negligible ε\varepsilon would solve XX non-negligibly, a contradiction.
  4. So ε\varepsilon is negligible.

A′\mathcal A' uses A\mathcal A as a black box, with no knowledge of how it works. Every proof in the book has this form (Principle 3).


Computationally secure encryption

DefinitionPrivate-key encryption scheme (Def. 3.8)

Ppt algorithms with k←Gen(1n)k\leftarrow\mathrm{Gen}(1^n) (where ∣k∣≥n\lvert k\rvert\ge n), c←Enck(m)c\leftarrow\mathrm{Enc}_k(m) for m∈{0,1}∗m\in\{0,1\}^* (possibly randomised), and m:=Deck(c)m := \mathrm{Dec}_k(c) (deterministic), with perfect correctness. Fixed-length with parameter ℓ\ell: Enc is defined only on {0,1}ℓ(n)\{0,1\}^{\ell(n)}.

DefinitionEavesdropping indistinguishability experiment PrivKA,Πeav(n)\mathrm{PrivK}^{\mathrm{eav}}_{\mathcal A,\Pi}(n)

  1. A(1n)\mathcal A(1^n) outputs m0,m1m_0, m_1 of equal length.
  2. k←Gen(1n)k\leftarrow\mathrm{Gen}(1^n), b←{0,1}b\leftarrow\{0,1\}, c←Enck(mb)c\leftarrow\mathrm{Enc}_k(m_b) given to A\mathcal A.
  3. A\mathcal A outputs b′b'; success iff b′=bb' = b.

Def. 3.9: Π\Pi has indistinguishable encryptions in the presence of an eavesdropper (is EAV-secure) if for every ppt A\mathcal A,

Pr⁡[PrivKA,Πeav(n)=1]≤12+negl(n)\Pr[\mathrm{PrivK}^{\mathrm{eav}}_{\mathcal A,\Pi}(n) = 1]\le\frac12 + \mathrm{negl}(n)

This is Definition 2.4 with two relaxations: ppt adversaries and a negligible advantage.

ComponentDetail
Powersees one ciphertext, chooses the two candidate messages, polynomial time
Breakguessing which message was encrypted noticeably better than ½
Strategyunrestricted (the arbitrary-adversary principle)

WarningEncryption doesn’t hide length

Equal-length messages are required. For schemes encrypting arbitrary lengths, unequal lengths make the definition unsatisfiable: compare a 1-bit message with one longer than any 1-bit ciphertext could be (Exercise 3.3). Bounded-length schemes can drop the restriction by padding everything to the maximum (Exercise 3.4). In practice, pad when length itself is sensitive (a salary’s number of digits).

DefinitionEquivalent form (Def. 3.10)

Fixing bb in the experiment, ∣Pr⁡[out(PrivKeav(n,0))=1]−Pr⁡[out(PrivKeav(n,1))=1]∣≤negl(n)\big\lvert\Pr[\mathrm{out}(\mathrm{PrivK}^{\mathrm{eav}}(n,0)) = 1] - \Pr[\mathrm{out}(\mathrm{PrivK}^{\mathrm{eav}}(n,1)) = 1]\big\rvert\le\mathrm{negl}(n): the adversary behaves the same on encryptions of m0m_0 and m1m_1. Equivalence (Exercise 3.5): Pr⁡[success]=12+12(Pr⁡[out0=0]−Pr⁡[out1=0])\Pr[\text{success}] = \frac12 + \frac12(\Pr[\mathrm{out}_0 = 0] - \Pr[\mathrm{out}_1 = 0]).

Semantic security

TheoremClaims 3.11–3.12 — Indistinguishability hides partial information

For an EAV-secure scheme:

  • No bit leaks: for uniform m∈{0,1}nm\in\{0,1\}^n and any position ii, Pr⁡[A(1n,Enck(m))=mi]≤12+negl\Pr[\mathcal A(1^n,\mathrm{Enc}_k(m)) = m^i]\le\frac12 + \mathrm{negl}. If A\mathcal A predicted bit ii, distinguish random messages with bit i=0i = 0 from ones with bit i=1i = 1.
  • No function leaks (uniform over an efficiently sampleable set SnS_n, ff poly-time): some A′\mathcal A' without the ciphertext computes f(m)f(m) almost as well. A′\mathcal A' simply runs A\mathcal A on Enck(1n)\mathrm{Enc}_k(1^n), a ciphertext of a fixed dummy message. A gap would distinguish Enc(m)\mathrm{Enc}(m) from Enc(1n)\mathrm{Enc}(1^n).

DefinitionSemantic security (Def. 3.13; Goldwasser–Micali)

For every ppt A\mathcal A there is a ppt A′\mathcal A' such that for every efficiently sampleable plaintext distribution XX (equal lengths per nn) and all poly-time ff (target) and hh (external information),

∣Pr⁡[A(1n,Enck(m),h(m))=f(m)]−Pr⁡[A′(1n,h(m))=f(m)]∣≤negl(n)\big\lvert\Pr[\mathcal A(1^n,\mathrm{Enc}_k(m),h(m)) = f(m)] - \Pr[\mathcal A'(1^n,h(m)) = f(m)]\big\rvert\le\mathrm{negl}(n)

The ciphertext adds nothing beyond what external knowledge h(m)h(m) already gives. This is the formal version of “no function of the plaintext can be computed”.

TheoremTheorem 3.14 — Indistinguishability ⟺ semantic security

Use indistinguishability (easier to prove) and get semantic security (what we want). Analogous equivalences hold for every definition in this chapter.


Pseudorandomness

IntuitionLooks random to anyone efficient

Pseudorandomness is a property of a distribution (strictly, a sequence of distributions), not of a string: no ppt algorithm can tell it from uniform. It is the computational relaxation of true randomness, just as indistinguishability relaxes perfect secrecy. Payoff: XOR a long pseudorandom pad, grown from a short seed, into the message. To an efficient observer this is the one-time pad.

DefinitionPseudorandom generator (Def. 3.15)

A deterministic poly-time GG with ∣G(s)∣=ℓ(∣s∣)\lvert G(s)\rvert = \ell(\lvert s\rvert) such that

  1. Expansion: ℓ(n)>n\ell(n) > n;
  2. Pseudorandomness: for every ppt distinguisher DD, ∣Pr⁡[D(r)=1]−Pr⁡[D(G(s))=1]∣≤negl(n),r←{0,1}ℓ(n), s←{0,1}n\big\lvert\Pr[D(r) = 1] - \Pr[D(G(s)) = 1]\big\rvert\le\mathrm{negl}(n),\qquad r\leftarrow\{0,1\}^{\ell(n)},\ s\leftarrow\{0,1\}^n

ℓ\ell is the expansion factor.

WarningPRG outputs are far from uniform

With ℓ(n)=2n\ell(n) = 2n, at most 2n2^n of the 22n2^{2n} strings are outputs, so a random string is in the range with probability at most 2−n2^{-n}. The exponential-time brute-force distinguisher (“does some seed produce this?”) has advantage 1−2−n1 - 2^{-n}. Pseudorandomness holds only because efficient algorithms can’t run it. Hence: the seed must be uniform, secret, and long enough to make seed search infeasible.

NoteExistence

Unproven, but implied by one-way functions (Chapter 6), which exist if, for example, factoring is hard. Practical constructions (stream and block ciphers) are believed to satisfy even stronger properties.


Constructing secure encryption schemes

The pseudorandom one-time pad

AlgorithmConstruction 3.16

With GG a PRG of expansion ℓ\ell: k←{0,1}nk\leftarrow\{0,1\}^n; Enck(m)=G(k)⊕m\mathrm{Enc}_k(m) = G(k)\oplus m for m∈{0,1}ℓ(n)m\in\{0,1\}^{\ell(n)}; Deck(c)=G(k)⊕c\mathrm{Dec}_k(c) = G(k)\oplus c.

TheoremTheorem 3.17 — PRG ⇒ EAV-secure encryption

If GG is a pseudorandom generator, Construction 3.16 has indistinguishable encryptions in the presence of an eavesdropper.

ProofReduction to the generator

Let ε(n)=Pr⁡[PrivKA,Πeav(n)=1]−12\varepsilon(n) = \Pr[\mathrm{PrivK}^{\mathrm{eav}}_{\mathcal A,\Pi}(n) = 1] - \frac12. Distinguisher D(w)D(w), w∈{0,1}ℓ(n)w\in\{0,1\}^{\ell(n)}: run A(1n)\mathcal A(1^n) to get m0,m1m_0, m_1; pick bb; give c=w⊕mbc = w\oplus m_b; output 1 iff A\mathcal A guesses bb.

  • If ww is uniform, A\mathcal A sees a genuine one-time pad Π~\tilde\Pi, so Pr⁡[D=1]=12\Pr[D = 1] = \frac12 by perfect secrecy.
  • If w=G(k)w = G(k), A\mathcal A sees exactly Π\Pi, so Pr⁡[D=1]=12+ε(n)\Pr[D = 1] = \frac12 + \varepsilon(n).

The distinguishing gap is ε(n)\varepsilon(n), which must be negligible.

∎

ImportantWhat was gained

Still XOR with an ℓ\ell-bit pad, but the pad comes from an nn-bit key, so a 128-bit key encrypts megabytes. This contradicts nothing: Theorem 2.7 is about unbounded adversaries. Reducing to a lower-level primitive is preferable because primitives are easier to design, study and gain confidence in.

Variable lengths and stream ciphers

DefinitionVariable output-length PRG (Def. 3.18)

G(s,1ℓ)G(s,1^\ell) outputs ℓ\ell bits; shorter outputs are prefixes of longer ones; and for every polynomial ℓ(⋅)\ell(\cdot), s↦G(s,1ℓ(∣s∣))s\mapsto G(s,1^{\ell(\lvert s\rvert)}) is a PRG. Encrypt with c=G(k,1∣m∣)⊕mc = G(k,1^{\lvert m\rvert})\oplus m. Any PRG can be converted to one; from a PRF: G(s,1ℓ)=Fs(⟨1⟩)∥Fs(⟨2⟩)∥⋯G(s,1^\ell) = F_s(\langle1\rangle)\Vert F_s(\langle2\rangle)\Vert\cdots, truncated (Exercise 3.9).

WarningStream ciphers in practice

The book’s terminology: a stream cipher is the pad-generating tool (ideally a variable output-length PRG), not an encryption scheme. How it is used determines security.

  • RC4: fast and once trusted, but early output bytes are biased, which broke WEP (802.11). The advice was to discard about the first 1024 bits. (Since then RC4 has been prohibited in TLS by RFC 7465, 2015.)
  • LFSRs: completely insecure, since the key is recoverable from enough output.

Stream ciphers are less well understood than block ciphers, so prefer block ciphers (perhaps in a streaming mode) unless resources are very tight. RC4 was only about twice as fast as AES on a PC.

Multiple encryptions

DefinitionMulti-message experiment PrivKmult\mathrm{PrivK}^{\mathrm{mult}} (Def. 3.19)

A\mathcal A outputs two vectors m⃗0,m⃗1\vec m_0,\vec m_1 of the same number of messages, with pairwise equal lengths, and receives encryptions of all of m⃗b\vec m_b under one key. Same success condition.

TheoremClaim 3.20, Theorem 3.21 — Deterministic encryption fails for multiple messages

Any scheme whose Enc is a deterministic function of key and message is insecure for multiple encryptions. Output m⃗0=(0n,0n)\vec m_0 = (0^n,0^n) and m⃗1=(0n,1n)\vec m_1 = (0^n,1^n), then check whether the two ciphertexts are equal: success probability 1. Construction 3.16 is EAV-secure but not multi-message secure. Secure multi-message encryption must be probabilistic (or stateful).

WarningReusing a stream is a classic implementation error

Microsoft Word and Excel once reused the pad across documents. Even without repeated messages, c⊕c′=m⊕m′c\oplus c' = m\oplus m' is devastating.

AlgorithmUsing a stream cipher safely

  • Synchronized (stateful): both parties consume successive, never-reused portions of one stream. Within a session, the whole conversation is one long message, so Theorem 3.17 applies. Stateful, so it escapes Theorem 3.21.
  • Unsynchronized (IV-based): Enck(m)=⟨IV, G(k,IV)⊕m⟩\mathrm{Enc}_k(m) = \langle IV,\ G(k,IV)\oplus m\rangle with a fresh uniform IVIV. This needs a much stronger generator: streams for independent random IVIVs must look independent and random even given the IVIVs. That is nearly a pseudorandom function.

Chosen-plaintext attacks

DefinitionCPA experiment PrivKA,Πcpa(n)\mathrm{PrivK}^{\mathrm{cpa}}_{\mathcal A,\Pi}(n) (Def. 3.22)

  1. k←Gen(1n)k\leftarrow\mathrm{Gen}(1^n).
  2. AEnck(⋅)(1n)\mathcal A^{\mathrm{Enc}_k(\cdot)}(1^n), with an encryption oracle (fresh coins per query), outputs equal-length m0,m1m_0, m_1.
  3. Challenge c←Enck(mb)c\leftarrow\mathrm{Enc}_k(m_b).
  4. A\mathcal A keeps oracle access and outputs b′b'; success iff b′=bb' = b.

CPA-secure: success at most 12+negl(n)\frac12 + \mathrm{negl}(n) for every ppt A\mathcal A. This implies EAV security (just ignore the oracle).

ImportantCPA security requires randomised encryption

Otherwise, query m0m_0 and m1m_1 and compare with the challenge. No deterministic (stateless) scheme is CPA-secure.

ExampleChosen-plaintext attacks happen: Midway, 1942

US Navy cryptanalysts suspected the ciphertext fragment “AF” meant Midway, but couldn’t convince Washington. They had Midway send a plaintext report of low freshwater. Japanese intercepts soon reported “AF” was short of water. The Japanese had unknowingly encrypted a chosen plaintext, confirming the target, and the resulting US victory is often called the Pacific war’s turning point. Modern analogue: servers encrypting messages derived from user-controlled requests. Always use CPA-secure encryption.

TheoremClaim 3.23 and length extension

  • CPA security for one message ⇒ CPA security for many (proved later in the public-key setting). Unlike EAV security, there is no separate multi-message notion.
  • Arbitrary lengths for free: from a CPA-secure scheme for 1-bit messages, Enck′(m)=Enck(m1),…,Enck(mℓ)\mathrm{Enc}'_k(m) = \mathrm{Enc}_k(m_1),\ldots,\mathrm{Enc}_k(m_\ell) is CPA-secure (by the multi-message property). Inefficient, but it means fixed-length constructions lose no generality.

ExampleMulti-message EAV security does not imply CPA (Exercise 3.7)

Take Enck(m)=⟨r, Fk(r)⊕m, Fk(0n)⟩\mathrm{Enc}_k(m) = \langle r,\ F_k(r)\oplus m,\ F_k(0^n)\rangle for r≠0nr\ne0^n, but also output kk if m=Fk(0n)m = F_k(0^n). A multi-message eavesdropper fixes all its messages before seeing anything, so it hits Fk(0n)F_k(0^n) with negligible probability. A CPA adversary queries once, reads Fk(0n)F_k(0^n), and queries it to get the key. Adaptivity matters. (Construction worked here.)

TheoremPerfect CPA security is impossible (Exercise 3.12)

Even against unbounded adversaries. Query m0m_0 and m1m_1 once each, getting fresh c0′,c1′c_0', c_1'. Guess 0 if only c0′c_0' equals the challenge cc, 1 if only c1′c_1' does, at random otherwise. With Pk,bP_{k,b} the ciphertext distribution of mbm_b under kk,

Pr⁡[success]−12=14 Ek[∑c(Pk,0(c)−Pk,1(c))2]>0\Pr[\text{success}] - \tfrac12 = \tfrac14\,\mathbb E_k\Big[\sum_c\big(P_{k,0}(c) - P_{k,1}(c)\big)^2\Big] > 0

because correctness forces Pk,0P_{k,0} and Pk,1P_{k,1} to have disjoint supports. The advantage may be negligible, but never zero. (Argument worked here.)


Pseudorandom functions and CPA-secure encryption

DefinitionKeyed functions and Funcn\mathrm{Func}_n

A keyed function F(k,x)F(k,x), written Fk(x)F_k(x), is efficient if poly-time computable and, here, length-preserving (∣k∣=∣x∣=∣Fk(x)∣=n\lvert k\rvert = \lvert x\rvert = \lvert F_k(x)\rvert = n). Funcn\mathrm{Func}_n is all functions {0,1}n→{0,1}n\{0,1\}^n\to\{0,1\}^n: a look-up table of n2nn2^n bits, so ∣Funcn∣=2n⋅2n\lvert\mathrm{Func}_n\rvert = 2^{n\cdot2^n}. A uniform ff has independent uniform values at every point. FkF_k ranges over at most 2n2^n of these 2n2n2^{n2^n} functions.

DefinitionPseudorandom function (Def. 3.24; Goldreich–Goldwasser–Micali)

For every ppt DD with oracle access (adaptive, polynomially many queries),

∣Pr⁡[DFk(⋅)(1n)=1]−Pr⁡[Df(⋅)(1n)=1]∣≤negl(n),k←{0,1}n, f←Funcn\big\lvert\Pr[D^{F_k(\cdot)}(1^n) = 1] - \Pr[D^{f(\cdot)}(1^n) = 1]\big\rvert\le\mathrm{negl}(n),\qquad k\leftarrow\{0,1\}^n,\ f\leftarrow\mathrm{Func}_n

Oracle access is needed because a random function’s description is exponentially long.

PointMeaning
Key stays secretwith kk known, query 0n0^n and compare with Fk(0n)F_k(0^n); distinguished with advantage 1−2−n1 - 2^{-n}
Inherits random-function behaviourinputs differing in one bit give unrelated outputs; finding xx with Fk(x)=0nF_k(x) = 0^n is hard
ExistencePRFs exist ⟺ PRGs exist (Chapter 6); block ciphers are believed PRFs
Proof paradigm(1) analyse with a truly random ff (pure probability); (2) any gap would distinguish FkF_k from ff

ExamplePRF counterexamples (Exercises 3.6, 3.8, 3.10)

  • Fk(x)=G′(k)⊕xF_k(x) = G'(k)\oplus x (a truncated PRG output XOR the input) isn’t a PRF: Fk(x)⊕Fk(x′)=x⊕x′F_k(x)\oplus F_k(x') = x\oplus x' always, unlike a random function.
  • PRG modifications: G′(s)=G(s∥0∣s∣)G'(s) = G(s\Vert0^{\lvert s\rvert}) need not be a PRG (a valid PRG can misbehave on that negligible set of seeds). G′(s)=G(s1⋯sn/2)G'(s) = G(s_1\cdots s_{n/2}) stays pseudorandom but may fail to expand if ∣G(s)∣=2∣s∣\lvert G(s)\rvert = 2\lvert s\rvert exactly.

(Worked here.)

AlgorithmConstruction 3.25 — Encrypt with FkF_k at a fresh random point

k←{0,1}nk\leftarrow\{0,1\}^n. Enck(m)\mathrm{Enc}_k(m): choose r←{0,1}nr\leftarrow\{0,1\}^n, output ⟨r, Fk(r)⊕m⟩\langle r,\ F_k(r)\oplus m\rangle. Deck(⟨r,s⟩)=Fk(r)⊕s\mathrm{Dec}_k(\langle r,s\rangle) = F_k(r)\oplus s.

Naive Enck(m)=Fk(m)\mathrm{Enc}_k(m) = F_k(m) is deterministic, hence not CPA-secure. Here each encryption gets an (almost certainly) new pseudorandom pad.

TheoremTheorem 3.26 — PRF ⇒ CPA-secure encryption

If FF is a PRF, Construction 3.25 is a CPA-secure fixed-length scheme for nn-bit messages.

ProofRandom-function world, then reduction

Step 1: Ideal scheme Π~\tilde\Pi with a truly random ff. Let rcr_c be the challenge’s randomness, and Repeat\mathsf{Repeat} the event that some oracle query used rcr_c.

  • Repeat\mathsf{Repeat}: the adversary learns f(rc)=s⊕mf(r_c) = s\oplus m and wins. But Pr⁡[Repeat]≤q(n)/2n\Pr[\mathsf{Repeat}]\le q(n)/2^n for q(n)q(n) queries.
  • ¬Repeat\neg\mathsf{Repeat}: f(rc)f(r_c) is uniform and independent of everything seen, a one-time pad, so success is exactly 12\frac12.

So Pr⁡[PrivKA,Π~cpa=1]≤12+q(n)/2n\Pr[\mathrm{PrivK}^{\mathrm{cpa}}_{\mathcal A,\tilde\Pi} = 1]\le\frac12 + q(n)/2^n (3.4), with no computational assumption on A\mathcal A beyond qq queries.

Step 2: Distinguisher DOD^{\mathcal O}. Run A\mathcal A. Answer each oracle query mm with a fresh rr and ⟨r,O(r)⊕m⟩\langle r,\mathcal O(r)\oplus m\rangle, the challenge likewise with mbm_b. Output 1 iff A\mathcal A guesses bb. With O=Fk\mathcal O = F_k this is exactly Π\Pi; with O=f\mathcal O = f, exactly Π~\tilde\Pi. Then negl≥(12+ε(n))−(12+q(n)2n)\mathrm{negl}\ge\big(\frac12 + \varepsilon(n)\big) - \big(\frac12 + \frac{q(n)}{2^n}\big), so ε(n)≤negl(n)+q(n)/2n\varepsilon(n)\le\mathrm{negl}(n) + q(n)/2^n, which is negligible.

∎

NoteCorollary 3.27 and cost

Block by block with fresh rir_i: ⟨r1,Fk(r1)⊕m1,…,rℓ,Fk(rℓ)⊕mℓ⟩\langle r_1, F_k(r_1)\oplus m_1,\ldots,r_\ell, F_k(r_\ell)\oplus m_\ell\rangle is CPA-secure for arbitrary lengths, but the ciphertext is twice as long as the plaintext. Modes of operation fix this.

Pseudorandom permutations and block ciphers

Definition(Strong) pseudorandom permutation (Def. 3.28)

A keyed permutation (each FkF_k a bijection, with FkF_k and Fk−1F_k^{-1} efficient) such that no ppt DD with oracles for both FkF_k and Fk−1F_k^{-1} can distinguish them from a uniform permutation ff with f−1f^{-1}. (Elsewhere, the forward-only version is “PRP” and this one “strong” or “super” PRP.)

TheoremProposition 3.29 — PRP ⇒ PRF

A random permutation and a random function differ only if a collision f(x)=f(x′)f(x) = f(x') with x≠x′x\ne x' is seen. With qq queries this has probability at most (q2)/2n\binom q2/2^n (birthday bound, Exercise 3.11), which is negligible. So PRPs can replace PRFs anywhere.

ImportantBlock ciphers are PRPs, not encryption schemes

Model block ciphers as (strong) PRPs, which makes modes, MACs and protocols analysable. c=Fk(m)c = F_k(m) alone is deterministic and not CPA-secure. In practice the key length may differ from the block length, which is what the input and output share (see block-cipher-constructions).

ExampleA PRP-only scheme that is CPA (even CCA) secure (Exercise 3.13)

Enck(m)=Fk(r∥m)\mathrm{Enc}_k(m) = F_k(r\Vert m) for m,r∈{0,1}n/2m, r\in\{0,1\}^{n/2} with rr fresh. Decrypt by computing Fk−1(c)F_k^{-1}(c) and keeping the second half. CPA intuition: the inputs r∥mr\Vert m are all distinct except with probability about q2/2n/2q^2/2^{n/2}, and a random permutation on distinct inputs gives near-uniform outputs. Since FF is a strong PRP, any modified ciphertext decrypts to an unrelated random-looking input, which is the basis of CCA security. (Sketch worked here.)

Modes of operation

NoteSetup

Block cipher FF with block length nn, messages of ℓ\ell blocks. Pad unambiguously with “1 then 0s”, adding a whole block if the length is already a multiple. The ciphertext expansion is ciphertext length minus message length.

ModeEncryptDecryptSecurityNeeds F−1F^{-1}Parallel encrypt / decrypt
ECBci=Fk(mi)c_i = F_k(m_i)mi=Fk−1(ci)m_i = F_k^{-1}(c_i)not even EAV-secure: equal blocks showyesyes / yes
CBCc0=IVc_0 = IV, ci=Fk(ci−1⊕mi)c_i = F_k(c_{i-1}\oplus m_i)mi=Fk−1(ci)⊕ci−1m_i = F_k^{-1}(c_i)\oplus c_{i-1}CPA (PRP), random IVyesno / yes
OFBr0=IVr_0 = IV, ri=Fk(ri−1)r_i = F_k(r_{i-1}), ci=mi⊕ric_i = m_i\oplus r_imi=ci⊕rim_i = c_i\oplus r_iCPA (PRF)nostream precomputable, then XOR
CTR (randomised)ri=Fk(ctr+i)r_i = F_k(ctr + i), ci=mi⊕ric_i = m_i\oplus r_imi=ci⊕Fk(ctr+i)m_i = c_i\oplus F_k(ctr + i)CPA (PRF), Theorem 3.30noyes / yes; random access

(The decryption column answers Exercise 3.15.) The IVIV/ctrctr is sent in the clear, giving one block of expansion.

WarningECB should never be used

Deterministic, and repeated plaintext blocks are visible: it leaks structure even for a single message. It is included only for history.

ExampleCBC with a counter IV is not CPA-secure (Exercise 3.14)

If the IV is incremented rather than random, it is predictable. Query 0n0^n under IV vv to learn Fk(v)F_k(v). The challenge will use IV=v+1IV = v+1. Submit m0=v⊕(v+1)m_0 = v\oplus(v+1), so the first block is Fk((v+1)⊕m0)=Fk(v)F_k((v+1)\oplus m_0) = F_k(v), a known value, and m1m_1 anything else. Win with probability 1. (This is the logic behind the 2011 BEAST attack on TLS 1.0’s chained IVs.) (Worked here.)

TheoremTheorem 3.30 — Randomised CTR mode is CPA-secure

If FF is a PRF, randomised counter mode has indistinguishable encryptions under chosen-plaintext attack.

ProofRandom function plus an overlap bound

Ideal world with a truly random ff. Bound each query and the challenge at q=q(n)q = q(n) blocks, with qq queries. The challenge uses ff at ctrc+1,…,ctrc+qctr_c + 1,\ldots,ctr_c + q.

  • No overlap with any query’s counters: the challenge pad is fresh and uniform, so success is 12\frac12.
  • Overlap: query ii‘s range intersects the challenge’s iff ctrc+1−q≤ctri≤ctrc+q−1ctr_c + 1 - q\le ctr_i\le ctr_c + q - 1, which is 2q−12q - 1 values, so probability (2q−1)/2n(2q-1)/2^n. A union bound over queries gives Pr⁡[Overlap]≤2q2/2n\Pr[\mathsf{Overlap}]\le2q^2/2^n.

So success is at most 12+2q(n)2/2n\frac12 + 2q(n)^2/2^n, again requiring only polynomially many polynomial-length queries. The step from ff to FkF_k is the same reduction as in Theorem 3.26 (Exercise 3.16).

∎

ImportantBlock length matters, not just key length

Every secure mode relies on the block cipher never seeing the same input twice. Even with a perfect 64-bit block cipher, CTR’s adversary gets about q2/264q^2/2^{64} advantage, which is significant at q≈230q\approx2^{30}. Use larger blocks for large data volumes. (Bhargavan–Leurent’s 2016 “Sweet32” attack exploited exactly this against 64-bit ciphers like 3DES in TLS.)

ExampleCTR with other input and output lengths (Exercise 3.17)

For Fk:{0,1}ℓin→{0,1}ℓoutF_k : \{0,1\}^{\ell_{in}}\to\{0,1\}^{\ell_{out}}:

  • CPA: need ℓin(n)=ω(log⁡n)\ell_{in}(n) = \omega(\log n) so random counter ranges rarely overlap (2q2/2ℓin2q^2/2^{\ell_{in}} negligible). Any ℓout≥1\ell_{out}\ge1 works.
  • Fixed length ℓ(n)⋅ℓout\ell(n)\cdot\ell_{out}, one message (EAV): only need 2ℓin≥ℓ(n)2^{\ell_{in}}\ge\ell(n) so the counter doesn’t wrap within the message.

(Worked here.)

ExampleCombining two schemes, one of which is secure (Exercise 3.18)

Split m=m1⊕m2m = m_1\oplus m_2 with m1m_1 uniform, and send (Enck11(m1),Enck22(m2))(\mathrm{Enc}^1_{k_1}(m_1),\mathrm{Enc}^2_{k_2}(m_2)) under independent keys. Either share alone is uniform, so breaking the combination means seeing through the secure component’s share. The reduction simulates the other scheme itself. (Worked here.)

RemarkStream versus block ciphers, and integrity

A block cipher yields many independent streams (one per IVIV), while a stream cipher gives essentially one. Stream ciphers’ only advantage is speed (often about 2×). Block ciphers are better studied and harder to misuse, so prefer them. None of these modes provides integrity; that is handled separately with message-authentication-codes (Chapter 4).


Chosen-ciphertext attacks

DefinitionCCA experiment PrivKA,Πcca(n)\mathrm{PrivK}^{\mathrm{cca}}_{\mathcal A,\Pi}(n) (Def. 3.31)

As CPA, but A\mathcal A also has a decryption oracle Deck(⋅)\mathrm{Dec}_k(\cdot) throughout, and may not query it on the challenge ciphertext itself (otherwise no scheme could be secure). CCA-secure: success at most 12+negl(n)\frac12 + \mathrm{negl}(n).

ExampleWhen adversaries influence decryption

  • Midway again: send encrypted messages and watch the enemy’s reaction.
  • Unauthenticated bank channels: inject ciphertexts and learn from error behaviour whether the plaintext was well formed.
  • Protocols where a party decrypts a challenge and returns the result: that party is a decryption oracle.

WarningMalleability breaks CCA security

Construction 3.25 is not CCA-secure. Choose m0=0nm_0 = 0^n and m1=1nm_1 = 1^n, flip the first bit of ss in ⟨r,s⟩\langle r,s\rangle, and ask for a decryption: 10n−110^{n-1} means b=0b = 0, 01n−101^{n-1} means b=1b = 1. CBC, OFB and CTR all fail the same way (Exercise 3.19): flipping a bit of the IV in CBC flips that bit of m1m_1, and flipping a bit of cic_i in OFB or CTR flips the same bit of mim_i. CCA security implies non-malleability: a modified ciphertext must be invalid or decrypt to something unrelated. Construction: §4.8 (encryption combined with a MAC).


Further exercises

ExampleFactoring-based key sizes (Exercise 3.2)

100 years at 4 GHz is about 1.3×1019≈263.41.3\times10^{19}\approx2^{63.4} cycles. Solve n1/3(log⁡n)2/3≥63.4n^{1/3}(\log n)^{2/3}\ge63.4. With log⁡2\log_2, n≈2,100n\approx2{,}100 bits (2048 gives about 62.9). With natural log, about 3,800 bits. The base of the log in a crude cost model changes the answer substantially. (Calculation worked here; the base is ambiguous in the exercise.)


Quick reference

ObjectStatementNote
Relaxationsppt adversaries + negligible successboth necessary when ∣K∣<∣M∣\lvert\mathcal K\rvert<\lvert\mathcal M\rvert
Negligible<1/p(n)< 1/p(n) eventually, for every polynomial ppclosed under ++ and × poly\times\,\mathrm{poly}
Reductionadversary for Π\Pi ⇒ solver for XXblack-box simulation
EAVPr⁡[PrivKeav=1]≤12+negl\Pr[\mathrm{PrivK}^{\mathrm{eav}} = 1]\le\frac12 + \mathrm{negl}equal-length messages
Semantic securityciphertext adds nothing beyond h(m)h(m)⟺ indistinguishability
PRGG(s)G(s) indistinguishable from uniform, ℓ(n)>n\ell(n)>nbrute force advantage 1−2−n1 - 2^{-n}
PRG-OTPG(k)⊕mG(k)\oplus mEAV-secure, not multi-message
Deterministicinsecure for multiple messages and CPAmust randomise or keep state
CPAencryption oracleone-message ⇒ many-message
PRFFkF_k vs f←Funcnf\leftarrow\mathrm{Func}_n via oracle∣Funcn∣=2n2n\lvert\mathrm{Func}_n\rvert = 2^{n2^n}
⟨r,Fk(r)⊕m⟩\langle r, F_k(r)\oplus m\rangleCPA-secure, ε≤negl+q/2n\varepsilon\le\mathrm{negl} + q/2^n2× expansion
Strong PRPoracles for Fk,Fk−1F_k, F_k^{-1}⇒ PRF (birthday)
ModesECB ✗; CBC, OFB, CTR CPA-secure with random IVCTR: parallel, random access
CTR bound12+2q2/2n\frac12 + 2q^2/2^nblock length matters
CCAplus decryption oracle (not on the challenge)implies non-malleability; all modes fail

Facts to keep to hand

  • Computational security trades a little for a lot. Restricting to efficient adversaries and forgiving negligible success makes short keys possible, at the cost of assumptions. Asymptotic statements must still be turned into concrete parameter choices.
  • Indistinguishability is the working definition. No efficient adversary can tell encryptions of two chosen messages apart. It is equivalent to semantic security (no function of the plaintext leaks), and it never hides length.
  • Pseudorandomness is the engine. A PRG stretches a short key into a pad (EAV-secure). A PRF gives a fresh pad per encryption (CPA-secure). Proofs first use a truly random object, then reduce. Pad reuse, deterministic encryption and predictable IVs are the classic failures.
  • Block ciphers are PRPs, used through modes. CBC, OFB and CTR with random IVs are CPA-secure up to birthday-type bounds in the block length. None is non-malleable, so CCA security needs integrity protection on top.

References

  • Katz & Lindell, Introduction to Modern Cryptography — Chapter 3
  • Goldwasser & Micali, “Probabilistic Encryption” (1984) — semantic security
  • Goldreich, Goldwasser & Micali, “How to Construct Random Functions” (1986)
  • Bellare, Desai, Jokipii & Rogaway, “A Concrete Security Treatment of Symmetric Encryption” (1997) — CPA proofs for CBC and CTR

← All notes