1*b077aed3SPierre Pronchery=pod 2*b077aed3SPierre Pronchery 3*b077aed3SPierre Pronchery=head1 NAME 4*b077aed3SPierre Pronchery 5*b077aed3SPierre Proncheryprovider-asym_cipher - The asym_cipher 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_asym_cipher_newctx(void *provctx); 22*b077aed3SPierre Pronchery void OSSL_FUNC_asym_cipher_freectx(void *ctx); 23*b077aed3SPierre Pronchery void *OSSL_FUNC_asym_cipher_dupctx(void *ctx); 24*b077aed3SPierre Pronchery 25*b077aed3SPierre Pronchery /* Encryption */ 26*b077aed3SPierre Pronchery int OSSL_FUNC_asym_cipher_encrypt_init(void *ctx, void *provkey, 27*b077aed3SPierre Pronchery const OSSL_PARAM params[]); 28*b077aed3SPierre Pronchery int OSSL_FUNC_asym_cipher_encrypt(void *ctx, unsigned char *out, size_t *outlen, 29*b077aed3SPierre Pronchery size_t outsize, const unsigned char *in, 30*b077aed3SPierre Pronchery size_t inlen); 31*b077aed3SPierre Pronchery 32*b077aed3SPierre Pronchery /* Decryption */ 33*b077aed3SPierre Pronchery int OSSL_FUNC_asym_cipher_decrypt_init(void *ctx, void *provkey, 34*b077aed3SPierre Pronchery const OSSL_PARAM params[]); 35*b077aed3SPierre Pronchery int OSSL_FUNC_asym_cipher_decrypt(void *ctx, unsigned char *out, size_t *outlen, 36*b077aed3SPierre Pronchery size_t outsize, const unsigned char *in, 37*b077aed3SPierre Pronchery size_t inlen); 38*b077aed3SPierre Pronchery 39*b077aed3SPierre Pronchery /* Asymmetric Cipher parameters */ 40*b077aed3SPierre Pronchery int OSSL_FUNC_asym_cipher_get_ctx_params(void *ctx, OSSL_PARAM params[]); 41*b077aed3SPierre Pronchery const OSSL_PARAM *OSSL_FUNC_asym_cipher_gettable_ctx_params(void *provctx); 42*b077aed3SPierre Pronchery int OSSL_FUNC_asym_cipher_set_ctx_params(void *ctx, const OSSL_PARAM params[]); 43*b077aed3SPierre Pronchery const OSSL_PARAM *OSSL_FUNC_asym_cipher_settable_ctx_params(void *provctx); 44*b077aed3SPierre Pronchery 45*b077aed3SPierre Pronchery=head1 DESCRIPTION 46*b077aed3SPierre Pronchery 47*b077aed3SPierre ProncheryThis documentation is primarily aimed at provider authors. See L<provider(7)> 48*b077aed3SPierre Proncheryfor further information. 49*b077aed3SPierre Pronchery 50*b077aed3SPierre ProncheryThe asymmetric cipher (OSSL_OP_ASYM_CIPHER) operation enables providers to 51*b077aed3SPierre Proncheryimplement asymmetric cipher algorithms and make them available to applications 52*b077aed3SPierre Proncheryvia the API functions L<EVP_PKEY_encrypt(3)>, 53*b077aed3SPierre ProncheryL<EVP_PKEY_decrypt(3)> and 54*b077aed3SPierre Proncheryother related functions). 55*b077aed3SPierre Pronchery 56*b077aed3SPierre ProncheryAll "functions" mentioned here are passed as function pointers between 57*b077aed3SPierre ProncheryF<libcrypto> and the provider in L<OSSL_DISPATCH(3)> arrays via 58*b077aed3SPierre ProncheryL<OSSL_ALGORITHM(3)> arrays that are returned by the provider's 59*b077aed3SPierre Proncheryprovider_query_operation() function 60*b077aed3SPierre Pronchery(see L<provider-base(7)/Provider Functions>). 61*b077aed3SPierre Pronchery 62*b077aed3SPierre ProncheryAll these "functions" have a corresponding function type definition 63*b077aed3SPierre Proncherynamed B<OSSL_FUNC_{name}_fn>, and a helper function to retrieve the 64*b077aed3SPierre Proncheryfunction pointer from an L<OSSL_DISPATCH(3)> element named 65*b077aed3SPierre ProncheryB<OSSL_FUNC_{name}>. 66*b077aed3SPierre ProncheryFor example, the "function" OSSL_FUNC_asym_cipher_newctx() has these: 67*b077aed3SPierre Pronchery 68*b077aed3SPierre Pronchery typedef void *(OSSL_FUNC_asym_cipher_newctx_fn)(void *provctx); 69*b077aed3SPierre Pronchery static ossl_inline OSSL_FUNC_asym_cipher_newctx_fn 70*b077aed3SPierre Pronchery OSSL_FUNC_asym_cipher_newctx(const OSSL_DISPATCH *opf); 71*b077aed3SPierre Pronchery 72*b077aed3SPierre ProncheryL<OSSL_DISPATCH(3)> arrays are indexed by numbers that are provided as 73*b077aed3SPierre Proncherymacros in L<openssl-core_dispatch.h(7)>, as follows: 74*b077aed3SPierre Pronchery 75*b077aed3SPierre Pronchery OSSL_FUNC_asym_cipher_newctx OSSL_FUNC_ASYM_CIPHER_NEWCTX 76*b077aed3SPierre Pronchery OSSL_FUNC_asym_cipher_freectx OSSL_FUNC_ASYM_CIPHER_FREECTX 77*b077aed3SPierre Pronchery OSSL_FUNC_asym_cipher_dupctx OSSL_FUNC_ASYM_CIPHER_DUPCTX 78*b077aed3SPierre Pronchery 79*b077aed3SPierre Pronchery OSSL_FUNC_asym_cipher_encrypt_init OSSL_FUNC_ASYM_CIPHER_ENCRYPT_INIT 80*b077aed3SPierre Pronchery OSSL_FUNC_asym_cipher_encrypt OSSL_FUNC_ASYM_CIPHER_ENCRYPT 81*b077aed3SPierre Pronchery 82*b077aed3SPierre Pronchery OSSL_FUNC_asym_cipher_decrypt_init OSSL_FUNC_ASYM_CIPHER_DECRYPT_INIT 83*b077aed3SPierre Pronchery OSSL_FUNC_asym_cipher_decrypt OSSL_FUNC_ASYM_CIPHER_DECRYPT 84*b077aed3SPierre Pronchery 85*b077aed3SPierre Pronchery OSSL_FUNC_asym_cipher_get_ctx_params OSSL_FUNC_ASYM_CIPHER_GET_CTX_PARAMS 86*b077aed3SPierre Pronchery OSSL_FUNC_asym_cipher_gettable_ctx_params OSSL_FUNC_ASYM_CIPHER_GETTABLE_CTX_PARAMS 87*b077aed3SPierre Pronchery OSSL_FUNC_asym_cipher_set_ctx_params OSSL_FUNC_ASYM_CIPHER_SET_CTX_PARAMS 88*b077aed3SPierre Pronchery OSSL_FUNC_asym_cipher_settable_ctx_params OSSL_FUNC_ASYM_CIPHER_SETTABLE_CTX_PARAMS 89*b077aed3SPierre Pronchery 90*b077aed3SPierre ProncheryAn asymmetric cipher algorithm implementation may not implement all of these 91*b077aed3SPierre Proncheryfunctions. 92*b077aed3SPierre ProncheryIn order to be a consistent set of functions a provider must implement 93*b077aed3SPierre ProncheryOSSL_FUNC_asym_cipher_newctx and OSSL_FUNC_asym_cipher_freectx. 94*b077aed3SPierre ProncheryIt must also implement both of OSSL_FUNC_asym_cipher_encrypt_init and 95*b077aed3SPierre ProncheryOSSL_FUNC_asym_cipher_encrypt, or both of OSSL_FUNC_asym_cipher_decrypt_init and 96*b077aed3SPierre ProncheryOSSL_FUNC_asym_cipher_decrypt. 97*b077aed3SPierre ProncheryOSSL_FUNC_asym_cipher_get_ctx_params is optional but if it is present then so must 98*b077aed3SPierre ProncheryOSSL_FUNC_asym_cipher_gettable_ctx_params. 99*b077aed3SPierre ProncherySimilarly, OSSL_FUNC_asym_cipher_set_ctx_params is optional but if it is present then 100*b077aed3SPierre Proncheryso must OSSL_FUNC_asym_cipher_settable_ctx_params. 101*b077aed3SPierre Pronchery 102*b077aed3SPierre ProncheryAn asymmetric cipher algorithm must also implement some mechanism for generating, 103*b077aed3SPierre Proncheryloading or importing keys via the key management (OSSL_OP_KEYMGMT) operation. 104*b077aed3SPierre ProncherySee L<provider-keymgmt(7)> for further details. 105*b077aed3SPierre Pronchery 106*b077aed3SPierre Pronchery=head2 Context Management Functions 107*b077aed3SPierre Pronchery 108*b077aed3SPierre ProncheryOSSL_FUNC_asym_cipher_newctx() should create and return a pointer to a provider side 109*b077aed3SPierre Proncherystructure for holding context information during an asymmetric cipher operation. 110*b077aed3SPierre ProncheryA pointer to this context will be passed back in a number of the other 111*b077aed3SPierre Proncheryasymmetric cipher operation function calls. 112*b077aed3SPierre ProncheryThe parameter I<provctx> is the provider context generated during provider 113*b077aed3SPierre Proncheryinitialisation (see L<provider(7)>). 114*b077aed3SPierre Pronchery 115*b077aed3SPierre ProncheryOSSL_FUNC_asym_cipher_freectx() is passed a pointer to the provider side asymmetric 116*b077aed3SPierre Proncherycipher context in the I<ctx> parameter. 117*b077aed3SPierre ProncheryThis function should free any resources associated with that context. 118*b077aed3SPierre Pronchery 119*b077aed3SPierre ProncheryOSSL_FUNC_asym_cipher_dupctx() should duplicate the provider side asymmetric cipher 120*b077aed3SPierre Proncherycontext in the I<ctx> parameter and return the duplicate copy. 121*b077aed3SPierre Pronchery 122*b077aed3SPierre Pronchery=head2 Encryption Functions 123*b077aed3SPierre Pronchery 124*b077aed3SPierre ProncheryOSSL_FUNC_asym_cipher_encrypt_init() initialises a context for an asymmetric encryption 125*b077aed3SPierre Proncherygiven a provider side asymmetric cipher context in the I<ctx> parameter, and a 126*b077aed3SPierre Proncherypointer to a provider key object in the I<provkey> parameter. 127*b077aed3SPierre ProncheryThe I<params>, if not NULL, should be set on the context in a manner similar to 128*b077aed3SPierre Proncheryusing OSSL_FUNC_asym_cipher_set_ctx_params(). 129*b077aed3SPierre ProncheryThe key object should have been previously generated, loaded or imported into 130*b077aed3SPierre Proncherythe provider using the key management (OSSL_OP_KEYMGMT) operation (see L<provider-keymgmt(7)>). 131*b077aed3SPierre ProncheryOSSL_FUNC_asym_cipher_encrypt() performs the actual encryption itself. 132*b077aed3SPierre ProncheryA previously initialised asymmetric cipher context is passed in the I<ctx> 133*b077aed3SPierre Proncheryparameter. 134*b077aed3SPierre ProncheryThe data to be encrypted is pointed to by the I<in> parameter which is I<inlen> 135*b077aed3SPierre Proncherybytes long. 136*b077aed3SPierre ProncheryUnless I<out> is NULL, the encrypted data should be written to the location 137*b077aed3SPierre Proncherypointed to by the I<out> parameter and it should not exceed I<outsize> bytes in 138*b077aed3SPierre Proncherylength. 139*b077aed3SPierre ProncheryThe length of the encrypted data should be written to I<*outlen>. 140*b077aed3SPierre ProncheryIf I<out> is NULL then the maximum length of the encrypted data should be 141*b077aed3SPierre Proncherywritten to I<*outlen>. 142*b077aed3SPierre Pronchery 143*b077aed3SPierre Pronchery=head2 Decryption Functions 144*b077aed3SPierre Pronchery 145*b077aed3SPierre ProncheryOSSL_FUNC_asym_cipher_decrypt_init() initialises a context for an asymmetric decryption 146*b077aed3SPierre Proncherygiven a provider side asymmetric cipher context in the I<ctx> parameter, and a 147*b077aed3SPierre Proncherypointer to a provider key object in the I<provkey> parameter. 148*b077aed3SPierre ProncheryThe I<params>, if not NULL, should be set on the context in a manner similar to 149*b077aed3SPierre Proncheryusing OSSL_FUNC_asym_cipher_set_ctx_params(). 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 ProncheryL<provider-keymgmt(7)>). 153*b077aed3SPierre Pronchery 154*b077aed3SPierre ProncheryOSSL_FUNC_asym_cipher_decrypt() performs the actual decryption itself. 155*b077aed3SPierre ProncheryA previously initialised asymmetric cipher context is passed in the I<ctx> 156*b077aed3SPierre Proncheryparameter. 157*b077aed3SPierre ProncheryThe data to be decrypted is pointed to by the I<in> parameter which is I<inlen> 158*b077aed3SPierre Proncherybytes long. 159*b077aed3SPierre ProncheryUnless I<out> is NULL, the decrypted data should be written to the location 160*b077aed3SPierre Proncherypointed to by the I<out> parameter and it should not exceed I<outsize> bytes in 161*b077aed3SPierre Proncherylength. 162*b077aed3SPierre ProncheryThe length of the decrypted data should be written to I<*outlen>. 163*b077aed3SPierre ProncheryIf I<out> is NULL then the maximum length of the decrypted data should be 164*b077aed3SPierre Proncherywritten to I<*outlen>. 165*b077aed3SPierre Pronchery 166*b077aed3SPierre Pronchery=head2 Asymmetric Cipher Parameters 167*b077aed3SPierre Pronchery 168*b077aed3SPierre ProncherySee L<OSSL_PARAM(3)> for further details on the parameters structure used by 169*b077aed3SPierre Proncherythe OSSL_FUNC_asym_cipher_get_ctx_params() and OSSL_FUNC_asym_cipher_set_ctx_params() 170*b077aed3SPierre Proncheryfunctions. 171*b077aed3SPierre Pronchery 172*b077aed3SPierre ProncheryOSSL_FUNC_asym_cipher_get_ctx_params() gets asymmetric cipher parameters associated 173*b077aed3SPierre Proncherywith the given provider side asymmetric cipher context I<ctx> and stores them in 174*b077aed3SPierre ProncheryI<params>. 175*b077aed3SPierre ProncheryPassing NULL for I<params> should return true. 176*b077aed3SPierre Pronchery 177*b077aed3SPierre ProncheryOSSL_FUNC_asym_cipher_set_ctx_params() sets the asymmetric cipher parameters associated 178*b077aed3SPierre Proncherywith the given provider side asymmetric cipher context I<ctx> to I<params>. 179*b077aed3SPierre ProncheryAny parameter settings are additional to any that were previously set. 180*b077aed3SPierre ProncheryPassing NULL for I<params> should return true. 181*b077aed3SPierre Pronchery 182*b077aed3SPierre ProncheryParameters currently recognised by built-in asymmetric cipher algorithms are as 183*b077aed3SPierre Proncheryfollows. 184*b077aed3SPierre ProncheryNot all parameters are relevant to, or are understood by all asymmetric cipher 185*b077aed3SPierre Proncheryalgorithms: 186*b077aed3SPierre Pronchery 187*b077aed3SPierre Pronchery=over 4 188*b077aed3SPierre Pronchery 189*b077aed3SPierre Pronchery=item "pad-mode" (B<OSSL_ASYM_CIPHER_PARAM_PAD_MODE>) <UTF8 string> OR <integer> 190*b077aed3SPierre Pronchery 191*b077aed3SPierre ProncheryThe type of padding to be used. The interpretation of this value will depend 192*b077aed3SPierre Proncheryon the algorithm in use. 193*b077aed3SPierre Pronchery 194*b077aed3SPierre Pronchery=item "digest" (B<OSSL_ASYM_CIPHER_PARAM_OAEP_DIGEST>) <UTF8 string> 195*b077aed3SPierre Pronchery 196*b077aed3SPierre ProncheryGets or sets the name of the OAEP digest algorithm used when OAEP padding is in 197*b077aed3SPierre Proncheryuse. 198*b077aed3SPierre Pronchery 199*b077aed3SPierre Pronchery=item "digest" (B<OSSL_ASYM_CIPHER_PARAM_DIGEST>) <UTF8 string> 200*b077aed3SPierre Pronchery 201*b077aed3SPierre ProncheryGets or sets the name of the digest algorithm used by the algorithm (where 202*b077aed3SPierre Proncheryapplicable). 203*b077aed3SPierre Pronchery 204*b077aed3SPierre Pronchery=item "digest-props" (B<OSSL_ASYM_CIPHER_PARAM_OAEP_DIGEST_PROPS>) <UTF8 string> 205*b077aed3SPierre Pronchery 206*b077aed3SPierre ProncheryGets or sets the properties to use when fetching the OAEP digest algorithm. 207*b077aed3SPierre Pronchery 208*b077aed3SPierre Pronchery=item "digest-props" (B<OSSL_ASYM_CIPHER_PARAM_DIGEST_PROPS>) <UTF8 string> 209*b077aed3SPierre Pronchery 210*b077aed3SPierre ProncheryGets or sets the properties to use when fetching the cipher digest algorithm. 211*b077aed3SPierre Pronchery 212*b077aed3SPierre Pronchery=item "mgf1-digest" (B<OSSL_ASYM_CIPHER_PARAM_MGF1_DIGEST>) <UTF8 string> 213*b077aed3SPierre Pronchery 214*b077aed3SPierre ProncheryGets or sets the name of the MGF1 digest algorithm used when OAEP or PSS padding 215*b077aed3SPierre Proncheryis in use. 216*b077aed3SPierre Pronchery 217*b077aed3SPierre Pronchery=item "mgf1-digest-props" (B<OSSL_ASYM_CIPHER_PARAM_MGF1_DIGEST_PROPS>) <UTF8 string> 218*b077aed3SPierre Pronchery 219*b077aed3SPierre ProncheryGets or sets the properties to use when fetching the MGF1 digest algorithm. 220*b077aed3SPierre Pronchery 221*b077aed3SPierre Pronchery=item "oaep-label" (B<OSSL_ASYM_CIPHER_PARAM_OAEP_LABEL>) <octet string ptr> 222*b077aed3SPierre Pronchery 223*b077aed3SPierre ProncheryGets the OAEP label used when OAEP padding is in use. 224*b077aed3SPierre Pronchery 225*b077aed3SPierre Pronchery=item "oaep-label" (B<OSSL_ASYM_CIPHER_PARAM_OAEP_LABEL>) <octet string> 226*b077aed3SPierre Pronchery 227*b077aed3SPierre ProncherySets the OAEP label used when OAEP padding is in use. 228*b077aed3SPierre Pronchery 229*b077aed3SPierre Pronchery=item "tls-client-version" (B<OSSL_ASYM_CIPHER_PARAM_TLS_CLIENT_VERSION>) <unsigned integer> 230*b077aed3SPierre Pronchery 231*b077aed3SPierre ProncheryThe TLS protocol version first requested by the client. 232*b077aed3SPierre Pronchery 233*b077aed3SPierre Pronchery=item "tls-negotiated-version" (B<OSSL_ASYM_CIPHER_PARAM_TLS_CLIENT_VERSION>) <unsigned integer> 234*b077aed3SPierre Pronchery 235*b077aed3SPierre ProncheryThe negotiated TLS protocol version. 236*b077aed3SPierre Pronchery 237*b077aed3SPierre Pronchery=back 238*b077aed3SPierre Pronchery 239*b077aed3SPierre ProncheryOSSL_FUNC_asym_cipher_gettable_ctx_params() and OSSL_FUNC_asym_cipher_settable_ctx_params() 240*b077aed3SPierre Proncheryget a constant L<OSSL_PARAM(3)> array that describes the gettable and settable 241*b077aed3SPierre Proncheryparameters, i.e. parameters that can be used with OSSL_FUNC_asym_cipherget_ctx_params() 242*b077aed3SPierre Proncheryand OSSL_FUNC_asym_cipher_set_ctx_params() respectively. 243*b077aed3SPierre Pronchery 244*b077aed3SPierre Pronchery=head1 RETURN VALUES 245*b077aed3SPierre Pronchery 246*b077aed3SPierre ProncheryOSSL_FUNC_asym_cipher_newctx() and OSSL_FUNC_asym_cipher_dupctx() should return the newly 247*b077aed3SPierre Proncherycreated provider side asymmetric cipher context, or NULL on failure. 248*b077aed3SPierre Pronchery 249*b077aed3SPierre ProncheryAll other functions should return 1 for success or 0 on error. 250*b077aed3SPierre Pronchery 251*b077aed3SPierre Pronchery=head1 SEE ALSO 252*b077aed3SPierre Pronchery 253*b077aed3SPierre ProncheryL<provider(7)> 254*b077aed3SPierre Pronchery 255*b077aed3SPierre Pronchery=head1 HISTORY 256*b077aed3SPierre Pronchery 257*b077aed3SPierre ProncheryThe provider ASYM_CIPHER interface was introduced in OpenSSL 3.0. 258*b077aed3SPierre Pronchery 259*b077aed3SPierre Pronchery=head1 COPYRIGHT 260*b077aed3SPierre Pronchery 261*b077aed3SPierre ProncheryCopyright 2019-2023 The OpenSSL Project Authors. All Rights Reserved. 262*b077aed3SPierre Pronchery 263*b077aed3SPierre ProncheryLicensed under the Apache License 2.0 (the "License"). You may not use 264*b077aed3SPierre Proncherythis file except in compliance with the License. You can obtain a copy 265*b077aed3SPierre Proncheryin the file LICENSE in the source distribution or at 266*b077aed3SPierre ProncheryL<https://www.openssl.org/source/license.html>. 267*b077aed3SPierre Pronchery 268*b077aed3SPierre Pronchery=cut 269