HKDF (HMAC-based Key Derivation Function, defined in RFC 5869) expands a single master key into multiple cryptographically independent derived keys.
\[\text{HKDF}(salt, IKM, info, L) = \text{Expand}(\text{Extract}(salt, IKM), info, L)\]
where \(IKM\) is input keying material, \(info\) is a context string, and \(L\) is the desired output length in bytes.
Working through an example:
Given: 32-byte master key provisioned during manufacturing, derive 3 session keys for encryption, signing, and authentication.
Step 1: Extract phase (create pseudorandom key) \[PRK = \text{HMAC-SHA256}(salt, IKM)\]
- \(IKM\): 32-byte master key
- \(salt\): 16-byte random value (or all-zero if no salt available)
- \(PRK\): 32-byte pseudorandom key
Step 2: Expand phase (derive multiple keys) \[K_1 = \text{HMAC-SHA256}(PRK, info_1 \,||\, 0x01)\] \[K_2 = \text{HMAC-SHA256}(PRK, K_1 \,||\, info_2 \,||\, 0x02)\] \[K_3 = \text{HMAC-SHA256}(PRK, K_2 \,||\, info_3 \,||\, 0x03)\]
Step 3: Apply to IoT scenario - \(info_1\) = “session_encryption_key” - \(info_2\) = “session_signing_key” - \(info_3\) = “session_auth_key”
Result: One 32-byte master key generates unlimited derived keys. Compromising \(K_1\) (encryption key) does not expose \(K_2\) (signing) or \(K_3\) (auth) due to HMAC’s one-way property.
In practice: Provision one master key per device during manufacturing. Derive session-specific keys at runtime using HKDF. No need to store derived keys – regenerate deterministically on each boot. This limits flash wear and reduces the key extraction attack surface.