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
Authentication tag: a short value that a message authentication code §5.7 (MAC) computes from a secret key and a message. HMAC §5.8 (hash-based message authentication code) is a widely used MAC. The sender attaches the tag to the message; the receiver holds the same key, recomputes the tag over the message it received and compares the two. For a new message, someone without the key should have only a negligible chance of producing a valid tag. With an ideal 128-bit tag, one blind guess succeeds with probability . A digital signature §5.14 does the same job with a private key for signing and a public key for checking; everything below applies to signatures unchanged.
Valid: the tag matches the message under the receiver’s key, so the check succeeds.
Old: the message and its tag were produced, sent and accepted earlier. Anyone who can listen to the channel, for example a radio link, can record them.
Problem: the receiver performs the requested action again, or at a time the sender did not intend. Sending a recorded genuine message again is a replay attack. The property that defeats it is replay resistance: the receiver acts on each genuine message at most once, and only while the message is current. A test that enforces replay resistance is a freshness check.
Full answer
Step 1: the check has no memory. Write for the receiver’s check of tag on message under key . The check recomputes the tag from and and compares the result with . 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 that passed once therefore passes every later time, for as long as the receiver keeps the key .
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.
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.
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.
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 . A command consists of a 4-byte counter followed by the command text, and its tag is the HMAC of those bytes under . The lock keeps the floor in persistent storage; at the start, .
The phone sends counter 3 with
unlockand the tag . The lock recomputes the tag over the received bytes; it equals . The lock compares , that is : true. It writes to persistent storage and then unlocks. An attacker nearby records the message and .That evening the attacker sends the recorded bytes again. The recomputed tag again equals , because the bytes and the key are unchanged. The lock compares : false. It rejects the message.
The attacker changes the counter to 4 and keeps . The lock recomputes the tag over the bytes that now contain 4. The result differs from , so the lock rejects the message. Computing the right tag for counter 4 needs .
A flawed lock keeps only in RAM, so every power cut sets back to 0 while stays the same. After a power cut, the attacker sends the recorded counter-3 message. The lock compares : 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 each time the phone asks to unlock, and the phone answers with unlock and the tag over the bytes of followed by unlock. A recorded answer carries a tag over an earlier challenge . Producing the tag over the new needs , so the copy fails, also after a power cut, unless . By the birthday bound §5.6, the probability that any two of random 128-bit challenges are equal is at most . For challenges, , so the probability is below .
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).