PROVIDER-KEM(7SSL)

πŸŽ€ provider-kem πŸŽ€ β€” the kem library ↔ provider functions (it's giving OpenSSL, fr)

ok so bestie, welcome to PROVIDER-KEM(7SSL) πŸ’– this is one of the OpenSSL pages, and honestly it's a lot, but we're gonna get through it together. No cap. Grab a snack. πŸ“


✨ NAME ✨

provider-kem β€” the kem library <-> provider functions.

no fr that's the whole name section, short and sweet, iconic behavior honestly πŸ’…


🌸 SYNOPSIS 🌸

#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_kem_newctx(void *provctx);
void OSSL_FUNC_kem_freectx(void *ctx);
void *OSSL_FUNC_kem_dupctx(void *ctx);

/* Encapsulation */
int OSSL_FUNC_kem_encapsulate_init(void *ctx, void *provkey,
                                   const OSSL_PARAM params[]);
int OSSL_FUNC_kem_auth_encapsulate_init(void *ctx, void *provkey,
                                        void *provauthkey,
                                        const OSSL_PARAM params[]);
int OSSL_FUNC_kem_encapsulate(void *ctx, unsigned char *out, size_t *outlen,
                              unsigned char *secret, size_t *secretlen);

/* Decapsulation */
int OSSL_FUNC_kem_decapsulate_init(void *ctx, void *provkey,
                                   const OSSL_PARAM params[]);
int OSSL_FUNC_kem_auth_decapsulate_init(void *ctx, void *provkey,
                                        void *provauthkey,
                                        const OSSL_PARAM params[]);
int OSSL_FUNC_kem_decapsulate(void *ctx, unsigned char *out, size_t *outlen,
                              const unsigned char *in, size_t inlen);

/* KEM parameters */
int OSSL_FUNC_kem_get_ctx_params(void *ctx, OSSL_PARAM params[]);
const OSSL_PARAM *OSSL_FUNC_kem_gettable_ctx_params(void *ctx, void *provctx);
int OSSL_FUNC_kem_set_ctx_params(void *ctx, const OSSL_PARAM params[]);
const OSSL_PARAM *OSSL_FUNC_kem_settable_ctx_params(void *ctx, void *provctx);

and yes, they all look like regular functions but they are not 😭 the comment up top literally says so β€” this is just how we display the function signatures of stuff that gets handed around as function pointers inside OSSL_DISPATCH arrays. iykyk.


πŸ¦‹ DESCRIPTION πŸ¦‹

ok so first thing β€” this documentation is primarily aimed at provider authors, bestie. If that's not you, go peek at provider(7) for the bigger picture. 🫢

The asymmetric kem (OSSL_OP_KEM) operation is what lets providers implement asymmetric kem algorithms and then make them available to applications through the API functions EVP_PKEY_encapsulate(3), EVP_PKEY_decapsulate(3) and other related functions. very demure, very mindful, very encapsulation-core. ✨

All the "functions" mentioned here (and yes, the scare quotes are load-bearing) get passed as function pointers between libcrypto and the provider inside OSSL_DISPATCH(3) arrays, which themselves live inside OSSL_ALGORITHM(3) arrays that are returned by the provider's provider_query_operation() function β€” see "Provider Functions" in provider-base(7). nesting dolls but make it crypto. πŸͺ†

Every one of these "functions" has two friends:

  • a corresponding function type definition named OSSL_FUNC_{name}_fn, and
  • a helper function to grab the function pointer out of an OSSL_DISPATCH(3) element, named OSSL_FUNC_{name}.

so like, for the "function" OSSL_FUNC_kem_newctx() you get these two:

typedef void *(OSSL_FUNC_kem_newctx_fn)(void *provctx);
static ossl_inline OSSL_FUNC_kem_newctx_fn
    OSSL_FUNC_kem_newctx(const OSSL_DISPATCH *opf);

and the OSSL_DISPATCH(3) arrays are indexed by numbers that are handed to you as macros in openssl-core_dispatch.h(7), like this:

OSSL_FUNC_kem_newctx                OSSL_FUNC_KEM_NEWCTX
OSSL_FUNC_kem_freectx               OSSL_FUNC_KEM_FREECTX
OSSL_FUNC_kem_dupctx                OSSL_FUNC_KEM_DUPCTX

OSSL_FUNC_kem_encapsulate_init      OSSL_FUNC_KEM_ENCAPSULATE_INIT
OSSL_FUNC_kem_auth_encapsulate_init OSSL_FUNC_KEM_AUTH_ENCAPSULATE_INIT
OSSL_FUNC_kem_encapsulate           OSSL_FUNC_KEM_ENCAPSULATE

OSSL_FUNC_kem_decapsulate_init      OSSL_FUNC_KEM_DECAPSULATE_INIT
OSSL_FUNC_kem_auth_decapsulate_init OSSL_FUNC_KEM_AUTH_DECAPSULATE_INIT
OSSL_FUNC_kem_decapsulate           OSSL_FUNC_KEM_DECAPSULATE

OSSL_FUNC_kem_get_ctx_params        OSSL_FUNC_KEM_GET_CTX_PARAMS
OSSL_FUNC_kem_gettable_ctx_params   OSSL_FUNC_KEM_GETTABLE_CTX_PARAMS
OSSL_FUNC_kem_set_ctx_params        OSSL_FUNC_KEM_SET_CTX_PARAMS
OSSL_FUNC_kem_settable_ctx_params   OSSL_FUNC_KEM_SETTABLE_CTX_PARAMS

now, vibe check on the rules, because this is the part that lowkey matters most πŸ‘‘

  • an asymmetric kem algorithm implementation may not implement all of these functions, and that's fine.
  • but to be a consistent set of functions, a provider must implement OSSL_FUNC_kem_newctx and OSSL_FUNC_kem_freectx. non-negotiable.
  • it must also implement both OSSL_FUNC_kem_encapsulate_init and OSSL_FUNC_kem_encapsulate, or both OSSL_FUNC_kem_decapsulate_init and OSSL_FUNC_kem_decapsulate. pick your lane, but commit. πŸ’…
  • OSSL_FUNC_kem_auth_encapsulate_init is optional β€” but if it's present, then so must OSSL_FUNC_kem_auth_decapsulate_init be. they're a package deal, like you and your emotional support water bottle.
  • OSSL_FUNC_kem_get_ctx_params is optional β€” but if it's present, then so must OSSL_FUNC_kem_gettable_ctx_params be.
  • similarly, OSSL_FUNC_kem_set_ctx_params is optional β€” but if it's present then OSSL_FUNC_kem_settable_ctx_params must also be present.

and one more: an asymmetric kem algorithm must also implement some mechanism for generating, loading or importing keys via the key management (OSSL_OP_KEYMGMT) operation. go read provider-keymgmt(7) for the details, bestie.

πŸ’œ Context Management Functions πŸ’œ

OSSL_FUNC_kem_newctx() should create and return a pointer to a provider-side structure that holds context information during an asymmetric kem operation. that pointer gets passed back into a bunch of the other asymmetric kem operation function calls. the parameter provctx is the provider context that was generated during provider initialisation β€” see provider(7). ✨

OSSL_FUNC_kem_freectx() gets handed a pointer to the provider-side asymmetric kem context in the ctx parameter. this function should free any resources associated with that context. clean up after yourself, queen. 🧹

OSSL_FUNC_kem_dupctx() should duplicate the provider-side asymmetric kem context in the ctx parameter and return the duplicate copy. twin where have you been πŸ¦‹

🌈 Asymmetric Key Encapsulation Functions 🌈

OSSL_FUNC_kem_encapsulate_init() initialises a context for an asymmetric encapsulation, given a provider-side asymmetric kem 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 in a manner similar to using OSSL_FUNC_kem_set_ctx_params(). the key object should have been previously generated, loaded or imported into the provider using the key management (OSSL_OP_KEYMGMT) operation (see provider-keymgmt(7)).

OSSL_FUNC_kem_auth_encapsulate_init() is basically OSSL_FUNC_kem_encapsulate_init() but it also passes an additional authentication key provauthkey, which cannot be NULL. it said what it said. πŸ™ˆ

OSSL_FUNC_kem_encapsulate() does the actual encapsulation itself. 😀 a previously initialised asymmetric kem context comes in through the ctx parameter. unless out is NULL, the data to be encapsulated is generated internally and returned into the buffer that the secret parameter points to, and the encapsulated data should also be written to the location out points to. the length of the encapsulated data should be written to *outlen, and the length of the generated secret should be written to *secretlen.

and if out is NULL? then the maximum length of the encapsulated data should be written to *outlen, and the maximum length of the generated secret should be written to *secretlen. it's giving "just tell me how much room I need" and honestly? respect. πŸ’…

🧚 Decapsulation Functions 🧚

OSSL_FUNC_kem_decapsulate_init() initialises a context for an asymmetric decapsulation, given a provider-side asymmetric kem 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 in a manner similar to using OSSL_FUNC_kem_set_ctx_params(). the key object should have been previously generated, loaded or imported into the provider using the key management (OSSL_OP_KEYMGMT) operation (see provider-keymgmt(7)).

OSSL_FUNC_kem_auth_decapsulate_init() is similar to OSSL_FUNC_kem_decapsulate_init(), but it also passes an additional authentication key provauthkey which cannot be NULL. same energy as before, no exceptions. πŸ’€

OSSL_FUNC_kem_decapsulate() does the actual decapsulation itself. a previously initialised asymmetric kem context arrives in the ctx parameter. the data to be decapsulated is pointed to by the in parameter, which is inlen bytes long. unless out is NULL, the decapsulated data should be written to the location out points to. the length of the decapsulated data should be written to *outlen. and if out is NULL then the maximum length of the decapsulated data should be written to *outlen. 🫑

⭐ Asymmetric Key Encapsulation Parameters ⭐

peep OSSL_PARAM(3) for more on the parameters structure that OSSL_FUNC_kem_get_ctx_params() and OSSL_FUNC_kem_set_ctx_params() use. πŸ“–

The OpenSSL FIPS provider also supports the following parameters:

  • "fips-indicator" (OSSL_KEM_PARAM_FIPS_APPROVED_INDICATOR) <integer> β€” a getter that returns 1 if the operation is FIPS approved, or 0 otherwise. this may be used after calling either OSSL_FUNC_kem_encapsulate() or OSSL_FUNC_kem_decapsulate(). it may return 0 if the "key-check" is set to 0.
  • "key-check" (OSSL_KEM_PARAM_FIPS_KEY_CHECK) <integer> β€” if required, this parameter should be set using OSSL_FUNC_kem_encapsulate_init() or OSSL_FUNC_kem_decapsulate_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. πŸ‘€ so like. know what you're doing, okay?

πŸ’– Asymmetric Key Encapsulation Parameter Functions πŸ’–

OSSL_FUNC_kem_get_ctx_params() gets asymmetric KEM parameters associated with the given provider-side asymmetric kem context ctx and stores them in params. passing NULL for params should return true.

OSSL_FUNC_kem_set_ctx_params() sets the asymmetric KEM parameters associated with the given provider-side asymmetric kem context ctx to params. any parameter settings are additional to any that were previously set. passing NULL for params should return true.

no parameters are currently recognised by built-in asymmetric kem algorithms. (so if you went looking for a big juicy list β€” there isn't one, bestie, it's a ghost town 🏜️)

OSSL_FUNC_kem_gettable_ctx_params() and OSSL_FUNC_kem_settable_ctx_params() get a constant OSSL_PARAM(3) array that describes the gettable and settable parameters β€” i.e. parameters that can be used with OSSL_FUNC_kem_get_ctx_params() and OSSL_FUNC_kem_set_ctx_params() respectively. πŸŽ€


πŸ”₯ RETURN VALUES πŸ”₯

OSSL_FUNC_kem_newctx() and OSSL_FUNC_kem_dupctx() should return the newly created provider-side asymmetric kem context, or NULL on failure.

All other functions should return 1 for success or 0 on error. that's it, that's the whole personality. πŸ’…


πŸ‘‘ SEE ALSO πŸ‘‘


🌟 HISTORY 🌟

  • The provider KEM interface was introduced in OpenSSL 3.0.
  • OSSL_FUNC_kem_auth_encapsulate_init() and OSSL_FUNC_kem_auth_decapsulate_init() were added in OpenSSL 3.2.
  • The Asymmetric Key Encapsulation Parameters "fips-indicator" and "key-check" were added in OpenSSL 3.4.

(part 2 is loading… don't go anywhere πŸ¦‹βœ¨)

Okay so before anyone comes for us: Copyright 2020-2026 The OpenSSL Project Authors. All Rights Reserved. πŸ’– Yeah, all of them. Every last right. We checked.

This file is licensed under the Apache License 2.0 (aka "the License", that's the official nickname, use it with respect ✨). And the rule is the rule, no negotiating:

You may not use this file except in compliance with the License. Like, genuinely. Read it first. It's giving terms and conditions but make it load-bearing. 🫢

Want your very own copy of the License? Periodt, here's where you get it:


And that's the whole page, bestie, you ✨ate✨ it. This one shipped as 4.0.3 dated 2026-09-29, and honestly? Iconic. Go read the license fr fr πŸ’…πŸ‘‘

πŸ“¦ where this page comes from