Section 5.34

Post-compromise security

Definition

Post-compromise security is a property of a protocol that keeps secret state across many messages or sessions: after an attacker has learned the complete secret state of a party, the protocol restores the secrecy and authenticity of later messages once the attacker has lost access and the parties have completed an exchange that adds fresh secret randomness the attacker did not see. Forward secrecy §5.33 protects messages sent before a compromise; post-compromise security restores protection for messages sent after it. Cohn-Gordon, Cremers and Garratt defined the term in 2016 [334].

The idea

A phone is taken at a border for an hour, its memory is copied, and the phone is returned. The copy contains every key the messaging application holds. If the application derives each new key from the previous one with a fixed function, the attacker runs the same function on the copy and can read every future message, without ever touching the phone again.

The core idea is that a fixed function of a known value is a known value. Hashing, renaming, re-encrypting or rotating keys computed only from the stolen state yields values that the attacker can compute as well. Security can return only through something new and secret: random numbers generated after the attacker lost access, mixed into the state by a step the attacker cannot repeat. A Diffie–Hellman §19.1.4 exchange provides such a step. Each side contributes a fresh private value, only public values travel, and a listener who knows the old state still cannot compute the new shared secret.

How it works

The Diffie–Hellman ratchet, part of the Double Ratchet algorithm §14.1 of the Signal messaging protocol, shows the mechanism. Let gg be the public generator of a group in which computing gxyg^{xy} from gxg^{x} and gyg^{y} alone is infeasible, and let SS be the secret state that the two parties share. In simplified form it runs as follows; the full algorithm also derives a separate key for every message.

  1. Each party holds a current private value, and the other party knows the matching public value, which travels with every message.

  2. When a party receives a public value from the other that it has not seen before, it draws a new private value from its random number generator and attaches the matching public value to the messages it sends next.

  3. Each new pair of values gives a Diffie–Hellman output: if x′x' is one party’s new private value and gyg^{y} the other party’s latest public value, both can compute Z=gx′yZ = g^{x'y}, one from x′x' and gyg^{y}, the other from yy and gx′g^{x'}.

  4. Both replace the state by S′=KDF(S,Z)S' = \mathrm{KDF}(S, Z), where KDF §5.20 is a key derivation function, an algorithm that turns secrets into keys, and both erase SS and the private values they no longer need. Message keys come from S′S'.

  5. Because each new public value answers the other party’s latest one, the parties take turns, and each party’s private value is replaced once per round trip.

Recovery happens at the first Diffie–Hellman output whose two private values the attacker has never seen. Suppose the attacker copied Bob’s state, including Bob’s current private value yy, and then lost access. Alice’s next message carries Alice’s new public value gx′g^{x'}, and the attacker still computes gx′yg^{x'y} with the stolen yy. On receiving that message, Bob draws a fresh y′y', and the next output gx′y′g^{x'y'} combines two private values the attacker never saw; from then on the state is secret again. If the attacker copied Alice’s state instead, the same happens with the roles exchanged. In a conversation in which the parties take turns, recovery therefore takes at most one round trip after the attacker loses access.

Recovery also needs the attacker to leave that step alone. An attacker that still holds the copied state can intercept the next exchange, pose as each party to the other, and substitute public values of its own; it then shares one new state with each side and keeps reading. The recovering exchange must therefore be one the attacker does not tamper with, or one authenticated by a secret the attacker does not hold, such as the peer’s uncompromised long-term key §7.28 or a comparison of codes that the users make over another channel.

The same pattern serves a device and its server. After the attacker has lost access, the two run a new authenticated key exchange §19.1.6, a key agreement in which each side also proves its identity, with fresh private values and derive all later keys from its result. The device checks the server’s long-term key, which the attacker never had, so the attacker cannot sit in the middle of that exchange; with the stolen device key it can still pose as the device to the server until that key is revoked. In group protocols such as MLS (Messaging Layer Security, RFC 9420) [335], a member recovers by sending an update that replaces its own key material, which takes effect once a member commits it, that is, applies it to the group’s shared state.

Worked example

At the moment of compromise, both the device and the attacker know the state SS. Suppose the device then sets S1=HMAC(S,next)S_1 = \mathrm{HMAC}(S, \text{next}), using HMAC §5.8 (hash-based message authentication code) as a one-way mixing function. The attacker computes the same S1S_1 from the same SS. After ten such steps the attacker still knows S10S_{10}; repetition changes nothing.

Now add a Diffie–Hellman step in the toy group of the numbers 1 to 22 multiplied modulo the prime 23, with generator g=5g = 5; real groups are vastly larger. After the attacker has lost access, the device draws x=9x = 9 and an uncompromised peer draws y=13y = 13. Repeated squaring gives 52=25≡25^{2} = 25 \equiv 2, 54≡45^{4} \equiv 4 and 58≡165^{8} \equiv 16, where ≡\equiv means equal after reduction modulo 23. So 59=58⋅5≡16⋅5=80=3×23+115^{9} = 5^{8} \cdot 5 \equiv 16 \cdot 5 = 80 = 3 \times 23 + 11, giving the device’s public value X=11X = 11, and 513=58⋅54⋅5≡16⋅4⋅5=320=13×23+215^{13} = 5^{8} \cdot 5^{4} \cdot 5 \equiv 16 \cdot 4 \cdot 5 = 320 = 13 \times 23 + 21, giving the peer’s public value Y=21Y = 21.

The device computes Z=Yx=219Z = Y^{x} = 21^{9}. Since 21≡−221 \equiv -2, 219≡(−2)9=−51221^{9} \equiv (-2)^{9} = -512; and 512=22×23+6512 = 22 \times 23 + 6, so −512≡−6≡17-512 \equiv -6 \equiv 17. The peer computes Xy=1113X^{y} = 11^{13}: 112=121≡611^{2} = 121 \equiv 6, 114≡62=36≡1311^{4} \equiv 6^{2} = 36 \equiv 13 and 118≡132=169≡811^{8} \equiv 13^{2} = 169 \equiv 8, so 1113=118⋅114⋅11≡8⋅13⋅11=1144=49×23+1711^{13} = 11^{8} \cdot 11^{4} \cdot 11 \equiv 8 \cdot 13 \cdot 11 = 1144 = 49 \times 23 + 17, again 17. Both set S′=KDF(S,17)S' = \mathrm{KDF}(S, 17). The attacker knows SS and saw 11 and 21, but to obtain 17 it needs 9 or 13. In this toy group it finds one in at most 22 tries; in a group of practical size it cannot.

Had the attacker, still holding SS, replaced both public values in transit with values of its own, it would share one new state with the device and another with the peer, and could keep relaying messages between them. That is why the recovering exchange must be left alone by the attacker or be authenticated by a key the attacker lacks.

Stated precisely

Let σt\sigma_t be a party’s complete secret state after step tt, and let the attacker learn σc\sigma_c at step cc. If every update has the form σt+1=f(σt,mt)\sigma_{t+1} = f(\sigma_t, m_t), where ff is a public function and mtm_t is a message the attacker sees, then by induction the attacker can compute σt\sigma_t for every t≥ct \ge c. Post-compromise security is therefore impossible unless some update after step cc has the form σt+1=f(σt,mt,rt)\sigma_{t+1} = f(\sigma_t, m_t, r_t), where rtr_t is a secret random input that the attacker does not know.

Conversely, keys derived after a recovering exchange cannot be told apart from random by the attacker when four conditions hold.

  1. Lost access: from some step on, the attacker no longer reads the party’s state.

  2. Fresh private values: both private values used in the recovering exchange come from random sources that the attacker does not know, either generated after it lost access or never exposed to it.

  3. An untampered exchange: the attacker does not inject or alter messages in that exchange, or the exchange is authenticated by a secret the attacker does not hold.

  4. Sound primitives: the Diffie–Hellman problem §19.1.3 is hard in the group, and the key derivation function behaves as a pseudorandom function §15.1, a keyed function whose outputs look random to anyone without the key.

The word ratchet implies no fixed number of steps or messages; the recovery time depends on when each party next contributes fresh randomness.

Limits and common mistakes

Post-compromise security does not evict an attacker. Malware that keeps reading the state sees every fresh value as it is generated, and no protocol recovers until the malware is removed, for example by reinstalling software and using secure boot §6.31 to start a known-good image authorized by the platform.

An active attacker that holds the copied state during the next exchange can stay in the middle indefinitely. Recovery against such an attacker needs an authentication §1.6 secret that it lacks.

The stolen long-term identity key stays stolen. Recovering the session state does not stop the attacker from opening new sessions as the victim; the identity key must be replaced and the old one revoked.

Rotating or re-deriving keys from material the attacker knows is not recovery. A key rotation §5.29 that computes the new key from the old one, or from a root key §5.25 the attacker copied, leaves the attacker able to compute the new key.

The random number generator is part of the state. If the attacker copied the internal state of a CSPRNG §5.27 (cryptographically secure pseudorandom number generator) and the generator is not reseeded from a hardware entropy §5.26 source, its future outputs, and with them the fresh private values, are predictable.

Messages sent between the compromise and the recovery are exposed. Messages sent before the compromise depend on forward secrecy, a separate property.

A party that never sends never contributes fresh randomness, so recovery waits for it.

Questions answered

What uncompromised source can restore security after total key-state disclosure?

Only a secret that the attacker has never seen, created after the attacker lost access, can restore security; nothing computed from the disclosed state can. In practice that secret is fresh randomness from a source the attacker does not control, typically the device’s hardware random number generator, which must also reseed the device’s cryptographically secure pseudorandom number generator, because the copied generator state would otherwise make its future outputs predictable. The fresh value is combined with a fresh contribution from an uncompromised peer through a Diffie–Hellman exchange, so that the new shared secret is gxyg^{xy} for two private values xx and yy that the attacker never saw.

That exchange must also be one the attacker cannot hijack. Either the attacker no longer acts on the link, or the exchange is authenticated by something the attacker does not hold: the peer’s uncompromised long-term key, a key inside a secure element §5.38 that the attacker could use only while it controlled the device and could not copy, or a physical or out-of-band step such as re-provisioning the device over a cable. Labels, counters, timestamps, public random values and any hash or rotation of the disclosed state supply nothing new.

Related entries: Forward secrecy (§5.33), CSPRNG (§5.27), Key rotation (§5.29), Secure element (§5.38), Diffie–Hellman key agreement (§19.1.4). Further reading: [334, 335].