EVP_KDF-HKDF(7SSL)
π EVP_KDF-HKDF β the HKDF EVP_KDF implementations π
okay bestie, gather round, because this is the EVP_KDF-HKDF(7SSL) page from the OpenSSL docs and it is lowkey a whole vibe. it's the manual for computing the HKDF key derivation function through the EVP_KDF API. stay with me, it's giving cryptography but make it cute β¨
πΈ NAME πΈ
EVP_KDF-HKDF β the HKDF EVP_KDF implementations. that's it, that's the name, periodt π
β¨ DESCRIPTION β¨
so. support for computing the HKDF KDF through the EVP_KDF API. yes, KDF inside of KDF, we love a recursive moment π«Ά
the EVP_KDF-HKDF algorithm implements the HKDF key derivation function. HKDF follows the "extract-then-expand" paradigm, where 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).
and honey, the output is considered to be keying material. that's the whole point π
π Identity π
the following algorithms are available for this implementation; they can be used with the EVP_KDF_fetch() function.
in this list, names are grouped together to signify that they are the same algorithm having multiple names. this also includes the OID in canonical decimal form (which means that they are possible to fetch if the caller has a mere OID which came out in this form after a call to OBJ_obj2txt(3)). π iykyk.
"HKDF"β theOSSL_KDF_PARAM_DIGESTparameter must be set for HKDF before it can be used."HKDF-SHA256","id-alg-hkdf-with-sha256","1.2.840.113549.1.9.16.3.28""HKDF-SHA384","id-alg-hkdf-with-sha384","1.2.840.113549.1.9.16.3.29""HKDF-SHA512","id-alg-hkdf-with-sha512","1.2.840.113549.1.9.16.3.30"β HKDF-SHA256, HKDF-SHA384 and HKDF-SHA512 are fixed-digest versions of HKDF with the appropriate digest already configured.EVP_KDF_CTX_reset(3)will not reset the context's digest for fixed-digest versions.
(the last three bullets are all one big glow-up group in the original, so yes, the digest explanation covers all three of them. no gatekeeping here.)
π¦ Supported parameters π¦
the supported parameters are:
"properties"(OSSL_KDF_PARAM_PROPERTIES)<UTF8 string>"digest"(OSSL_KDF_PARAM_DIGEST)<UTF8 string>β attempting to set the digest on a fixed-digest HKDF will result in an error. so don't, bestie π"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). go read that one, it's the source of truth π"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 honestly, 1024 bytes of info? that's a lot of lore."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 key, salt and info values must be set before a key is derived otherwise an error will occur. for non-fixed mode (HKDF) the digest must also be set."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 key and salt values must be set before a key is derived otherwise an error will occur. for non-fixed mode (HKDF) the digest must also be set."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 key and info values must be set before a key is derived otherwise an error will occur. for non-fixed mode (HKDF) the digest must also be set.
the OpenSSL FIPS provider also supports the following parameters:
"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. so like, be mindful, queen. this is not a casual toggle.
π NOTES π
a context for HKDF can be obtained by calling:
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.
not me giving you the exact recipe for not getting an error β¨ slay.
π EXAMPLES π
π HKDF Algorithm
this example derives 10 bytes using SHA-256 with the secret key "secret", salt value "salt" and info value "label":
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);
π§ HKDF-SHA256 Algorithm
this example derives 10 bytes using HKDF-SHA256 with the secret key "secret", salt value "salt" and info value "label":
EVP_KDF *kdf;
EVP_KDF_CTX *kctx;
unsigned char out[10];
OSSL_PARAM params[4], *p = params;
kdf = EVP_KDF_fetch(NULL, "HKDF-SHA256", NULL);
kctx = EVP_KDF_CTX_new(kdf);
EVP_KDF_free(kdf);
*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);
okay notice how in the HKDF-SHA256 one you don't set the digest at all? because the digest is already baked in. that's the fixed-digest moment. main character energy fr fr π
β CONFORMING TO β
RFC 5869 and RFC 8619. we follow the rules, we're certified, we're iconic.
π 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)
go follow them they're all in the same friend group π«Ά
π HISTORY π
HKDF-SHA256,HKDF-SHA384andHKDF-SHA512were added in OpenSSL 3.6.- all other functionality was added in OpenSSL 3.0.
look at us, we contain multitudes of versions. growth π
π COPYRIGHT π
Copyright 2016-2025 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>.
and that's the whole page bestie, no cap. this was the EVP_KDF-HKDF(7SSL) manpage, version 4.0.3, dated 2026-09-29, brought to you by the OpenSSL crew. now go derive some keys responsibly π
β¨π¦π
π¦ where this page comes from
- ubuntu stonking: openssl 4.0.3-1ubuntu1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms