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 , evaluating the function on 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.
- 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 .
- 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.
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 where each is indexed by a key . We write for the two-argument description, with . The family is efficient if there is a polynomial-time algorithm computing given both arguments. A pseudorandom function (PRF) is an efficient function family such that, when the key is chosen uniformly at random and hidden from an adversary, the function is computationally indistinguishable from a function drawn uniformly at random from the set of all functions . The adversary is modeled as interacting with an oracle: it submits inputs adaptively and receives outputs, but never sees the key or the internal randomness. Formally, for every probabilistic polynomial-time (PPT) oracle adversary ,
where the first probability is over the random key and 's coins, and the second is over a uniformly random function (drawn from the exponentially large space of all such functions) and 's coins. A pseudorandom permutation (PRP) is the same idea specialized to bijections. Here , and each is required to be a permutation of — invertible, and efficiently invertible given (this second requirement matters for decryption). The security definition compares against a permutation drawn uniformly at random from the symmetric group on , 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 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 and — 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 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 | ``` is a PRF iff `Advantage(A)` is negligible in for every PPT . The PRP game is identical except the two branches instantiate a keyed permutation and a uniformly random permutation , 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 be a PRG, and write as its left and right -bit halves. Define the keyed family by walking down a binary tree of depth 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 defines a full binary tree of depth with leaves, one per possible input ; the value is the leaf reached by following the path dictated by the bits of . Crucially, the algorithm only ever expands the single root-to-leaf path actually queried — it runs in time per evaluation, where 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 is small relative to the domain size . ``` 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
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 queries.
Complexity & correctness
Efficiency of the definitions themselves. Being a PRF/PRP is a property of an efficient family: evaluating must run in time polynomial in the security parameter (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 itself.
GGM construction cost. If runs in time , evaluating for an -bit input requires exactly sequential applications of , giving time and using 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 : the first levels of the tree are generated by real PRG expansions, and the values at depth (there are of them, but only those on paths actually queried are materialized) are replaced, level by level, with fresh true randomness. 2. is the real GGM function ; 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 again). 3. If and were distinguishable with non-negligible advantage , that distinguisher can be converted into a distinguisher for the PRG itself (comparing against a truly random -bit string) with related advantage — because the only difference between and at any queried node is whether its two children came from applying to a pseudorandom seed or were chosen freshly at random. 4. A standard hybrid/triangle-inequality argument sums the level-by-level advantages: if has distinguishing advantage at most , then 's distinguishing advantage is at most , still negligible since is polynomial and 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 distinct queries to either a uniformly random function or a uniformly random permutation . Couple the two experiments by using the same underlying randomness except where they must differ: sample first, and let agree with unless a "collision" would be forced. Concretely, condition on the event that all answers from happen to be distinct (exactly as a permutation's must be). Given , 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 , and
by a union bound over the pairs of queries, each colliding with probability under a random function. This gives the stated bound and explains why block ciphers with -bit blocks (like AES, ) remain safely modeled as PRPs (equivalently, safely swapped for PRFs) as long as query counts stay far below — 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 PRG calls (e.g. 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: -bit inputs, so the domain has points, and suppose a distinguisher is trying to tell apart a keyed PRP (modeling a toy 3-bit block cipher) from a uniformly random permutation of , using queries.
| Query | Real world: | Ideal world: |
|---|---|---|
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 , matching ), that would be an instant giveaway that this could not be the ideal-permutation world, since never repeats. This is exactly the birthday-bound argument in miniature: with and queries, the chance a random function would accidentally avoid all repeats is
meaning a random function reveals itself (via a repeat) with probability around at just out of — small domains make PRF/PRP switching risky, which is exactly why the switching lemma's bound demands 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 with key and a (toy, illustrative) PRG doubling rule , so and : ``` 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 , and the hybrid argument says that as long as is a good PRG, no efficient observer of these leaf values can tell they came from a deterministic tree walk rather than from independent coin flips.
Common pitfalls & traps
| Pitfall | Why it's wrong |
|---|---|
| Treating "PRF" and "random function" as interchangeable in analysis | A 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) security | A 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/modes | Using a PRP as if it were a PRF forever is unsound once 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 recipe | GGM is a feasibility proof, not an engineering blueprint; real PRFs (AES, HMAC) are designed and cryptanalyzed directly, not built by literally composing a PRG times |
| Forgetting that PRF/PRP security says nothing about related-key or side-channel attacks | The 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
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.
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 -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 with probability 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 , 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 '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 , 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.