HKDF key derivation
[OpenSSL Home][Home]
HKDF (HMAC Key Derivation function) is used to derive an encryption key from a pass phrase. Initially HKDF creates a pseudorandom key (PRK) using a pass phrase and a salt value (and any other random functions which are relavent), in order to produce an HMAC hash function (such as HMAC-SHA256), andalong with a salt value. Next the PRK output is used to produce a key of the required length. If we generate a 16-byte output (32 hex characters), we have a 128-bit key, and a 32-byte output (64 hex characters) will generate a 256-bit key. HKDF is used in TLS 1.3 for generating encryption keys.
|
Outline
HMAC Key Derivation function (HKDF) is used to derive an encryption key from a passphrase. Initially, HKDF creates a pseudorandom key (PRK) using a passphrase and a salt value (and any other random functions which are relavent), in order to produce an HMAC hash function (such as HMAC-SHA256), and along with a salt value. Next, the PRK output is used to produce a key of the required length. If we generate a 16-byte output (32 hex characters), we have a 128-bit key, and a 32-byte output (64 hex characters) will generate a 256-bit key. HKDF is used in TLS 1.3 for generating encryption keys [RFC 5869][article]. In this case, we will use SHA-256.
The following shows how an encryption key can be generated using HKDF, and where we need a secret and a salt value. Both Bob and Alice have the same secret and salt.
Sample run
For example:
Command: openssl kdf -keylen 32 -kdfopt digest:NaCl -kdfopt key:Hello -kdfopt salt:sha512-256 HKDF Password: Hello KDF: HKDF Salt: NaCl Hash: sha512-256 Digest size: 32 ------------- 32:43:D9:1D:D6:C3:3B:F0:9B:11:43:E2:49:F1:99:74:2F:3F:48:28:FA:14:C6:40:65:07:E2:F2:85:E2:A6:71