Section 20.14

Tree 14: “How are good keys generated and provisioned?”

Setting

A sensor gateway is a small device that collects readings from sensors and passes them on. In this invented example a factory builds many gateways. A publisher, the one party authorized to change a gateway’s policy, later sends each gateway policy updates through a phone that only carries the bytes. Before a gateway ships, it needs two secrets:

A technician proposes two shortcuts. First, compute each gateway’s KaK_a as the SHA-256 §5.2 digest of the gateway’s serial number followed by the second at which the gateway left the production line. SHA-256 (Secure Hash Algorithm with a 256-bit output) turns any input into a 32-byte value called a digest. The serial number is printed on the gateway’s label, and every gateway of a batch leaves the line within one known hour. Second, seed the random number generator once on a workstation and copy the resulting generator state into every gateway’s firmware, the software stored on the gateway. An engineer proposes a third design: compute every gateway’s KaK_a from one secret root key §5.25 RR and the gateway’s public device ID.

The guiding question is what the attacker does not know. The number of bytes in a printed key answers a different question.

Short answer

Good keys come from a cryptographically secure random generator seeded with enough unpredictable input, run inside the device or in protected equipment. Provisioning then installs each key, bound to one device and one purpose, over a protected path, and records who holds copies. A key’s strength is the number of guesses an attacker needs, not its length: a 32-byte digest of a public serial number and a second within a known hour has only 60×60=360060 \times 60 = 3600 possible values.

Follow-up questions

Start with entropy §5.26

Start by counting what the attacker cannot predict, because a key is never harder to guess than the inputs it was computed from, whatever its length. Entropy measures that unpredictability in bits. If the attacker can narrow the possible inputs to NN equally likely candidates, the input has log2N\log_2 N bits of entropy, and each extra bit doubles the number of candidates.

Apply this to a key computed as the SHA-256 (Secure Hash Algorithm with a 256-bit output) digest of a gateway’s serial number followed by the second at which the gateway left the production line. The serial number is printed on the label, so it adds nothing secret. The exit time lies within one known hour, so there are 60×60=360060 \times 60 = 3600 candidates and log23600≈11.8\log_2 3600 \approx 11.8 bits of entropy. The digest is 32×8=25632 \times 8 = 256 bits long, but there are at most 3600 different digests, one per candidate time. An attacker who has recorded one tagged update computes the 3600 candidate keys and tests each against the tag, which takes a laptop a small fraction of a second. Hashing cannot add candidates. If two candidates happen to give the same digest, the number of distinct keys only falls. With 4 equally likely seeds, the same reasoning gives log24=2\log_2 4 = 2 bits and at most 4 keys.

When the candidates are not equally likely, the measure that matters for guessing is min-entropy: H∞=−log2pmax,H_\infty = -\log_2 p_{\max}, where pmaxp_{\max} is the probability of the most likely candidate. Take four candidates with probabilities 1/21/2, 1/41/4, 1/81/8 and 1/81/8. Then pmax=1/2p_{\max} = 1/2 and H∞=−log2(1/2)=1H_\infty = -\log_2 (1/2) = 1 bit: the attacker’s first guess is right half the time. Shannon entropy, −∑ipilog2pi-\sum_i p_i \log_2 p_i, where pip_i is the probability of candidate ii, is the average uncertainty. Here it is (1/2)(1)+(1/4)(2)+2(1/8)(3)=0.5+0.5+0.75=1.75(1/2)(1) + (1/4)(2) + 2(1/8)(3) = 0.5 + 0.5 + 0.75 = 1.75 bits, which overstates how hard the first guess is.

For the attacker’s best single guess to succeed with probability at most 2−1282^{-128}, the key must come from a source with at least 128 bits of min-entropy. On a gateway, that unpredictability comes from a physical noise source on the chip, a circuit that samples electrical noise. A cryptographically secure pseudorandom number generator §5.27 then turns it into keys.

What does a CSPRNG supply?

A CSPRNG (cryptographically secure pseudorandom number generator) supplies as many output bytes as requested, which nobody without its internal state can predict or tell apart from random bytes; it does not supply new unpredictability. It is a deterministic algorithm §14.1. It starts from a seed, input taken from an entropy source such as a noise circuit, and keeps a secret internal state. Each request returns bytes computed from the state and then updates the state.

NIST Special Publication (SP) 800-90A, the recommendation of the United States standards agency for such generators, calls such a generator a DRBG (deterministic random bit generator) [305]. It defines three designs, built on a hash function, on HMAC §5.8 (hash-based message authentication code) and on a block cipher §15.3. It requires the seed to carry at least as much entropy as the security strength that the generator claims, for example at least 128 bits for a strength of 128 bits.

If the seed had that much min-entropy and the state stays secret, the outputs are computationally unpredictable: no feasible computation predicts the next output from all earlier outputs. Two further properties concern an attacker who reads the state at some moment.

A CSPRNG cannot create entropy: an attacker who can guess the seed computes every output. The technician’s second proposal copies one generator state into every gateway. Given the same state and the same inputs, the algorithm returns the same bytes, so gateway 1 and gateway 2 generate identical keys, and anyone who reads the state from one gateway, or from the workstation, predicts the keys of all of them. The same repetition occurs without copying when a device goes back to an earlier saved state, for example by restoring a backup: the generator then gives again outputs it gave before. A generator that produces keys at start-up, before its noise source has delivered enough entropy, gives guessable keys.

The repair is to seed each gateway from its own noise source, never to ship or restore a saved generator state, to reseed from time to time, and to make the generator refuse output until it has been seeded.

What is provisioning?

Provisioning is the process that gives a device its identity and its first secrets and records both with the parties that will rely on them; it is also called enrollment §5.28. In this setting a factory provisions sensor gateways. Each needs KaK_a, the active message-authentication key that it shares with the publisher of its policy updates, and KrK_r, a separate recovery credential that authorizes a replacement for KaK_a. Provisioning a gateway takes these steps:

  1. Identify the device. Establish that the unit receiving the keys is a genuine gateway and is the unit that the records will name: for example, it sits in a controlled station on the production line, or it proves that it holds a key installed by the chip maker.

  2. Generate the secrets. Generate each key with a cryptographically secure generator seeded with enough entropy, either inside the gateway, so that the key never travels, or inside a hardware security module (HSM), a tamper-resistant device built to generate, store and use keys inside its own protected hardware.

  3. Transfer over a protected path. A key that must travel, such as the publisher’s copy of KaK_a, is encrypted and authenticated from end to end, and no tool on the way writes it to a log.

  4. Record the binding. The publisher records which device ID holds which key, for which role (KaK_a for policy updates, KrK_r for recovery), and the generation number gg, a counter of key replacements that starts at 1 for the first KaK_a and increases by 1 at each replacement.

  5. Decide who keeps copies. The publisher must hold KaK_a to compute tags, so one copy lives outside the gateway, in protected storage. KrK_r is kept offline, apart from KaK_a. Nobody else, such as the technician’s workstation, keeps a copy.

  6. Lock the device. Close the debug port, or turn on readout protection §16.5, a chip setting that blocks reading the chip’s memory through the debug port, so that the keys cannot be read back out.

  7. Handle failure. A unit whose provisioning stops halfway is either completed with freshly generated keys or erased and marked unprovisioned. Keys that may have been exposed in the failed attempt are not reused.

A cable is a transport, not a security property. Writing KaK_a over a cable from a workstation proves that the bytes arrived. It does not prove that nobody else read them, on the workstation, in its logs or on the cable; that the intended gateway received them; or that the publisher’s records match the gateway.

Does per-device derivation isolate every compromise?

No: deriving each gateway’s key from a shared root key isolates the leak of one gateway’s key, but a leak of the root exposes every gateway, because the device-specific inputs are public. Per-device key derivation §5.24 computes each device’s key from a root key and the device’s identity with a key derivation function §5.20 (KDF), an algorithm that turns one secret into keys for stated purposes. In this setting a publisher sends tagged policy updates to sensor gateways, and each gateway needs its own message-authentication key. With root key RR and public device IDs, gateway 1 gets K1=KDF(R,𝚙𝚘𝚕𝚒𝚌𝚢‖ID1)K_1 = \mathrm{KDF}(R, \texttt{policy} \mathbin{\Vert} \mathrm{ID}_1) and gateway 2 gets K2=KDF(R,𝚙𝚘𝚕𝚒𝚌𝚢‖ID2)K_2 = \mathrm{KDF}(R, \texttt{policy} \mathbin{\Vert} \mathrm{ID}_2), where ID1\mathrm{ID}_1 and ID2\mathrm{ID}_2 are the device IDs and ‖\Vert joins byte strings. Only the publisher holds RR; each gateway receives only its own key.

A device ID separates contexts: different IDs give different keys. It adds no secret, because the attacker knows it. The damage of a root leak is limited by keeping RR only in protected equipment such as a hardware security module (HSM), a tamper-resistant device built to store and use keys inside its own protected hardware; by using a separate root for each batch or region; or by giving each gateway an independent random key with no root at all, at the cost of a table of keys at the publisher.

What if the firmware image contains roots?

If the firmware image contains a secret root key, anyone who obtains the image holds that root, and every key derived from it must be treated as compromised. The firmware image is the software file installed on every gateway. It is identical on every unit and is copied to update servers, build machines and workstations. An attacker can obtain it from any of these, or by reading the flash memory §6.6 of one gateway whose readout protection is off. Hiding the root inside the image by obfuscation only delays an analyst.

In this setting each sensor gateway’s active message-authentication key KaK_a, the key that authenticates policy updates from the publisher, is derived from a root key RR and the gateway’s public device ID. With RR taken from the image, the attacker computes every gateway’s KaK_a and forges policy updates that every gateway accepts. New public labels in the derivation do not help, since the attacker can read them too. Nor does a firmware update that installs a new root, if that update is itself authenticated with keys derived from RR: the attacker can forge such an update, and can read the new root from the new image.

Recovery needs a trust path outside the compromise. Suppose each gateway also holds a recovery credential KrK_r, generated at random for that gateway alone at provisioning, stored only in the gateway’s protected storage and in the publisher’s offline storage, never in the image and never derived from RR. The publisher can then use KrK_r to authorize freshly generated replacement keys. If KrK_r was also derived from RR, or stored in the image, no remote recovery exists, and each gateway must be provisioned again by hand.

Public roots are a different matter. A public key that the gateway uses only to verify signatures may sit in the image; signature-based secure boot §6.31 uses that public key to verify firmware before running it. Anyone can have the verification key. By contrast, anyone who obtains an image containing a secret root can use that root. Distributing such an image therefore distributes the secret to every recipient.

Related entries: HKDF (§5.21), Per-device key derivation (§5.24), Root key and root seed (§5.25), Entropy and min-entropy (§5.26), CSPRNG (§5.27), Key provisioning (§5.28), Readout protection (§16.5), Secure boot (§6.31), Secure element (§5.38), Pseudorandom function (PRF) (§15.1). Further reading: [148, 305].