1*b077aed3SPierre Pronchery=pod 2*b077aed3SPierre Pronchery 3*b077aed3SPierre Pronchery=head1 NAME 4*b077aed3SPierre Pronchery 5*b077aed3SPierre Proncheryprovider-kem - The kem library E<lt>-E<gt> provider functions 6*b077aed3SPierre Pronchery 7*b077aed3SPierre Pronchery=head1 SYNOPSIS 8*b077aed3SPierre Pronchery 9*b077aed3SPierre Pronchery=for openssl multiple includes 10*b077aed3SPierre Pronchery 11*b077aed3SPierre Pronchery #include <openssl/core_dispatch.h> 12*b077aed3SPierre Pronchery #include <openssl/core_names.h> 13*b077aed3SPierre Pronchery 14*b077aed3SPierre Pronchery /* 15*b077aed3SPierre Pronchery * None of these are actual functions, but are displayed like this for 16*b077aed3SPierre Pronchery * the function signatures for functions that are offered as function 17*b077aed3SPierre Pronchery * pointers in OSSL_DISPATCH arrays. 18*b077aed3SPierre Pronchery */ 19*b077aed3SPierre Pronchery 20*b077aed3SPierre Pronchery /* Context management */ 21*b077aed3SPierre Pronchery void *OSSL_FUNC_kem_newctx(void *provctx); 22*b077aed3SPierre Pronchery void OSSL_FUNC_kem_freectx(void *ctx); 23*b077aed3SPierre Pronchery void *OSSL_FUNC_kem_dupctx(void *ctx); 24*b077aed3SPierre Pronchery 25*b077aed3SPierre Pronchery /* Encapsulation */ 26*b077aed3SPierre Pronchery int OSSL_FUNC_kem_encapsulate_init(void *ctx, void *provkey, const char *name, 27*b077aed3SPierre Pronchery const OSSL_PARAM params[]); 28*b077aed3SPierre Pronchery int OSSL_FUNC_kem_encapsulate(void *ctx, unsigned char *out, size_t *outlen, 29*b077aed3SPierre Pronchery unsigned char *secret, size_t *secretlen); 30*b077aed3SPierre Pronchery 31*b077aed3SPierre Pronchery /* Decapsulation */ 32*b077aed3SPierre Pronchery int OSSL_FUNC_kem_decapsulate_init(void *ctx, void *provkey, const char *name); 33*b077aed3SPierre Pronchery int OSSL_FUNC_kem_decapsulate(void *ctx, unsigned char *out, size_t *outlen, 34*b077aed3SPierre Pronchery const unsigned char *in, size_t inlen); 35*b077aed3SPierre Pronchery 36*b077aed3SPierre Pronchery /* KEM parameters */ 37*b077aed3SPierre Pronchery int OSSL_FUNC_kem_get_ctx_params(void *ctx, OSSL_PARAM params[]); 38*b077aed3SPierre Pronchery const OSSL_PARAM *OSSL_FUNC_kem_gettable_ctx_params(void *ctx, void *provctx); 39*b077aed3SPierre Pronchery int OSSL_FUNC_kem_set_ctx_params(void *ctx, const OSSL_PARAM params[]); 40*b077aed3SPierre Pronchery const OSSL_PARAM *OSSL_FUNC_kem_settable_ctx_params(void *ctx, void *provctx); 41*b077aed3SPierre Pronchery 42*b077aed3SPierre Pronchery=head1 DESCRIPTION 43*b077aed3SPierre Pronchery 44*b077aed3SPierre ProncheryThis documentation is primarily aimed at provider authors. See L<provider(7)> 45*b077aed3SPierre Proncheryfor further information. 46*b077aed3SPierre Pronchery 47*b077aed3SPierre ProncheryThe asymmetric kem (OSSL_OP_KEM) operation enables providers to 48*b077aed3SPierre Proncheryimplement asymmetric kem algorithms and make them available to applications 49*b077aed3SPierre Proncheryvia the API functions L<EVP_PKEY_encapsulate(3)>, 50*b077aed3SPierre ProncheryL<EVP_PKEY_decapsulate(3)> and other related functions. 51*b077aed3SPierre Pronchery 52*b077aed3SPierre ProncheryAll "functions" mentioned here are passed as function pointers between 53*b077aed3SPierre ProncheryF<libcrypto> and the provider in L<OSSL_DISPATCH(3)> arrays via 54*b077aed3SPierre ProncheryL<OSSL_ALGORITHM(3)> arrays that are returned by the provider's 55*b077aed3SPierre Proncheryprovider_query_operation() function 56*b077aed3SPierre Pronchery(see L<provider-base(7)/Provider Functions>). 57*b077aed3SPierre Pronchery 58*b077aed3SPierre ProncheryAll these "functions" have a corresponding function type definition 59*b077aed3SPierre Proncherynamed B<OSSL_FUNC_{name}_fn>, and a helper function to retrieve the 60*b077aed3SPierre Proncheryfunction pointer from an L<OSSL_DISPATCH(3)> element named 61*b077aed3SPierre ProncheryB<OSSL_FUNC_{name}>. 62*b077aed3SPierre ProncheryFor example, the "function" OSSL_FUNC_kem_newctx() has these: 63*b077aed3SPierre Pronchery 64*b077aed3SPierre Pronchery typedef void *(OSSL_FUNC_kem_newctx_fn)(void *provctx); 65*b077aed3SPierre Pronchery static ossl_inline OSSL_FUNC_kem_newctx_fn 66*b077aed3SPierre Pronchery OSSL_FUNC_kem_newctx(const OSSL_DISPATCH *opf); 67*b077aed3SPierre Pronchery 68*b077aed3SPierre ProncheryL<OSSL_DISPATCH(3)> arrays are indexed by numbers that are provided as 69*b077aed3SPierre Proncherymacros in L<openssl-core_dispatch.h(7)>, as follows: 70*b077aed3SPierre Pronchery 71*b077aed3SPierre Pronchery OSSL_FUNC_kem_newctx OSSL_FUNC_KEM_NEWCTX 72*b077aed3SPierre Pronchery OSSL_FUNC_kem_freectx OSSL_FUNC_KEM_FREECTX 73*b077aed3SPierre Pronchery OSSL_FUNC_kem_dupctx OSSL_FUNC_KEM_DUPCTX 74*b077aed3SPierre Pronchery 75*b077aed3SPierre Pronchery OSSL_FUNC_kem_encapsulate_init OSSL_FUNC_KEM_ENCAPSULATE_INIT 76*b077aed3SPierre Pronchery OSSL_FUNC_kem_encapsulate OSSL_FUNC_KEM_ENCAPSULATE 77*b077aed3SPierre Pronchery 78*b077aed3SPierre Pronchery OSSL_FUNC_kem_decapsulate_init OSSL_FUNC_KEM_DECAPSULATE_INIT 79*b077aed3SPierre Pronchery OSSL_FUNC_kem_decapsulate OSSL_FUNC_KEM_DECAPSULATE 80*b077aed3SPierre Pronchery 81*b077aed3SPierre Pronchery OSSL_FUNC_kem_get_ctx_params OSSL_FUNC_KEM_GET_CTX_PARAMS 82*b077aed3SPierre Pronchery OSSL_FUNC_kem_gettable_ctx_params OSSL_FUNC_KEM_GETTABLE_CTX_PARAMS 83*b077aed3SPierre Pronchery OSSL_FUNC_kem_set_ctx_params OSSL_FUNC_KEM_SET_CTX_PARAMS 84*b077aed3SPierre Pronchery OSSL_FUNC_kem_settable_ctx_params OSSL_FUNC_KEM_SETTABLE_CTX_PARAMS 85*b077aed3SPierre Pronchery 86*b077aed3SPierre ProncheryAn asymmetric kem algorithm implementation may not implement all of these 87*b077aed3SPierre Proncheryfunctions. 88*b077aed3SPierre ProncheryIn order to be a consistent set of functions a provider must implement 89*b077aed3SPierre ProncheryOSSL_FUNC_kem_newctx and OSSL_FUNC_kem_freectx. 90*b077aed3SPierre ProncheryIt must also implement both of OSSL_FUNC_kem_encapsulate_init and 91*b077aed3SPierre ProncheryOSSL_FUNC_kem_encapsulate, or both of OSSL_FUNC_kem_decapsulate_init and 92*b077aed3SPierre ProncheryOSSL_FUNC_kem_decapsulate. 93*b077aed3SPierre ProncheryOSSL_FUNC_kem_get_ctx_params is optional but if it is present then so must 94*b077aed3SPierre ProncheryOSSL_FUNC_kem_gettable_ctx_params. 95*b077aed3SPierre ProncherySimilarly, OSSL_FUNC_kem_set_ctx_params is optional but if it is present then 96*b077aed3SPierre Proncheryso must OSSL_FUNC_kem_settable_ctx_params. 97*b077aed3SPierre Pronchery 98*b077aed3SPierre ProncheryAn asymmetric kem algorithm must also implement some mechanism for generating, 99*b077aed3SPierre Proncheryloading or importing keys via the key management (OSSL_OP_KEYMGMT) operation. 100*b077aed3SPierre ProncherySee L<provider-keymgmt(7)> for further details. 101*b077aed3SPierre Pronchery 102*b077aed3SPierre Pronchery=head2 Context Management Functions 103*b077aed3SPierre Pronchery 104*b077aed3SPierre ProncheryOSSL_FUNC_kem_newctx() should create and return a pointer to a provider side 105*b077aed3SPierre Proncherystructure for holding context information during an asymmetric kem operation. 106*b077aed3SPierre ProncheryA pointer to this context will be passed back in a number of the other 107*b077aed3SPierre Proncheryasymmetric kem operation function calls. 108*b077aed3SPierre ProncheryThe parameter I<provctx> is the provider context generated during provider 109*b077aed3SPierre Proncheryinitialisation (see L<provider(7)>). 110*b077aed3SPierre Pronchery 111*b077aed3SPierre ProncheryOSSL_FUNC_kem_freectx() is passed a pointer to the provider side asymmetric 112*b077aed3SPierre Proncherykem context in the I<ctx> parameter. 113*b077aed3SPierre ProncheryThis function should free any resources associated with that context. 114*b077aed3SPierre Pronchery 115*b077aed3SPierre ProncheryOSSL_FUNC_kem_dupctx() should duplicate the provider side asymmetric kem 116*b077aed3SPierre Proncherycontext in the I<ctx> parameter and return the duplicate copy. 117*b077aed3SPierre Pronchery 118*b077aed3SPierre Pronchery=head2 Asymmetric Key Encapsulation Functions 119*b077aed3SPierre Pronchery 120*b077aed3SPierre ProncheryOSSL_FUNC_kem_encapsulate_init() initialises a context for an asymmetric 121*b077aed3SPierre Proncheryencapsulation given a provider side asymmetric kem context in the I<ctx> 122*b077aed3SPierre Proncheryparameter, a pointer to a provider key object in the I<provkey> parameter and 123*b077aed3SPierre Proncherythe I<name> of the algorithm. 124*b077aed3SPierre ProncheryThe I<params>, if not NULL, should be set on the context in a manner similar to 125*b077aed3SPierre Proncheryusing OSSL_FUNC_kem_set_ctx_params(). 126*b077aed3SPierre ProncheryThe key object should have been previously generated, loaded or imported into 127*b077aed3SPierre Proncherythe provider using the key management (OSSL_OP_KEYMGMT) operation (see 128*b077aed3SPierre Proncheryprovider-keymgmt(7)>. 129*b077aed3SPierre Pronchery 130*b077aed3SPierre ProncheryOSSL_FUNC_kem_encapsulate() performs the actual encapsulation itself. 131*b077aed3SPierre ProncheryA previously initialised asymmetric kem context is passed in the I<ctx> 132*b077aed3SPierre Proncheryparameter. 133*b077aed3SPierre ProncheryUnless I<out> is NULL, the data to be encapsulated is internally generated, 134*b077aed3SPierre Proncheryand returned into the buffer pointed to by the I<secret> parameter and the 135*b077aed3SPierre Proncheryencapsulated data should also be written to the location pointed to by the 136*b077aed3SPierre ProncheryI<out> parameter. The length of the encapsulated data should be written to 137*b077aed3SPierre ProncheryI<*outlen> and the length of the generated secret should be written to 138*b077aed3SPierre ProncheryI<*secretlen>. 139*b077aed3SPierre Pronchery 140*b077aed3SPierre ProncheryIf I<out> is NULL then the maximum length of the encapsulated data should be 141*b077aed3SPierre Proncherywritten to I<*outlen>, and the maximum length of the generated secret should be 142*b077aed3SPierre Proncherywritten to I<*secretlen>. 143*b077aed3SPierre Pronchery 144*b077aed3SPierre Pronchery=head2 Decapsulation Functions 145*b077aed3SPierre Pronchery 146*b077aed3SPierre ProncheryOSSL_FUNC_kem_decapsulate_init() initialises a context for an asymmetric 147*b077aed3SPierre Proncherydecapsulation given a provider side asymmetric kem context in the I<ctx> 148*b077aed3SPierre Proncheryparameter, a pointer to a provider key object in the I<provkey> parameter, and 149*b077aed3SPierre Proncherya I<name> of the algorithm. 150*b077aed3SPierre ProncheryThe key object should have been previously generated, loaded or imported into 151*b077aed3SPierre Proncherythe provider using the key management (OSSL_OP_KEYMGMT) operation (see 152*b077aed3SPierre Proncheryprovider-keymgmt(7)>. 153*b077aed3SPierre Pronchery 154*b077aed3SPierre ProncheryOSSL_FUNC_kem_decapsulate() performs the actual decapsulation itself. 155*b077aed3SPierre ProncheryA previously initialised asymmetric kem context is passed in the I<ctx> 156*b077aed3SPierre Proncheryparameter. 157*b077aed3SPierre ProncheryThe data to be decapsulated is pointed to by the I<in> parameter which is I<inlen> 158*b077aed3SPierre Proncherybytes long. 159*b077aed3SPierre ProncheryUnless I<out> is NULL, the decapsulated data should be written to the location 160*b077aed3SPierre Proncherypointed to by the I<out> parameter. 161*b077aed3SPierre ProncheryThe length of the decapsulated data should be written to I<*outlen>. 162*b077aed3SPierre ProncheryIf I<out> is NULL then the maximum length of the decapsulated data should be 163*b077aed3SPierre Proncherywritten to I<*outlen>. 164*b077aed3SPierre Pronchery 165*b077aed3SPierre Pronchery=head2 Asymmetric Key Encapsulation Parameters 166*b077aed3SPierre Pronchery 167*b077aed3SPierre ProncherySee L<OSSL_PARAM(3)> for further details on the parameters structure used by 168*b077aed3SPierre Proncherythe OSSL_FUNC_kem_get_ctx_params() and OSSL_FUNC_kem_set_ctx_params() 169*b077aed3SPierre Proncheryfunctions. 170*b077aed3SPierre Pronchery 171*b077aed3SPierre ProncheryOSSL_FUNC_kem_get_ctx_params() gets asymmetric kem parameters associated 172*b077aed3SPierre Proncherywith the given provider side asymmetric kem context I<ctx> and stores them in 173*b077aed3SPierre ProncheryI<params>. 174*b077aed3SPierre ProncheryPassing NULL for I<params> should return true. 175*b077aed3SPierre Pronchery 176*b077aed3SPierre ProncheryOSSL_FUNC_kem_set_ctx_params() sets the asymmetric kem parameters associated 177*b077aed3SPierre Proncherywith the given provider side asymmetric kem context I<ctx> to I<params>. 178*b077aed3SPierre ProncheryAny parameter settings are additional to any that were previously set. 179*b077aed3SPierre ProncheryPassing NULL for I<params> should return true. 180*b077aed3SPierre Pronchery 181*b077aed3SPierre ProncheryNo parameters are currently recognised by built-in asymmetric kem algorithms. 182*b077aed3SPierre Pronchery 183*b077aed3SPierre ProncheryOSSL_FUNC_kem_gettable_ctx_params() and OSSL_FUNC_kem_settable_ctx_params() 184*b077aed3SPierre Proncheryget a constant L<OSSL_PARAM(3)> array that describes the gettable and settable 185*b077aed3SPierre Proncheryparameters, i.e. parameters that can be used with OSSL_FUNC_kem_get_ctx_params() 186*b077aed3SPierre Proncheryand OSSL_FUNC_kem_set_ctx_params() respectively. 187*b077aed3SPierre Pronchery 188*b077aed3SPierre Pronchery=head1 RETURN VALUES 189*b077aed3SPierre Pronchery 190*b077aed3SPierre ProncheryOSSL_FUNC_kem_newctx() and OSSL_FUNC_kem_dupctx() should return the newly 191*b077aed3SPierre Proncherycreated provider side asymmetric kem context, or NULL on failure. 192*b077aed3SPierre Pronchery 193*b077aed3SPierre ProncheryAll other functions should return 1 for success or 0 on error. 194*b077aed3SPierre Pronchery 195*b077aed3SPierre Pronchery=head1 SEE ALSO 196*b077aed3SPierre Pronchery 197*b077aed3SPierre ProncheryL<provider(7)> 198*b077aed3SPierre Pronchery 199*b077aed3SPierre Pronchery=head1 HISTORY 200*b077aed3SPierre Pronchery 201*b077aed3SPierre ProncheryThe provider KEM interface was introduced in OpenSSL 3.0. 202*b077aed3SPierre Pronchery 203*b077aed3SPierre Pronchery=head1 COPYRIGHT 204*b077aed3SPierre Pronchery 205*b077aed3SPierre ProncheryCopyright 2020-2021 The OpenSSL Project Authors. All Rights Reserved. 206*b077aed3SPierre Pronchery 207*b077aed3SPierre ProncheryLicensed under the Apache License 2.0 (the "License"). You may not use 208*b077aed3SPierre Proncherythis file except in compliance with the License. You can obtain a copy 209*b077aed3SPierre Proncheryin the file LICENSE in the source distribution or at 210*b077aed3SPierre ProncheryL<https://www.openssl.org/source/license.html>. 211*b077aed3SPierre Pronchery 212*b077aed3SPierre Pronchery=cut 213