EVP_KDF-HKDF(7ossl)
π NAME π
ok so bestie, gather round: EVP_KDF-HKDF is the HKDF EVP_KDF implementation β literally the whole manual page for it, from the OpenSSL manual set (that's 7ossl for the section, iykyk). π
β¨ DESCRIPTION β¨
So this is all about computing the HKDF KDF through the EVP_KDF API. π¦
The EVP_KDF-HKDF algorithm implements the HKDF key derivation function. HKDF follows the "extract-then-expand" paradigm, and the way that works is the KDF logically consists of two modules:
- The first stage takes the input keying material and "extracts" from it a fixed-length pseudorandom key
K. - The second stage "expands" the key
Kinto several additional pseudorandom keys (the output of the KDF).
The output is considered to be keying material. periodt. π
πΈ Identity πΈ
"HKDF" is the name for this implementation β that's the icon, that's the name, no cap. You can use it with the EVP_KDF_fetch() function. β
π«Ά Supported parameters π«Ά
The supported parameters are, and honestly? iconic lineup:
"properties"(OSSL_KDF_PARAM_PROPERTIES)<UTF8 string>"digest"(OSSL_KDF_PARAM_DIGEST)<UTF8 string>"key"(OSSL_KDF_PARAM_KEY)<octet string>"salt"(OSSL_KDF_PARAM_SALT)<octet string>
These parameters work as described in "PARAMETERS" in EVP_KDF(3). π
"info"(OSSL_KDF_PARAM_INFO)<octet string>β this parameter sets the info value. The length of the context info buffer cannot exceed 1024 bytes; this should be more than enough for any normal use of HKDF. (like 1024 is already so much, don't be greedy babe π)"mode"(OSSL_KDF_PARAM_MODE)<UTF8 string>or<integer>β this parameter sets the mode for the HKDF operation. There are three modes that are currently defined:"EXTRACT_AND_EXPAND"orEVP_KDF_HKDF_MODE_EXTRACT_AND_EXPANDβ this is the default mode. CallingEVP_KDF_derive(3)on anEVP_KDF_CTXset up for HKDF will perform an extract followed by an expand operation in one go. The derived key returned will be the result after the expand operation. The intermediate fixed-length pseudorandom keyKis not returned. In this mode the digest, key, salt and info values must be set before a key is derived otherwise an error will occur. β οΈ"EXTRACT_ONLY"orEVP_KDF_HKDF_MODE_EXTRACT_ONLYβ in this mode callingEVP_KDF_derive(3)will just perform the extract operation. The value returned will be the intermediate fixed-length pseudorandom keyK. Thekeylenparameter must match the size ofK, which can be looked up by callingEVP_KDF_CTX_get_kdf_size()after setting the mode and digest. The digest, key and salt values must be set before a key is derived otherwise an error will occur. β οΈ"EXPAND_ONLY"orEVP_KDF_HKDF_MODE_EXPAND_ONLYβ in this mode callingEVP_KDF_derive(3)will just perform the expand operation. The input key should be set to the intermediate fixed-length pseudorandom keyKreturned from a previous extract operation. The digest, key and info values must be set before a key is derived otherwise an error will occur. β οΈ
The OpenSSL FIPS provider also supports the following parameters, bestie, pay attention π§:
"fips-indicator"(OSSL_KDF_PARAM_FIPS_APPROVED_INDICATOR)<integer>β a getter that returns1if the operation is FIPS approved, or0otherwise. This may be used after callingEVP_KDF_derive. It returns0if"key-check"is set to0and the check fails."key-check"(OSSL_KDF_PARAM_FIPS_KEY_CHECK)<integer>β the default value of1causes an error duringEVP_KDF_CTX_set_params()if the length of used key-derivation key (OSSL_KDF_PARAM_KEY) is shorter than 112 bits. Setting this to zero will ignore the error and set the approved"fips-indicator"to0. This option breaks FIPS compliance if it causes the approved"fips-indicator"to return0. π«£
π NOTES π
A context for HKDF can be obtained by calling β look at her go:
EVP_KDF *kdf = EVP_KDF_fetch(NULL, "HKDF", NULL);
EVP_KDF_CTX *kctx = EVP_KDF_CTX_new(kdf);
The output length of an HKDF expand operation is specified via the keylen parameter to the EVP_KDF_derive(3) function. When using EVP_KDF_HKDF_MODE_EXTRACT_ONLY the keylen parameter must equal the size of the intermediate fixed-length pseudorandom key otherwise an error will occur. For that mode, the fixed output size can be looked up by calling EVP_KDF_CTX_get_kdf_size() after setting the mode and digest on the EVP_KDF_CTX. π
π EXAMPLES π
This example derives 10 bytes using SHA-256 with the secret key "secret", salt value "salt" and info value "label" β main character example fr fr:
EVP_KDF *kdf;
EVP_KDF_CTX *kctx;
unsigned char out[10];
OSSL_PARAM params[5], *p = params;
kdf = EVP_KDF_fetch(NULL, "HKDF", NULL);
kctx = EVP_KDF_CTX_new(kdf);
EVP_KDF_free(kdf);
*p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_DIGEST,
SN_sha256, strlen(SN_sha256));
*p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_KEY,
"secret", (size_t)6);
*p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_INFO,
"label", (size_t)5);
*p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SALT,
"salt", (size_t)4);
*p = OSSL_PARAM_construct_end();
if (EVP_KDF_derive(kctx, out, sizeof(out), params) <= 0) {
error("EVP_KDF_derive");
}
EVP_KDF_CTX_free(kctx);
she ate that ngl π
π CONFORMING TO π
RFC 5869 β yes, we stan a standards-compliant queen. β
π¦ SEE ALSO π¦
EVP_KDF(3), EVP_KDF_CTX_new(3), EVP_KDF_CTX_free(3), EVP_KDF_CTX_get_kdf_size(3), EVP_KDF_CTX_set_params(3), EVP_KDF_derive(3), "PARAMETERS" in EVP_KDF(3), EVP_KDF-TLS13_KDF(7)
like go read them, they're all besties of this page π«Ά
π HISTORY π
This functionality was added in OpenSSL 3.0. vintage but still slaying π
πΈ COPYRIGHT πΈ
Copyright 2016-2024 The OpenSSL Project Authors. All Rights Reserved.
Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.
ok that's the whole thing bestie, ily, go derive some keys responsibly πβ¨ β signed, sealed, delivered from page version 3.5.6, dated 2026-04-07, in the EVP_KDF-HKDF(7ossl) era ππ
π¦ where this page comes from
- freebsd 15.1: base 15.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms