provider-digest.pod 9.9 KB

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