EVP_KDF-KB(7ossl)
π NAME
EVP_KDF-KB β the Key-Based EVP_KDF implementation, aka the KBKDF glow-up, and yes bestie it is exactly as iconic as it sounds π
Also hi, this is the OpenSSL manual page (section 7ossl), hope u enjoy the read π«Ά
β¨ DESCRIPTION
So the EVP_KDF-KB algorithm implements the Key-Based key derivation function (KBKDF). And what does KBKDF do? It derives a key by repeatedly applying a keyed MAC to an input secret (plus other optional values). That's it. That's the whole vibe. π₯
The output is considered to be keying material. Like, that's literally what it is. Periodt.
πͺͺ Identity
"KBKDF" is the name for this implementation, and you can use it with the EVP_KDF_fetch() function. That string is your golden ticket, don't lose it π
ποΈ Supported parameters
These are the parameters that get supported, no gatekeeping:
"mode"(OSSL_KDF_PARAM_MODE) <UTF8 string> β this decides which flavor of KBKDF u get π¦ Right now the choices are"counter"and"feedback"."counter"is the default and will be used if unspecified, so if u forgot, it's giving counter energy by default."mac"(OSSL_KDF_PARAM_MAC) <UTF8 string> β the value is eitherCMAC,HMAC,KMAC128orKMAC256."digest"(OSSL_KDF_PARAM_DIGEST) <UTF8 string> β the digest, obvs."cipher"(OSSL_KDF_PARAM_CIPHER) <UTF8 string> β the cipher, also obvs."properties"(OSSL_KDF_PARAM_PROPERTIES) <UTF8 string> β the property query string, the usual."key"(OSSL_KDF_PARAM_KEY) <octet string> β the key."salt"(OSSL_KDF_PARAM_SALT) <octet string> β the salt."info (OSSL_KDF_PARAM_INFO) <octet string>β the info. (Yeah the original page's quote marks are a little feral here, we keep them exactly as they are, no editing the source, that's a promise π«‘)"seed"(OSSL_KDF_PARAM_SEED) <octet string> β listen, the seed parameter is unused in counter mode. Just so you know before u try something cute π"use-l"(OSSL_KDF_PARAM_KBKDF_USE_L) <integer> β set it 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 gets 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', which indicates 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 (special guest stars β):
"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 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. Heads up: this option breaks FIPS compliance if it causes the approved"fips-indicator"to return0. Not a vibe, but a fact.
Depending on whether mac isCMACorHMAC, either digest or cipher is required (respectively) and the other is unused. They are unused forKMAC128andKMAC256.
The parameters key, salt, info, and seed correspond to KI, Label, Context, and IV (respectively) in SP800-108. And just like in that document, salt, info, and seed are optional and may be omitted. Slay, optional parameters π
"mac", "digest", cipher" and "properties" are described in "PARAMETERS" in EVP_KDF(3).
π NOTES
Ok so u can get a context for KBKDF by calling this, copy it exactly bestie:
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. That's where u tell it how much key material u want π₯
And ngl, note that currently OpenSSL only implements counter and feedback modes. Other variants may be supported in the future β so don't come for the implementation, it's doing its best π«Ά
π EXAMPLES
Example 1: counter girlie π
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 2: feedback era π¦
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 behavior, we love to see it β¨
π 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)
Go read them, they're all part of the friend group π«Ά
β HISTORY
This functionality was added in OpenSSL 3.0. Then support for KMAC was added in OpenSSL 3.1. Growth! Evolution! We cheer π
π 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>.
ok that's the whole page, no cap π this was version 3.5.6, dated 2026-04-07, page EVP_KDF-KB(7ossl) β mwah, go derive some keys bestie, u got this πΈ
π¦ 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