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.
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:
- security only against efficient adversaries;
- 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 -secure if every adversary running for time at most breaks it with probability at most (for example, cycles, ).
ExampleHow big is big (Example 3.1)
Good private-key schemes with -bit keys are believed to be essentially optimal: success about for time (brute force achieves this).
- cycles at 1 GHz is about 35 years, barely within reach with massive parallelism.
- , a 21-digit factor. The universe is about seconds old.
- An event once a century has probability about per second; per second is about once per 100 billion years.
WarningPitfalls of concrete claims
“No adversary running 5 years succeeds with probability above ”: 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 means “secure”.
DefinitionAsymptotic security
Schemes take a security parameter , known to the adversary and given in unary so that running time is polynomial in input length. Running times and success probabilities are functions of .
-
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 (Examples 3.2–3.4)
- An attack taking minutes with success is asymptotically negligible. Yet at it takes about 6 weeks and succeeds with certainty; at , about 3 months with success about ; at , about 240 years with success .
- Faster computers help defenders: honest cost cycles, attack cycles for success . At 1 GHz with : honest 2.5 s, the attack about a week for . After everyone upgrades to 16 GHz, honest parties move to and still take only 0.625 s, while the same week-long attack now succeeds with only .
- Asymptotic to concrete: “time ⇒ success ” with and gives -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 .
ImportantBoth relaxations are necessary
If (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 .
- Guessing: try one random key. Polynomial time, success about .
So we must bound time and forgive tiny success. Asymptotically, the key space must grow super-polynomially in .
Efficient algorithms and negligible probabilities
DefinitionProbabilistic polynomial time
Runs within steps for some polynomial , with access to unbiased independent coin flips (equivalently, a random tape of length ).
- Why polynomial: the class is closed under composition. Otherwise nothing is special: results also hold for, say, -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)
is negligible if for every polynomial there is with for all . Equivalently, eventually, for every . Write .
ExampleNegligible functions differ wildly (Example 3.6)
, and are all negligible. They drop below at , and respectively. Yet for all (where ). Asymptotic order and practical size can disagree.
TheoremProposition 3.7 — Closure
and (for any polynomial ) 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 is hard (every ppt algorithm solves it with negligible probability). Goal: construction is secure.
- Fix any ppt adversary against , with success .
- Build a ppt that, given an instance of , simulates
for :
- (a) ‘s view is (close to) identical to a real attack;
- (b) ‘s success lets solve with probability at least .
- A non-negligible would solve non-negligibly, a contradiction.
- So is negligible.
uses 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 (where ), for (possibly randomised), and (deterministic), with perfect correctness. Fixed-length with parameter : Enc is defined only on .
DefinitionEavesdropping indistinguishability experiment
- outputs of equal length.
- , , given to .
- outputs ; success iff .
Def. 3.9: has indistinguishable encryptions in the presence of an eavesdropper (is EAV-secure) if for every ppt ,
This is Definition 2.4 with two relaxations: ppt adversaries and a negligible advantage.
| Component | Detail |
|---|---|
| Power | sees one ciphertext, chooses the two candidate messages, polynomial time |
| Break | guessing which message was encrypted noticeably better than ½ |
| Strategy | unrestricted (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 in the experiment, : the adversary behaves the same on encryptions of and . Equivalence (Exercise 3.5): .
Semantic security
TheoremClaims 3.11–3.12 — Indistinguishability hides partial information
For an EAV-secure scheme:
- No bit leaks: for uniform and any position , . If predicted bit , distinguish random messages with bit from ones with bit .
- No function leaks (uniform over an efficiently sampleable set , poly-time): some without the ciphertext computes almost as well. simply runs on , a ciphertext of a fixed dummy message. A gap would distinguish from .
DefinitionSemantic security (Def. 3.13; Goldwasser–Micali)
For every ppt there is a ppt such that for every efficiently sampleable plaintext distribution (equal lengths per ) and all poly-time (target) and (external information),
The ciphertext adds nothing beyond what external knowledge 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 with such that
- Expansion: ;
- Pseudorandomness: for every ppt distinguisher ,
is the expansion factor.
WarningPRG outputs are far from uniform
With , at most of the strings are outputs, so a random string is in the range with probability at most . The exponential-time brute-force distinguisher (“does some seed produce this?”) has advantage . 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 a PRG of expansion : ; for ; .
TheoremTheorem 3.17 — PRG ⇒ EAV-secure encryption
If is a pseudorandom generator, Construction 3.16 has indistinguishable encryptions in the presence of an eavesdropper.
ProofReduction to the generator
Let . Distinguisher , : run to get ; pick ; give ; output 1 iff guesses .
- If is uniform, sees a genuine one-time pad , so by perfect secrecy.
- If , sees exactly , so .
The distinguishing gap is , which must be negligible.
∎
ImportantWhat was gained
Still XOR with an -bit pad, but the pad comes from an -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)
outputs bits; shorter outputs are prefixes of longer ones; and for every polynomial , is a PRG. Encrypt with . Any PRG can be converted to one; from a PRF: , 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 (Def. 3.19)
outputs two vectors of the same number of messages, with pairwise equal lengths, and receives encryptions of all of 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 and , 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, 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): with a fresh uniform . This needs a much stronger generator: streams for independent random s must look independent and random even given the s. That is nearly a pseudorandom function.
Chosen-plaintext attacks
DefinitionCPA experiment (Def. 3.22)
- .
- , with an encryption oracle (fresh coins per query), outputs equal-length .
- Challenge .
- keeps oracle access and outputs ; success iff .
CPA-secure: success at most for every ppt . This implies EAV security (just ignore the oracle).
ImportantCPA security requires randomised encryption
Otherwise, query and 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, 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 for , but also output if . A multi-message eavesdropper fixes all its messages before seeing anything, so it hits with negligible probability. A CPA adversary queries once, reads , 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 and once each, getting fresh . Guess 0 if only equals the challenge , 1 if only does, at random otherwise. With the ciphertext distribution of under ,
because correctness forces and to have disjoint supports. The advantage may be negligible, but never zero. (Argument worked here.)
Pseudorandom functions and CPA-secure encryption
DefinitionKeyed functions and
A keyed function , written , is efficient if poly-time computable and, here, length-preserving (). is all functions : a look-up table of bits, so . A uniform has independent uniform values at every point. ranges over at most of these functions.
DefinitionPseudorandom function (Def. 3.24; Goldreich–Goldwasser–Micali)
For every ppt with oracle access (adaptive, polynomially many queries),
Oracle access is needed because a random function’s description is exponentially long.
| Point | Meaning |
|---|---|
| Key stays secret | with known, query and compare with ; distinguished with advantage |
| Inherits random-function behaviour | inputs differing in one bit give unrelated outputs; finding with is hard |
| Existence | PRFs exist ⟺ PRGs exist (Chapter 6); block ciphers are believed PRFs |
| Proof paradigm | (1) analyse with a truly random (pure probability); (2) any gap would distinguish from |
ExamplePRF counterexamples (Exercises 3.6, 3.8, 3.10)
- (a truncated PRG output XOR the input) isn’t a PRF: always, unlike a random function.
- PRG modifications: need not be a PRG (a valid PRG can misbehave on that negligible set of seeds). stays pseudorandom but may fail to expand if exactly.
(Worked here.)
AlgorithmConstruction 3.25 — Encrypt with at a fresh random point
. : choose , output . .
Naive is deterministic, hence not CPA-secure. Here each encryption gets an (almost certainly) new pseudorandom pad.
TheoremTheorem 3.26 — PRF ⇒ CPA-secure encryption
If is a PRF, Construction 3.25 is a CPA-secure fixed-length scheme for -bit messages.
ProofRandom-function world, then reduction
Step 1: Ideal scheme with a truly random . Let be the challenge’s randomness, and the event that some oracle query used .
- : the adversary learns and wins. But for queries.
- : is uniform and independent of everything seen, a one-time pad, so success is exactly .
So (3.4), with no computational assumption on beyond queries.
Step 2: Distinguisher . Run . Answer each oracle query with a fresh and , the challenge likewise with . Output 1 iff guesses . With this is exactly ; with , exactly . Then , so , which is negligible.
∎
NoteCorollary 3.27 and cost
Block by block with fresh : 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 a bijection, with and efficient) such that no ppt with oracles for both and can distinguish them from a uniform permutation with . (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 with is seen. With queries this has probability at most (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. 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)
for with fresh. Decrypt by computing and keeping the second half. CPA intuition: the inputs are all distinct except with probability about , and a random permutation on distinct inputs gives near-uniform outputs. Since 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 with block length , messages of 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.
| Mode | Encrypt | Decrypt | Security | Needs | Parallel encrypt / decrypt |
|---|---|---|---|---|---|
| ECB | not even EAV-secure: equal blocks show | yes | yes / yes | ||
| CBC | , | CPA (PRP), random IV | yes | no / yes | |
| OFB | , , | CPA (PRF) | no | stream precomputable, then XOR | |
| CTR (randomised) | , | CPA (PRF), Theorem 3.30 | no | yes / yes; random access |
(The decryption column answers Exercise 3.15.) The / 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 under IV to learn . The challenge will use . Submit , so the first block is , a known value, and 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 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 . Bound each query and the challenge at blocks, with queries. The challenge uses at .
- No overlap with any query’s counters: the challenge pad is fresh and uniform, so success is .
- Overlap: query ‘s range intersects the challenge’s iff , which is values, so probability . A union bound over queries gives .
So success is at most , again requiring only polynomially many polynomial-length queries. The step from to 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 advantage, which is significant at . 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 :
- CPA: need so random counter ranges rarely overlap ( negligible). Any works.
- Fixed length , one message (EAV): only need so the counter doesn’t wrap within the message.
(Worked here.)
ExampleCombining two schemes, one of which is secure (Exercise 3.18)
Split with uniform, and send 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 ), 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 (Def. 3.31)
As CPA, but also has a decryption oracle throughout, and may not query it on the challenge ciphertext itself (otherwise no scheme could be secure). CCA-secure: success at most .
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 and , flip the first bit of in , and ask for a decryption: means , means . CBC, OFB and CTR all fail the same way (Exercise 3.19): flipping a bit of the IV in CBC flips that bit of , and flipping a bit of in OFB or CTR flips the same bit of . 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 cycles. Solve . With , 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
| Object | Statement | Note |
|---|---|---|
| Relaxations | ppt adversaries + negligible success | both necessary when |
| Negligible | eventually, for every polynomial | closed under and |
| Reduction | adversary for ⇒ solver for | black-box simulation |
| EAV | equal-length messages | |
| Semantic security | ciphertext adds nothing beyond | ⟺ indistinguishability |
| PRG | indistinguishable from uniform, | brute force advantage |
| PRG-OTP | EAV-secure, not multi-message | |
| Deterministic | insecure for multiple messages and CPA | must randomise or keep state |
| CPA | encryption oracle | one-message ⇒ many-message |
| PRF | vs via oracle | |
| CPA-secure, | 2× expansion | |
| Strong PRP | oracles for | ⇒ PRF (birthday) |
| Modes | ECB ✗; CBC, OFB, CTR CPA-secure with random IV | CTR: parallel, random access |
| CTR bound | block length matters | |
| CCA | plus 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
Mentioned in
- Block Cipher Constructions and Pseudorandom Objects
- Classical Cryptography and Perfect Secrecy
- CPA-Secure Encryption — Modes of Operation
- Message Authentication Codes and Hash Functions
- Number Theory for Cryptography
- Public-Key Encryption Schemes
- Stream Cipher Attacks and Case Studies
- The Learning With Errors Assumption and the Random Oracle Model