PROVIDER-KEYEXCH(7SSL)
π¦ PROVIDER-KEYEXCH(7SSL) π¦
okay so bestie, welcome to OpenSSL's PROVIDER-KEYEXCH(7SSL) page π this is where the provider-side key exchange situation lives. It's all about the bridge between the keyexch library and the provider functions. no cap.
β¨ NAME β¨
provider-keyexch β The keyexch library <-> provider functions
fr fr, that's the whole name: it's the keyexch library <-> provider functions. iconic.
β¨ SYNOPSIS β¨
okay so here's the cast list. First, drag in the headers:
#include <openssl/core_dispatch.h>
#include <openssl/core_names.h>
/*
* None of these are actual functions, but are displayed like this for
* the function signatures for functions that are offered as function
* pointers in OSSL_DISPATCH arrays.
*/
/* Context management */
void *OSSL_FUNC_keyexch_newctx(void *provctx);
void OSSL_FUNC_keyexch_freectx(void *ctx);
void *OSSL_FUNC_keyexch_dupctx(void *ctx);
/* Shared secret derivation */
int OSSL_FUNC_keyexch_init(void *ctx, void *provkey,
const OSSL_PARAM params[]);
int OSSL_FUNC_keyexch_set_peer(void *ctx, void *provkey);
int OSSL_FUNC_keyexch_derive(void *ctx, unsigned char *secret, size_t *secretlen,
size_t outlen);
void *OSSL_FUNC_keyexch_derive_skey(void *ctx, const char *key_type,
void *provctx,
OSSL_FUNC_skeymgmt_import_fn *import,
size_t keylen, const OSSL_PARAM params[]);
/* Key Exchange parameters */
int OSSL_FUNC_keyexch_set_ctx_params(void *ctx, const OSSL_PARAM params[]);
const OSSL_PARAM *OSSL_FUNC_keyexch_settable_ctx_params(void *ctx,
void *provctx);
int OSSL_FUNC_keyexch_get_ctx_params(void *ctx, OSSL_PARAM params[]);
const OSSL_PARAM *OSSL_FUNC_keyexch_gettable_ctx_params(void *ctx,
void *provctx);
Heads up bestie: none of these are actual functions β they're displayed like this because they're the function signatures for functions that are offered as function pointers in OSSL_DISPATCH arrays. The original says it right in the comments, so here's the full synopsis, exactly as it is π
The synopsis groups them like this:
- Context management β
OSSL_FUNC_keyexch_newctx,OSSL_FUNC_keyexch_freectx,OSSL_FUNC_keyexch_dupctx - Shared secret derivation β
OSSL_FUNC_keyexch_init,OSSL_FUNC_keyexch_set_peer,OSSL_FUNC_keyexch_derive,OSSL_FUNC_keyexch_derive_skey - Key Exchange parameters β
OSSL_FUNC_keyexch_set_ctx_params,OSSL_FUNC_keyexch_settable_ctx_params,OSSL_FUNC_keyexch_get_ctx_params,OSSL_FUNC_keyexch_gettable_ctx_params
π DESCRIPTION π
okay so first things first: this page is mostly for provider authors, bestie. Like, if you're just out here calling functions, go read provider(7) instead, this one's for the people building the thing.
The key exchange operation β that's OSSL_OP_KEYEXCH if we're being formal β is what lets providers implement key exchange algorithms and hand them off to applications through EVP_PKEY_derive(3) and all the other related functions. π«Ά
So all the "functions" we're talking about here? They get passed around as function pointers between libcrypto and your provider inside OSSL_DISPATCH(3) arrays, which live inside OSSL_ALGORITHM(3) arrays, which get returned by your provider's provider_query_operation() function. (check out "Provider Functions" in provider-base(7) if you wanna see the whole handoff π
)
Every single one of these "functions" has a matching function type definition named OSSL_FUNC_{name}_fn, plus a lil helper that pulls the function pointer out of an OSSL_DISPATCH(3) element, named OSSL_FUNC_{name}. Like for example, the "function" OSSL_FUNC_keyexch_newctx() has these:
typedef void *(OSSL_FUNC_keyexch_newctx_fn)(void *provctx);
static ossl_inline OSSL_FUNC_keyexch_newctx_fn
OSSL_FUNC_keyexch_newctx(const OSSL_DISPATCH *opf);
And the OSSL_DISPATCH(3) arrays are indexed by numbers, and those numbers are given to you as macros in openssl-core_dispatch.h(7). Here's the whole map, no cap:
OSSL_FUNC_keyexch_newctx OSSL_FUNC_KEYEXCH_NEWCTX
OSSL_FUNC_keyexch_freectx OSSL_FUNC_KEYEXCH_FREECTX
OSSL_FUNC_keyexch_dupctx OSSL_FUNC_KEYEXCH_DUPCTX
OSSL_FUNC_keyexch_init OSSL_FUNC_KEYEXCH_INIT
OSSL_FUNC_keyexch_set_peer OSSL_FUNC_KEYEXCH_SET_PEER
OSSL_FUNC_keyexch_derive OSSL_FUNC_KEYEXCH_DERIVE
OSSL_FUNC_keyexch_derive_skey OSSL_FUNC_KEYEXCH_DERIVE_SKEY
OSSL_FUNC_keyexch_set_ctx_params OSSL_FUNC_KEYEXCH_SET_CTX_PARAMS
OSSL_FUNC_keyexch_settable_ctx_params OSSL_FUNC_KEYEXCH_SETTABLE_CTX_PARAMS
OSSL_FUNC_keyexch_get_ctx_params OSSL_FUNC_KEYEXCH_GET_CTX_PARAMS
OSSL_FUNC_keyexch_gettable_ctx_params OSSL_FUNC_KEYEXCH_GETTABLE_CTX_PARAMS
Now β and this part matters β a key exchange algorithm implementation doesn't have to implement all of these. To be a "consistent set of functions" tho, your provider must implement OSSL_FUNC_keyexch_newctx, OSSL_FUNC_keyexch_freectx, OSSL_FUNC_keyexch_init, and at least one of OSSL_FUNC_keyexch_derive and OSSL_FUNC_keyexch_derive_skey. Everything else? Optional, babe. π
Also a key exchange algorithm has to implement some way of generating, loading, or importing keys, through the key management operation (OSSL_OP_KEYMGMT). Go peek at provider-keymgmt(7) for the deets.
π Context Management Functions π
OSSL_FUNC_keyexch_newctx()β should create and return a pointer to a provider side structure that holds context info during a key exchange operation. That pointer gets passed back into a bunch of the other key exchange operation function calls. Theprovctxparameter is the provider context that got generated during provider initialisation (seeprovider(7)). β¨OSSL_FUNC_keyexch_freectx()β gets handed a pointer to the provider side key exchange context in thectxparameter, and it should free anything and everything associated with that context. clean up after urself bestie π§ΉOSSL_FUNC_keyexch_dupctx()β should duplicate the provider side key exchange context in thectxparameter and return the duplicate copy. twin energy π―ββοΈ
πΈ Shared Secret Derivation Functions πΈ
OSSL_FUNC_keyexch_init()β initialises a key exchange operation. You give it a provider side key exchange context in thectxparameter, plus a pointer to a provider key object in theprovkeyparameter. Theparams, if they're notNULL, should be set on the context kind of the same way you'd do it withOSSL_FUNC_keyexch_set_ctx_params(). And that key object should've already been generated, loaded, or imported into the provider using the key management (OSSL_OP_KEYMGMT) operation (seeprovider-keymgmt(7)).OSSL_FUNC_keyexch_set_peer()β gets called to supply the peer's public key (in theprovkeyparameter) that you'll use when deriving the shared secret. It also gets a previously initialised key exchange context in thectxparameter. Same deal as before: the key object should've already been generated, loaded, or imported into the provider using the key management (OSSL_OP_KEYMGMT) operation (seeprovider-keymgmt(7)).OSSL_FUNC_keyexch_derive()β this is the one doing the actual key exchange, deriving the shared secret for real. A previously initialised key exchange context comes in via thectxparameter. The derived secret should be written to the locationsecret, and it must not exceedoutlenbytes. The length of the shared secret should be written to*secretlen. And ifsecretisNULL, then you write the maximum length of the shared secret to*secretleninstead. (sizing query moment π )OSSL_FUNC_keyexch_derive_skey()β basicallyOSSL_FUNC_keyexch_derive()'s cousin, but it uses an opaque object to store the derived key. It takes akey_typeparameter that hints to the provider what type of key would be generated (like, generic or AES, for example), plus an import function from theEVP_SKEYMGMTobject to be associated with the key. Oh and β theEVP_SKEYMGMTobject comes from the same provider as the key exchange implementation. iykyk. π
π Key Exchange Parameters Functions π
OSSL_FUNC_keyexch_set_ctx_params()β sets key exchange parameters associated with the given provider side key exchange contextctxtoparams, see "Common Key Exchange parameters" below. Any param settings you do here are additional to whatever was set before (they stack, they don't replace π«Ά). PassingNULLforparamsshould return true.OSSL_FUNC_keyexch_get_ctx_params()β gets key exchange parameters associated with the given provider side key exchange contextctxintoparams, see "Common Key Exchange parameters". PassingNULLforparamsshould return true.OSSL_FUNC_keyexch_settable_ctx_params()β yields a constantOSSL_PARAM(3)array describing the settable parameters, aka the ones you can use withOP_signature_set_ctx_params(). IfOSSL_FUNC_keyexch_settable_ctx_params()is present, thenOSSL_FUNC_keyexch_set_ctx_params()must also be present, and vice versa. Same energy forOSSL_FUNC_keyexch_gettable_ctx_params(): it yields a constantOSSL_PARAM(3)array describing the gettable parameters, aka the ones that can be handled byOP_signature_get_ctx_params(). IfOSSL_FUNC_keyexch_gettable_ctx_params()is present, thenOSSL_FUNC_keyexch_get_ctx_params()must also be present, and vice versa. it's giving package deal β¨
Heads up: not all settable parameters are also gettable, and vice versa. not everything goes both ways, and that's fine π
β Common Key Exchange parameters β
Peep OSSL_PARAM(3) for the full run-down on the parameters structure used by the OSSL_FUNC_keyexch_set_ctx_params() and OSSL_FUNC_keyexch_get_ctx_params() functions.
Here are the common parameters that the built-in key exchange algorithms currently recognise:
"kdf-type"(OSSL_EXCHANGE_PARAM_KDF_TYPE)<UTF8 string>β sets or gets the Key Derivation Function type to apply within the associated key exchangectx."kdf-digest"(OSSL_EXCHANGE_PARAM_KDF_DIGEST)<UTF8 string>β sets or gets the Digest algorithm to be used as part of the Key Derivation Function associated with the given key exchangectx."kdf-digest-props"(OSSL_EXCHANGE_PARAM_KDF_DIGEST_PROPS)<UTF8 string>β sets properties to be used when looking up the implementation for the selected Digest algorithm for the Key Derivation Function associated with the given key exchangectx."kdf-outlen"(OSSL_EXCHANGE_PARAM_KDF_OUTLEN)<unsigned integer>β sets or gets the desired size for the output of the chosen Key Derivation Function associated with the given key exchangectx. The length of the"kdf-outlen"parameter should not exceed that of asize_t."kdf-ukm"(OSSL_EXCHANGE_PARAM_KDF_UKM)<octet string>β sets the User Key Material to be used as part of the selected Key Derivation Function associated with the given key exchangectx."kdf-ukm"(OSSL_EXCHANGE_PARAM_KDF_UKM)<octet string ptr>β gets a pointer to the User Key Material to be used as part of the selected Key Derivation Function associated with the given key exchangectx. Providers usually don't need to support this gettable parameter, because its only purpose is to support the functionality of the deprecatedEVP_PKEY_CTX_get0_ecdh_kdf_ukm()andEVP_PKEY_CTX_get0_dh_kdf_ukm()functions. (deprecated things staying deprecated, we love to see it π)
The OpenSSL FIPS provider also supports these bad boys:
"fips-indicator"(OSSL_EXCHANGE_PARAM_FIPS_APPROVED_INDICATOR)<integer>β a getter that returns 1 if the operation is FIPS approved, or 0 otherwise. You can use this after callingOSSL_FUNC_keyexch_derive(). It may return 0 if either the"digest-check"or the"key-check"are set to 0."key-check"(OSSL_EXCHANGE_PARAM_FIPS_KEY_CHECK)<integer>β if you require it, this parameter should be set usingOSSL_FUNC_keyexch_init(). The default value of1causes an error during the init if the key is not FIPS approved (e.g. the key has a security strength of less than 112 bits). Setting this to0will ignore the error and set the approved"fips-indicator"to 0. This option breaks FIPS compliance if it causes the approved"fips-indicator"to return 0."digest-check"(OSSL_EXCHANGE_PARAM_FIPS_DIGEST_CHECK)<integer>β if you require it, this parameter should be set before any optional digest is set. The default value of1causes an error when the digest is set, if the digest is not FIPS approved. Setting this to0will ignore the error and set the approved"fips-indicator"to 0. This option breaks FIPS compliance if it causes the approved"fips-indicator"to return 0.
β¨ RETURN VALUES β¨
OSSL_FUNC_keyexch_newctx()andOSSL_FUNC_keyexch_dupctx()should return the newly created provider side key exchange context, orNULLon failure. πOSSL_FUNC_keyexch_derive_skey()should return the newly created opaque provider-side key object, orNULLon failure. πOSSL_FUNC_keyexch_init(),OSSL_FUNC_keyexch_set_peer(),OSSL_FUNC_keyexch_derive(),OSSL_FUNC_keyexch_set_ctx_params(), andOSSL_FUNC_keyexch_get_ctx_params()should return1for success or0on error. (classic yes/no, iconique)OSSL_FUNC_keyexch_settable_ctx_params()andOSSL_FUNC_keyexch_gettable_ctx_params()should always return a constantOSSL_PARAM(3)array. no exceptions bestie π«Ά
π SEE ALSO π
π¦ HISTORY π¦
- The provider KEYEXCH interface was introduced in OpenSSL 3.0. π±
- The Key Exchange Parameters
"fips-indicator","key-check"and"digest-check"were added in OpenSSL 3.4. - The
OSSL_FUNC_keyexch_derive_skey()function was added in OpenSSL 3.6. π₯
π 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 a wrap on the whole page, bestie!! π this version came from source 4.0.3, dated 2026-09-29, and it's officially page PROVIDER-KEYEXCH(7SSL) β go forth and derive those shared secrets responsibly, mwah πβ¨π¦
π¦ where this page comes from
- ubuntu stonking: openssl 4.0.3-1ubuntu1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms