HKDF
Extract-and-expand key derivation (RFC 5869) over every fixed-output hash.
from oxcrypto.kdf.hkdf import HKDF
algorithm = HKDF.SHA256
key = algorithm.derive(shared_secret, salt=salt, info=b"context", length=32)
prk = algorithm.extract(shared_secret, salt=salt)
key = algorithm.expand(prk, info=b"context", length=32)extract returns a pseudorandom key of the hash output size. When salt is
omitted it is HashLen zero bytes, as RFC 5869 specifies. expand requires
a prk of at least the hash output size and returns length bytes, from 0 up
to 255 times the hash output size. derive runs both steps.
Every selector of oxcrypto.hash with a fixed output size is available, from
HKDF.SHA256 and HKDF.SHA3_256 to HKDF.STREEBOG512 and HKDF.BLAKE3.
Prefer SHA-2 or SHA-3 for interoperability. MD2, MD4, MD5 and SHA-1 exist only
for legacy protocols.
| Standard | RFC 5869 (Informational), approved for key derivation in NIST SP 800-56C Rev. 2 |
| Crate | hkdf 0.13.0 with hmac 0.13.0 |
| Maturity | Stable release, no published audit |
| MSRV | Rust 1.85, builds with the project MSRV 1.88 |
| Experimental | No. HMAC over hashes other than SHA-1, SHA-2 and SHA-3 is not covered by NIST approval. |
| Zeroization | hkdf keeps the previous T(i) blocks, and hmac keeps the padded key block and the inner hash, without wiping them. |