2
0

provider-digest.pod 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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_numbers.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 *OP_digest_newctx(void *provctx);
  14. void OP_digest_freectx(void *dctx);
  15. void *OP_digest_dupctx(void *dctx);
  16. /* Digest generation */
  17. int OP_digest_init(void *dctx);
  18. int OP_digest_update(void *dctx, const unsigned char *in, size_t inl);
  19. int OP_digest_final(void *dctx, unsigned char *out, size_t *outl,
  20. size_t outsz);
  21. int OP_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 *OP_digest_gettable_params(void);
  25. /* Digest operation parameter descriptors */
  26. const OSSL_PARAM *OP_digest_gettable_ctx_params(void);
  27. const OSSL_PARAM *OP_digest_settable_ctx_params(void);
  28. /* Digest parameters */
  29. int OP_digest_get_params(OSSL_PARAM params[]);
  30. /* Digest operation parameters */
  31. int OP_digest_set_ctx_params(void *dctx, const OSSL_PARAM params[]);
  32. int OP_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_get_{name}>.
  48. For example, the "function" OP_digest_newctx() has these:
  49. typedef void *(OSSL_OP_digest_newctx_fn)(void *provctx);
  50. static ossl_inline OSSL_OP_digest_newctx_fn
  51. OSSL_get_OP_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_numbers.h(7)>, as follows:
  54. OP_digest_newctx OSSL_FUNC_DIGEST_NEWCTX
  55. OP_digest_freectx OSSL_FUNC_DIGEST_FREECTX
  56. OP_digest_dupctx OSSL_FUNC_DIGEST_DUPCTX
  57. OP_digest_init OSSL_FUNC_DIGEST_INIT
  58. OP_digest_update OSSL_FUNC_DIGEST_UPDATE
  59. OP_digest_final OSSL_FUNC_DIGEST_FINAL
  60. OP_digest_digest OSSL_FUNC_DIGEST_DIGEST
  61. OP_digest_get_params OSSL_FUNC_DIGEST_GET_PARAMS
  62. OP_digest_get_ctx_params OSSL_FUNC_DIGEST_GET_CTX_PARAMS
  63. OP_digest_set_ctx_params OSSL_FUNC_DIGEST_SET_CTX_PARAMS
  64. OP_digest_gettable_params OSSL_FUNC_DIGEST_GETTABLE_PARAMS
  65. OP_digest_gettable_ctx_params OSSL_FUNC_DIGEST_GETTABLE_CTX_PARAMS
  66. OP_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 OP_digest_newctx, OP_digest_freectx,
  69. OP_digest_init, OP_digest_update and OP_digest_final should be implemented.
  70. All other functions are optional.
  71. =head2 Context Management Functions
  72. OP_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. OP_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. OP_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. OP_digest_init() initialises a digest operation given a newly created
  85. provider side digest context in the I<dctx> parameter.
  86. OP_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. OP_digest_update() should digest I<inl> bytes of data at the location pointed to
  91. by I<in>.
  92. OP_digest_update() may be called multiple times for a single digest operation.
  93. OP_digest_final() generates a digest started through previous OP_digest_init()
  94. and OP_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. OP_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. OP_digest_get_params() gets details of the algorithm implementation
  110. and stores them in I<params>.
  111. OP_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. OP_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. OP_digest_gettable_params(), OP_digest_gettable_ctx_params(), and
  117. OP_digest_settable_ctx_params() all return constant B<OSSL_PARAM> arrays
  118. as descriptors of the parameters that OP_digest_get_params(),
  119. OP_digest_get_ctx_params(), and OP_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. OP_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. OP_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. Parameters currently recognised by built-in digests are as follows. Not all
  166. parameters are relevant to, or are understood by all digests:
  167. =over 4
  168. =item "xoflen" (B<OSSL_DIGEST_PARAM_XOFLEN>) <unsigned integer>
  169. Sets the digest length for extendable output functions.
  170. The length of the "xoflen" parameter should not exceed that of a B<size_t>.
  171. =item "ssl3-ms" (B<OSSL_DIGEST_PARAM_SSL3_MS>) <octet string>
  172. This parameter is set by libssl in order to calculate a signature hash for an
  173. SSLv3 CertificateVerify message as per RFC6101.
  174. It is only set after all handshake messages have already been digested via
  175. OP_digest_update() calls.
  176. The parameter provides the master secret value to be added to the digest.
  177. The digest implementation should calculate the complete digest as per RFC6101
  178. section 5.6.8.
  179. The next call after setting this parameter will be OP_digest_final().
  180. This is only relevant for implementations of SHA1 or MD5_SHA1.
  181. =item "pad_type" (B<OSSL_DIGEST_PARAM_PAD_TYPE>) <unsigned integer>
  182. Sets the pad type to be used.
  183. The only built-in digest that uses this is MDC2.
  184. Normally the final MDC2 block is padded with 0s.
  185. If the pad type is set to 2 then the final block is padded with 0x80 followed by
  186. 0s.
  187. =item "micalg" (B<OSSL_DIGEST_PARAM_MICALG>) <UTF8 string>
  188. Gets the digest Message Integrity Check algorithm string.
  189. This is used when creating S/MIME multipart/signed messages, as specified in
  190. RFC 5751.
  191. =back
  192. =head1 RETURN VALUES
  193. OP_digest_newctx() and OP_digest_dupctx() should return the newly created
  194. provider side digest context, or NULL on failure.
  195. OP_digest_init(), OP_digest_update(), OP_digest_final(), OP_digest_digest(),
  196. OP_digest_set_params() and OP_digest_get_params() should return 1 for success or
  197. 0 on error.
  198. OP_digest_size() should return the digest size.
  199. OP_digest_block_size() should return the block size of the underlying digest
  200. algorithm.
  201. =head1 SEE ALSO
  202. L<provider(7)>
  203. =head1 HISTORY
  204. The provider DIGEST interface was introduced in OpenSSL 3.0.
  205. =head1 COPYRIGHT
  206. Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
  207. Licensed under the Apache License 2.0 (the "License"). You may not use
  208. this file except in compliance with the License. You can obtain a copy
  209. in the file LICENSE in the source distribution or at
  210. L<https://www.openssl.org/source/license.html>.
  211. =cut