Speed

Keys From the Secret

A traffic key and IV are expanded from a traffic secret by HKDF-Expand-Label; the RFC 8448 server key is 3fce516009c21727d0f2e4e86ee403bc and the recording's secrets give the keys of its records.

The question

The protected part of the handshake is encrypted with a key and an IV. Where do they come from, when the only secret that was logged is a traffic secret?

Both are expanded from the traffic secret with HKDF-Expand-Label (RFC 9846, 7.1 and 7.3): a hash-based expansion of the secret, with an info block that names what is wanted. For TLS_AES_128_GCM_SHA256 the key is 16 bytes and the IV 12 bytes. This page uses numbers that RFC 8448 publishes for the demo and the secrets of the recorded loopback connection (2026-11-20, test material, protecting nothing) for the exercise.

Work it by hand

The info block, called HkdfLabel, is three parts: the wanted length as 2 bytes, the label as one length byte and the label text, and the context as one length byte and its bytes. The label is the text tls13 followed by a name, and the context is empty here. For the name key and 16 bytes: 00 10, then 09 and tls13 key (9 bytes: 74 6c 73 31 33 20 6b 65 79), then 00. That is 13 bytes: 001009746c733133206b657900.

The output is a single HMAC when at most 32 bytes are wanted: HMAC-SHA-256 under the secret of the info followed by the byte 01, cut to the wanted length. The length byte 09 counts tls13 key, six bytes of prefix and three of name.

Run it

The command asks OpenSSL's key derivation HKDF in its expand-only mode, with SHA-256, for 16 bytes. The secret is the server handshake traffic secret of RFC 8448, section 3, and the info is the block above; the result is written to out.bin and the page shows its bytes.

The first 16 bytes of the published secret b6 7b 7d 69 and the 16-byte key the command writes, starting 3f ce 51 60.

Public test material, generated for this lesson. Never use it for anything real.

# HKDF-Expand with the RFC 8448 server handshake traffic secret (published).
# The info is the HkdfLabel for "key": length 16, label "tls13 key", empty context.
kdf -binary -keylen 16 -kdfopt digest:SHA256 -kdfopt hexkey:b67b7d690cc16c4e75e54213cb2d37b4e9c912bcded9105d42befd59d391ad38 \
  -kdfopt hexinfo:001009746c733133206b657900 -kdfopt mode:EXPAND_ONLY \
  -out out.bin HKDF
{
  "answer": "3fce516009c21727d0f2e4e86ee403bc",
  "file": "out.bin",
  "bytes": 16
}

RFC 8448 publishes the same key as 3fce516009c21727d0f2e4e86ee403bc; the command reproduces it. With 12 bytes and the info 000c08746c73313320697600 (label tls13 iv) the same secret gives the published IV 5d313eb2671276ee13000b30. You can change the numbers on the command line. A secret with a character that is not a hex digit makes OpenSSL refuse the command with a message ending "illegal hex digit", and an info of an odd number of digits ends with "odd number of digits" (both as the page shows them).

Your turn

A reader wants a key, an IV or a finished key from one of the logged secrets of the recorded connection, without the kdf command. The program below is meant to return the HKDF-Expand-Label output as hex for the secret in secret, the label name in label and the length in bytes in length (at most 32). Decide whether it does, and find the candidates that do. Check runs each candidate on the data shown and on four others. All secrets are test material from one finished loopback connection.

The first 16 bytes of a traffic secret, the label key and the length 16.

Public test material, generated for this lesson. Never use it for anything real.

let full = "tls13 " + label;
let info = u16_hex(length) + u8_hex(str_len(full)) + ssl.hex(full) + "00";
let block = ssl.hmac("SHA256", ssl.unhex(secret), ssl.unhex(info + ""));
let answer = hex_slice(block, 0, length);
{
  "answer": "e9f9af6b28e961ad157096e2cc32cf4d"
}

Return the output of HKDF-Expand-Label (RFC 9846, 7.1) as hex for the traffic secret in secret, the label name in label (without the tls13 prefix) and length bytes, with an empty context. The length is at most 32.

Read the result carefully

The early steps of the schedule are not run here. The recording logged the traffic secrets and not the ephemeral private keys, so its shared secret and the early and handshake secrets cannot be recomputed from it. The RFC 8448 trace is a published example of those steps: its early secret begins 33ad0a1c607ec03b and its handshake secret 1dc826e93606aa6f (stated here, not run).

The label names a purpose: key, iv and finished give three unrelated values from one secret. A page that shows a key shows test material; no real connection's secret is printed here.

Recap

  • A traffic key and IV come from the traffic secret by HKDF-Expand-Label.
  • The info block is the length (2 bytes), the label tls13 plus a name with its length byte, and an empty context byte.
  • For one block of output the expansion is a single HMAC under the traffic secret.
  • This suite needs 16 bytes of key and 12 of IV; the recording's secrets are test material.