K063 / Hashes, MACs and key derivation
HKDF
HKDF is a KDF that derives one or more cryptographically strong secret keys from initial keying material.
CRYPTOGRAPHY LAB / K063
Cryptography Lab · HKDF
Run real computations and inspect intermediate states step by step.
Educational only. Never enter real passwords or secret keys. Computation stays in your browser; input and trace values are not sent to a server. Do not use this implementation in production.
HKDF-SHA-256 (32 B)
See the scope above for fixed examples, reduced parameters and supported variants. Standard operation names and formulas are retained.Output
Previous state
- Definition and overview
- HKDF is a KDF that derives one or more cryptographically strong secret keys from initial keying material. Source document ↗
- Classification and reversibility
- KDF rather than encryption or encoding; source excerpt gives no decryption/decoding procedure. Source document ↗
- Key or secret requirements
- Secret IKM, optional salt and context string info separating derived keys. Source document ↗
- Operating principle and structure
- Two stages: HMAC Extract produces PRK; Expand takes info and length to produce OKM. Source document ↗
- Key size, block size and parameters
- Output limited to 255 times the hash-length unit described in source; truncate to requested L. Source document ↗
- Security strength and recommendation
- RFC 5869 remains the HKDF specification. Source document ↗
- Known attacks and vulnerabilities
- Insufficient transcript/context binding relates to attacks such as Triple Handshake; bind info/context. Source document ↗
- Standards and certification
- IETF RFC 5869 HMAC-based KDF; HKDF-SHA256 specified for CMS content-key derivation. Source document ↗
- Typical uses
- IKEv2/PANA/EAP-AKA, CMS content keys and purpose-specific key separation from master secret. Source document ↗
- Implementations, libraries and tools
- Go crypto/hkdf, RustCrypto hkdf, libsodium and WebCrypto deriveKey. Source document ↗
- Decryption or decoding
- No decryption/decoding; recompute with identical IKM/salt/info/length to rederive OKM. Source document ↗
- Advantages
- One PRK derives multiple purpose-specific keys by varying info; simple and fast HMAC construction. Source document ↗
- Limitations and cautions
- Suitable for already-random secrets; passwords need Argon2 or similar. Mind context binding and length limit. Source document ↗
- Distinguishing encryption, encoding and hashing
- HMAC-based KDF, not encryption, encoding or simple hash; no ciphertext or decoded output. Source document ↗
Practical examples
Example
Input master secret, salt, info and desired length to derive purpose-specific keys. Same inputs/info reproduce key; different info yields different keys.
Procedure
Choose IKM/salt/info/length, Extract PRK, Expand OKM, use OKM as symmetric key. Cannot reverse HKDF output; rederive with same inputs/info then decrypt through actual cipher.
Scenario
Separate shared secret into session/direction/purpose keys in protocol key schedules; derive separate AES/ChaCha keys for databases, tokens and storage from one master key.
Pitfalls and alternatives
Do not use HKDF alone for low-entropy passwords; use Argon2. Bind purpose/session context in info, respect output limit and manage salt/info. Distinguish from encryption, hashing and encoding; no decryption API.
References
- RFC 5869: HMAC-based Extract-and-Expand Key Derivation Function (HKDF) | RFC Editor ↗
- HKDF | The Sodium crypto library (libsodium) ↗
- hkdf - Rust ↗
- RFC 6234 - US Secure Hash Algorithms (SHA and SHA-based HMAC and HKDF) ↗
- HKDF vs PBKDF2: SP 800-108 Comments Due Dec. 18 [2026] ↗
- One Secret Is Not One Key: The Discipline of Key Derivation with HKDF ↗
- hkdf package - crypto/hkdf - Go Packages ↗
- Derive keys - unsecure ↗