Section 17.10

Replay resistance requires state or a fresh challenge

Question

Why does an old valid authentication §1.6 tag remain a problem?

Short answer

An old valid authentication tag remains a problem because it still verifies. The check shows that a holder of the key produced exactly these bytes, not when they were produced or whether the receiver has already acted on them. An attacker who recorded a genuine message can resend it, and the receiver accepts it again: a replay attack §1.26. Only a rule over the receiver’s state can refuse the copy, such as a stored counter that each new message must exceed, or a fresh challenge that the tag must cover.

Terms in the question

Full answer

Step 1: the check has no memory. Write Verify(K,m,t)\mathrm{Verify}(K, m, t) for the receiver’s check of tag tt on message mm under key KK. The check recomputes the tag from KK and mm and compares the result with tt. Its outcome depends on these three inputs and on nothing else: not on the time, not on earlier messages, not on what the receiver has done. A pair (m,t)(m, t) that passed once therefore passes every later time, for as long as the receiver keeps the key KK.

Step 2: a replay is not a forgery. The usual unforgeability test lets someone obtain tags on messages of their choice, then asks them to produce a valid tag for a message they never submitted. Their chance of success should be negligible. A stronger test also counts producing a different valid tag on a previously submitted message. Sending the exact same message and tag again wins neither test. The attacker needs no key and breaks no cryptography. A longer tag or a stronger hash function therefore changes nothing.

Step 3: the harm is acting again, or at the wrong time. A recorded unlock command opens a door again while the owner is away. A recorded payment order pays twice. A recorded order to install an old setting undoes a newer one. The bytes are genuine; only the moment of use is wrong.

Step 4: something on the receiver’s side must have changed. The copy has the same bytes as the original, and its tag passes only because the receiver still uses the same key. The only thing that can differ between the first arrival and the second is the receiver: what it remembers, or what it now demands. Every defense against replay is therefore a rule over receiver state. There are three families.

  1. A stored counter. The sender places a sequence number inside the bytes that the tag covers and increases it for every message. The receiver keeps, in persistent storage (storage that keeps its content without power), the highest number it has accepted; call it the floor. It accepts a message only if the message’s number is greater than the floor, and then raises the floor to that number. A copy carries a number no greater than the floor and fails.

  2. A fresh challenge. Before the sender acts, the receiver picks an unpredictable random value, a nonce §5.18 (a number used once), and sends it as a challenge. The sender’s tag must cover the challenge. The receiver accepts only a response whose tag covers the challenge it is waiting for at that moment, and then discards that challenge. A recorded response covers an earlier challenge and fails. This costs one extra message and needs a random source whose values cannot be predicted and do not repeat after a restart. In return, the receiver keeps no long-term record: a reset that forgets the pending challenge only makes every old response fail.

  3. A time window. The message carries the time at which it was sent, and the receiver accepts it only if that time lies within a few seconds of its own clock. This needs a clock that the attacker cannot set back, and a copy sent within the window still passes unless the receiver also records what it has accepted.

Key rotation §5.29 changes what the receiver checks. Old requests lose their authority when the receiver stops accepting the old key and enforces the current key generation. During a transition that still accepts the old key, the receiver still needs its replay checks for that generation.

Step 5: the tag must cover the freshness value, and the receiver must enforce it. A counter or challenge outside the authenticated bytes helps nothing, because the attacker can change it without making the tag fail. A field labeled nonce inside the authenticated bytes helps nothing either if the receiver accepts any value there, because the copy simply carries its old value. Replay resistance comes from the receiver’s comparison with its own state, not from the presence of a field.

Worked example

A door lock and its owner’s phone share a 32-byte key KK. A command consists of a 4-byte counter followed by the command text, and its tag is the HMAC of those bytes under KK. The lock keeps the floor FF in persistent storage; at the start, F=2F = 2.

  1. The phone sends counter 3 with unlock and the tag t3t_3. The lock recomputes the tag over the received bytes; it equals t3t_3. The lock compares 3>F3 > F, that is 3>23 > 2: true. It writes F=3F = 3 to persistent storage and then unlocks. An attacker nearby records the message and t3t_3.

  2. That evening the attacker sends the recorded bytes again. The recomputed tag again equals t3t_3, because the bytes and the key are unchanged. The lock compares 3>33 > 3: false. It rejects the message.

  3. The attacker changes the counter to 4 and keeps t3t_3. The lock recomputes the tag over the bytes that now contain 4. The result differs from t3t_3, so the lock rejects the message. Computing the right tag for counter 4 needs KK.

  4. A flawed lock keeps FF only in RAM, so every power cut sets FF back to 0 while KK stays the same. After a power cut, the attacker sends the recorded counter-3 message. The lock compares 3>03 > 0: true, and it unlocks. The cryptography is intact; the state that made old messages stale was lost.

A lock that uses challenges instead sends a fresh 16-byte (128-bit) random challenge cc each time the phone asks to unlock, and the phone answers with unlock and the tag over the bytes of cc followed by unlock. A recorded answer carries a tag over an earlier challenge c′c'. Producing the tag over the new cc needs KK, so the copy fails, also after a power cut, unless c=c′c = c'. By the birthday bound §5.6, the probability that any two of nn random 128-bit challenges are equal is at most n(n−1)2⋅2−128\frac{n(n-1)}{2} \cdot 2^{-128}. For n=232=4,294,967,296n = 2^{32} = 4{,}294{,}967{,}296 challenges, n(n−1)2<2642=263\frac{n(n-1)}{2} < \frac{2^{64}}{2} = 2^{63}, so the probability is below 263⋅2−128=2−652^{63} \cdot 2^{-128} = 2^{-65}.

Follow-up questions and limits

In which order should the receiver store the new floor and perform the action? Store the floor first, wait until the write has reached persistent storage, then act. If power fails between the two, the floor advances and the action can be lost. With no reply, the sender cannot tell whether the action took place. Sending a new counter is safe for an idempotent §8.31 action such as setting a limit. For a one-time payment, the two attempts need the same durable payment identifier and a payment system that uses it to prevent a second charge. In the opposite order, a power cut after the action and before the write leaves the old floor in place, and the recorded message is accepted once more.

Does encryption stop a replay? No. A copy of an encrypted message decrypts to the same content, and under authenticated encryption §5.16 it also passes the integrity §1.9 check. Encryption hides the content; it does not mark a message as used.

How does the receiver tell a replay from an honest retransmission §7.36? It cannot tell from the bytes. A retransmission, in which the genuine sender sends the same message again because no reply arrived, is byte for byte a replay. The protocol must decide what a duplicate receives. Either the operation is idempotent, meaning that performing it twice has the same effect as performing it once (“set the limit to 10”), or the receiver recognizes the duplicate by its counter and answers with the stored result of the first acceptance without repeating the effect. Retries, duplicates and the confirmation that the sender waits for are separate parts of the protocol and need separate rules.

What else must the tag cover? Everything that decides what the receiver does: the identity of the intended receiver, the operation, and the version of the data that the command refers to. This list is the authentication coverage §5.41 of the protocol; without it, a genuine message for one device or one operation can be replayed to another. If counters restart at 0 for each session or each boot, the tag must also cover a session or boot number that never repeats, or messages from an earlier session become acceptable again.

This answer does not cover two related attacks. In a delay attack, the attacker holds back a fresh response and delivers it later; a time limit on each pending challenge bounds the delay. In a relay attack, the attacker forwards a live exchange between a distant phone and the lock in real time. Every freshness check passes, because the exchange really is current; defeating a relay needs a bound on distance, for example on the round-trip time.

Fullest treatment: Replay attack (§1.26).

Related entries: Authentication coverage (§5.41), Version high-water mark (§8.27), Idempotency (§8.31), Key confirmation versus application confirmation (§5.42), Monotonic counter (§8.28), Nonce (§5.18), Chosen-message unforgeability and a MAC security game (§19.1.8).