Section 5.33

Forward secrecy

Definition

Forward secrecy, also called perfect forward secrecy (PFS), is a property of a protocol by which two parties agree on session keys: if a party’s long-term key §7.28, the secret it keeps across many sessions to prove its identity, is stolen after a session has ended, that session’s keys stay secret, so the recorded traffic of the session still cannot be decrypted. Protocols achieve it by deriving each session key from short-lived secrets that both parties erase after use, so that nothing stolen later determines an old key.

The idea

An attacker can record encrypted traffic today and wait. If one long-term key can decrypt that traffic, then a single later theft, legal order or software bug that exposes the key exposes every recorded conversation. Older versions of TLS (Transport Layer Security, the protocol that protects web traffic) allowed exactly this with RSA key transport, RSA being a public-key scheme named after Rivest, Shamir and Adleman. The client chose the secret from which the session keys were derived and sent it encrypted under the server’s long-term RSA public key. Whoever later held the server’s private key could decrypt that secret from every recorded handshake, and so decrypt every recorded session. TLS 1.3, published in 2018 as RFC 8446 [325], removed this option.

The remedy is to make each session key depend on a secret that exists only during the session. In ephemeral Diffie–Hellman key agreement §19.1.4, each side draws a fresh random private number for this one session, and the two sides combine public values derived from those numbers into a shared secret. The long-term key is used only to sign the public values, which proves who sent them. After the session both sides erase the private numbers. A later thief obtains a signing key: it can sign new messages, but signing does not help to recompute a secret built from numbers that no longer exist anywhere.

How it works

Signed ephemeral Diffie–Hellman, the pattern that every full TLS 1.3 handshake uses, works as follows. Let pp be a large public prime and gg a public number called the generator; all arithmetic is modulo pp, meaning that only the remainder after division by pp is kept. Computing gxyg^{xy} from gxg^{x} and gyg^{y} without knowing xx or yy is believed infeasible for well-chosen large groups; this belief is the computational Diffie–Hellman assumption. Most deployments use elliptic-curve §19.1.5 groups, which have the same structure with a different multiplication rule.

  1. Client and server each draw a fresh private value, xx and yy, from a cryptographically secure pseudorandom number generator §5.27 (CSPRNG), and compute the public values X=gxX = g^{x} and Y=gyY = g^{y}.

  2. They exchange XX and YY. The server signs the handshake transcript, the record of all handshake messages so far, which contains both public values, with its long-term private key. The client checks that signature with the public key in the server’s certificate, a signed statement that binds the server’s name to that key.

  3. Each side computes the shared secret Z=Yx=Xy=gxyZ = Y^{x} = X^{y} = g^{xy} and derives the session keys from ZZ and the transcript with a key derivation function §5.20 (KDF), an algorithm §14.1 that turns a secret into keys.

  4. Each side erases its private value and ZZ as soon as the session keys exist, and erases the session keys when the session ends.

Four common designs lack forward secrecy:

Forward secrecy can also be obtained without public-key operations, by a one-way ratchet. Keep a current key KiK_i. To move to the next period, compute Ki+1=H(Ki)K_{i+1} = H(K_i) with a one-way function HH, such as a cryptographic hash function §5.1, and then erase KiK_i. An attacker who steals the state in period jj obtains KjK_j and can compute every later key, but no earlier one, because that would require inverting HH. This protects past periods against theft of the current state, provided the starting key was erased as well. It does nothing for the periods after the theft; regaining security for those is the subject of post-compromise security §5.34.

Worked example

Take a toy group: the numbers 1 to 22 multiplied modulo the prime p=23p = 23, with generator g=5g = 5. Real systems use elliptic-curve groups with about 22562^{256} elements or primes of at least 2048 bits; these small numbers only make the steps visible. In session 1 the client draws x=6x = 6 and the server draws y=15y = 15. The client’s public value is X=56mod23=15,625mod23=8X = 5^{6} \bmod 23 = 15{,}625 \bmod 23 = 8, because 15,625=679×23+815{,}625 = 679 \times 23 + 8. For the server’s value, square repeatedly: 52=25≡25^{2} = 25 \equiv 2, 54≡22=45^{4} \equiv 2^{2} = 4 and 58≡42=165^{8} \equiv 4^{2} = 16, where ≡\equiv means equal after reduction modulo 23. Then 515=58⋅54⋅52⋅5≡16⋅4⋅2⋅5=640=27×23+195^{15} = 5^{8} \cdot 5^{4} \cdot 5^{2} \cdot 5 \equiv 16 \cdot 4 \cdot 2 \cdot 5 = 640 = 27 \times 23 + 19, so Y=19Y = 19.

The client computes Z=Yx=196mod23Z = Y^{x} = 19^{6} \bmod 23. Since 19≡−419 \equiv -4, 196≡(−4)6=4096=178×23+219^{6} \equiv (-4)^{6} = 4096 = 178 \times 23 + 2, so Z=2Z = 2. The server computes Xy=815mod23X^{y} = 8^{15} \bmod 23: 82=64≡188^{2} = 64 \equiv 18, 84≡182=324≡28^{4} \equiv 18^{2} = 324 \equiv 2 and 88≡22=48^{8} \equiv 2^{2} = 4, so 815=88⋅84⋅82⋅8≡4⋅2⋅18⋅8=1152=50×23+28^{15} = 8^{8} \cdot 8^{4} \cdot 8^{2} \cdot 8 \equiv 4 \cdot 2 \cdot 18 \cdot 8 = 1152 = 50 \times 23 + 2, again Z=2Z = 2. Both derive the session keys from ZZ and then erase 6, 15 and 2.

A year later the attacker steals the server’s long-term signing key. It holds the recording, with X=8X = 8, Y=19Y = 19 and the server’s signature, and it holds the signing key. None of these yields ZZ. To compute ZZ the attacker needs xx or yy, for example the xx with 5x≡85^{x} \equiv 8, which is a discrete logarithm §19.1.3. In this toy group at most 22 tries find it; in the groups used in practice, no known method on ordinary computers finds it in feasible time.

Compare a design without forward secrecy. A device keeps a root secret SS and derives the key of session ii as Ki=HMAC(S,i)K_i = \mathrm{HMAC}(S, i), the HMAC §5.8 (hash-based message authentication code) of the session number under SS. A device that opened one session per hour for a year ran 24×365=8,76024 \times 365 = 8{,}760 sessions. An attacker who later steals SS recomputes all 8,760 session keys with 8,760 HMAC computations and decrypts every recorded session. That every session had its own key did not help.

Stated precisely

Forward secrecy is defined by an experiment with four stages.

  1. The attacker observes and records any number of sessions between honest parties.

  2. A target session completes, and both parties erase its ephemeral secrets and its session keys.

  3. The attacker then receives the long-term secret keys of both parties.

  4. The attacker is given either the target session’s key or a random string of the same length, and must say which.

The protocol has forward secrecy if no feasible attacker answers correctly with probability noticeably above 1/21/2, the success rate of a blind guess.

The guarantee rests on five assumptions.

Some definitions distinguish weak forward secrecy, which covers only sessions in which the attacker merely listened, from full forward secrecy, which also covers sessions that the attacker tried to tamper with before it held any long-term key.

Limits and common mistakes

Erasure is the assumption most often broken in practice. Keys left in freed memory, in swap files, in crash dumps or in debug logs undo forward secrecy; the secret zeroization §5.37 entry treats erasure.

Forward secrecy protects only sessions that ended before the theft. With the stolen long-term key, the attacker can impersonate its owner in new sessions. Regaining security after a theft is post-compromise security, a separate property.

Forward secrecy does not survive a later break of the key agreement itself. A future quantum computer able to compute discrete logarithms in the groups used today would decrypt recorded sessions despite forward secrecy; recorded traffic is one reason to adopt post-quantum key agreement, designed to resist such computers, early.

An endpoint that is compromised while the session runs exposes the plaintext. Forward secrecy protects keys after the fact, not endpoints during the session.

Distinct keys are not forward secrecy. Per-device or per-session keys that are all derived from a kept root fall together when the root is stolen.

Predictable ephemeral values destroy the property: if xx came from a weak random number generator, the attacker recomputes xx instead of stealing it.

Metadata, such as who talked to whom, when and how much, is not protected. The word perfect is historical; the property holds only under the assumptions above.

Questions answered

Does deterministic derivation from a persistent root provide forward secrecy?

No. If every session key is computed by a fixed function from a root secret that is kept, together with public inputs such as labels, counters or device identifiers, then anyone who later obtains the root recomputes every earlier session key and decrypts every recorded session. Making the keys different per session or per device limits the harm of losing one session key, not the harm of losing the root.

Forward secrecy needs the material that can be stolen later to no longer determine the earlier keys. Two designs achieve that. In the first, each session key depends on an ephemeral secret that both sides erase after the session, as in ephemeral Diffie–Hellman key agreement. In the second, the key state is advanced through a one-way function and each old state is erased, as in a hash ratchet. Deterministic derivation qualifies only in the second form, and only for keys whose predecessors, including the original root, have really been erased.

Related entries: Post-compromise security (§5.34), Secret zeroization (§5.37), Root key and root seed (§5.25), Diffie–Hellman key agreement (§19.1.4), Authenticated key exchange and transcript binding (§19.1.6). Further reading: [325].