Pseudorandom Functions and Permutations

Imagine a bank needs to encrypt millions of transactions per second, each with the same secret key. It cannot store a giant lookup table of "correct" outputs. It also cannot afford true randomness that would need to be transmitted or remembered. What it needs is a keyed algorithm that behaves like a random function. No adversary should be able to predict outputs on new inputs. Yet the algorithm must be completely determined by a short key. It must also run in microseconds. This is the exact gap that pseudorandom functions (PRFs) and pseudorandom permutations (PRPs) fill. PRFs and PRPs are the central abstraction that separates cryptographic engineering from cryptographic theory. Real ciphers like AES are conjectured PRPs. Real message authentication codes like HMAC are built from conjectured PRFs. The abstraction lets a protocol designer prove a system secure. This proof only assumes "the underlying primitive behaves like a random function." Separately, cryptanalysts try to show AES does or does not meet that bar. This division of labor is why modern cryptography can have clean security proofs at all. The big picture is a chain of increasingly structured randomness. A pseudorandom generator stretches a short seed into a long pseudorandom string. A PRF goes further: it is a keyed, input-indexed family of pseudorandom strings. For every input xx, evaluating the function on xx looks like consulting an independent random string. Yet the whole family is computable in polynomial time from one short key. A PRP is a PRF restricted to be a bijection. It models exactly what a block cipher does: invertibly scrambling a fixed-size block. This article defines PRFs and PRPs with full mathematical precision. It walks through the indistinguishability-based security game that defines them. It proves the classic PRF-to-PRP switching lemma. It also traces the construction of PRFs from PRGs (the Goldreich–Goldwasser–Micali construction). It sets up the abstraction that block ciphers instantiate. MACs rely on this same abstraction for their security proofs.

Key takeaways
  • A PRF is a keyed function family that no efficient adversary can distinguish from a truly random function, given oracle access.
  • A PRP is a PRF that is also a bijection on its domain — the abstraction modeling block ciphers like AES.
  • Security is defined via an indistinguishability game between the real keyed function and an ideal random function/permutation.
  • The PRF/PRP switching lemma shows the two notions are computationally close, with distinguishing advantage bounded by a birthday-type term q2/2nq^2/2n.
  • The GGM construction builds a PRF from any length-doubling PRG, proving PRFs exist if PRGs do.
  • PRFs and PRPs underlie MAC constructions (CBC-MAC, HMAC), symmetric encryption modes, and key derivation functions.
The core insight

A pseudorandom function is a keyed algorithm that no efficient adversary, given only oracle access, can distinguish from a genuinely random function or permutation.

The idea

A function family is a collection of functions {Fk}k∈{0,1}n\{F_k\}_{k \in \{0,1\}^n} where each Fk:{0,1}m→{0,1}ℓF_k: \{0,1\}^m \to \{0,1\}^\ell is indexed by a key kk. We write F:{0,1}n×{0,1}m→{0,1}ℓF: \{0,1\}^n \times \{0,1\}^m \to \{0,1\}^\ell for the two-argument description, with F(k,x)=Fk(x)F(k, x) = F_k(x). The family is efficient if there is a polynomial-time algorithm computing F(k,x)F(k,x) given both arguments. A pseudorandom function (PRF) is an efficient function family such that, when the key kk is chosen uniformly at random and hidden from an adversary, the function Fk(⋅)F_k(\cdot) is computationally indistinguishable from a function ff drawn uniformly at random from the set of all functions {0,1}m→{0,1}ℓ\{0,1\}^m \to \{0,1\}^\ell. The adversary is modeled as interacting with an oracle: it submits inputs x1,x2,…x_1, x_2, \dots adaptively and receives outputs, but never sees the key or the internal randomness. Formally, for every probabilistic polynomial-time (PPT) oracle adversary A\mathcal{A},

∣Pr⁡k[AFk(⋅)(1n)=1]−Pr⁡f[Af(⋅)(1n)=1]∣≤negl(n),\left| \Pr_{k}\big[\mathcal{A}^{F_k(\cdot)}(1^n) = 1\big] - \Pr_{f}\big[\mathcal{A}^{f(\cdot)}(1^n) = 1\big] \right| \le \mathrm{negl}(n),

where the first probability is over the random key kk and A\mathcal{A}'s coins, and the second is over a uniformly random function ff (drawn from the exponentially large space of all such functions) and A\mathcal{A}'s coins. A pseudorandom permutation (PRP) is the same idea specialized to bijections. Here m=ℓm = \ell, and each FkF_k is required to be a permutation of {0,1}m\{0,1\}^m — invertible, and efficiently invertible given kk (this second requirement matters for decryption). The security definition compares FkF_k against a permutation π\pi drawn uniformly at random from the symmetric group on {0,1}m\{0,1\}^m, rather than against an arbitrary random function. This is precisely the abstraction that models a block cipher: the key selects one specific, secret shuffling of the 2m2^m possible blocks, and no efficient adversary with oracle access can tell it apart from a "perfectly random shuffle." Two terminological refinements matter. A strong PRP (or "super PRP") requires indistinguishability even when the adversary is given a two-way oracle — it may query both Fk(⋅)F_k(\cdot) and Fk−1(⋅)F_k^{-1}(\cdot) — modeling an attacker who can both encrypt and decrypt under a fixed unknown key. An ordinary PRP only grants forward queries. Real block ciphers such as AES are conjectured to be strong PRPs.

How it works

The definition above is a game, not an algorithm, so "how it works" means: how do we use this game to certify security, how do we build a PRF from more primitive assumptions, and how does the PRF/PRP distinction actually bite in practice?

The distinguishing game. Security is defined operationally via an experiment run against an adversary A\mathcal{A} who does not know which "world" it is in. ``` Experiment PRF-Distinguish[A, n]: b ← {0, 1} // choose a world uniformly if b == 0: k ← {0,1}^n Oracle := F_k(·) // real keyed function else: f ← Uniform( Func[m -> ℓ] ) // truly random function Oracle := f(·) b' ← A^Oracle(1^n) // A queries oracle adaptively return (b' == b) Advantage(A) := | 2 · Pr[PRF-Distinguish[A,n] returns true] - 1 | ``` FF is a PRF iff `Advantage(A)` is negligible in nn for every PPT A\mathcal{A}. The PRP game is identical except the two branches instantiate a keyed permutation FkF_k and a uniformly random permutation π\pi, and (for the strong PRP notion) the oracle also answers inverse queries in both worlds.

Building a PRF from a PRG (GGM construction). The theoretical anchor result is that PRFs can be constructed from any length-doubling pseudorandom generator, which in turn can be built from any one-way function. This is the Goldreich–Goldwasser–Micali (GGM) construction. Let G:{0,1}n→{0,1}2nG: \{0,1\}^n \to \{0,1\}^{2n} be a PRG, and write G(s)=G0(s) ∥ G1(s)G(s) = G_0(s) \, \| \, G_1(s) as its left and right nn-bit halves. Define the keyed family F:{0,1}n×{0,1}n→{0,1}nF: \{0,1\}^n \times \{0,1\}^n \to \{0,1\}^n by walking down a binary tree of depth nn determined by the input bits: ``` Function F(k, x): // k is the n-bit key (root seed) s := k for i := 1 to n: if x[i] == 0: s := G_0(s) else: s := G_1(s) return s ``` Each key kk defines a full binary tree of depth nn with 2n2^n leaves, one per possible input xx; the value Fk(x)F_k(x) is the leaf reached by following the path dictated by the bits of xx. Crucially, the algorithm only ever expands the single root-to-leaf path actually queried — it runs in time O(n⋅TG(n))O(n \cdot T_G(n)) per evaluation, where TGT_G is the PRG's running time, and never materializes the exponential tree.

Switching between PRF and PRP: the birthday bound. In practice we often want the stronger, structured object (a PRP, i.e., a block cipher) but analyze protocols as if a plain PRF were available, since PRFs compose more simply in proofs. The PRF/PRP switching lemma justifies this: a random permutation and a random function are themselves hard to distinguish, as long as the number of queries qq is small relative to the domain size N=2mN = 2^m. ``` Experiment Func-vs-Perm[A, N, q]: b ← {0,1} if b == 0: Oracle := f, f ← Uniform(Func[N -> N]) else: Oracle := π, π ← Uniform(Perm[N]) b' ← A^Oracle // A makes at most q queries return (b' == b) ``` No adversary, however unbounded computationally, can win this game with advantage exceeding

q(q−1)2N\frac{q(q-1)}{2N}

This bound is intrinsic to the birthday paradox: a random function occasionally repeats an output value on two distinct queries (a "collision"), while a permutation by definition never does. An adversary's best strategy is exactly to look for a repeated output among its q≤Nq \le N queries.

Figure
The security game: real world vs. ideal world, indistinguishable to the adversary
PRF/PRP Indistinguishability Game World 0: Real k ← {0,1}ⁿ (secret key) F_k x → F_k(x) deterministic given k World 1: Ideal f ← Uniform(Func) or π ← Uniform(Perm) f / π x → f(x) truly random table Adversary 𝒜 sees only queries/answers outputs guess b′ ∈ {0,1} Secure iff |Pr[𝒜 says "real" | World 0] − Pr[𝒜 says "real" | World 1]| ≤ negl(n)

Complexity & correctness

Efficiency of the definitions themselves. Being a PRF/PRP is a property of an efficient family: evaluating Fk(x)F_k(x) must run in time polynomial in the security parameter nn (in practice, a fixed constant number of cipher rounds, e.g. 10–14 for AES). This is separate from the security claim, which is a statement about the absence of efficient distinguishers, not about running time of FF itself.

GGM construction cost. If GG runs in time TG(n)T_G(n), evaluating Fk(x)F_k(x) for an nn-bit input requires exactly nn sequential applications of GG, giving time O(n⋅TG(n))O(n \cdot T_G(n)) and using O(n)O(n) space for the path of intermediate seeds (no exponential blowup, since only one root-to-leaf path is ever computed). Correctness of GGM as a PRF reduces to a hybrid argument over the levels of the tree: 1. Define hybrid HiH_i: the first ii levels of the tree are generated by real PRG expansions, and the values at depth ii (there are 2i2^i of them, but only those on paths actually queried are materialized) are replaced, level by level, with fresh true randomness. 2. H0H_0 is the real GGM function FkF_k; HnH_n is a truly random function (every leaf value is an independent uniform string, since it was replaced with fresh randomness before ever being run through GG again). 3. If Hi−1H_{i-1} and HiH_i were distinguishable with non-negligible advantage ε\varepsilon, that distinguisher can be converted into a distinguisher for the PRG GG itself (comparing G(s)G(s) against a truly random 2n2n-bit string) with related advantage — because the only difference between Hi−1H_{i-1} and HiH_i at any queried node is whether its two children came from applying GG to a pseudorandom seed or were chosen freshly at random. 4. A standard hybrid/triangle-inequality argument sums the nn level-by-level advantages: if GG has distinguishing advantage at most δ(n)\delta(n), then FF's distinguishing advantage is at most n⋅δ(n)n \cdot \delta(n), still negligible since nn is polynomial and δ\delta is negligible. This is the formal sense in which "PRFs exist if PRGs exist if one-way functions exist" — a foundational, unconditional-modulo-OWF existence result, even though in deployed systems we instead use heuristic constructions like AES for speed.

PRF/PRP switching lemma, proof sketch. Consider any adversary making qq distinct queries to either a uniformly random function f:[N]→[N]f: [N] \to [N] or a uniformly random permutation π\pi. Couple the two experiments by using the same underlying randomness except where they must differ: sample π\pi first, and let ff agree with π\pi unless a "collision" would be forced. Concretely, condition on the event NoCollision\mathsf{NoCollision} that all qq answers from ff happen to be distinct (exactly as a permutation's must be). Given NoCollision\mathsf{NoCollision}, the transcript is identically distributed in both experiments, so no adversary — regardless of running time — can distinguish them at all. The adversary can only win by exploiting ¬NoCollision\lnot\mathsf{NoCollision}, and

Pr⁡[¬NoCollision]≤(q2)⋅1N=q(q−1)2N,\Pr[\lnot\mathsf{NoCollision}] \le \binom{q}{2} \cdot \frac{1}{N} = \frac{q(q-1)}{2N},

by a union bound over the (q2)\binom{q}{2} pairs of queries, each colliding with probability 1/N1/N under a random function. This gives the stated bound and explains why block ciphers with m=128m = 128-bit blocks (like AES, N=2128N = 2^{128}) remain safely modeled as PRPs (equivalently, safely swapped for PRFs) as long as query counts stay far below 2642^{64} — the birthday bound on a 128-bit block.

Honest tradeoffs. GGM is a beautiful existence proof but is far too slow for practice: each evaluation costs nn PRG calls (e.g. n=128n=128 calls to build one output), whereas AES computes a comparable-security output in about 10 rounds. Deployed PRFs/PRPs (AES, ChaCha20-based PRFs, HMAC) are not proven secure from weaker assumptions; they are conjectured secure based on decades of public cryptanalysis withstanding differential and linear attacks. The abstraction is what lets protocol designers reason rigorously despite this gap: assume the primitive is a PRF/PRP, prove the protocol secure relative to that assumption, and let cryptanalysis separately stress-test the primitive.

Worked example

Take a tiny toy instance to make the game concrete: m=3m = 3-bit inputs, so the domain has N=8N = 8 points, and suppose a distinguisher A\mathcal{A} is trying to tell apart a keyed PRP FkF_k (modeling a toy 3-bit block cipher) from a uniformly random permutation π\pi of {0,1,…,7}\{0,1,\dots,7\}, using q=4q = 4 queries.

Query xxReal world: Fk(x)F_k(x)Ideal world: π(x)\pi(x)
000000101101011011
001001110110101101
010010011011110110
011011000000100100

The adversary sees only one column (it does not know which world it's in) and must guess. Notice both columns list four distinct 3-bit strings — consistent with either column being a genuine permutation's outputs, so nothing here looks locally wrong. If instead the "real" column had repeated a value (say Fk(011)=101F_k(011) = 101, matching Fk(000)F_k(000)), that would be an instant giveaway that this could not be the ideal-permutation world, since π\pi never repeats. This is exactly the birthday-bound argument in miniature: with N=8N=8 and q=4q=4 queries, the chance a random function would accidentally avoid all repeats is

Pr⁡[no collision]=88⋅78⋅68⋅58≈0.41,\Pr[\text{no collision}] = \frac{8}{8} \cdot \frac{7}{8} \cdot \frac{6}{8} \cdot \frac{5}{8} \approx 0.41,

meaning a random function reveals itself (via a repeat) with probability around 59%59\% at just q=4q=4 out of N=8N=8 — small domains make PRF/PRP switching risky, which is exactly why the switching lemma's bound q(q−1)/2Nq(q-1)/2N demands NN be exponentially large (as it is for a 128-bit block cipher) before the two notions are safely interchangeable. Now trace the GGM construction concretely for n=3n = 3 with key k=s0=010k = s_0 = 010 and a (toy, illustrative) PRG doubling rule G(s)=(s⊕100) ∥ (s⊕111)G(s) = (s \oplus 100)\,\|\,(s \oplus 111), so G0(s)=s⊕100G_0(s) = s \oplus 100 and G1(s)=s⊕111G_1(s) = s \oplus 111: ``` F(k=010, x=101): level 1, bit=1: s := G_1(010) = 010 ⊕ 111 = 101 level 2, bit=0: s := G_0(101) = 101 ⊕ 100 = 001 level 3, bit=1: s := G_1(001) = 001 ⊕ 111 = 110 return 110 ``` Different inputs walk different root-to-leaf paths through the same tree rooted at kk, and the hybrid argument says that as long as GG is a good PRG, no efficient observer of these leaf values can tell they came from a deterministic tree walk rather than from 23=82^3 = 8 independent coin flips.

Figure
GGM tree: one key, exponentially many pseudorandom leaves, only one path expanded per query
GGM Construction (n = 3) k=010 G₀(k) G₁(k)=101 bit=0 bit=1 G₀=001 110 F(k, 101) = 110 unexpanded siblings never computed

Common pitfalls & traps

PitfallWhy it's wrong
Treating "PRF" and "random function" as interchangeable in analysisA PRF is only indistinguishable from random to efficient adversaries; it is fully deterministic given the key and has short description — an unbounded adversary breaks it trivially
Assuming PRP security implies strong-PRP (two-way) securityA cipher secure against chosen-plaintext queries can still leak structure under chosen-ciphertext (decryption) queries; the two notions require separate proofs/assumptions
Ignoring the birthday bound in PRP-based MACs/modesUsing a PRP as if it were a PRF forever is unsound once q≈Nq \approx \sqrt{N} queries accumulate under one key; this is the root cause of real attacks like Sweet32 on 64-bit block ciphers
Confusing "PRG exists ⇒ PRF exists" with a practical construction recipeGGM is a feasibility proof, not an engineering blueprint; real PRFs (AES, HMAC) are designed and cryptanalyzed directly, not built by literally composing a PRG nn times
Forgetting that PRF/PRP security says nothing about related-key or side-channel attacksThe standard game only grants oracle query access under one fixed unknown key; power/timing leakage or key-related queries are outside the base definition and need extended models

Pioneers & history

The formal definitions of pseudorandom functions and their reduction to one-way primitives are due to Oded Goldreich, Shafi Goldwasser, and Silvio Micali, whose 1984 construction (published 1986) turned "randomness that merely looks random" into a fully composable, keyed cryptographic tool. This built directly on Andrew Yao's and Manuel Blum's earlier work formalizing computational indistinguishability and pseudorandom generators, and set the stage for the modern provable-security paradigm used throughout symmetric cryptography.

Origins · 1 minShafi Goldwasser and how this was discovered
SG
Shafi Goldwasser
born 1958 · Theoretical computer scientist, co-inventor of the definitional framework for modern cryptography

Goldwasser, along with Goldwasser–Micali's broader body of work on probabilistic encryption, zero-knowledge proofs, and pseudorandom functions, helped establish the reductionist paradigm — define security precisely as a game, then reduce it to a hard problem — that underlies essentially all rigorous cryptographic definitions used today, including the PRF and PRP games presented here.

History
1982
— Andrew Yao formalizes computational indistinguishability and pseudorandomness for cryptographic use.
1984
— Goldreich, Goldwasser, and Micali construct pseudorandom function families from pseudorandom generators (GGM construction).
1988
— Michael Luby and Charles Rackoff prove that a small number of Feistel rounds over a PRF yields a PRP (Luby–Rackoff theorem), formally connecting PRFs to block-cipher design.
1998–2001
— NIST's AES competition selects Rijndael, treated in analysis as a conjectured strong PRP.
2016
— The Sweet32 attack exploits birthday-bound collisions in 64-bit block ciphers (3DES, Blowfish) in real TLS deployments, validating the practical importance of the switching-lemma bound.

Where this matters

Every symmetric-key primitive deployed at scale is, at heart, a claim about being a PRF or PRP. AES is analyzed and standardized as a strong pseudorandom permutation; its security in modes like GCM and CBC is proven assuming AES meets that bar. HMAC, used to authenticate essentially all TLS records and countless API requests, is proven a secure MAC under the assumption that its underlying compression function behaves as a PRF. Key derivation functions (HKDF, used throughout TLS 1.3 and Signal's key ratcheting) rely on PRF security to argue that derived subkeys look independent and random even though they come from one master secret. Stream cipher and CTR-mode encryption treat the block cipher as a PRF evaluated on a counter, directly invoking the PRF definition rather than the permutation one, since no inversion is needed there. The GGM construction itself, while impractical to deploy directly, remains foundational in theory: it underlies feasibility results for oblivious transfer, garbled circuits, and constrained/updatable PRFs used in advanced protocols like private set intersection and searchable encryption. Understanding PRFs and PRPs is thus the prerequisite for reading any serious security proof about a block cipher or a MAC, and for understanding why "AES is secure" is really shorthand for "AES is assumed to be a strong PRP."

Ask the tutor: How does the Luby–Rackoff construction turn a PRF into a provably secure PRP using a Feistel network?

Is AES actually proven to be a PRP?

No. AES is a conjectured strong pseudorandom permutation, not a proven one, because no one has proven P≠NPP \neq NP-level lower bounds needed to unconditionally rule out efficient distinguishers. Confidence in AES comes instead from over two decades of intense public cryptanalysis — differential, linear, algebraic, and related-key attacks — all of which have failed to find a practical distinguisher better than brute force. This is the standard epistemic status of all deployed symmetric primitives: security proofs for protocols (like GCM mode) are rigorous and reduce cleanly to "AES is a strong PRP," but that base assumption itself rests on empirical cryptanalytic confidence, not a mathematical proof. This is analogous to how the definitions in this article treat one-way functions: their existence is also unproven but widely conjectured.

Why does the PRF definition compare against ALL functions, but the PRP definition compares against only permutations?

Because a PRP by construction can never output the same value twice on distinct inputs — it must be injective, hence bijective on a finite domain — so comparing it against an arbitrary random function would let a trivial distinguisher win by simply checking for a repeated output. A random function frequently produces collisions (by the birthday bound), while a permutation structurally cannot, so that check alone would break "indistinguishability" for reasons that have nothing to do with the cipher's actual cryptographic strength. Restricting the ideal object to a random permutation removes this structural artifact and isolates the meaningful question: does the keyed permutation look like a random permutation, not merely like some random object.

What is the Luby–Rackoff theorem and how does it relate to PRFs and PRPs?

The Luby–Rackoff theorem shows that composing just three or four rounds of a balanced Feistel cipher structure, each round keyed by an independent PRF, yields a construction that is provably a PRP (three rounds suffice for a plain PRP, four for a strong/super PRP). This is historically important because it gives a concrete, provable bridge from the PRF abstraction to the PRP abstraction: instead of relying only on the existential GGM-style argument, Luby–Rackoff shows a specific, efficient composition pattern — the same pattern used in real Feistel ciphers like DES — turns "random-function-like" building blocks into "random-permutation-like" ciphers with a clean security reduction.

Does a negligible distinguishing advantage mean an adversary can never win the PRF game?

No — it means the advantage over random guessing shrinks faster than any inverse polynomial in the security parameter as the parameter grows, not that the adversary's success probability is literally zero. An adversary can always guess the bit bb with probability 1/21/2 by pure chance, and it can even sometimes get lucky and do slightly better. "Negligible" formalizes "no efficient strategy does non-trivially better than guessing," which is exactly the guarantee protocol designers need: it lets them bound the probability that a real-world attacker, running in feasible time, gains any meaningful edge, while still allowing for astronomically small residual success probabilities that no realistic adversary could exploit.

How does a PRF relate to a pseudorandom generator, which is a prerequisite concept?

A PRG stretches one short random seed into one long pseudorandom string, with no structured indexing — you get a single output stream. A PRF instead gives you an entire family of pseudorandom strings, one per possible input xx, all derived from a single short key, with the crucial property that the whole family remains indistinguishable from independent randomness even when an adversary can adaptively choose which xx's to probe. You can think of a PRF as "a PRG with addressable, re-derivable outputs": the GGM construction literally builds a PRF by repeatedly applying a PRG down a tree, showing formally that PRFs are no stronger an assumption than PRGs, just a more usable interface for keyed, per-input randomness.

Why do MACs and encryption modes need a PRF/PRP rather than just a PRG?

A MAC or encryption scheme must process arbitrarily many distinct messages under one fixed secret key, computing a different, input-dependent tag or ciphertext block for each one, while still resisting forgery or distinguishing attacks across all of them jointly. A PRG only gives you one pseudorandom stream per seed, with no natural way to re-derive independent-looking randomness for many different inputs without seed reuse (which is catastrophic for security, as reusing a stream cipher's keystream leaks the XOR of two plaintexts). A PRF instead is designed exactly for this multi-input regime: keyed evaluation at any point looks random and independent of evaluations at other points, which is precisely what a MAC's tag function or a block cipher's per-block encryption needs.

Can a PRP ever be a bad PRF, or vice versa?

A secure PRP is automatically a "good enough" PRF for most practical purposes once you account for the birthday-bound gap: the switching lemma guarantees that as long as query counts stay well below N\sqrt{N}, no adversary can exploit the fact that a PRP never repeats outputs, so a PRP can safely substitute for a PRF in most security proofs. The reverse fails outright: a secure PRF need not be injective at all (many inputs can map to the same output, as expected from a random function), so it may not even be well-defined as a permutation, let alone efficiently invertible — meaning a generic PRF cannot generally serve as a block cipher, which specifically requires the bijective, invertible PRP structure.

Before this

Where this leads