Section 15.2

Pseudorandom permutation (PRP)

Definition

A pseudorandom permutation (PRP) is a keyed permutation: for each secret key, an efficient algorithm §14.1 rearranges the set of all nn-bit blocks, so that every block is the output for exactly one input block, and a second efficient algorithm undoes the rearrangement with the same key. Its defining property is that nobody who lacks the key and has limited computing power can tell the PRP apart from a permutation chosen uniformly at random (every rearrangement equally likely) from all rearrangements of the nn-bit blocks. Block ciphers §15.3 are modeled as PRPs.

The idea

A block cipher encrypts one block, 16 bytes for AES (the Advanced Encryption Standard), under a secret key. The receiver holds the same key and must get back exactly the block that was sent. That works only if, under that key, no two different blocks encrypt to the same result. A map from a finite set to itself with this property is a permutation: a rearrangement of the set.

Picture a codebook for one key: two columns that pair each of the 2n2^n possible blocks with exactly one ciphertext block, where every ciphertext block also appears exactly once. Encryption looks a block up in the left column; decryption looks it up in the right column. The picture is inaccurate in one respect: for n=128n = 128 the book has 21282^{128} lines and cannot be written down, so the cipher computes each line from the key when it is needed.

Invertibility is easy to get and worth nothing on its own. The identity map, which leaves every block unchanged, is a permutation. So is bitwise XOR (exclusive or) with the key, which flips each bit of the block where the key has a 1 bit. Security needs a second property: the codebook that the key selects must look, to anyone without the key, like a codebook chosen uniformly at random from all possible codebooks. There are (2n)!(2^n)! possible codebooks, where (2n)!(2^n)!, read “2n2^n factorial”, is the product 1×2×…×2n1 \times 2 \times \dots \times 2^n, the number of ways to put 2n2^n items in order. For n=128n = 128, writing down one codebook takes about 21352^{135} bits, while an AES key has at most 256 bits. A key therefore selects one of a vanishingly small fraction of all codebooks, and the PRP property says that membership in this fraction cannot be recognized with feasible effort.

How it works

A PRP is a pair of algorithms. Encryption takes a key KK of kk bits and an nn-bit block xx and returns the nn-bit block EK(x)E_K(x). Inversion takes KK and an nn-bit block yy and returns EK−1(y)E_K^{-1}(y), the unique block xx with EK(x)=yE_K(x) = y.

Security is defined by the same kind of experiment as for a pseudorandom function §15.1: a game in which an adversary, the party that tries to tell two worlds apart, sends queries and receives answers, and must finally say which world it is in.

  1. A challenger flips a fair coin in secret to choose the real or the ideal world.

  2. Real world: the challenger picks a key KK uniformly at random and answers each query xx with EK(x)E_K(x).

  3. Ideal world: the challenger answers each new input with a block chosen uniformly at random among the blocks not yet given as an answer, records the pair, and repeats the recorded answer for a repeated input. A table filled in this way, on demand, behaves exactly like a permutation chosen uniformly at random at the start.

  4. The adversary outputs 1 or 0. Its advantage is the difference between the probabilities that it outputs 1 in the two worlds, taken as a positive number.

In a strong PRP experiment the adversary may also send inverse queries: in the real world they are answered with EK−1E_K^{-1}, in the ideal world with the inverse of the random permutation. The strong version models an attacker who can obtain decryptions of blocks of the attacker’s choice.

A random permutation and a random function behave alike until the random function gives two different inputs the same output, which a permutation never does. With qq queries such a repeat happens with probability at most q(q−1)/2n+1q(q-1)/2^{n+1}, by the birthday bound §5.6. This is the PRP/PRF switching lemma, where PRF stands for pseudorandom function: a PRP with long blocks can be used wherever a PRF is needed, at that small extra cost.

Invertibility for every key can come from the structure of a cipher rather than from its parts. A Feistel network splits the block into a left half LL and a right half RR, and each round replaces (L,R)(L, R) by (R,L⊕f(R))(R, L \oplus f(R)), where ff is a keyed function that need not be invertible. Given the output (R,L′)(R, L'), the round is undone by computing L=L′⊕f(R)L = L' \oplus f(R). Luby and Rackoff proved in 1988 that three Feistel rounds with independent pseudorandom functions as ff give a PRP, and that four rounds give a strong PRP [362]. AES uses a different structure, in which every step is itself invertible; the AES round structure §15.4 entry describes it.

Worked example

A permutation and its inverse. Blocks of n=2n = 2 bits take 22=42^2 = 4 values: 00, 01, 10, 11. Let one key select the permutation 00 →\to 10, 01 →\to 00, 10 →\to 11, 11 →\to 01. Each of the four values appears exactly once on the right, so reading the pairs backwards gives the inverse: 10 →\to 00, 00 →\to 01, 11 →\to 10, 01 →\to 11. A receiver of the ciphertext block 11 returns 10.

A map that cannot be decrypted. Change the second pair to 01 →\to 10. Now 00 and 01 both map to 10, and no block maps to 00. A receiver of 10 cannot tell which of the two blocks was sent.

Counting. A permutation of 4 values has 4 choices for the image of 00, then 3 unused values for 01, then 2 for 10, then 1 for 11: 4!=4×3×2×1=244! = 4 \times 3 \times 2 \times 1 = 24 permutations. A function from the 4 values to the 4 values chooses each of the 4 images freely: 44=4×4×4×4=2564^4 = 4 \times 4 \times 4 \times 4 = 256 functions. Only 24/256=0.0937524 / 256 = 0.09375 of all functions are permutations.

The switching cost, exactly. An adversary queries two different 2-bit inputs and outputs 1 if the two answers differ. A random permutation always gives different answers, so the adversary outputs 1 with probability 1. A random function gives the second input the first input’s answer with probability 1/41/4, so the adversary outputs 1 with probability 3/43/4. The advantage is 1−3/4=1/41 - 3/4 = 1/4. The switching bound gives q(q−1)/2n+1=2×1/23=2/8=1/4q(q-1)/2^{n+1} = 2 \times 1 / 2^{3} = 2/8 = 1/4, the same value.

The switching cost for AES. Here n=128n = 128. After q=232q = 2^{32} blocks, which is 232×16=2362^{32} \times 16 = 2^{36} bytes or 64 GiB, the bound is 232(232−1)/21292^{32}(2^{32} - 1)/2^{129}, just below 264/2129=2−652^{64}/2^{129} = 2^{-65}. After q=264q = 2^{64} blocks it is close to 2128/2129=1/22^{128}/2^{129} = 1/2: by then the absence of repeated outputs gives the permutation away.

A Feistel round undone. Take 4-bit blocks with 2-bit halves and a round function ff that is not invertible: f(𝟶𝟶)=𝟷𝟷f(\texttt{00}) = \texttt{11}, f(𝟶𝟷)=𝟷𝟷f(\texttt{01}) = \texttt{11}, f(𝟷𝟶)=𝟶𝟶f(\texttt{10}) = \texttt{00}, f(𝟷𝟷)=𝟶𝟷f(\texttt{11}) = \texttt{01}. For the input (L,R)=(𝟷𝟶,𝟶𝟷)(L, R) = (\texttt{10}, \texttt{01}) the round outputs (R,L⊕f(R))=(𝟶𝟷,𝟷𝟶⊕𝟷𝟷)=(𝟶𝟷,𝟶𝟷)(R, L \oplus f(R)) = (\texttt{01}, \texttt{10} \oplus \texttt{11}) = (\texttt{01}, \texttt{01}). To undo the round, read R=𝟶𝟷R = \texttt{01} from the left half of the output and compute L=𝟶𝟷⊕f(𝟶𝟷)=𝟶𝟷⊕𝟷𝟷=𝟷𝟶L = \texttt{01} \oplus f(\texttt{01}) = \texttt{01} \oplus \texttt{11} = \texttt{10}. The input (𝟷𝟶,𝟶𝟷)(\texttt{10}, \texttt{01}) is recovered, although ff maps both 00 and 01 to 11.

Stated precisely

Let E:{0,1}k×{0,1}n→{0,1}nE\colon \{0,1\}^k \times \{0,1\}^n \to \{0,1\}^n be a keyed function such that for every key KK the map EK=E(K,⋅)E_K = E(K, \cdot) is a permutation of {0,1}n\{0,1\}^n and its inverse EK−1E_K^{-1} is efficiently computable from KK. Let Perm(n)\mathrm{Perm}(n) be the set of all permutations of {0,1}n\{0,1\}^n; it has (2n)!(2^n)! members. Write AG⇒1A^{G} \Rightarrow 1 for the event that adversary AA, allowed to query GG, outputs 1, and AG,H⇒1A^{G, H} \Rightarrow 1 when AA may query both GG and HH. With KK uniform over {0,1}k\{0,1\}^k and π\pi uniform over Perm(n)\mathrm{Perm}(n), AdvEprp(A)=|Pr[AEK⇒1]−Pr[Aπ⇒1]|,AdvEsprp(A)=|Pr[AEK,EK−1⇒1]−Pr[Aπ,π−1⇒1]|.\begin{aligned} \mathrm{Adv}^{\mathrm{prp}}_E(A) &= \bigl| \Pr[A^{E_K} \Rightarrow 1] - \Pr[A^{\pi} \Rightarrow 1] \bigr|, \\ \mathrm{Adv}^{\mathrm{sprp}}_E(A) &= \bigl| \Pr[A^{E_K, E_K^{-1}} \Rightarrow 1] - \Pr[A^{\pi, \pi^{-1}} \Rightarrow 1] \bigr|. \end{aligned} EE is a (t,q,ε)(t, q, \varepsilon)-secure PRP if AdvEprp(A)≤ε\mathrm{Adv}^{\mathrm{prp}}_E(A) \le \varepsilon for every AA that runs for at most tt steps and makes at most qq queries. EE is a (t,q,ε)(t, q, \varepsilon)-secure strong PRP if the same holds for AdvEsprp\mathrm{Adv}^{\mathrm{sprp}}_E, with queries in both directions counted.

Switching lemma. Let ρ\rho be a function chosen uniformly from all functions from {0,1}n\{0,1\}^n to {0,1}n\{0,1\}^n. For every adversary AA that makes at most qq queries, |Pr[Aπ⇒1]−Pr[Aρ⇒1]|≤q(q−1)2n+1.\bigl| \Pr[A^{\pi} \Rightarrow 1] - \Pr[A^{\rho} \Rightarrow 1] \bigr| \le \frac{q(q-1)}{2^{n+1}}. The two functions answer identically unless ρ\rho repeats an output, and among qq uniform nn-bit outputs a repeat has probability at most q(q−1)/2n+1q(q-1)/2^{n+1}. Hence AdvEprf(A)≤AdvEprp(A)+q(q−1)/2n+1\mathrm{Adv}^{\mathrm{prf}}_E(A) \le \mathrm{Adv}^{\mathrm{prp}}_E(A) + q(q-1)/2^{n+1}, where AdvEprf(A)\mathrm{Adv}^{\mathrm{prf}}_E(A) is the same difference of probabilities with ρ\rho in place of π\pi.

Why invertible. Decryption under KK is the map EK−1E_K^{-1}, which exists exactly when EKE_K is one-to-one. A one-to-one map from the 2n2^n blocks to the same 2n2^n blocks produces 2n2^n different outputs, so it uses every block exactly once as an output (the pigeonhole principle) and is a permutation.

The security claims rest on these assumptions.

  1. A uniform, independent, secret key. KK is chosen uniformly at random, independently of any other key, and does not leak.

  2. Query access only. The adversary sees only the answers to its queries, not timing, power consumption or any other side channel §1.29.

  3. Bounded resources: at most tt steps and qq queries.

  4. Direction of queries. The plain definition gives the adversary no inverse queries; the strong definition gives them and counts them.

No block cipher in use has a proof of PRP security. For AES it is a conjecture supported by more than two decades of public cryptanalysis in which no attack on the full cipher has come near practical cost, and the security proofs of modes of operation start from that conjecture.

Limits and common mistakes

Invertible does not mean secure. Being a permutation is the format requirement and pseudorandomness is the security requirement. The identity map and XOR with the key meet the first and fail the second.

A PRP handles one block and is deterministic. Two equal blocks encrypted under one key give two equal ciphertext blocks, so applying a PRP block by block to a message reveals which blocks are equal. Messages need a mode of operation, as the block cipher and counter mode §15.5 entries explain.

Plain PRP security says nothing about an attacker who can obtain the inverses of chosen blocks. When a design lets an attacker have blocks of their choice decrypted, the strong PRP definition is the relevant one.

The never-repeat behavior limits how much data one key may process when the proof of a mode treats the cipher as a PRF. With nn-bit blocks the behavior becomes visible after about 2n/22^{n/2} blocks. For 64-bit block ciphers such as Triple DES (Triple Data Encryption Standard) that is 2322^{32} blocks, which is 232×8=2352^{32} \times 8 = 2^{35} bytes or 32 GiB; the Sweet32 attack of 2016 [363] exploited this against long-lived encrypted connections. For 128-bit blocks the corresponding amount is 2642^{64} blocks.

The model assumes independently chosen keys. Attacks that use encryptions under several keys with a known relation between them, called related-key attacks, lie outside it, as do leaks through timing or power consumption.

A PRP provides no integrity §1.9: it does not let a receiver detect that a ciphertext block was altered. Any altered block still decrypts to some block.

Questions answered

Why must a permutation be invertible for each key?

A keyed permutation must be invertible for each key because it models a block cipher, and decryption under a key must return exactly the block that was encrypted under that key. If two different plaintext blocks gave the same ciphertext block under some key, a receiver holding that key could not tell which of the two was sent, so that key could not be used. On the finite set of nn-bit blocks, a map from the set to itself that is one-to-one produces 2n2^n different outputs and therefore uses every block exactly once; such a map is a permutation, and every ciphertext block decrypts to exactly one plaintext block. Invertibility must hold for every key, because the key is chosen at random and any key may be the one in use, and the inverse must be efficient to compute with the key, because it is the decryption algorithm.

Invertibility is only the correctness requirement. The security requirement of a pseudorandom permutation (PRP) is separate: without the key, the permutation must be impossible to tell apart, with feasible effort, from one chosen uniformly at random. The identity map is invertible and offers no security at all.

Related entries: Pseudorandom function (PRF) (§15.1), Block cipher (§15.3), Birthday bound (§5.6), AES round structure (§15.4), Counter mode (CTR) (§15.5). Further reading: [47, 66, 362, 363].