Section 5.24

Per-device key derivation

Definition

Per-device key derivation is a method that gives every device in a group its own secret key by computing that key from one secret key, called the master key, and the device’s identifier. A key derivation function §5.20, an algorithm §14.1 that turns a secret key and public inputs into new keys, takes the master key and an encoding of the identifier and returns the device key. Each device stores only its own key. Whoever holds the master key can compute every device key from the device’s identifier.

The idea

A company makes 10,000 devices. Each must prove to the company’s server that a message came from that particular device, using a message authentication code §5.7, an algorithm that computes a short tag from a secret key and a message. The keys can be arranged in three ways.

The third arrangement combines the isolation of independent keys with the storage cost of a single key. The price is concentration: the master key stands behind every device key, so its disclosure exposes all of them at once. The chip maker NXP describes the technique for smart cards under the name key diversification: deriving keys from a master key using some unique input, so that if one key is broken, the damage is limited to that key on that card rather than the whole system.

How it works

The parties and values are these.

The keys are made and used in four steps.

  1. The authority generates KMK_M once and keeps it. KMK_M never leaves the authority.

  2. At manufacture, the authority computes KIDK_{\mathrm{ID}} from KMK_M, the label and the device’s identifier, and the factory installs KIDK_{\mathrm{ID}} in the device’s protected storage. This installation is key provisioning §5.28.

  3. In use, the device sends its identifier in the clear, together with a message and the message’s tag computed with KIDK_{\mathrm{ID}}.

  4. The server recomputes KIDK_{\mathrm{ID}} from the received identifier and checks the tag. A correct tag shows that the sender holds the key of that identifier, so the server treats the message as coming from that device and from no other.

A standard derivation function is the key derivation function in counter mode §15.5 of NIST Special Publication 800-108 [306]. Write a‖ba \mathbin{\Vert} b for the byte string aa followed by the byte string bb. The publication builds its key derivation functions from a pseudorandom function §15.1, a keyed function whose outputs look random to anyone without the key. With HMAC-SHA-256 §5.9 as that function, meaning HMAC §5.8 (hash-based message authentication code) built on the hash function SHA-256 §5.2 (Secure Hash Algorithm with a 256-bit output), each block of output is HMAC(KM,[i]‖Label‖𝟶𝚡𝟶𝟶‖Context‖[L]),\mathrm{HMAC}(K_M,\ [i] \mathbin{\Vert} \mathrm{Label} \mathbin{\Vert} \mathtt{0x00} \mathbin{\Vert} \mathrm{Context} \mathbin{\Vert} [L]), where [i][i] is the block counter, starting at 1, Label names the purpose, the byte 0x00 separates Label from Context, Context holds the information the key is bound to, here the device identifier, and [L][L] is the requested output length in bits. The blocks for i=1,2,…i = 1, 2, \dots are joined, and the first LL bits are the derived key. The application fixes how many bits encode [i][i] and [L][L]. The publication says that the Context may include the identities of the parties who derive or use the key.

Worked example

The values are invented. The master key KMK_M is the 32 bytes 0x00, 0x01, and so on up to 0x1f. The label is dev-auth, the 8 ASCII bytes 64 65 76 2d 61 75 74 68. The identifier is a 4-byte number written most significant byte first. The device key is 256 bits long, so L=256L = 256. One HMAC-SHA-256 call gives 256 bits, so one block is enough: ⌈256/256⌉=1\lceil 256 / 256 \rceil = 1, where ⌈x⌉\lceil x \rceil means xx rounded up to a whole number. The counter and the length are each written in 4 bytes: [1][1] is 00 00 00 01, and [256][256] is 00 00 01 00, because 256 is 0x100.

For device 42, which is 0x2a, the HMAC message is the counter, the label, the separator, the identifier and the length, 4+8+1+4+4=214 + 8 + 1 + 4 + 4 = 21 bytes:

00 00 00 01 64 65 76 2d 61 75 74 68 00 00 00 00 2a 00 00 01 00

The device key is

K42K_{42} = 9660e5adc795011069398e5b39df461ae368255b11a9abd0ce3b8e7f266ddd5c

For device 43, which is 0x2b, only the last byte of the identifier changes, from 2a to 2b, and the key is

K43K_{43} = 068329176cbbc4d81f98e0d7bc82f4cdf627b253a2a15fcfc8e62a8415af506c

What the numbers mean:

Stated precisely

Let KMK_M be the master key, ℓ\ell the label, E(ID)E(\mathrm{ID}) the fixed-length encoding of the identifier ID\mathrm{ID}, and FF the key derivation function. The key of device ID\mathrm{ID} is KID=F(KM,ℓ,E(ID)).K_{\mathrm{ID}} = F(K_M,\ \ell,\ E(\mathrm{ID})). Isolation statement. Take an attacker who knows the label and every identifier, has extracted the keys of any set of devices, and has seen any number of messages and tags from those devices. For every other device ID*\mathrm{ID}^{*}, that attacker still cannot tell KID*K_{\mathrm{ID}^{*}} apart from a uniformly random key.

The statement rests on four assumptions.

  1. KMK_M is uniformly random and secret: only the derivation authority holds it, and the authority never releases it.

  2. FF is built from a pseudorandom function keyed with KMK_M, as the functions of NIST Special Publication 800-108 are. A pseudorandom function is a keyed function whose outputs, to anyone without the key, cannot feasibly be told apart from random values, even after seeing its outputs on other inputs.

  3. The encoding is injective and the identifiers are unique, so no two devices share an input to FF.

  4. Each device receives only its own key.

Under these assumptions the statement follows from the definition of a pseudorandom function: the extracted keys are outputs on other inputs, and they reveal nothing about the output on the input E(ID*)E(\mathrm{ID}^{*}).

Without assumption 1 there is no isolation at all, because KIDK_{\mathrm{ID}} is a public computation on KMK_M and public values. NIST Special Publication 800-57 Part 1 says so directly: if the key-derivation key is known by an adversary, the adversary can generate any of the derived keys, so derived keys are only as secure as the key-derivation key.

Limits and common mistakes

The identifier adds no secrecy. A key computed from the identifier alone, such as a hash of the serial number, is known to anyone who knows the serial number. Only the master key makes KIDK_{\mathrm{ID}} secret.

Disclosure of the master key cannot be repaired device by device. It exposes every device key at once, including keys of devices made later, and the repair is a new master key and a new key in every device. Every backup, factory station or test system that holds KMK_M is one more place from which it can leak.

Duplicate identifiers give duplicate keys. Two devices with the same identifier receive the same key, and a cloned device carries its key along with the rest of its memory. Derivation does nothing against cloning.

Replacing one device’s key needs a new input. Deriving again with the same master key, label and identifier gives the same key, so a replacement needs, for example, a version number in the label or the Context. A replacement derived from the same master key is still exposed if the master key leaks.

The master key must be used for derivation only, as NIST Special Publication 800-108 requires of key-derivation keys in a key hierarchy. If KMK_M also computed tags over data an attacker chooses, a tag could equal a device key.

Derived keys give no forward secrecy §5.33, which is protection of earlier sessions after a long-term key, a key kept and used across many sessions, leaks. The derivation is deterministic, so if a device key encrypts data directly, an attacker who later learns that key, or the master key, can decrypt data recorded before the leak.

Questions answered

Does deriving distinct keys also isolate compromise of the shared root?

No. Deriving a distinct key for each device isolates the compromise of one device key, not the compromise of the shared root, the master key from which every device key is computed. Each device key is computed from the master key and public inputs only, a label and the device identifier, so whoever learns the master key recomputes every device key, including keys of devices made later, with one key derivation call each. NIST Special Publication 800-57 Part 1 says that keys derived from a key-derivation key are only as secure as that key.

What the distinct keys do isolate is a leak at one device. An attacker who extracts one device’s key cannot compute another device’s key, provided that the master key stays secret and the derivation function is a pseudorandom function (a keyed function whose outputs look random to anyone without the key). Limiting the damage of a root disclosure needs secrets that the root does not determine.

Related entries: Domain separation (§5.22), Root key and root seed (§5.25), Forward secrecy (§5.33), UICR (User Information Configuration Registers) (§16.1), Key derivation function (KDF) (§5.20), Key provisioning (§5.28), Pseudorandom function (PRF) (§15.1), Key separation (§5.23). Further reading: [147, 148, 306].