EVP_KDF-KB(7SSL)
π EVP_KDF-KB β the Key-Based EVP_KDF implementation π
okay bestie, this is EVP_KDF-KB from the OpenSSL manuals (yes, 7SSL, the fancy section 7 one) and it's genuinely one of the good ones. buckle up π
β¨ NAME β¨
EVP_KDF-KB β literally just: the Key-Based EVP_KDF implementation. that's the whole name. short. iconic. π
πΈ DESCRIPTION πΈ
so the EVP_KDF-KB algorithm is the Key-Based key derivation function, aka KBKDF for the girlies who like acronyms. what KBKDF does is derive a key by repeatedly applying a keyed MAC to an input secret (and some other optional values, because we love options π«Ά).
the output? it's considered to be keying material. yes queen, that's the whole point.
π¦ Identity π¦
the name for this implementation is "KBKDF" β that's the string you pass. it can be used with the EVP_KDF_fetch() function. that's it, that's the identity, no cap.
π Supported parameters π
here's the whole roster, no skips, no cuts:
"mode"(OSSL_KDF_PARAM_MODE)<UTF8 string>β this one picks which flavor of KBKDF you want. right now your choices are"counter"and"feedback"."counter"is the default and it'll be used if you don't say anything. she's the main character mode 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 quote is missing in the original, i'm keeping it exactly like that, we don't fix the source, we respect the source π)"seed"(OSSL_KDF_PARAM_SEED)<octet string>β bestie, heads up: theseedparameter is unused in counter mode. it's just sitting there, chilling."use-l"(OSSL_KDF_PARAM_KBKDF_USE_L)<integer>β set it to0to disable use of the optional Fixed Input data'L'(see SP800-108). if you say nothing, the default value of1is used."use-separator"(OSSL_KDF_PARAM_KBKDF_USE_SEPARATOR)<integer>β set it to0to disable use of the optional Fixed Input data'zero separator'(see SP800-108) that gets placed between the Label and Context. default value1if unspecified."r"(OSSL_KDF_PARAM_KBKDF_R)<integer>β sets the fixed value'r', which indicates the length of the counter in bits. supported values are8,16,24, and32. the default value of32is used if you don't specify.
and the OpenSSL FIPS provider ALSO supports these two, extra special:
"fips-indicator"(OSSL_KDF_PARAM_FIPS_APPROVED_INDICATOR)<integer>β this one's a getter that returns1if the operation is FIPS approved, or0otherwise. you can use it 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 the 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.
β οΈ real talk: this option breaks FIPS compliance if it causes the approved"fips-indicator"to return0. setting it isn't a vibe, it's a choice. choose wisely π
depending on whether mac is CMAC or HMAC, either digest or cipher is required (respectively) and the other one is unused. and for KMAC128 and KMAC256? both of them are unused. they simply don't get invited.
the parameters key, salt, info, and seed correspond to KI, Label, Context, and IV (respectively) in SP800-108. and, as in that document, salt, info, and seed are optional and may be omitted. slay, optionality.
"mac", "digest", cipher" and "properties" are described in "PARAMETERS" in EVP_KDF(3).
π NOTES π
okay so to get a context for KBKDF you call:
EVP_KDF *kdf = EVP_KDF_fetch(NULL, "KBKDF", NULL);
EVP_KDF_CTX *kctx = EVP_KDF_CTX_new(kdf);
the output length of a KBKDF is specified via the "keylen" parameter to the EVP_KDF_derive(3) function. remember that. "keylen". it's the length. of the output. π
also, ngl, currently OpenSSL only implements counter and feedback modes. other variants may be supported in the future β so like, watch this space, but today's menu is those two.
π EXAMPLES π
example one: 10 bytes, COUNTER-HMAC-SHA256 πΈ
this one derives 10 bytes using COUNTER-HMAC-SHA256, with KI "secret", Label "label", and Context "context". so cute, so simple.
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: 10 bytes, FEEDBACK-CMAC-AES256 π₯
this one 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. certified. standards girlie. π
β SEE ALSO β
EVP_KDF(3)EVP_KDF_CTX_free(3)EVP_KDF_CTX_get_kdf_size(3)EVP_KDF_derive(3)"PARAMETERS"inEVP_KDF(3)
go read those too, iykyk π
π 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!! this was 4.0.3 2026-09-29 EVP_KDF-KB(7SSL) and she ate, fr fr π«Άπβ¨
π¦ 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