EVP_KDF(3ossl)
π EVP_KDF π
okay bestie, listen up β this is the EVP_KDF(3ossl) page from OpenSSL, and it's literally the group chat for all your Key Derivation Function needs. π
β¨ NAME β¨
EVP_KDF, EVP_KDF_fetch, EVP_KDF_free, EVP_KDF_up_ref, EVP_KDF_CTX, EVP_KDF_CTX_new, EVP_KDF_CTX_free, EVP_KDF_CTX_dup, EVP_KDF_CTX_reset, EVP_KDF_derive, EVP_KDF_CTX_get_kdf_size, EVP_KDF_get0_provider, EVP_KDF_CTX_kdf, EVP_KDF_is_a, EVP_KDF_get0_name, EVP_KDF_names_do_all, EVP_KDF_get0_description, EVP_KDF_CTX_get_params, EVP_KDF_CTX_set_params, EVP_KDF_do_all_provided, EVP_KDF_get_params, EVP_KDF_gettable_params, EVP_KDF_gettable_ctx_params, EVP_KDF_settable_ctx_params, EVP_KDF_CTX_gettable_params, EVP_KDF_CTX_settable_params β the EVP KDF routines. π«Ά
πΈ SYNOPSIS πΈ
#include <openssl/kdf.h>
typedef struct evp_kdf_st EVP_KDF;
typedef struct evp_kdf_ctx_st EVP_KDF_CTX;
EVP_KDF_CTX *EVP_KDF_CTX_new(EVP_KDF *kdf);
const EVP_KDF *EVP_KDF_CTX_kdf(EVP_KDF_CTX *ctx);
void EVP_KDF_CTX_free(EVP_KDF_CTX *ctx);
EVP_KDF_CTX *EVP_KDF_CTX_dup(const EVP_KDF_CTX *src);
void EVP_KDF_CTX_reset(EVP_KDF_CTX *ctx);
size_t EVP_KDF_CTX_get_kdf_size(EVP_KDF_CTX *ctx);
int EVP_KDF_derive(EVP_KDF_CTX *ctx, unsigned char *key, size_t keylen,
const OSSL_PARAM params[]);
int EVP_KDF_up_ref(EVP_KDF *kdf);
void EVP_KDF_free(EVP_KDF *kdf);
EVP_KDF *EVP_KDF_fetch(OSSL_LIB_CTX *libctx, const char *algorithm,
const char *properties);
int EVP_KDF_is_a(const EVP_KDF *kdf, const char *name);
const char *EVP_KDF_get0_name(const EVP_KDF *kdf);
const char *EVP_KDF_get0_description(const EVP_KDF *kdf);
const OSSL_PROVIDER *EVP_KDF_get0_provider(const EVP_KDF *kdf);
void EVP_KDF_do_all_provided(OSSL_LIB_CTX *libctx,
void (*fn)(EVP_KDF *kdf, void *arg),
void *arg);
int EVP_KDF_names_do_all(const EVP_KDF *kdf,
void (*fn)(const char *name, void *data),
void *data);
int EVP_KDF_get_params(EVP_KDF *kdf, OSSL_PARAM params[]);
int EVP_KDF_CTX_get_params(EVP_KDF_CTX *ctx, OSSL_PARAM params[]);
int EVP_KDF_CTX_set_params(EVP_KDF_CTX *ctx, const OSSL_PARAM params[]);
const OSSL_PARAM *EVP_KDF_gettable_params(const EVP_KDF *kdf);
const OSSL_PARAM *EVP_KDF_gettable_ctx_params(const EVP_KDF *kdf);
const OSSL_PARAM *EVP_KDF_settable_ctx_params(const EVP_KDF *kdf);
const OSSL_PARAM *EVP_KDF_CTX_gettable_params(const EVP_KDF *kdf);
const OSSL_PARAM *EVP_KDF_CTX_settable_params(const EVP_KDF *kdf);
const OSSL_PROVIDER *EVP_KDF_get0_provider(const EVP_KDF *kdf);
π yes, EVP_KDF_get0_provider really does show up twice in the synopsis. that's not me being extra, that's just what's there. leave it be.
π DESCRIPTION π
The EVP KDF routines are the high-level interface to Key Derivation Function algorithms, and the vibe check says: use these instead of the algorithm-specific functions. periodt. π
So here's the flow β you make an EVP_KDF_CTX for the algorithm you want with EVP_KDF_CTX_new(), and then you feed the algorithm its inputs. Two ways, bestie:
- pass them as part of the
EVP_KDF_derive()call itself, or - use
EVP_KDF_CTX_set_params()before you callEVP_KDF_derive()to derive the key.
β¨ Types β¨
EVP_KDFβ a type that holds the implementation of a KDF. πEVP_KDF_CTXβ a context type that holds the algorithm inputs. π§Ί
π¦ Algorithm implementation fetching π¦
EVP_KDF_fetch() fetches an implementation of a KDF algorithm, given a library context libctx and a set of properties. For the full tea, see "ALGORITHM FETCHING" in crypto(7). π
For the lists of algorithms supported by the default provider, see "Key Derivation Function (KDF)" in OSSL_PROVIDER-default(7).
The returned value must eventually be freed with EVP_KDF_free(3). no leaving it lying around, it's giving littering. ποΈ
EVP_KDF_up_ref() increments the reference count of an already fetched KDF. πͺ
EVP_KDF_free() frees a fetched algorithm. NULL is a valid parameter, and for that this function is a no-op β so it's the chill friend who doesn't make a scene. π
π Context manipulation functions π
EVP_KDF_CTX_new() creates a new context for the KDF implementation kdf. β¨
EVP_KDF_CTX_free() frees up the context ctx. If ctx is NULL, nothing is done. iconic, zero drama. π
EVP_KDF_CTX_kdf() returns the EVP_KDF associated with the context ctx.
π Computing functions π
EVP_KDF_CTX_reset() resets the context to the default state β as if the context had just been created. fresh start, rebrand, glow up. π±
EVP_KDF_derive() processes any parameters in Params and then derives keylen bytes of key material, dropping it into the key buffer. β οΈ heads up though: if the algorithm produces a fixed amount of output, an error will occur unless the keylen parameter is equal to that output size β the size you get back from EVP_KDF_CTX_get_kdf_size(). no negotiating on that one.
EVP_KDF_get_params() retrieves details about the implementation kdf. The set of parameters given with params determine exactly what should be retrieved. Note that a parameter that is unknown in the underlying context is simply ignored β it's not gonna fight you about it. π
EVP_KDF_CTX_get_params() retrieves chosen parameters, given the context ctx and its underlying context. The set of parameters given with params determine exactly what should be retrieved. Note that a parameter that is unknown in the underlying context is simply ignored. same energy. π
EVP_KDF_CTX_set_params() passes chosen parameters to the underlying context, given a context ctx. The set of parameters given with params determine exactly what parameters are passed down. Note that a parameter that is unknown in the underlying context is simply ignored. Also β and this is the important bit β what happens when a needed parameter isn't passed down is defined by the implementation. so, y'know, know your algorithm. π
EVP_KDF_gettable_params() returns an OSSL_PARAM(3) array that describes the retrievable and settable parameters. EVP_KDF_gettable_params() returns parameters that can be used with EVP_KDF_get_params(). ποΈ
EVP_KDF_gettable_ctx_params() and EVP_KDF_CTX_gettable_params() return constant OSSL_PARAM(3) arrays that describe the retrievable parameters that can be used with EVP_KDF_CTX_get_params(). EVP_KDF_gettable_ctx_params() returns the parameters that can be retrieved from the algorithm, whereas EVP_KDF_CTX_gettable_params() returns the parameters that can be retrieved in the context's current state. π
EVP_KDF_settable_ctx_params() and EVP_KDF_CTX_settable_params() return constant OSSL_PARAM(3) arrays that describe the settable parameters that can be used with EVP_KDF_CTX_set_params(). EVP_KDF_settable_ctx_params() returns the parameters that can be retrieved from the algorithm, whereas EVP_KDF_CTX_settable_params() returns the parameters that can be retrieved in the context's current state. (yes, the wording is literally the same as above. that's the manpage's choice, not mine. π)
β Information functions β
EVP_KDF_CTX_get_kdf_size() returns the output size if the algorithm produces a fixed amount of output, and SIZE_MAX otherwise. If an error occurs then 0 is returned. For some algorithms an error may result if input parameters necessary to calculate a fixed output size have not yet been supplied. so feed it first, then ask. π
EVP_KDF_is_a() returns 1 if kdf is an implementation of an algorithm that's identifiable with name, otherwise 0. yes/no, slay/not slay.
EVP_KDF_get0_provider() returns the provider that holds the implementation of the given kdf. π
EVP_KDF_do_all_provided() traverses all KDF implemented by all activated providers in the given library context libctx, and for each of the implementations, calls the given function fn with the implementation method and the given arg as argument. a little tour, one KDF at a time. πΆβοΈβ¨
EVP_KDF_get0_name() return the name of the given KDF. For fetched KDFs with multiple names, only one of them is returned β it's recommended to use EVP_KDF_names_do_all() instead. π
EVP_KDF_names_do_all() traverses all names for kdf, and calls fn with each name and data. π
EVP_KDF_get0_description() returns a description of the kdf, meant for display and human consumption. The description is at the discretion of the kdf implementation. (so don't @ me if it's boring, blame the implementation.) π¬
π§ PARAMETERS π§
The standard parameter names are:
"pass"(OSSL_KDF_PARAM_PASSWORD) <octet string> β Some KDF implementations require a password. For those KDF implementations that support it, this parameter sets the password. π"salt"(OSSL_KDF_PARAM_SALT) <octet string> β Some KDF implementations can take a non-secret unique cryptographic salt. For those KDF implementations that support it, this parameter sets the salt. π§
The default value, if any, is implementation dependent.
"iter"(OSSL_KDF_PARAM_ITER) <unsigned integer> β Some KDF implementations require an iteration count. For those KDF implementations that support it, this parameter sets the iteration count. π
The default value, if any, is implementation dependent.
"properties"(OSSL_KDF_PARAM_PROPERTIES) <UTF8 string> β π"mac"(OSSL_KDF_PARAM_MAC) <UTF8 string> β πͺ"digest"(OSSL_KDF_PARAM_DIGEST) <UTF8 string> β π§¬"cipher"(OSSL_KDF_PARAM_CIPHER) <UTF8 string> β π
For KDF implementations that use an underlying computation MAC, digest or cipher, these parameters set what the algorithm should be.
The value is always the name of the intended algorithm, or the properties.
Note that not all algorithms may support all possible underlying implementations. π
"key"(OSSL_KDF_PARAM_KEY) <octet string> β Some KDF implementations require a key. For those KDF implementations that support it, this octet string parameter sets the key. ποΈ"info"(OSSL_KDF_PARAM_INFO) <octet string> β Some KDF implementations, such asEVP_KDF-HKDF(7), take an 'info' parameter for binding the derived key material to application- and context-specific information. This parameter sets the info, fixed info, other info or shared info argument. You can specify this parameter multiple times, and each instance will be concatenated to form the final value. so yes, spam it, it stacks. π§΅β¨"maclen"(OSSL_KDF_PARAM_MAC_SIZE) <unsigned integer> β Used by implementations that use a MAC with a variable output size (KMAC). For those KDF implementations that support it, this parameter sets the MAC output size. π
The default value, if any, is implementation dependent. The length must never exceed what can be given with a size_t. π¨
"maxmem_bytes"(OSSL_KDF_PARAM_SCRYPT_MAXMEM) <unsigned integer> β Memory-hard password-based KDF algorithms, such as scrypt, use an amount of memory that depends on the load factors provided as input. For those KDF implementations that support it, thisuint64_tparameter sets an upper limit on the amount of memory that may be consumed while performing a key derivation. If this memory usage limit is exceeded because the load factors are chosen too high, the key derivation will fail. π
The default value is implementation dependent. The memory size must never exceed what can be given with a size_t. π¨
lowkey the most important thing on this whole page: that size_t ceiling shows up twice, and it is NOT a suggestion. don't be the one who blows past it. π
β¨ RETURN VALUES β¨
okay bestie, here's the receipts section β what each lil function hands back to you π
EVP_KDF_fetch()β gives you a pointer to a freshly fetchedEVP_KDF, orNULLif the allocation flopped πEVP_KDF_get0_provider()β hands you a pointer to the provider for the KDF, orNULLon errorEVP_KDF_up_ref()β returns1when it slays,0when it doesn'tEVP_KDF_CTX_new()β returns either the brand new allocatedEVP_KDF_CTXstructure, orNULLif something went wrongEVP_KDF_CTX_free()andEVP_KDF_CTX_reset()β these two give you literally nothing back, no return value, they just do their thing π«ΆEVP_KDF_CTX_get_kdf_size()β returns the output size. BUT:SIZE_MAXmeans the algorithm produces a variable amount of output, and0means failure πEVP_KDF_get0_name()β returns the name of the KDF, orNULLon errorEVP_KDF_names_do_all()β returns1if the callback was called for all names. A return value of0means the callback was not called for any names- The remaining functions β
1for success,0for failure, that's the whole vibe periodt
π NOTES π
The KDF life-cycle is described in life_cycle-kdf(7). In the future, the transitions described there will be enforced. And when that happens, it will not be considered a breaking change to the API. so like, don't come for them about it bestie, they told us in advance π
π SEE ALSO π
- "Key Derivation Function (KDF)" in
OSSL_PROVIDER-default(7) life_cycle-kdf(7)
π¦ HISTORY π¦
This functionality was added in OpenSSL 3.0. iconic behavior honestly πΈ
Β©οΈ COPYRIGHT Β©οΈ
Copyright 2019-2024 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 a wrap on EVP_KDF(3ossl) bestie!! π this page is from the 3.5.9 era, dated 2026-09-29 β go forth and derive those keys, you absolute main character πβ¨
π¦ where this page comes from
- fedora 43: openssl-devel 1:3.5.9-1.fc43 Β· Apache-2.0
- fedora 43: openssl-devel 1:3.5.9-1.fc43 Β· Apache-2.0
- fedora 44: openssl-devel 1:3.5.9-1.fc44 Β· Apache-2.0
- fedora 44: openssl-devel 1:3.5.9-1.fc44 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms