1*b077aed3SPierre Pronchery=pod 2*b077aed3SPierre Pronchery 3*b077aed3SPierre Pronchery=head1 NAME 4*b077aed3SPierre Pronchery 5*b077aed3SPierre Proncheryprovider-keyexch - The keyexch 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_keyexch_newctx(void *provctx); 22*b077aed3SPierre Pronchery void OSSL_FUNC_keyexch_freectx(void *ctx); 23*b077aed3SPierre Pronchery void *OSSL_FUNC_keyexch_dupctx(void *ctx); 24*b077aed3SPierre Pronchery 25*b077aed3SPierre Pronchery /* Shared secret derivation */ 26*b077aed3SPierre Pronchery int OSSL_FUNC_keyexch_init(void *ctx, void *provkey, 27*b077aed3SPierre Pronchery const OSSL_PARAM params[]); 28*b077aed3SPierre Pronchery int OSSL_FUNC_keyexch_set_peer(void *ctx, void *provkey); 29*b077aed3SPierre Pronchery int OSSL_FUNC_keyexch_derive(void *ctx, unsigned char *secret, size_t *secretlen, 30*b077aed3SPierre Pronchery size_t outlen); 31*b077aed3SPierre Pronchery 32*b077aed3SPierre Pronchery /* Key Exchange parameters */ 33*b077aed3SPierre Pronchery int OSSL_FUNC_keyexch_set_ctx_params(void *ctx, const OSSL_PARAM params[]); 34*b077aed3SPierre Pronchery const OSSL_PARAM *OSSL_FUNC_keyexch_settable_ctx_params(void *ctx, 35*b077aed3SPierre Pronchery void *provctx); 36*b077aed3SPierre Pronchery int OSSL_FUNC_keyexch_get_ctx_params(void *ctx, OSSL_PARAM params[]); 37*b077aed3SPierre Pronchery const OSSL_PARAM *OSSL_FUNC_keyexch_gettable_ctx_params(void *ctx, 38*b077aed3SPierre Pronchery void *provctx); 39*b077aed3SPierre Pronchery 40*b077aed3SPierre Pronchery=head1 DESCRIPTION 41*b077aed3SPierre Pronchery 42*b077aed3SPierre ProncheryThis documentation is primarily aimed at provider authors. See L<provider(7)> 43*b077aed3SPierre Proncheryfor further information. 44*b077aed3SPierre Pronchery 45*b077aed3SPierre ProncheryThe key exchange (OSSL_OP_KEYEXCH) operation enables providers to implement key 46*b077aed3SPierre Proncheryexchange algorithms and make them available to applications via 47*b077aed3SPierre ProncheryL<EVP_PKEY_derive(3)> and 48*b077aed3SPierre Proncheryother related functions). 49*b077aed3SPierre Pronchery 50*b077aed3SPierre ProncheryAll "functions" mentioned here are passed as function pointers between 51*b077aed3SPierre ProncheryF<libcrypto> and the provider in L<OSSL_DISPATCH(3)> arrays via 52*b077aed3SPierre ProncheryL<OSSL_ALGORITHM(3)> arrays that are returned by the provider's 53*b077aed3SPierre Proncheryprovider_query_operation() function 54*b077aed3SPierre Pronchery(see L<provider-base(7)/Provider Functions>). 55*b077aed3SPierre Pronchery 56*b077aed3SPierre ProncheryAll these "functions" have a corresponding function type definition 57*b077aed3SPierre Proncherynamed B<OSSL_FUNC_{name}_fn>, and a helper function to retrieve the 58*b077aed3SPierre Proncheryfunction pointer from an L<OSSL_DISPATCH(3)> element named 59*b077aed3SPierre ProncheryB<OSSL_FUNC_{name}>. 60*b077aed3SPierre ProncheryFor example, the "function" OSSL_FUNC_keyexch_newctx() has these: 61*b077aed3SPierre Pronchery 62*b077aed3SPierre Pronchery typedef void *(OSSL_FUNC_keyexch_newctx_fn)(void *provctx); 63*b077aed3SPierre Pronchery static ossl_inline OSSL_FUNC_keyexch_newctx_fn 64*b077aed3SPierre Pronchery OSSL_FUNC_keyexch_newctx(const OSSL_DISPATCH *opf); 65*b077aed3SPierre Pronchery 66*b077aed3SPierre ProncheryL<OSSL_DISPATCH(3)> arrays are indexed by numbers that are provided as 67*b077aed3SPierre Proncherymacros in L<openssl-core_dispatch.h(7)>, as follows: 68*b077aed3SPierre Pronchery 69*b077aed3SPierre Pronchery OSSL_FUNC_keyexch_newctx OSSL_FUNC_KEYEXCH_NEWCTX 70*b077aed3SPierre Pronchery OSSL_FUNC_keyexch_freectx OSSL_FUNC_KEYEXCH_FREECTX 71*b077aed3SPierre Pronchery OSSL_FUNC_keyexch_dupctx OSSL_FUNC_KEYEXCH_DUPCTX 72*b077aed3SPierre Pronchery 73*b077aed3SPierre Pronchery OSSL_FUNC_keyexch_init OSSL_FUNC_KEYEXCH_INIT 74*b077aed3SPierre Pronchery OSSL_FUNC_keyexch_set_peer OSSL_FUNC_KEYEXCH_SET_PEER 75*b077aed3SPierre Pronchery OSSL_FUNC_keyexch_derive OSSL_FUNC_KEYEXCH_DERIVE 76*b077aed3SPierre Pronchery 77*b077aed3SPierre Pronchery OSSL_FUNC_keyexch_set_ctx_params OSSL_FUNC_KEYEXCH_SET_CTX_PARAMS 78*b077aed3SPierre Pronchery OSSL_FUNC_keyexch_settable_ctx_params OSSL_FUNC_KEYEXCH_SETTABLE_CTX_PARAMS 79*b077aed3SPierre Pronchery OSSL_FUNC_keyexch_get_ctx_params OSSL_FUNC_KEYEXCH_GET_CTX_PARAMS 80*b077aed3SPierre Pronchery OSSL_FUNC_keyexch_gettable_ctx_params OSSL_FUNC_KEYEXCH_GETTABLE_CTX_PARAMS 81*b077aed3SPierre Pronchery 82*b077aed3SPierre ProncheryA key exchange algorithm implementation may not implement all of these functions. 83*b077aed3SPierre ProncheryIn order to be a consistent set of functions a provider must implement 84*b077aed3SPierre ProncheryOSSL_FUNC_keyexch_newctx, OSSL_FUNC_keyexch_freectx, OSSL_FUNC_keyexch_init and OSSL_FUNC_keyexch_derive. 85*b077aed3SPierre ProncheryAll other functions are optional. 86*b077aed3SPierre Pronchery 87*b077aed3SPierre ProncheryA key exchange algorithm must also implement some mechanism for generating, 88*b077aed3SPierre Proncheryloading or importing keys via the key management (OSSL_OP_KEYMGMT) operation. 89*b077aed3SPierre ProncherySee L<provider-keymgmt(7)> for further details. 90*b077aed3SPierre Pronchery 91*b077aed3SPierre Pronchery=head2 Context Management Functions 92*b077aed3SPierre Pronchery 93*b077aed3SPierre ProncheryOSSL_FUNC_keyexch_newctx() should create and return a pointer to a provider side 94*b077aed3SPierre Proncherystructure for holding context information during a key exchange operation. 95*b077aed3SPierre ProncheryA pointer to this context will be passed back in a number of the other key 96*b077aed3SPierre Proncheryexchange operation function calls. 97*b077aed3SPierre ProncheryThe parameter I<provctx> is the provider context generated during provider 98*b077aed3SPierre Proncheryinitialisation (see L<provider(7)>). 99*b077aed3SPierre Pronchery 100*b077aed3SPierre ProncheryOSSL_FUNC_keyexch_freectx() is passed a pointer to the provider side key exchange 101*b077aed3SPierre Proncherycontext in the I<ctx> parameter. 102*b077aed3SPierre ProncheryThis function should free any resources associated with that context. 103*b077aed3SPierre Pronchery 104*b077aed3SPierre ProncheryOSSL_FUNC_keyexch_dupctx() should duplicate the provider side key exchange context in 105*b077aed3SPierre Proncherythe I<ctx> parameter and return the duplicate copy. 106*b077aed3SPierre Pronchery 107*b077aed3SPierre Pronchery=head2 Shared Secret Derivation Functions 108*b077aed3SPierre Pronchery 109*b077aed3SPierre ProncheryOSSL_FUNC_keyexch_init() initialises a key exchange operation given a provider side key 110*b077aed3SPierre Proncheryexchange context in the I<ctx> parameter, and a pointer to a provider key object 111*b077aed3SPierre Proncheryin the I<provkey> parameter. 112*b077aed3SPierre ProncheryThe I<params>, if not NULL, should be set on the context in a manner similar to 113*b077aed3SPierre Proncheryusing OSSL_FUNC_keyexch_set_params(). 114*b077aed3SPierre ProncheryThe key object should have been previously 115*b077aed3SPierre Proncherygenerated, loaded or imported into the provider using the key management 116*b077aed3SPierre Pronchery(OSSL_OP_KEYMGMT) operation (see provider-keymgmt(7)>. 117*b077aed3SPierre Pronchery 118*b077aed3SPierre ProncheryOSSL_FUNC_keyexch_set_peer() is called to supply the peer's public key (in the 119*b077aed3SPierre ProncheryI<provkey> parameter) to be used when deriving the shared secret. 120*b077aed3SPierre ProncheryIt is also passed a previously initialised key exchange context in the I<ctx> 121*b077aed3SPierre Proncheryparameter. 122*b077aed3SPierre ProncheryThe key object should have been previously generated, loaded or imported into 123*b077aed3SPierre Proncherythe provider using the key management (OSSL_OP_KEYMGMT) operation (see 124*b077aed3SPierre Proncheryprovider-keymgmt(7)>. 125*b077aed3SPierre Pronchery 126*b077aed3SPierre ProncheryOSSL_FUNC_keyexch_derive() performs the actual key exchange itself by deriving a shared 127*b077aed3SPierre Proncherysecret. 128*b077aed3SPierre ProncheryA previously initialised key exchange context is passed in the I<ctx> 129*b077aed3SPierre Proncheryparameter. 130*b077aed3SPierre ProncheryThe derived secret should be written to the location I<secret> which should not 131*b077aed3SPierre Proncheryexceed I<outlen> bytes. 132*b077aed3SPierre ProncheryThe length of the shared secret should be written to I<*secretlen>. 133*b077aed3SPierre ProncheryIf I<secret> is NULL then the maximum length of the shared secret should be 134*b077aed3SPierre Proncherywritten to I<*secretlen>. 135*b077aed3SPierre Pronchery 136*b077aed3SPierre Pronchery=head2 Key Exchange Parameters Functions 137*b077aed3SPierre Pronchery 138*b077aed3SPierre ProncheryOSSL_FUNC_keyexch_set_ctx_params() sets key exchange parameters associated with the 139*b077aed3SPierre Proncherygiven provider side key exchange context I<ctx> to I<params>, 140*b077aed3SPierre Proncherysee L</Common Key Exchange parameters>. 141*b077aed3SPierre ProncheryAny parameter settings are additional to any that were previously set. 142*b077aed3SPierre ProncheryPassing NULL for I<params> should return true. 143*b077aed3SPierre Pronchery 144*b077aed3SPierre ProncheryOSSL_FUNC_keyexch_get_ctx_params() gets key exchange parameters associated with the 145*b077aed3SPierre Proncherygiven provider side key exchange context I<ctx> into I<params>, 146*b077aed3SPierre Proncherysee L</Common Key Exchange parameters>. 147*b077aed3SPierre ProncheryPassing NULL for I<params> should return true. 148*b077aed3SPierre Pronchery 149*b077aed3SPierre ProncheryOSSL_FUNC_keyexch_settable_ctx_params() yields a constant L<OSSL_PARAM(3)> array that 150*b077aed3SPierre Proncherydescribes the settable parameters, i.e. parameters that can be used with 151*b077aed3SPierre ProncheryOP_signature_set_ctx_params(). 152*b077aed3SPierre ProncheryIf OSSL_FUNC_keyexch_settable_ctx_params() is present, OSSL_FUNC_keyexch_set_ctx_params() must 153*b077aed3SPierre Proncheryalso be present, and vice versa. 154*b077aed3SPierre ProncherySimilarly, OSSL_FUNC_keyexch_gettable_ctx_params() yields a constant L<OSSL_PARAM(3)> 155*b077aed3SPierre Proncheryarray that describes the gettable parameters, i.e. parameters that can be 156*b077aed3SPierre Proncheryhandled by OP_signature_get_ctx_params(). 157*b077aed3SPierre ProncheryIf OSSL_FUNC_keyexch_gettable_ctx_params() is present, OSSL_FUNC_keyexch_get_ctx_params() must 158*b077aed3SPierre Proncheryalso be present, and vice versa. 159*b077aed3SPierre Pronchery 160*b077aed3SPierre ProncheryNotice that not all settable parameters are also gettable, and vice versa. 161*b077aed3SPierre Pronchery 162*b077aed3SPierre Pronchery=head2 Common Key Exchange parameters 163*b077aed3SPierre Pronchery 164*b077aed3SPierre ProncherySee L<OSSL_PARAM(3)> for further details on the parameters structure used by 165*b077aed3SPierre Proncherythe OSSL_FUNC_keyexch_set_ctx_params() and OSSL_FUNC_keyexch_get_ctx_params() functions. 166*b077aed3SPierre Pronchery 167*b077aed3SPierre ProncheryCommon parameters currently recognised by built-in key exchange algorithms are 168*b077aed3SPierre Proncheryas follows. 169*b077aed3SPierre Pronchery 170*b077aed3SPierre Pronchery=over 4 171*b077aed3SPierre Pronchery 172*b077aed3SPierre Pronchery=item "kdf-type" (B<OSSL_EXCHANGE_PARAM_KDF_TYPE>) <UTF8 string> 173*b077aed3SPierre Pronchery 174*b077aed3SPierre ProncherySets or gets the Key Derivation Function type to apply within the associated key 175*b077aed3SPierre Proncheryexchange ctx. 176*b077aed3SPierre Pronchery 177*b077aed3SPierre Pronchery=item "kdf-digest" (B<OSSL_EXCHANGE_PARAM_KDF_DIGEST>) <UTF8 string> 178*b077aed3SPierre Pronchery 179*b077aed3SPierre ProncherySets or gets the Digest algorithm to be used as part of the Key Derivation Function 180*b077aed3SPierre Proncheryassociated with the given key exchange ctx. 181*b077aed3SPierre Pronchery 182*b077aed3SPierre Pronchery=item "kdf-digest-props" (B<OSSL_EXCHANGE_PARAM_KDF_DIGEST_PROPS>) <UTF8 string> 183*b077aed3SPierre Pronchery 184*b077aed3SPierre ProncherySets properties to be used upon look up of the implementation for the selected 185*b077aed3SPierre ProncheryDigest algorithm for the Key Derivation Function associated with the given key 186*b077aed3SPierre Proncheryexchange ctx. 187*b077aed3SPierre Pronchery 188*b077aed3SPierre Pronchery=item "kdf-outlen" (B<OSSL_EXCHANGE_PARAM_KDF_OUTLEN>) <unsigned integer> 189*b077aed3SPierre Pronchery 190*b077aed3SPierre ProncherySets or gets the desired size for the output of the chosen Key Derivation Function 191*b077aed3SPierre Proncheryassociated with the given key exchange ctx. 192*b077aed3SPierre ProncheryThe length of the "kdf-outlen" parameter should not exceed that of a B<size_t>. 193*b077aed3SPierre Pronchery 194*b077aed3SPierre Pronchery=item "kdf-ukm" (B<OSSL_EXCHANGE_PARAM_KDF_UKM>) <octet string> 195*b077aed3SPierre Pronchery 196*b077aed3SPierre ProncherySets the User Key Material to be used as part of the selected Key Derivation 197*b077aed3SPierre ProncheryFunction associated with the given key exchange ctx. 198*b077aed3SPierre Pronchery 199*b077aed3SPierre Pronchery=item "kdf-ukm" (B<OSSL_EXCHANGE_PARAM_KDF_UKM>) <octet string ptr> 200*b077aed3SPierre Pronchery 201*b077aed3SPierre ProncheryGets a pointer to the User Key Material to be used as part of the selected 202*b077aed3SPierre ProncheryKey Derivation Function associated with the given key exchange ctx. Providers 203*b077aed3SPierre Proncheryusually do not need to support this gettable parameter as its sole purpose 204*b077aed3SPierre Proncheryis to support functionality of the deprecated EVP_PKEY_CTX_get0_ecdh_kdf_ukm() 205*b077aed3SPierre Proncheryand EVP_PKEY_CTX_get0_dh_kdf_ukm() functions. 206*b077aed3SPierre Pronchery 207*b077aed3SPierre Pronchery=back 208*b077aed3SPierre Pronchery 209*b077aed3SPierre Pronchery=head1 RETURN VALUES 210*b077aed3SPierre Pronchery 211*b077aed3SPierre ProncheryOSSL_FUNC_keyexch_newctx() and OSSL_FUNC_keyexch_dupctx() should return the newly created 212*b077aed3SPierre Proncheryprovider side key exchange context, or NULL on failure. 213*b077aed3SPierre Pronchery 214*b077aed3SPierre ProncheryOSSL_FUNC_keyexch_init(), OSSL_FUNC_keyexch_set_peer(), OSSL_FUNC_keyexch_derive(), 215*b077aed3SPierre ProncheryOSSL_FUNC_keyexch_set_params(), and OSSL_FUNC_keyexch_get_params() should return 1 for success 216*b077aed3SPierre Proncheryor 0 on error. 217*b077aed3SPierre Pronchery 218*b077aed3SPierre ProncheryOSSL_FUNC_keyexch_settable_ctx_params() and OSSL_FUNC_keyexch_gettable_ctx_params() should 219*b077aed3SPierre Proncheryalways return a constant L<OSSL_PARAM(3)> array. 220*b077aed3SPierre Pronchery 221*b077aed3SPierre Pronchery=head1 SEE ALSO 222*b077aed3SPierre Pronchery 223*b077aed3SPierre ProncheryL<provider(7)> 224*b077aed3SPierre Pronchery 225*b077aed3SPierre Pronchery=head1 HISTORY 226*b077aed3SPierre Pronchery 227*b077aed3SPierre ProncheryThe provider KEYEXCH interface was introduced in OpenSSL 3.0. 228*b077aed3SPierre Pronchery 229*b077aed3SPierre Pronchery=head1 COPYRIGHT 230*b077aed3SPierre Pronchery 231*b077aed3SPierre ProncheryCopyright 2019-2022 The OpenSSL Project Authors. All Rights Reserved. 232*b077aed3SPierre Pronchery 233*b077aed3SPierre ProncheryLicensed under the Apache License 2.0 (the "License"). You may not use 234*b077aed3SPierre Proncherythis file except in compliance with the License. You can obtain a copy 235*b077aed3SPierre Proncheryin the file LICENSE in the source distribution or at 236*b077aed3SPierre ProncheryL<https://www.openssl.org/source/license.html>. 237*b077aed3SPierre Pronchery 238*b077aed3SPierre Pronchery=cut 239