Key derivation

HKDF-Expand

HMAC-based extract-and-expand key derivation function (RFC 5869)

standard Safe API Specified in a FIPS standard

About HKDF-Expand

HKDF-Expand is one of 4 HKDF variants in the NextSSL registry, a key derivation function. It uses a 28–268,435,456-byte key and a 1–16,320-byte output. It takes the parameter hash (default sha256). Its registry entry cites RFC 5869 and NIST SP 800-56C. NextSSL lists it in the standard tier and exposes it through the safe API.

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–2020
  1. Krawczyk's HKDF paper at CRYPTO; specified in RFC 5869

  2. Specified in NIST SP 800-56C

How it works

  1. Extract: PRK = HMAC(salt, IKM), with a zero-filled salt if none is given.
  2. Expand: T(1) = HMAC(PRK, info || 0x01), T(i) = HMAC(PRK, T(i-1) || info || i).
  3. Output the first L bytes of T(1) || T(2) || ...
  4. 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

Key schedules in TLS 1.3, QUIC and HPKEDeriving encryption and MAC keys from ECDH or ML-KEM secretsDomain-separated sub-keys from a master key

Sizes

FieldBytesMeaning
key28 – 268,435,456Secret key
out1 – 16,320Output
salt0Salt

Parameters

NameTypeRangeDefaultRequired
hash enum 0 – sha256 no

Parameters are passed as a string, for example nextssl_mac("hmac", "hash=sha512", …). Omitted parameters take their declared default.

Use it

from nextssl_demo import NextSSL

ns = NextSSL()              # safe API: safe and standard tiers
okm = ns.call("kdf", "hkdf-expand", None, ikm, salt, b"context", 32)[0]

Calls follow the NextSSL C ABI and its language bindings. Buffer sizes are validated against the sizes above.

Other HKDF variants

3

Frequently asked questions

What is HKDF-Expand?

HKDF-Expand is a KDF in the HKDF family. HKDF derives one or more strong cryptographic keys from input keying material such as a Diffie-Hellman shared secret.

What are the HKDF-Expand sizes?

In NextSSL, HKDF-Expand uses: key 28 to 268,435,456 bytes, output 1 to 16,320 bytes.

Who designed HKDF-Expand and when?

HKDF-Expand belongs to the HKDF family, first published in 2010 by Hugo Krawczyk. Its origin: RFC 5869; NIST SP 800-56C.

Which standards define HKDF-Expand?

HKDF-Expand is referenced by RFC 5869, NIST SP 800-56C. It is specified in a FIPS standard.

Is HKDF-Expand safe to use?

HKDF-Expand is in the standard tier. Standardised and sound. Reachable from the safe API. It can be called from the safe API.

What other HKDF variants are there?

NextSSL also registers hkdf, hkdf-extract, hkdf-sha256 in the HKDF family.