EVP_KDF-KB(7ossl)
π NAME π
EVP_KDF-KB β the Key-Based EVP_KDF implementation, bestie. It's from the 7ossl manual fam, and it's basically the key-derivation glow-up you've been looking for.
β¨ DESCRIPTION β¨
okay so, the EVP_KDF-KB algorithm implements the Key-Based key derivation function (KBKDF). What KBKDF does is derive a key by repeatedly applying a keyed MAC to an input secret (plus some other optional values). Slay.
The output is considered to be keying material. That's the whole vibe. π₯
π Identity π
"KBKDF" is the name for this implementation β that's the string you feed to the EVP_KDF_fetch() function. iykyk.
πΈ Supported parameters πΈ
here's the lineup, no skips:
"mode"(OSSL_KDF_PARAM_MODE) <UTF8 string> β the mode parameter decides which flavor of KBKDF you're getting. currently the choices are"counter"and"feedback"."counter"is the default, and it will be used if unspecified. main character default energy fr."mac"(OSSL_KDF_PARAM_MAC) <UTF8 string> β the value is eitherCMAC,HMAC,KMAC128orKMAC256."digest"(OSSL_KDF_PARAM_DIGEST) <UTF8 string>"cipher"(OSSL_KDF_PARAM_CIPHER) <UTF8 string>"properties"(OSSL_KDF_PARAM_PROPERTIES) <UTF8 string>"key"(OSSL_KDF_PARAM_KEY) <octet string>"salt"(OSSL_KDF_PARAM_SALT) <octet string>"info (OSSL_KDF_PARAM_INFO) <octet string>β yes the missing quote is literally how it ships, not me being messy π"seed"(OSSL_KDF_PARAM_SEED) <octet string> β heads up: the seed parameter is unused in counter mode."use-l"(OSSL_KDF_PARAM_KBKDF_USE_L) <integer> β set to0to disable use of the optional Fixed Input data'L'(see SP800-108). the default value of1will be used if unspecified."use-separator"(OSSL_KDF_PARAM_KBKDF_USE_SEPARATOR) <integer> β set to0to disable use of the optional Fixed Input data'zero separator'(see SP800-108) that is placed between the Label and Context. the default value of1will be used if unspecified."r"(OSSL_KDF_PARAM_KBKDF_R) <integer> β sets the fixed value'r', indicating the length of the counter in bits. supported values are8,16,24, and32. the default value of32will be used if unspecified.
The OpenSSL FIPS provider also supports the following parameters, bestie, don't forget these π
"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.
β οΈ okay important: this option breaks FIPS compliance if it causes the approved"fips-indicator"to return0. like, that's the actual deal. not me being dramatic for once.
Depending on whether mac is CMAC or HMAC, either digest or cipher is required (respectively) and the other is unused. They are unused for KMAC128 and KMAC256.
The parameters key, salt, info, and seed correspond to KI, Label, Context, and IV (respectively) in SP800-108. As in that document, salt, info, and seed are optional and may be omitted.
"mac", "digest", cipher" and "properties" are described in "PARAMETERS" in EVP_KDF(3). (and yeah, that stray quote on cipher" is in the original too π«Ά)
π¦ NOTES π¦
A context for KBKDF can be obtained by calling:
EVP_KDF *kdf = EVP_KDF_fetch(NULL, "KBKDF", NULL);
EVP_KDF_CTX *kctx = EVP_KDF_CTX_new(kdf);
The output length of an KBKDF is specified via the "keylen" parameter to the EVP_KDF_derive(3) function. literally that's how you tell it how much to give you.
Note that currently OpenSSL only implements counter and feedback modes. Other variants may be supported in the future. so like, watch this space ig β
π EXAMPLES π
Example one β COUNTER-HMAC-SHA256 π
This example derives 10 bytes using COUNTER-HMAC-SHA256, with KI "secret", Label "label", and Context "context".
EVP_KDF *kdf;
EVP_KDF_CTX *kctx;
unsigned char out[10];
OSSL_PARAM params[6], *p = params;
kdf = EVP_KDF_fetch(NULL, "KBKDF", NULL);
kctx = EVP_KDF_CTX_new(kdf);
EVP_KDF_free(kdf);
*p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_DIGEST,
"SHA2-256", 0);
*p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_MAC,
"HMAC", 0);
*p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_KEY,
"secret", strlen("secret"));
*p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SALT,
"label", strlen("label"));
*p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_INFO,
"context", strlen("context"));
*p = OSSL_PARAM_construct_end();
if (EVP_KDF_derive(kctx, out, sizeof(out), params) <= 0)
error("EVP_KDF_derive");
EVP_KDF_CTX_free(kctx);
Example two β FEEDBACK-CMAC-AES256 π
This example derives 10 bytes using FEEDBACK-CMAC-AES256, with KI "secret", Label "label", and IV "sixteen bytes iv".
EVP_KDF *kdf;
EVP_KDF_CTX *kctx;
unsigned char out[10];
OSSL_PARAM params[8], *p = params;
unsigned char *iv = "sixteen bytes iv";
kdf = EVP_KDF_fetch(NULL, "KBKDF", NULL);
kctx = EVP_KDF_CTX_new(kdf);
EVP_KDF_free(kdf);
*p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_CIPHER, "AES256", 0);
*p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_MAC, "CMAC", 0);
*p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_MODE, "FEEDBACK", 0);
*p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_KEY,
"secret", strlen("secret"));
*p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SALT,
"label", strlen("label"));
*p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_INFO,
"context", strlen("context"));
*p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SEED,
iv, strlen(iv));
*p = OSSL_PARAM_construct_end();
if (EVP_KDF_derive(kctx, out, sizeof(out), params) <= 0)
error("EVP_KDF_derive");
EVP_KDF_CTX_free(kctx);
π CONFORMING TO π
NIST SP800-108, IETF RFC 6803, IETF RFC 8009. standards icon behaviour honestly.
π§ SEE ALSO π§
EVP_KDF(3), EVP_KDF_CTX_free(3), EVP_KDF_CTX_get_kdf_size(3), EVP_KDF_derive(3), "PARAMETERS" in EVP_KDF(3)
π HISTORY π
This functionality was added in OpenSSL 3.0.
Support for KMAC was added in OpenSSL 3.1.
π COPYRIGHT π
Copyright 2019-2024 The OpenSSL Project Authors. All Rights Reserved. Copyright 2019 Red Hat, Inc.
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 β brought to you by version3.5.0, dated2026-09-25. go derive some keys, you've got this π«Άβ¨
π¦ where this page comes from
- opensuse-leap 16.0: openssl-3 3.5.0-160000.11.1 Β· Apache-2.0
- opensuse-leap 16.0: openssl-3 3.5.0-160000.11.1 Β· Apache-2.0
- opensuse-leap 16.0: openssl-3 3.5.0-160000.11.1 Β· Apache-2.0
- opensuse-leap 16.0: openssl-3 3.5.0-160000.11.1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms