EVP_KDF-KB(7ossl)

πŸ“¦
version 15.1 Β· 3 versions
, in freebsd 15.1

πŸ’… 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 either CMAC, HMAC, KMAC128 or KMAC256.
  • "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 to 0 to disable use of the optional Fixed Input data 'L' (see SP800-108). The default value of 1 will be used if unspecified.
  • "use-separator" (OSSL_KDF_PARAM_KBKDF_USE_SEPARATOR) <integer> β€” set to 0 to disable use of the optional Fixed Input data 'zero separator' (see SP800-108) that gets placed between the Label and Context. The default value of 1 will 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 are 8, 16, 24, and 32. The default value of 32 will 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 returns 1 if the operation is FIPS approved, or 0 otherwise. This may be used after calling EVP_KDF_derive. It returns 0 if "key-check" is set to 0 and the check fails.
  • "key-check" (OSSL_KDF_PARAM_FIPS_KEY_CHECK) <integer> β€” the default value of 1 causes an error during EVP_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" to 0. Heads up: this option breaks FIPS compliance if it causes the approved "fips-indicator" to return 0. Not a vibe, but a fact.
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. 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

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 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