1=pod 2 3=head1 NAME 4 5provider-digest - The digest library E<lt>-E<gt> provider functions 6 7=head1 SYNOPSIS 8 9=for openssl multiple includes 10 11 #include <openssl/core_dispatch.h> 12 #include <openssl/core_names.h> 13 14 /* 15 * Digests support the following function signatures in OSSL_DISPATCH arrays. 16 * (The function signatures are not actual functions). 17 */ 18 19 /* Context management */ 20 void *OSSL_FUNC_digest_newctx(void *provctx); 21 void OSSL_FUNC_digest_freectx(void *dctx); 22 void *OSSL_FUNC_digest_dupctx(void *dctx); 23 24 /* Digest generation */ 25 int OSSL_FUNC_digest_init(void *dctx, const OSSL_PARAM params[]); 26 int OSSL_FUNC_digest_update(void *dctx, const unsigned char *in, size_t inl); 27 int OSSL_FUNC_digest_final(void *dctx, unsigned char *out, size_t *outl, 28 size_t outsz); 29 int OSSL_FUNC_digest_digest(void *provctx, const unsigned char *in, size_t inl, 30 unsigned char *out, size_t *outl, size_t outsz); 31 32 /* Digest parameter descriptors */ 33 const OSSL_PARAM *OSSL_FUNC_digest_gettable_params(void *provctx); 34 35 /* Digest operation parameter descriptors */ 36 const OSSL_PARAM *OSSL_FUNC_digest_gettable_ctx_params(void *dctx, 37 void *provctx); 38 const OSSL_PARAM *OSSL_FUNC_digest_settable_ctx_params(void *dctx, 39 void *provctx); 40 41 /* Digest parameters */ 42 int OSSL_FUNC_digest_get_params(OSSL_PARAM params[]); 43 44 /* Digest operation parameters */ 45 int OSSL_FUNC_digest_set_ctx_params(void *dctx, const OSSL_PARAM params[]); 46 int OSSL_FUNC_digest_get_ctx_params(void *dctx, OSSL_PARAM params[]); 47 48=head1 DESCRIPTION 49 50This documentation is primarily aimed at provider authors. See L<provider(7)> 51for further information. 52 53The DIGEST operation enables providers to implement digest algorithms and make 54them available to applications via the API functions L<EVP_DigestInit_ex(3)>, 55L<EVP_DigestUpdate(3)> and L<EVP_DigestFinal(3)> (and other related functions). 56 57All "functions" mentioned here are passed as function pointers between 58F<libcrypto> and the provider in L<OSSL_DISPATCH(3)> arrays via 59L<OSSL_ALGORITHM(3)> arrays that are returned by the provider's 60provider_query_operation() function 61(see L<provider-base(7)/Provider Functions>). 62 63All these "functions" have a corresponding function type definition 64named B<OSSL_FUNC_{name}_fn>, and a helper function to retrieve the 65function pointer from an L<OSSL_DISPATCH(3)> element named 66B<OSSL_FUNC_{name}>. 67For example, the "function" OSSL_FUNC_digest_newctx() has these: 68 69 typedef void *(OSSL_FUNC_digest_newctx_fn)(void *provctx); 70 static ossl_inline OSSL_FUNC_digest_newctx_fn 71 OSSL_FUNC_digest_newctx(const OSSL_DISPATCH *opf); 72 73L<OSSL_DISPATCH(3)> arrays are indexed by numbers that are provided as 74macros in L<openssl-core_dispatch.h(7)>, as follows: 75 76 OSSL_FUNC_digest_newctx OSSL_FUNC_DIGEST_NEWCTX 77 OSSL_FUNC_digest_freectx OSSL_FUNC_DIGEST_FREECTX 78 OSSL_FUNC_digest_dupctx OSSL_FUNC_DIGEST_DUPCTX 79 80 OSSL_FUNC_digest_init OSSL_FUNC_DIGEST_INIT 81 OSSL_FUNC_digest_update OSSL_FUNC_DIGEST_UPDATE 82 OSSL_FUNC_digest_final OSSL_FUNC_DIGEST_FINAL 83 OSSL_FUNC_digest_digest OSSL_FUNC_DIGEST_DIGEST 84 85 OSSL_FUNC_digest_get_params OSSL_FUNC_DIGEST_GET_PARAMS 86 OSSL_FUNC_digest_get_ctx_params OSSL_FUNC_DIGEST_GET_CTX_PARAMS 87 OSSL_FUNC_digest_set_ctx_params OSSL_FUNC_DIGEST_SET_CTX_PARAMS 88 89 OSSL_FUNC_digest_gettable_params OSSL_FUNC_DIGEST_GETTABLE_PARAMS 90 OSSL_FUNC_digest_gettable_ctx_params OSSL_FUNC_DIGEST_GETTABLE_CTX_PARAMS 91 OSSL_FUNC_digest_settable_ctx_params OSSL_FUNC_DIGEST_SETTABLE_CTX_PARAMS 92 93A digest algorithm implementation may not implement all of these functions. 94In order to be usable all or none of OSSL_FUNC_digest_newctx, OSSL_FUNC_digest_freectx, 95OSSL_FUNC_digest_init, OSSL_FUNC_digest_update and OSSL_FUNC_digest_final should be implemented. 96All other functions are optional. 97 98=head2 Context Management Functions 99 100OSSL_FUNC_digest_newctx() should create and return a pointer to a provider side 101structure for holding context information during a digest operation. 102A pointer to this context will be passed back in a number of the other digest 103operation function calls. 104The parameter I<provctx> is the provider context generated during provider 105initialisation (see L<provider(7)>). 106 107OSSL_FUNC_digest_freectx() is passed a pointer to the provider side digest context in 108the I<dctx> parameter. 109This function should free any resources associated with that context. 110 111OSSL_FUNC_digest_dupctx() should duplicate the provider side digest context in the 112I<dctx> parameter and return the duplicate copy. 113 114=head2 Digest Generation Functions 115 116OSSL_FUNC_digest_init() initialises a digest operation given a newly created 117provider side digest context in the I<dctx> parameter. 118The I<params>, if not NULL, should be set on the context in a manner similar to 119using OSSL_FUNC_digest_set_ctx_params(). 120 121OSSL_FUNC_digest_update() is called to supply data to be digested as part of a 122previously initialised digest operation. 123The I<dctx> parameter contains a pointer to a previously initialised provider 124side context. 125OSSL_FUNC_digest_update() should digest I<inl> bytes of data at the location pointed to 126by I<in>. 127OSSL_FUNC_digest_update() may be called multiple times for a single digest operation. 128 129OSSL_FUNC_digest_final() generates a digest started through previous OSSL_FUNC_digest_init() 130and OSSL_FUNC_digest_update() calls. 131The I<dctx> parameter contains a pointer to the provider side context. 132The digest should be written to I<*out> and the length of the digest to 133I<*outl>. 134The digest should not exceed I<outsz> bytes. 135 136OSSL_FUNC_digest_digest() is a "oneshot" digest function. 137No provider side digest context is used. 138Instead the provider context that was created during provider initialisation is 139passed in the I<provctx> parameter (see L<provider(7)>). 140I<inl> bytes at I<in> should be digested and the result should be stored at 141I<out>. The length of the digest should be stored in I<*outl> which should not 142exceed I<outsz> bytes. 143 144=head2 Digest Parameters 145 146See L<OSSL_PARAM(3)> for further details on the parameters structure used by 147these functions. 148 149OSSL_FUNC_digest_get_params() gets details of the algorithm implementation 150and stores them in I<params>. 151 152OSSL_FUNC_digest_set_ctx_params() sets digest operation parameters for the 153provider side digest context I<dctx> to I<params>. 154Any parameter settings are additional to any that were previously set. 155Passing NULL for I<params> should return true. 156 157OSSL_FUNC_digest_get_ctx_params() gets digest operation details details from 158the given provider side digest context I<dctx> and stores them in I<params>. 159Passing NULL for I<params> should return true. 160 161OSSL_FUNC_digest_gettable_params() returns a constant L<OSSL_PARAM(3)> array 162containing descriptors of the parameters that OSSL_FUNC_digest_get_params() 163can handle. 164 165OSSL_FUNC_digest_gettable_ctx_params() and 166OSSL_FUNC_digest_settable_ctx_params() both return constant 167L<OSSL_PARAM(3)> arrays as descriptors of the parameters that 168OSSL_FUNC_digest_get_ctx_params() and OSSL_FUNC_digest_set_ctx_params() 169can handle, respectively. The array is based on the current state of 170the provider side context if I<dctx> is not NULL and on the provider 171side algorithm I<provctx> otherwise. 172 173Parameters currently recognised by built-in digests with this function 174are as follows. Not all parameters are relevant to, or are understood 175by all digests: 176 177=over 4 178 179=item "blocksize" (B<OSSL_DIGEST_PARAM_BLOCK_SIZE>) <unsigned integer> 180 181The digest block size. 182The length of the "blocksize" parameter should not exceed that of a B<size_t>. 183 184=item "size" (B<OSSL_DIGEST_PARAM_SIZE>) <unsigned integer> 185 186The digest output size. 187The length of the "size" parameter should not exceed that of a B<size_t>. 188 189=item "flags" (B<OSSL_DIGEST_PARAM_FLAGS>) <unsigned integer> 190 191Diverse flags that describe exceptional behaviour for the digest: 192 193=over 4 194 195=item B<EVP_MD_FLAG_ONESHOT> 196 197This digest method can only handle one block of input. 198 199=item B<EVP_MD_FLAG_XOF> 200 201This digest method is an extensible-output function (XOF) and supports 202setting the B<OSSL_DIGEST_PARAM_XOFLEN> parameter. 203 204=item B<EVP_MD_FLAG_DIGALGID_NULL> 205 206When setting up a DigestAlgorithmIdentifier, this flag will have the 207parameter set to NULL by default. Use this for PKCS#1. I<Note: if 208combined with EVP_MD_FLAG_DIGALGID_ABSENT, the latter will override.> 209 210=item B<EVP_MD_FLAG_DIGALGID_ABSENT> 211 212When setting up a DigestAlgorithmIdentifier, this flag will have the 213parameter be left absent by default. I<Note: if combined with 214EVP_MD_FLAG_DIGALGID_NULL, the latter will be overridden.> 215 216=item B<EVP_MD_FLAG_DIGALGID_CUSTOM> 217 218Custom DigestAlgorithmIdentifier handling via ctrl, with 219B<EVP_MD_FLAG_DIGALGID_ABSENT> as default. I<Note: if combined with 220EVP_MD_FLAG_DIGALGID_NULL, the latter will be overridden.> 221Currently unused. 222 223=back 224 225The length of the "flags" parameter should equal that of an 226B<unsigned long int>. 227 228=back 229 230=head2 Digest Context Parameters 231 232OSSL_FUNC_digest_set_ctx_params() sets digest parameters associated with the 233given provider side digest context I<dctx> to I<params>. 234Any parameter settings are additional to any that were previously set. 235See L<OSSL_PARAM(3)> for further details on the parameters structure. 236 237OSSL_FUNC_digest_get_ctx_params() gets details of currently set parameters 238values associated with the give provider side digest context I<dctx> 239and stores them in I<params>. 240See L<OSSL_PARAM(3)> for further details on the parameters structure. 241 242=head1 RETURN VALUES 243 244OSSL_FUNC_digest_newctx() and OSSL_FUNC_digest_dupctx() should return the newly created 245provider side digest context, or NULL on failure. 246 247OSSL_FUNC_digest_init(), OSSL_FUNC_digest_update(), OSSL_FUNC_digest_final(), OSSL_FUNC_digest_digest(), 248OSSL_FUNC_digest_set_params() and OSSL_FUNC_digest_get_params() should return 1 for success or 2490 on error. 250 251OSSL_FUNC_digest_size() should return the digest size. 252 253OSSL_FUNC_digest_block_size() should return the block size of the underlying digest 254algorithm. 255 256=head1 BUGS 257 258The EVP_Q_digest(), EVP_Digest() and EVP_DigestFinal_ex() API calls do not 259expect the digest size to be larger than EVP_MAX_MD_SIZE. Any algorithm which 260produces larger digests is unusable with those API calls. 261 262=head1 SEE ALSO 263 264L<provider(7)>, L<OSSL_PROVIDER-FIPS(7)>, L<OSSL_PROVIDER-default(7)>, 265L<OSSL_PROVIDER-legacy(7)>, 266L<EVP_MD-common(7)>, L<EVP_MD-BLAKE2(7)>, L<EVP_MD-MD2(7)>, 267L<EVP_MD-MD4(7)>, L<EVP_MD-MD5(7)>, L<EVP_MD-MD5-SHA1(7)>, 268L<EVP_MD-MDC2(7)>, L<EVP_MD-RIPEMD160(7)>, L<EVP_MD-SHA1(7)>, 269L<EVP_MD-SHA2(7)>, L<EVP_MD-SHA3(7)>, L<EVP_MD-SHAKE(7)>, 270L<EVP_MD-SM3(7)>, L<EVP_MD-WHIRLPOOL(7)>, 271L<EVP_MD-NULL(7)>, 272L<life_cycle-digest(7)>, L<EVP_DigestInit(3)> 273 274=head1 HISTORY 275 276The provider DIGEST interface was introduced in OpenSSL 3.0. 277 278=head1 COPYRIGHT 279 280Copyright 2019-2023 The OpenSSL Project Authors. All Rights Reserved. 281 282Licensed under the Apache License 2.0 (the "License"). You may not use 283this file except in compliance with the License. You can obtain a copy 284in the file LICENSE in the source distribution or at 285L<https://www.openssl.org/source/license.html>. 286 287=cut 288