1*b077aed3SPierre Pronchery=pod 2*b077aed3SPierre Pronchery 3*b077aed3SPierre Pronchery=head1 NAME 4*b077aed3SPierre Pronchery 5*b077aed3SPierre Proncheryprovider-mac - The mac 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_mac_newctx(void *provctx); 22*b077aed3SPierre Pronchery void OSSL_FUNC_mac_freectx(void *mctx); 23*b077aed3SPierre Pronchery void *OSSL_FUNC_mac_dupctx(void *src); 24*b077aed3SPierre Pronchery 25*b077aed3SPierre Pronchery /* Encryption/decryption */ 26*b077aed3SPierre Pronchery int OSSL_FUNC_mac_init(void *mctx, unsigned char *key, size_t keylen, 27*b077aed3SPierre Pronchery const OSSL_PARAM params[]); 28*b077aed3SPierre Pronchery int OSSL_FUNC_mac_update(void *mctx, const unsigned char *in, size_t inl); 29*b077aed3SPierre Pronchery int OSSL_FUNC_mac_final(void *mctx, unsigned char *out, size_t *outl, size_t outsize); 30*b077aed3SPierre Pronchery 31*b077aed3SPierre Pronchery /* MAC parameter descriptors */ 32*b077aed3SPierre Pronchery const OSSL_PARAM *OSSL_FUNC_mac_gettable_params(void *provctx); 33*b077aed3SPierre Pronchery const OSSL_PARAM *OSSL_FUNC_mac_gettable_ctx_params(void *mctx, void *provctx); 34*b077aed3SPierre Pronchery const OSSL_PARAM *OSSL_FUNC_mac_settable_ctx_params(void *mctx, void *provctx); 35*b077aed3SPierre Pronchery 36*b077aed3SPierre Pronchery /* MAC parameters */ 37*b077aed3SPierre Pronchery int OSSL_FUNC_mac_get_params(OSSL_PARAM params[]); 38*b077aed3SPierre Pronchery int OSSL_FUNC_mac_get_ctx_params(void *mctx, OSSL_PARAM params[]); 39*b077aed3SPierre Pronchery int OSSL_FUNC_mac_set_ctx_params(void *mctx, const OSSL_PARAM params[]); 40*b077aed3SPierre Pronchery 41*b077aed3SPierre Pronchery=head1 DESCRIPTION 42*b077aed3SPierre Pronchery 43*b077aed3SPierre ProncheryThis documentation is primarily aimed at provider authors. See L<provider(7)> 44*b077aed3SPierre Proncheryfor further information. 45*b077aed3SPierre Pronchery 46*b077aed3SPierre ProncheryThe MAC operation enables providers to implement mac algorithms and make 47*b077aed3SPierre Proncherythem available to applications via the API functions L<EVP_MAC_init(3)>, 48*b077aed3SPierre ProncheryL<EVP_MAC_update(3)> and L<EVP_MAC_final(3)>. 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_mac_newctx() has these: 61*b077aed3SPierre Pronchery 62*b077aed3SPierre Pronchery typedef void *(OSSL_FUNC_mac_newctx_fn)(void *provctx); 63*b077aed3SPierre Pronchery static ossl_inline OSSL_FUNC_mac_newctx_fn 64*b077aed3SPierre Pronchery OSSL_FUNC_mac_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_mac_newctx OSSL_FUNC_MAC_NEWCTX 70*b077aed3SPierre Pronchery OSSL_FUNC_mac_freectx OSSL_FUNC_MAC_FREECTX 71*b077aed3SPierre Pronchery OSSL_FUNC_mac_dupctx OSSL_FUNC_MAC_DUPCTX 72*b077aed3SPierre Pronchery 73*b077aed3SPierre Pronchery OSSL_FUNC_mac_init OSSL_FUNC_MAC_INIT 74*b077aed3SPierre Pronchery OSSL_FUNC_mac_update OSSL_FUNC_MAC_UPDATE 75*b077aed3SPierre Pronchery OSSL_FUNC_mac_final OSSL_FUNC_MAC_FINAL 76*b077aed3SPierre Pronchery 77*b077aed3SPierre Pronchery OSSL_FUNC_mac_get_params OSSL_FUNC_MAC_GET_PARAMS 78*b077aed3SPierre Pronchery OSSL_FUNC_mac_get_ctx_params OSSL_FUNC_MAC_GET_CTX_PARAMS 79*b077aed3SPierre Pronchery OSSL_FUNC_mac_set_ctx_params OSSL_FUNC_MAC_SET_CTX_PARAMS 80*b077aed3SPierre Pronchery 81*b077aed3SPierre Pronchery OSSL_FUNC_mac_gettable_params OSSL_FUNC_MAC_GETTABLE_PARAMS 82*b077aed3SPierre Pronchery OSSL_FUNC_mac_gettable_ctx_params OSSL_FUNC_MAC_GETTABLE_CTX_PARAMS 83*b077aed3SPierre Pronchery OSSL_FUNC_mac_settable_ctx_params OSSL_FUNC_MAC_SETTABLE_CTX_PARAMS 84*b077aed3SPierre Pronchery 85*b077aed3SPierre ProncheryA mac algorithm implementation may not implement all of these functions. 86*b077aed3SPierre ProncheryIn order to be a consistent set of functions, at least the following functions 87*b077aed3SPierre Proncherymust be implemented: OSSL_FUNC_mac_newctx(), OSSL_FUNC_mac_freectx(), OSSL_FUNC_mac_init(), 88*b077aed3SPierre ProncheryOSSL_FUNC_mac_update(), OSSL_FUNC_mac_final(). 89*b077aed3SPierre ProncheryAll other functions are optional. 90*b077aed3SPierre Pronchery 91*b077aed3SPierre Pronchery=head2 Context Management Functions 92*b077aed3SPierre Pronchery 93*b077aed3SPierre ProncheryOSSL_FUNC_mac_newctx() should create and return a pointer to a provider side 94*b077aed3SPierre Proncherystructure for holding context information during a mac operation. 95*b077aed3SPierre ProncheryA pointer to this context will be passed back in a number of the other mac 96*b077aed3SPierre Proncheryoperation 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_mac_freectx() is passed a pointer to the provider side mac context in 101*b077aed3SPierre Proncherythe I<mctx> parameter. 102*b077aed3SPierre ProncheryIf it receives NULL as I<mctx> value, it should not do anything other than 103*b077aed3SPierre Proncheryreturn. 104*b077aed3SPierre ProncheryThis function should free any resources associated with that context. 105*b077aed3SPierre Pronchery 106*b077aed3SPierre ProncheryOSSL_FUNC_mac_dupctx() should duplicate the provider side mac context in the 107*b077aed3SPierre ProncheryI<mctx> parameter and return the duplicate copy. 108*b077aed3SPierre Pronchery 109*b077aed3SPierre Pronchery=head2 Encryption/Decryption Functions 110*b077aed3SPierre Pronchery 111*b077aed3SPierre ProncheryOSSL_FUNC_mac_init() initialises a mac operation given a newly created provider 112*b077aed3SPierre Proncheryside mac context in the I<mctx> parameter. The I<params> are set before setting 113*b077aed3SPierre Proncherythe MAC I<key> of I<keylen> bytes. 114*b077aed3SPierre Pronchery 115*b077aed3SPierre ProncheryOSSL_FUNC_mac_update() is called to supply data for MAC computation of a previously 116*b077aed3SPierre Proncheryinitialised mac operation. 117*b077aed3SPierre ProncheryThe I<mctx> parameter contains a pointer to a previously initialised provider 118*b077aed3SPierre Proncheryside context. 119*b077aed3SPierre ProncheryOSSL_FUNC_mac_update() may be called multiple times for a single mac operation. 120*b077aed3SPierre Pronchery 121*b077aed3SPierre ProncheryOSSL_FUNC_mac_final() completes the MAC computation started through previous 122*b077aed3SPierre ProncheryOSSL_FUNC_mac_init() and OSSL_FUNC_mac_update() calls. 123*b077aed3SPierre ProncheryThe I<mctx> parameter contains a pointer to the provider side context. 124*b077aed3SPierre ProncheryThe resulting MAC should be written to I<out> and the amount of data written 125*b077aed3SPierre Proncheryto I<*outl>, which should not exceed I<outsize> bytes. 126*b077aed3SPierre ProncheryThe same expectations apply to I<outsize> as documented for 127*b077aed3SPierre ProncheryL<EVP_MAC_final(3)>. 128*b077aed3SPierre Pronchery 129*b077aed3SPierre Pronchery=head2 Mac Parameters 130*b077aed3SPierre Pronchery 131*b077aed3SPierre ProncherySee L<OSSL_PARAM(3)> for further details on the parameters structure used by 132*b077aed3SPierre Proncherythese functions. 133*b077aed3SPierre Pronchery 134*b077aed3SPierre ProncheryOSSL_FUNC_mac_get_params() gets details of parameter values associated with the 135*b077aed3SPierre Proncheryprovider algorithm and stores them in I<params>. 136*b077aed3SPierre Pronchery 137*b077aed3SPierre ProncheryOSSL_FUNC_mac_set_ctx_params() sets mac parameters associated with the given 138*b077aed3SPierre Proncheryprovider side mac context I<mctx> to I<params>. 139*b077aed3SPierre ProncheryAny parameter settings are additional to any that were previously set. 140*b077aed3SPierre ProncheryPassing NULL for I<params> should return true. 141*b077aed3SPierre Pronchery 142*b077aed3SPierre ProncheryOSSL_FUNC_mac_get_ctx_params() gets details of currently set parameter values 143*b077aed3SPierre Proncheryassociated with the given provider side mac context I<mctx> and stores them 144*b077aed3SPierre Proncheryin I<params>. 145*b077aed3SPierre ProncheryPassing NULL for I<params> should return true. 146*b077aed3SPierre Pronchery 147*b077aed3SPierre ProncheryOSSL_FUNC_mac_gettable_params(), OSSL_FUNC_mac_gettable_ctx_params(), 148*b077aed3SPierre Proncheryand OSSL_FUNC_mac_settable_ctx_params() all return constant L<OSSL_PARAM(3)> 149*b077aed3SPierre Proncheryarrays as descriptors of the parameters that OSSL_FUNC_mac_get_params(), 150*b077aed3SPierre ProncheryOSSL_FUNC_mac_get_ctx_params(), and OSSL_FUNC_mac_set_ctx_params() 151*b077aed3SPierre Proncherycan handle, respectively. OSSL_FUNC_mac_gettable_ctx_params() and 152*b077aed3SPierre ProncheryOSSL_FUNC_mac_settable_ctx_params() will return the parameters associated 153*b077aed3SPierre Proncherywith the provider side context I<mctx> in its current state if it is 154*b077aed3SPierre Proncherynot NULL. Otherwise, they return the parameters associated with the 155*b077aed3SPierre Proncheryprovider side algorithm I<provctx>. 156*b077aed3SPierre Pronchery 157*b077aed3SPierre ProncheryAll MAC implementations are expected to handle the following parameters: 158*b077aed3SPierre Pronchery 159*b077aed3SPierre Pronchery=over 4 160*b077aed3SPierre Pronchery 161*b077aed3SPierre Pronchery=item with OSSL_FUNC_set_ctx_params(): 162*b077aed3SPierre Pronchery 163*b077aed3SPierre Pronchery=over 4 164*b077aed3SPierre Pronchery 165*b077aed3SPierre Pronchery=item "key" (B<OSSL_MAC_PARAM_KEY>) <octet string> 166*b077aed3SPierre Pronchery 167*b077aed3SPierre ProncherySets the key in the associated MAC ctx. This is identical to passing a I<key> 168*b077aed3SPierre Proncheryargument to the OSSL_FUNC_mac_init() function. 169*b077aed3SPierre Pronchery 170*b077aed3SPierre Pronchery=back 171*b077aed3SPierre Pronchery 172*b077aed3SPierre Pronchery=item with OSSL_FUNC_get_params(): 173*b077aed3SPierre Pronchery 174*b077aed3SPierre Pronchery=over 4 175*b077aed3SPierre Pronchery 176*b077aed3SPierre Pronchery=item "size" (B<OSSL_MAC_PARAM_SIZE>) <integer> 177*b077aed3SPierre Pronchery 178*b077aed3SPierre ProncheryCan be used to get the default MAC size (which might be the only allowable 179*b077aed3SPierre ProncheryMAC size for the implementation). 180*b077aed3SPierre Pronchery 181*b077aed3SPierre ProncheryNote that some implementations allow setting the size that the resulting MAC 182*b077aed3SPierre Proncheryshould have as well, see the documentation of the implementation. 183*b077aed3SPierre Pronchery 184*b077aed3SPierre Pronchery=back 185*b077aed3SPierre Pronchery 186*b077aed3SPierre Pronchery=over 4 187*b077aed3SPierre Pronchery 188*b077aed3SPierre Pronchery=item "size" (B<OSSL_MAC_PARAM_BLOCK_SIZE>) <integer> 189*b077aed3SPierre Pronchery 190*b077aed3SPierre ProncheryCan be used to get the MAC block size (if supported by the algorithm). 191*b077aed3SPierre Pronchery 192*b077aed3SPierre Pronchery=back 193*b077aed3SPierre Pronchery 194*b077aed3SPierre Pronchery=back 195*b077aed3SPierre Pronchery 196*b077aed3SPierre Pronchery=head1 NOTES 197*b077aed3SPierre Pronchery 198*b077aed3SPierre ProncheryThe MAC life-cycle is described in L<life_cycle-rand(7)>. Providers should 199*b077aed3SPierre Proncheryensure that the various transitions listed there are supported. At some point 200*b077aed3SPierre Proncherythe EVP layer will begin enforcing the listed transitions. 201*b077aed3SPierre Pronchery 202*b077aed3SPierre Pronchery=head1 RETURN VALUES 203*b077aed3SPierre Pronchery 204*b077aed3SPierre ProncheryOSSL_FUNC_mac_newctx() and OSSL_FUNC_mac_dupctx() should return the newly created 205*b077aed3SPierre Proncheryprovider side mac context, or NULL on failure. 206*b077aed3SPierre Pronchery 207*b077aed3SPierre ProncheryOSSL_FUNC_mac_init(), OSSL_FUNC_mac_update(), OSSL_FUNC_mac_final(), OSSL_FUNC_mac_get_params(), 208*b077aed3SPierre ProncheryOSSL_FUNC_mac_get_ctx_params() and OSSL_FUNC_mac_set_ctx_params() should return 1 for 209*b077aed3SPierre Proncherysuccess or 0 on error. 210*b077aed3SPierre Pronchery 211*b077aed3SPierre ProncheryOSSL_FUNC_mac_gettable_params(), OSSL_FUNC_mac_gettable_ctx_params() and 212*b077aed3SPierre ProncheryOSSL_FUNC_mac_settable_ctx_params() should return a constant L<OSSL_PARAM(3)> 213*b077aed3SPierre Proncheryarray, or NULL if none is offered. 214*b077aed3SPierre Pronchery 215*b077aed3SPierre Pronchery=head1 SEE ALSO 216*b077aed3SPierre Pronchery 217*b077aed3SPierre ProncheryL<provider(7)>, 218*b077aed3SPierre ProncheryL<EVP_MAC-BLAKE2(7)>, L<EVP_MAC-CMAC(7)>, L<EVP_MAC-GMAC(7)>, 219*b077aed3SPierre ProncheryL<EVP_MAC-HMAC(7)>, L<EVP_MAC-KMAC(7)>, L<EVP_MAC-Poly1305(7)>, 220*b077aed3SPierre ProncheryL<EVP_MAC-Siphash(7)>, 221*b077aed3SPierre ProncheryL<life_cycle-mac(7)>, L<EVP_MAC(3)> 222*b077aed3SPierre Pronchery 223*b077aed3SPierre Pronchery=head1 HISTORY 224*b077aed3SPierre Pronchery 225*b077aed3SPierre ProncheryThe provider MAC interface was introduced in OpenSSL 3.0. 226*b077aed3SPierre Pronchery 227*b077aed3SPierre Pronchery=head1 COPYRIGHT 228*b077aed3SPierre Pronchery 229*b077aed3SPierre ProncheryCopyright 2019-2022 The OpenSSL Project Authors. All Rights Reserved. 230*b077aed3SPierre Pronchery 231*b077aed3SPierre ProncheryLicensed under the Apache License 2.0 (the "License"). You may not use 232*b077aed3SPierre Proncherythis file except in compliance with the License. You can obtain a copy 233*b077aed3SPierre Proncheryin the file LICENSE in the source distribution or at 234*b077aed3SPierre ProncheryL<https://www.openssl.org/source/license.html>. 235*b077aed3SPierre Pronchery 236*b077aed3SPierre Pronchery=cut 237