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, namedOSSL_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_newctxandOSSL_FUNC_kem_freectx. non-negotiable. - it must also implement both
OSSL_FUNC_kem_encapsulate_initandOSSL_FUNC_kem_encapsulate, or bothOSSL_FUNC_kem_decapsulate_initandOSSL_FUNC_kem_decapsulate. pick your lane, but commit. π OSSL_FUNC_kem_auth_encapsulate_initis optional β but if it's present, then so mustOSSL_FUNC_kem_auth_decapsulate_initbe. they're a package deal, like you and your emotional support water bottle.OSSL_FUNC_kem_get_ctx_paramsis optional β but if it's present, then so mustOSSL_FUNC_kem_gettable_ctx_paramsbe.- similarly,
OSSL_FUNC_kem_set_ctx_paramsis optional β but if it's present thenOSSL_FUNC_kem_settable_ctx_paramsmust 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 returns1if the operation is FIPS approved, or0otherwise. this may be used after calling eitherOSSL_FUNC_kem_encapsulate()orOSSL_FUNC_kem_decapsulate(). it may return0if the"key-check"is set to0."key-check"(OSSL_KEM_PARAM_FIPS_KEY_CHECK)<integer>β if required, this parameter should be set usingOSSL_FUNC_kem_encapsulate_init()orOSSL_FUNC_kem_decapsulate_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"to0. this option breaks FIPS compliance if it causes the approved"fips-indicator"to return0. π 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()andOSSL_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 π¦β¨)
π COPYRIGHT (the legal tea, bestie) π
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:
- In the file
LICENSEin the source distribution π - Or online, at <https://www.openssl.org/source/license.html> πΈ
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
- 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