EVP_KDF(3SSL)
πΈ EVP_KDF(3SSL) β the OpenSSL KDF page, part 1 π
okay bestie, welcome to EVP_KDF(3SSL), aka the OpenSSL manual page for the EVP KDF routines. grab a snack, this one's a two-parter and we're only doing part 1 rn, so don't go anywhere. π
β¨ 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_set_SKEY, EVP_KDF_derive_SKEY, 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 β EVP KDF routines, periodt. π
π 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_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);
π DESCRIPTION π
so like, the EVP KDF routines are this high-level interface to Key Derivation Function algorithms, and the whole point is you should be using them instead of whatever algorithm-specific functions you were gonna reach for. no cap. π ββοΈ
Once you've made an EVP_KDF_CTX for the algorithm you want with EVP_KDF_CTX_new(), you feed inputs to the algorithm one of two ways: either pass them straight in as part of the EVP_KDF_derive() or EVP_KDF_derive_SKEY() call, or set them up first with EVP_KDF_CTX_set_params() or EVP_KDF_CTX_set_SKEY() and then call EVP_KDF_derive() or EVP_KDF_derive_SKEY() to actually derive the key. slay. β¨
π¦ Types π¦
EVP_KDFβ a type that holds the implementation of a KDF. it's giving "the algorithm itself."EVP_KDF_CTXβ a context type that holds the algorithm inputs. it's giving "the working state." π
π§ 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 whole rundown, go see "ALGORITHM FETCHING" in crypto(7).
and if you wanna know which algorithms the default provider actually supports, see "Key Derivation Function (KDF)" in OSSL_PROVIDER-default(7).
the value you get back must eventually be freed with EVP_KDF_free(3). don't be out here leaking, bestie. π
EVP_KDF_up_ref() bumps the reference count of an already fetched KDF up by one. β¨
EVP_KDF_free() frees a fetched algorithm. and fun fact: NULL is a totally valid parameter here, and when you pass it the function is just a no-op. iconic behavior honestly. π
π 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 happens. zero drama. π
EVP_KDF_CTX_kdf() returns the EVP_KDF that's associated with the context ctx.
π₯ Computing functions π₯
EVP_KDF_CTX_reset() resets the context back to the default state, like it had literally just been created. fresh start energy. π¦
EVP_KDF_derive() processes any parameters in Params and then derives keylen bytes of key material straight into the key buffer. heads up though: if the algorithm produces a fixed amount of output, you'll get an error unless the keylen parameter is equal to that output size β the one you'd get back from EVP_KDF_CTX_get_kdf_size(). so check that size first, okay? π
EVP_KDF_derive_SKEY() behaves similarly, except it returns an EVP_SKEY object instead. and here's the tea: if the skeymgmt argument is explicitly passed, it gets used for the generated key. if the skeymgmt argument is NULL, then key_type and propquery get used to fetch the EVP_SKEYMGMT object that's linked to the key. and if the KDF doesn't support dealing with opaque keys, or the EVP_SKEYMGMT you passed is from a different provider than the KDF method, then the operation will try to do export/import through the raw format. no cap. π
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. and if null is passed, the parameter OSSL_KDF_PARAM_KEY is implied. this one is used when the input key is represented by EVP_SKEY rather than raw bytes. π«Ά
EVP_KDF_get_params() retrieves details about the implementation kdf. the set of parameters you give it in params determines exactly which parameters get 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. same deal β the set of parameters given with params determines exactly what gets 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. note that a parameter that's unknown in the underlying context is simply ignored. also, what happens when a needed parameter isn't passed down is defined by the implementation β so like, that part is on them, not us. π
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 usable 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. different vibes, different param lists. π
EVP_KDF_settable_ctx_params() and EVP_KDF_CTX_settable_params() return constant OSSL_PARAM(3) arrays that describe the settable parameters usable 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 original says "retrieved" for both, we're keeping it exactly the way it is. π
π 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. and for some algorithms, an error may result if the input parameters necessary to calculate a fixed output size haven't been supplied yet. so like, 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. simple as. β¨
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, it calls the given function fn with the implementation method and the given arg as argument. little tour, one KDF at a time. πΆββοΈ
EVP_KDF_get0_name() returns the name of the given KDF. but bestie, listen: for fetched KDFs with multiple names, only one of them is returned β so 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 like, whatever they decided to say, that's what you get. π
to be continued in part 2, don't go anywhere π
π PARAMETERS π
okay bestie, here's the standard parameter name roster β the whole squad, no gatekeeping π«Ά
"pass"(OSSL_KDF_PARAM_PASSWORD) <octet string> β some KDF implementations literally can't function without a password. For the ones that support it, this parameter is where you set that 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 is the parameter that sets the salt. The default value, if there even is one, is implementation dependent β it's giving "figure it out per provider". π§"iter"(OSSL_KDF_PARAM_ITER) <unsigned integer> β some KDF implementations require an iteration count. For those that support it, this parameter sets that iteration count. And again: 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 four set what that algorithm should be. The value is always the name of the intended algorithm, or the properties. Lowkey important: not all algorithms may support all possible underlying implementations, so don't come for the provider when it says no. π
"key"(OSSL_KDF_PARAM_KEY) <octet string> β some KDF implementations require a key. For those that support it, this octet string parameter is the one that sets the key. ποΈ"info"(OSSL_KDF_PARAM_INFO) <octet string> β some KDF implementations, likeEVP_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 iconic part: you can specify this parameter multiple times, and each instance gets concatenated to form the final value. Stack 'em up, bestie. π§"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. β οΈ And the length must never exceed what can be given with asize_t."maxmem_bytes"(OSSL_KDF_PARAM_SCRYPT_MAXMEM) <unsigned integer> β memory-hard password-based KDF algorithms, like scrypt, use an amount of memory that depends on the load factors you feed in as input. For the implementations that support it, thisuint64_tparameter sets an upper limit on how much memory may be consumed while performing a key derivation. If that memory usage limit gets exceeded because the load factors were chosen too high, the key derivation will fail. Periodt. β
The default value is implementation dependent. And heads up: the memory size must never exceed what can be given with a size_t.
π RETURN VALUES π
every function's vibe check, one by one:
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 simply do their thing and go. π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. π²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.
π NOTES π
the KDF life-cycle is described in life_cycle-kdf(7). And bestie, listen β 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 don't act surprised, iykyk. π
π SEE ALSO π
- "Key Derivation Function (KDF)" in
OSSL_PROVIDER-default(7) life_cycle-kdf(7)
π°οΈ HISTORY π°οΈ
this functionality was added in OpenSSL 3.0.
EVP_KDF_derive_SKEY() and EVP_KDF_CTX_set_SKEY() functions were introduced in OpenSSL 3.6. glow-up behavior fr fr. β¨
Β©οΈ COPYRIGHT Β©οΈ
Copyright 2019-2025 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 π this was EVP_KDF(3SSL), version 4.0.3, dated 2026-09-29 β go forth and derive those keys responsibly, mwah ππ¦
π¦ where this page comes from
- ubuntu stonking: libssl-doc 4.0.3-1ubuntu1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms