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. The provctx parameter is the provider context that got generated during provider initialisation (see provider(7)). ✨
  • OSSL_FUNC_keyexch_freectx() β€” gets handed a pointer to the provider side key exchange context in the ctx parameter, 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 the ctx parameter 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 the ctx parameter, plus a pointer to a provider key object in the provkey parameter. The params, if they're not NULL, should be set on the context kind of the same way you'd do it with OSSL_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 (see provider-keymgmt(7)).
  • OSSL_FUNC_keyexch_set_peer() β€” gets called to supply the peer's public key (in the provkey parameter) that you'll use when deriving the shared secret. It also gets a previously initialised key exchange context in the ctx parameter. 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 (see provider-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 the ctx parameter. The derived secret should be written to the location secret, and it must not exceed outlen bytes. The length of the shared secret should be written to *secretlen. And if secret is NULL, then you write the maximum length of the shared secret to *secretlen instead. (sizing query moment πŸ’…)
  • OSSL_FUNC_keyexch_derive_skey() β€” basically OSSL_FUNC_keyexch_derive()'s cousin, but it uses an opaque object to store the derived key. It takes a key_type parameter that hints to the provider what type of key would be generated (like, generic or AES, for example), plus an import function from the EVP_SKEYMGMT object to be associated with the key. Oh and β€” the EVP_SKEYMGMT object 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 context ctx to params, 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 🫢). Passing NULL for params should return true.
  • OSSL_FUNC_keyexch_get_ctx_params() β€” gets key exchange parameters associated with the given provider side key exchange context ctx into params, see "Common Key Exchange parameters". Passing NULL for params should return true.
  • OSSL_FUNC_keyexch_settable_ctx_params() β€” yields a constant OSSL_PARAM(3) array describing the settable parameters, aka the ones you can use with OP_signature_set_ctx_params(). If OSSL_FUNC_keyexch_settable_ctx_params() is present, then OSSL_FUNC_keyexch_set_ctx_params() must also be present, and vice versa. Same energy for OSSL_FUNC_keyexch_gettable_ctx_params(): it yields a constant OSSL_PARAM(3) array describing the gettable parameters, aka the ones that can be handled by OP_signature_get_ctx_params(). If OSSL_FUNC_keyexch_gettable_ctx_params() is present, then OSSL_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 exchange ctx.
  • "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 exchange ctx.
  • "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 exchange ctx.
  • "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 exchange ctx. The length of the "kdf-outlen" parameter should not exceed that of a size_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 exchange ctx.
  • "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 exchange ctx. Providers usually don't need to support this gettable parameter, because its only purpose is to support the functionality of the deprecated EVP_PKEY_CTX_get0_ecdh_kdf_ukm() and EVP_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 calling OSSL_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 using OSSL_FUNC_keyexch_init(). The default value of 1 causes 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 to 0 will 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 of 1 causes an error when the digest is set, if the digest is not FIPS approved. Setting this to 0 will 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() and OSSL_FUNC_keyexch_dupctx() should return the newly created provider side key exchange context, or NULL on failure. πŸ’€
  • OSSL_FUNC_keyexch_derive_skey() should return the newly created opaque provider-side key object, or NULL on failure. πŸ’€
  • OSSL_FUNC_keyexch_init(), OSSL_FUNC_keyexch_set_peer(), OSSL_FUNC_keyexch_derive(), OSSL_FUNC_keyexch_set_ctx_params(), and OSSL_FUNC_keyexch_get_ctx_params() should return 1 for success or 0 on error. (classic yes/no, iconique)
  • OSSL_FUNC_keyexch_settable_ctx_params() and OSSL_FUNC_keyexch_gettable_ctx_params() should always return a constant OSSL_PARAM(3) array. no exceptions bestie 🫢

πŸ‘‘ SEE ALSO πŸ‘‘

provider(7)

πŸ¦‹ 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 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