HKDF
HMAC-based extract-and-expand key derivation function (RFC 5869)
Overview
HKDF derives one or more strong cryptographic keys from input keying material such as a Diffie-Hellman shared secret. It is the standard KDF in TLS 1.3, HPKE, Signal, QUIC and many other protocols.
HKDF splits key derivation into two stages. Extract compresses possibly non-uniform input keying material, together with an optional salt, into a fixed-length pseudorandom key using HMAC. Expand then stretches that key into as many output bytes as needed, with an info string that binds the output to its purpose, by iterating HMAC with a counter. Separating the stages gives a clean security argument based on HMAC being a good randomness extractor and pseudorandom function.
Protocols often call Extract and Expand separately, building key schedules where one extracted secret yields many purpose-specific keys; TLS 1.3 is the prominent example. NextSSL exposes the combined function, the two stages individually (hkdf-extract, hkdf-expand) and an HKDF-SHA256 instantiation. NIST SP 800-56C allows HKDF-style two-step derivation for key agreement. The salt is optional but recommended; it need not be secret, and a fixed protocol-specific salt is acceptable.
History
2010–2020Krawczyk's HKDF paper at CRYPTO; specified in RFC 5869
Specified in NIST SP 800-56C
How it works
- Extract: PRK = HMAC(salt, IKM), with a zero-filled salt if none is given.
- Expand: T(1) = HMAC(PRK, info || 0x01), T(i) = HMAC(PRK, T(i-1) || info || i).
- Output the first L bytes of T(1) || T(2) || ...
- Use distinct info strings for each derived key.
Security notes
Well analysed and sound. HKDF is not a password hashing function: for low-entropy passwords use Argon2, scrypt or PBKDF2. Output is limited to 255 times the hash length per Expand call.
Typical uses
Variants in NextSSL
4| Algorithm | Tier | Sizes (bytes) | Standards | API |
|---|---|---|---|---|
| HKDF hkdf |
standard FIPS | key 1–268435456 · out 1–16320 | RFC 5869, NIST SP 800-56C | safe |
| HKDF-Expand hkdf-expand |
standard FIPS | key 28–268435456 · out 1–16320 · salt 0 | RFC 5869, NIST SP 800-56C | safe |
| HKDF-Extract hkdf-extract |
standard FIPS | key 1–268435456 · out 28–64 · info 0 | RFC 5869, NIST SP 800-56C | safe |
| HKDF-SHA-256 hkdf-sha256 |
standard FIPS | key 1–268435456 · out 1–8160 | RFC 5869, NIST SP 800-56C | safe |
Frequently asked questions
Which HKDF variants does NextSSL include?
NextSSL registers 4 HKDF variants: hkdf, hkdf-expand, hkdf-extract, hkdf-sha256.
Other key derivation
All 10Related
NIST SP 800-90A deterministic random bit generator built on HMAC
SHA-2The NIST Merkle–Damgård hash family behind most of today's TLS, signatures and software
Concatenation KDF (one-step KDF)NIST's single-step hash-based key derivation from a shared secret, per SP 800-56A/56C
ML-KEMNIST's primary post-quantum key encapsulation mechanism, standardised in FIPS 203
ECDH (including X25519 and X448)Elliptic-curve Diffie-Hellman key agreement on NIST curves, Curve25519 and Curve448
HMACThe standard way to build a MAC from a cryptographic hash (RFC 2104, FIPS 198-1)