2
0

provider-digest.pod 11 KB

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