EVP_KDF(3ssl)
๐ EVP_KDF(3ssl) โ the KDF glow-up ๐
okay bestie, so this is the EVP_KDF(3ssl) page from OpenSSL (section 3ssl, aka the library-functions shelf). It's the whole high-level Key Derivation Function interface and honestly it's giving main character energy for the entire crypto library. Buckle up. ๐
๐ธ NAME ๐ธ
The full squad, in order, no cap โ 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_set_SKEY, EVP_KDF_derive_SKEY, EVP_KDF_CTX_get_kdf_size, EVP_KDF_CTX_get0_kdf, EVP_KDF_CTX_get1_kdf, 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 โ EVP KDF routines. ๐
โจ SYNOPSIS โจ
Like, here's the literal spellbook, copied exactly because we do not paraphrase signatures in this house:
#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_get0_kdf(const EVP_KDF_CTX *ctx);
EVP_KDF *EVP_KDF_CTX_get1_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_CTX_set_SKEY(EVP_KDF_CTX *ctx, EVP_SKEY *key, const char *paramname);
EVP_SKEY *EVP_KDF_derive_SKEY(EVP_KDF_CTX *ctx, EVP_SKEYMGMT *mgmt,
const char *key_type, const char *propquery,
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 up there โ that's just how the page is, iykyk ๐)
โ ๏ธ Deprecated alert, since OpenSSL 4.1 โ the following function can be hidden entirely by definingOPENSSL_API_COMPATwith a suitable version value, seeopenssl_user_macros(7):
const EVP_KDF *EVP_KDF_CTX_kdf(const EVP_KDF_CTX *ctx);
๐ซ DESCRIPTION ๐ซ
The EVP KDF routines are the โจhigh-levelโจ interface to Key Derivation Function algorithms, and bestie, you should be using these instead of the algorithm-specific functions. No exceptions, periodt.
So the flow is: you spin up an EVP_KDF_CTX for whatever algorithm you need using EVP_KDF_CTX_new(), then you feed the algorithm its inputs either by passing them along as part of the EVP_KDF_derive() or EVP_KDF_derive_SKEY() call, or by calling EVP_KDF_CTX_set_params() or EVP_KDF_CTX_set_SKEY() before you call EVP_KDF_derive() or EVP_KDF_derive_SKEY() to actually derive the key. Two paths, same destination. ๐ฆ
๐ง Types
EVP_KDFโ the 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 lore on how fetching works, see "ALGORITHM FETCHING" incrypto(7).- Curious which algorithms the default provider ships with? See "Key Derivation Function (KDF)" in
OSSL_PROVIDER-default(7)for the lists. - The returned value must eventually be freed with
EVP_KDF_free(3)โ don't just leave it out there, that's rude. EVP_KDF_up_ref()โ increments the reference count of an already fetched KDF.EVP_KDF_free()โ frees a fetched algorithm.NULLis a valid parameter, and for that it's a straight-up no-op. ๐ซถ
๐ 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 isNULL, nothing happens. Chill.EVP_KDF_CTX_get0_kdf()โ returns theEVP_KDFassociated with the context ctx. AndEVP_KDF_CTX_get1_kdf()is the same thing, except ownership is passed to the caller. AlsoEVP_KDF_CTX_kdf()is an alias forEVP_KDF_CTX_get0_kdf()(but remember that deprecation note above ๐).
๐งฎ Computing functions
EVP_KDF_CTX_reset()โ resets the context back to its default state, exactly as if the context had just been created. Fresh start, clean slate, new era. โจEVP_KDF_derive()โ processes any parameters inParams, then derives keylen bytes of key material and drops it in 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, as returned byEVP_KDF_CTX_get_kdf_size().EVP_KDF_derive_SKEY()โ behaves similarly, except it returns anEVP_SKEYobject. If the skeymgmt argument is explicitly passed, it will be used for the generated key. If the skeymgmt argument isNULL, then key_type and propquery get used for fetching theEVP_SKEYMGMTobject linked to the key. And if the KDF doesn't support dealing with opaque keys, or the passedEVP_SKEYMGMTis from a different provider than the KDF method, then the operation will try to perform export/import through the raw format. Adaptable queen. ๐EVP_KDF_CTX_set_SKEY()โ lets you set an skey object as the input parameter for the derivation functions. Since different KDFs may accept several parameters as key names, you can specify the particular parameter name you're setting. If null is passed, then the parameterOSSL_KDF_PARAM_KEYis implied. Basically this is the move when the input key is represented byEVP_SKEYrather than raw bytes.EVP_KDF_get_params()โ retrieves details about the implementation kdf. The set of parameters given with params determines exactly what gets retrieved. And note: a parameter that's unknown in the underlying context is simply ignored. ๐ซฅEVP_KDF_CTX_get_params()โ retrieves chosen parameters, given the context ctx and its underlying context. Again, the set of parameters given with params determines exactly what will be retrieved, and a parameter that's unknown in the underlying context is simply ignored.EVP_KDF_CTX_set_params()โ passes chosen parameters down to the underlying context, given a context ctx. The set of parameters given with params determines exactly what gets passed down. Same story: a parameter unknown in the underlying context is simply ignored. And also โ what happens when a needed parameter isn't passed down is entirely defined by the implementation. So that part's on them, not on you.EVP_KDF_gettable_params()โ returns anOSSL_PARAM(3)array describing the retrievable and settable parameters. This one returns parameters that can be used withEVP_KDF_get_params().EVP_KDF_gettable_ctx_params()andEVP_KDF_CTX_gettable_params()โ return constantOSSL_PARAM(3)arrays describing the retrievable parameters that can be used withEVP_KDF_CTX_get_params(). The diff:EVP_KDF_gettable_ctx_params()returns the parameters that can be retrieved from the algorithm, whereasEVP_KDF_CTX_gettable_params()returns the parameters that can be retrieved in the context's current state. Iconic and situational.EVP_KDF_settable_ctx_params()andEVP_KDF_CTX_settable_params()โ return constantOSSL_PARAM(3)arrays describing the settable parameters that can be used withEVP_KDF_CTX_set_params(). Same split as above:EVP_KDF_settable_ctx_params()returns the parameters that can be retrieved from the algorithm, whereasEVP_KDF_CTX_settable_params()returns the parameters that can be retrieved in the context's current state.
๐ Information functions
EVP_KDF_CTX_get_kdf_size()โ returns the output size if the algorithm produces a fixed amount of output, andSIZE_MAXotherwise. If an error occurs, then0is returned. Careful though: 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()โ returns1if kdf is an implementation of an algorithm that's identifiable with name, otherwise0.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. Tour de force. ๐EVP_KDF_get0_name()โ returns the name of the given KDF. For fetched KDFs with multiple names, only one of them is returned, so it's recommended to useEVP_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 like, whatever they feel like writing.
โฆand that's literally only half the lore, bestie. ๐ซถ๐
โจ PARAMETERS โจ
Okay bestie, this is the part where you tell the KDF what to actually do. These are the standard parameter names โ the string is the name you pass, and the thing in parens is the constant in the headers. Iykyk. ๐
"pass"(OSSL_KDF_PARAM_PASSWORD) <octet string> โ some KDF implementations literally require a password, no cap. For the ones that support this parameter, this sets the password. ๐"salt"(OSSL_KDF_PARAM_SALT) <octet string> โ some KDF implementations can take a non-secret unique cryptographic salt. For the implementations that support it, this parameter sets that salt. The default value, if any, is implementation dependent โ so like, don't assume, check your provider. ๐"iter"(OSSL_KDF_PARAM_ITER) <unsigned integer> โ some KDF implementations require an iteration count. For the ones that support it, this 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. โญ
Heads up: not all algorithms may support all possible underlying implementations. So yeah, vibe check your combo before you commit. ๐
"key"(OSSL_KDF_PARAM_KEY) <octet string> โ some KDF implementations require a key. For those 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. And the slay part: you can specify this parameter multiple times, and each instance will be concatenated to form the final value. ๐ซถ"maclen"(OSSL_KDF_PARAM_MAC_SIZE) <unsigned integer> โ used by implementations that use a MAC with a variable output size (KMAC). For the 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 asize_tโ that's a hard line, bestie, don't test it. ๐ญ"maxmem_bytes"(OSSL_KDF_PARAM_SCRYPT_MAXMEM) <unsigned integer> โ memory-hard password-based KDF algorithms, such asscrypt, use an amount of memory that depends on the load factors provided as input. For the 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.
๐ RETURN VALUES ๐
Not me listing every single one because you deserve the full picture, bestie. ๐
EVP_KDF_fetch()โ returns a pointer to a newly fetchedEVP_KDF, orNULLif allocation failed.EVP_KDF_get0_provider()โ returns a pointer to the provider for the KDF, orNULLon error.EVP_KDF_up_ref()โ returns1on success,0on error.EVP_KDF_CTX_new()โ returns either the newly allocatedEVP_KDF_CTXstructure orNULLif an error occurred.EVP_KDF_CTX_free()andEVP_KDF_CTX_reset()โ do not return a value. They just do, no notes. ๐EVP_KDF_CTX_get_kdf_size()โ returns the output size.SIZE_MAXis returned to indicate that the algorithm produces a variable amount of output;0to indicate failure. Two special cases, so read carefully, fr fr.EVP_KDF_get0_name()โ returns the name of the KDF, orNULLon error.EVP_KDF_names_do_all()โ returns1if the callback was called for all names. A return value of0means that the callback was not called for any names.EVP_KDF_derive_SKEY()โ returns theEVP_SKEYobject on success orNULLon failure.- The remaining functions โ return
1for success and0for failure. Classic. ๐
๐ธ NOTES ๐ธ
The KDF life-cycle is described in life_cycle-kdf(7). In the future, the transitions described there will be enforced. When that happens, it will not be considered a breaking change to the API โ so like, be aware, this is giving "future you will thank present you" energy. โจ
๐ฆ SEE ALSO ๐ฆ
"Key Derivation Function (KDF)"inOSSL_PROVIDER-default(7)life_cycle-kdf(7)
๐ HISTORY ๐
- This functionality was added in OpenSSL 3.0. ๐
EVP_KDF_derive_SKEY()andEVP_KDF_CTX_set_SKEY()functions were introduced in OpenSSL 3.6.EVP_KDF_CTX_get0_kdf()andEVP_KDF_CTX_get1_kdf()functions were introduced in OpenSSL 4.1.EVP_KDF_CTX_kdf()function was deprecated in favour ofEVP_KDF_CTX_get0_kdf()in OpenSSL 4.1. She's retired, wish her well. ๐
๐ COPYRIGHT ๐
Copyright 2019-2026 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 the whole page, bestie โ you ate that. ๐ซถ This one came from OpenSSL4.1.0, dated2026-10-23, pageEVP_KDF(3ssl). Go derive some keys, icon. ๐ โจ
๐ฆ where this page comes from
- nixos 26.05: openssl 4.1.0
- nixpkgs unstable: openssl 4.1.0
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms