Section 5.29

Key rotation

Definition

Key rotation is the planned replacement of a cryptographic key in use by a new key that does the same job, followed by the retirement of the old key. It limits how long, and for how much data, one key is used, and it moves a system to a fresh key when the old one may be known to an attacker. When keys are stored across restarts, rotation is a change of state that both sides must make in agreement, with a defined outcome for a restart at any point.

The idea

A server and a device share the key K4K_4, the fourth key in their history, and the server decides to replace it with K5K_5. If the device starts using K5K_5 while the server still uses K4K_4, or the other way round, every message fails verification. If the device writes K5K_5 over K4K_4 and power fails halfway, it holds neither key. Either way the device can no longer be reached, and a device that cannot be reached cannot be told how to recover. Rotation is therefore a small protocol between the two sides, not an overwrite of some bytes.

The intuition is a relay handover in which both runners hold the baton for a moment. The new key is first delivered and stored next to the old one, then shown to work, and only then does the old key stop being used. The analogy ends at the cost: in a relay the overlap costs nothing, but here the old key stays usable a little longer, which matters if the old key is the one an attacker knows.

NIST Special Publication (SP) 800-57 Part 1, NIST’s recommendation for key management, calls the replacement of a key by another key that performs the same function key change, and gives three reasons for it: the key may have been compromised, its cryptoperiod (the time span during which a specific key is authorized for use) may be nearing its end, or the amount of data protected with one key should be limited.

How it works

Rotation runs in stages. The labels follow SP 800-57, which names the states a key passes through: pre-activation (generated but not yet authorized for use), active, deactivated (no longer used to protect new data and, in some cases, still used to process data protected earlier) and destroyed. Each key also carries an epoch, a number that counts key generations and only ever increases.

  1. Generate. The server generates K5K_5 independently of K4K_4, from a CSPRNG §5.27 (cryptographically secure pseudorandom number generator) or a fresh key agreement; SP 800-57 calls this re-keying. K5K_5 is in pre-activation.

  2. Deliver and stage. The server sends K5K_5 to the device, encrypted and authenticated under a key the device already trusts, with the epoch number 5 inside the authenticated part. The device accepts the delivery only if its epoch is exactly one more than the epoch of its active key. It writes K5K_5 and its epoch into a spare storage slot together with an integrity §1.9 check, a checksum §4.32 or tag that shows whether the record was written completely. K4K_4 stays active.

  3. Confirm. The device proves that it holds K5K_5, for example by returning a tag computed with K5K_5 over a fresh challenge. SP 800-57 allows a key in pre-activation to be used for proof of possession §5.30 or key confirmation §5.42 (showing the other side that one holds the key) and for nothing else.

  4. Switch the sender. When the confirmation verifies, the server starts protecting new messages with K5K_5. For an overlap period it still accepts messages from the device protected with K4K_4.

  5. Activate on the device. The first server message that verifies under K5K_5 shows that the server has switched. The device then writes a selector, a small record that names the active epoch, as one atomic write: after a power failure the selector holds either the old value or the new one, never a mixture. One way is to keep two copies of the selector, each with a sequence number and an integrity check, and to treat the valid copy with the higher sequence number as current. Only after this write does the device act on the message.

  6. Retire. K4K_4 is deactivated: it no longer protects new data. When the overlap period ends, both sides destroy K4K_4 by overwriting every stored copy.

Worked example

When to rotate. GCM (Galois/Counter Mode §15.5), an authenticated encryption §5.16 mode specified in NIST SP 800-38D [319], limits one key to 232=4,294,967,2962^{32} = 4{,}294{,}967{,}296 encryptions whenever the per-message values it needs, called initialization vectors, are generated at random (SP 800-38D, Section 8.3). A device that encrypts 1,000 messages per second reaches that limit after 4,294,967,296/1,000≈4,294,9674{,}294{,}967{,}296 / 1{,}000 \approx 4{,}294{,}967 seconds, which is 4,294,967/86,400≈49.74{,}294{,}967 / 86{,}400 \approx 49.7 days, so it must change its key at least every seven weeks for this reason alone. At 10 messages per second the limit is about 4,971 days away, roughly 13.6 years, and other factors on the SP 800-57 list, such as the risk that the key is exposed, decide the cryptoperiod.

A reset at each stage. The device stores keys in two slots, A and B, plus the selector. Slot A holds epoch 4 and K4K_4, and the selector names epoch 4. Rotation to epoch 5 is in progress, and the device resets at one of four points.

In every case the device restarts with a key that the server can still use, and no partly written key ever becomes active.

Stated precisely

Let aa be the epoch of the device’s active key, and pp the epoch of its pending key, if there is one. A rotation procedure is correct when four conditions hold after every message, every failure and every restart.

  1. Validity. Every stored record is either complete and passes its integrity check, or is detected as incomplete and ignored. Only a valid record can become pending or active.

  2. Reachability. At every moment the device accepts at least one key that the server may be using: the active key KaK_a, and the pending key KpK_p if one exists.

  3. Ordered activation. The device sets a=pa = p only after evidence that the server holds KpK_p, such as a server message that verifies under KpK_p. The server stops accepting the old key only after evidence that the device has activated the new one, such as a device message protected with it, unless it deliberately gives up reachability, as after a suspected compromise of the old key.

  4. Increasing epochs. The device accepts a delivery only for epoch a+1a + 1, and aa never decreases, so a recorded old delivery cannot reinstall a retired key.

The conditions rest on four named assumptions: the selector write is atomic, so a reset leaves the old or the new value; the integrity check detects every incomplete record; K5K_5 is generated independently of K4K_4; and the key that protects the delivery is unknown to the attacker.

SP 800-57 describes the overlap with two periods of a symmetric key: the originator-usage period, during which protection may be applied with the key, and the recipient-usage period, during which data protected with it may still be processed. It allows the recipient-usage period to extend beyond the originator-usage period, which is what the overlap does for K4K_4.

Limits and common mistakes

Rotation does not by itself recover from a compromise. If K5K_5 is delivered encrypted under K4K_4, an attacker who knows K4K_4 and recorded the delivery decrypts K5K_5 as well. Recovery needs a new key that the attacker cannot compute from what it holds, for example one delivered under a separate key that was not compromised; the post-compromise security §5.34 entry treats this.

Key update, which SP 800-57 defines as computing the new key from the old one, has the same weakness by construction: an attacker who obtains one key in the chain and knows the update process can compute every later key. SP 800-57 names this exposure and states that United States federal applications shall not use key update.

The overlap is a trade-off. While K4K_4 is accepted, anyone who stole K4K_4 is accepted too. Bound the overlap by time or by message count, and after a suspected compromise of the old key end it at once, accepting that a device that missed the rotation must then be recovered by another route.

Rotation does not re-protect data stored under the old key. SP 800-57 notes that if the protected data must stay secure for longer than the cryptoperiod, the protection may need to be reapplied with a new key.

More frequent rotation is not always safer. SP 800-57 observes that where keys are distributed by hand, more frequent key changes can increase the risk of exposure.

Rotation is not revocation. Key revocation §5.32 tells other parties that a key must no longer be trusted; rotating the key does not tell them. Destroying the old key means overwriting every copy, including backups and copies in working memory, as the secret zeroization §5.37 entry explains.

Questions answered

What happens if reset occurs between staging and activation?

In a correctly designed rotation, a reset between staging and activation loses nothing: the device restarts with the old key still active, and with the new key either kept as pending, if its stored record is complete and passes its integrity check, or discarded, if the write was cut off. Staging means that the new key has been delivered and stored but is not yet in use; activation means that the device switches to it. After the restart the device keeps accepting the old key and, if a pending key exists, treats the first message that verifies under the new key as the signal to activate it. The server repeats the delivery if it never received the device’s confirmation, or continues with the new key, which the device can still verify. Neither side is locked out, and the old key is destroyed only after the new one has worked on both sides.

A naive design fails at the same moment. If the device overwrites the old key in place, a reset can leave a half-written key and no usable key. If it activates the new key and discards the old one as soon as the new one is written, a reset before the server learns of the switch leaves the device rejecting the server’s messages under the old key. If it discards pending keys at restart after the server has already switched, the two sides hold different keys. Each failure leaves the device unreachable until it is recovered by another route.

Related entries: Post-compromise security (§5.34), Key confirmation versus application confirmation (§5.42), Failure atomicity (§8.5), Staging versus commit versus activation (§8.22), Commit record and selector (§8.21), Torn write (§8.19), Proof of possession (§5.30), Key revocation (§5.32), Secret zeroization (§5.37), Idempotency (§8.31). Further reading: [147, 319].