provider-digest.7ossl 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. .\" -*- mode: troff; coding: utf-8 -*-
  2. .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43)
  3. .\"
  4. .\" Standard preamble:
  5. .\" ========================================================================
  6. .de Sp \" Vertical space (when we can't use .PP)
  7. .if t .sp .5v
  8. .if n .sp
  9. ..
  10. .de Vb \" Begin verbatim text
  11. .ft CW
  12. .nf
  13. .ne \\$1
  14. ..
  15. .de Ve \" End verbatim text
  16. .ft R
  17. .fi
  18. ..
  19. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
  20. .ie n \{\
  21. . ds C` ""
  22. . ds C' ""
  23. 'br\}
  24. .el\{\
  25. . ds C`
  26. . ds C'
  27. 'br\}
  28. .\"
  29. .\" Escape single quotes in literal strings from groff's Unicode transform.
  30. .ie \n(.g .ds Aq \(aq
  31. .el .ds Aq '
  32. .\"
  33. .\" If the F register is >0, we'll generate index entries on stderr for
  34. .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
  35. .\" entries marked with X<> in POD. Of course, you'll have to process the
  36. .\" output yourself in some meaningful fashion.
  37. .\"
  38. .\" Avoid warning from groff about undefined register 'F'.
  39. .de IX
  40. ..
  41. .nr rF 0
  42. .if \n(.g .if rF .nr rF 1
  43. .if (\n(rF:(\n(.g==0)) \{\
  44. . if \nF \{\
  45. . de IX
  46. . tm Index:\\$1\t\\n%\t"\\$2"
  47. ..
  48. . if !\nF==2 \{\
  49. . nr % 0
  50. . nr F 2
  51. . \}
  52. . \}
  53. .\}
  54. .rr rF
  55. .\" ========================================================================
  56. .\"
  57. .IX Title "PROVIDER-DIGEST 7ossl"
  58. .TH PROVIDER-DIGEST 7ossl 2025-01-17 3.4.0 OpenSSL
  59. .\" For nroff, turn off justification. Always turn off hyphenation; it makes
  60. .\" way too many mistakes in technical documents.
  61. .if n .ad l
  62. .nh
  63. .SH NAME
  64. provider\-digest \- The digest library <\-> provider functions
  65. .SH SYNOPSIS
  66. .IX Header "SYNOPSIS"
  67. .Vb 2
  68. \& #include <openssl/core_dispatch.h>
  69. \& #include <openssl/core_names.h>
  70. \&
  71. \& /*
  72. \& * Digests support the following function signatures in OSSL_DISPATCH arrays.
  73. \& * (The function signatures are not actual functions).
  74. \& */
  75. \&
  76. \& /* Context management */
  77. \& void *OSSL_FUNC_digest_newctx(void *provctx);
  78. \& void OSSL_FUNC_digest_freectx(void *dctx);
  79. \& void *OSSL_FUNC_digest_dupctx(void *dctx);
  80. \&
  81. \& /* Digest generation */
  82. \& int OSSL_FUNC_digest_init(void *dctx, const OSSL_PARAM params[]);
  83. \& int OSSL_FUNC_digest_update(void *dctx, const unsigned char *in, size_t inl);
  84. \& int OSSL_FUNC_digest_final(void *dctx, unsigned char *out, size_t *outl,
  85. \& size_t outsz);
  86. \& int OSSL_FUNC_digest_digest(void *provctx, const unsigned char *in, size_t inl,
  87. \& unsigned char *out, size_t *outl, size_t outsz);
  88. \&
  89. \& /* Digest parameter descriptors */
  90. \& const OSSL_PARAM *OSSL_FUNC_digest_gettable_params(void *provctx);
  91. \&
  92. \& /* Digest operation parameter descriptors */
  93. \& const OSSL_PARAM *OSSL_FUNC_digest_gettable_ctx_params(void *dctx,
  94. \& void *provctx);
  95. \& const OSSL_PARAM *OSSL_FUNC_digest_settable_ctx_params(void *dctx,
  96. \& void *provctx);
  97. \&
  98. \& /* Digest parameters */
  99. \& int OSSL_FUNC_digest_get_params(OSSL_PARAM params[]);
  100. \&
  101. \& /* Digest operation parameters */
  102. \& int OSSL_FUNC_digest_set_ctx_params(void *dctx, const OSSL_PARAM params[]);
  103. \& int OSSL_FUNC_digest_get_ctx_params(void *dctx, OSSL_PARAM params[]);
  104. .Ve
  105. .SH DESCRIPTION
  106. .IX Header "DESCRIPTION"
  107. This documentation is primarily aimed at provider authors. See \fBprovider\fR\|(7)
  108. for further information.
  109. .PP
  110. The DIGEST operation enables providers to implement digest algorithms and make
  111. them available to applications via the API functions \fBEVP_DigestInit_ex\fR\|(3),
  112. \&\fBEVP_DigestUpdate\fR\|(3) and \fBEVP_DigestFinal\fR\|(3) (and other related functions).
  113. .PP
  114. All "functions" mentioned here are passed as function pointers between
  115. \&\fIlibcrypto\fR and the provider in \fBOSSL_DISPATCH\fR\|(3) arrays via
  116. \&\fBOSSL_ALGORITHM\fR\|(3) arrays that are returned by the provider's
  117. \&\fBprovider_query_operation()\fR function
  118. (see "Provider Functions" in \fBprovider\-base\fR\|(7)).
  119. .PP
  120. All these "functions" have a corresponding function type definition
  121. named \fBOSSL_FUNC_{name}_fn\fR, and a helper function to retrieve the
  122. function pointer from an \fBOSSL_DISPATCH\fR\|(3) element named
  123. \&\fBOSSL_FUNC_{name}\fR.
  124. For example, the "function" \fBOSSL_FUNC_digest_newctx()\fR has these:
  125. .PP
  126. .Vb 3
  127. \& typedef void *(OSSL_FUNC_digest_newctx_fn)(void *provctx);
  128. \& static ossl_inline OSSL_FUNC_digest_newctx_fn
  129. \& OSSL_FUNC_digest_newctx(const OSSL_DISPATCH *opf);
  130. .Ve
  131. .PP
  132. \&\fBOSSL_DISPATCH\fR\|(3) arrays are indexed by numbers that are provided as
  133. macros in \fBopenssl\-core_dispatch.h\fR\|(7), as follows:
  134. .PP
  135. .Vb 3
  136. \& OSSL_FUNC_digest_newctx OSSL_FUNC_DIGEST_NEWCTX
  137. \& OSSL_FUNC_digest_freectx OSSL_FUNC_DIGEST_FREECTX
  138. \& OSSL_FUNC_digest_dupctx OSSL_FUNC_DIGEST_DUPCTX
  139. \&
  140. \& OSSL_FUNC_digest_init OSSL_FUNC_DIGEST_INIT
  141. \& OSSL_FUNC_digest_update OSSL_FUNC_DIGEST_UPDATE
  142. \& OSSL_FUNC_digest_final OSSL_FUNC_DIGEST_FINAL
  143. \& OSSL_FUNC_digest_digest OSSL_FUNC_DIGEST_DIGEST
  144. \&
  145. \& OSSL_FUNC_digest_get_params OSSL_FUNC_DIGEST_GET_PARAMS
  146. \& OSSL_FUNC_digest_get_ctx_params OSSL_FUNC_DIGEST_GET_CTX_PARAMS
  147. \& OSSL_FUNC_digest_set_ctx_params OSSL_FUNC_DIGEST_SET_CTX_PARAMS
  148. \&
  149. \& OSSL_FUNC_digest_gettable_params OSSL_FUNC_DIGEST_GETTABLE_PARAMS
  150. \& OSSL_FUNC_digest_gettable_ctx_params OSSL_FUNC_DIGEST_GETTABLE_CTX_PARAMS
  151. \& OSSL_FUNC_digest_settable_ctx_params OSSL_FUNC_DIGEST_SETTABLE_CTX_PARAMS
  152. .Ve
  153. .PP
  154. A digest algorithm implementation may not implement all of these functions.
  155. In order to be usable all or none of OSSL_FUNC_digest_newctx, OSSL_FUNC_digest_freectx,
  156. OSSL_FUNC_digest_init, OSSL_FUNC_digest_update and OSSL_FUNC_digest_final should be implemented.
  157. All other functions are optional.
  158. .SS "Context Management Functions"
  159. .IX Subsection "Context Management Functions"
  160. \&\fBOSSL_FUNC_digest_newctx()\fR should create and return a pointer to a provider side
  161. structure for holding context information during a digest operation.
  162. A pointer to this context will be passed back in a number of the other digest
  163. operation function calls.
  164. The parameter \fIprovctx\fR is the provider context generated during provider
  165. initialisation (see \fBprovider\fR\|(7)).
  166. .PP
  167. \&\fBOSSL_FUNC_digest_freectx()\fR is passed a pointer to the provider side digest context in
  168. the \fIdctx\fR parameter.
  169. This function should free any resources associated with that context.
  170. .PP
  171. \&\fBOSSL_FUNC_digest_dupctx()\fR should duplicate the provider side digest context in the
  172. \&\fIdctx\fR parameter and return the duplicate copy.
  173. .SS "Digest Generation Functions"
  174. .IX Subsection "Digest Generation Functions"
  175. \&\fBOSSL_FUNC_digest_init()\fR initialises a digest operation given a newly created
  176. provider side digest context in the \fIdctx\fR parameter.
  177. The \fIparams\fR, if not NULL, should be set on the context in a manner similar to
  178. using \fBOSSL_FUNC_digest_set_ctx_params()\fR.
  179. .PP
  180. \&\fBOSSL_FUNC_digest_update()\fR is called to supply data to be digested as part of a
  181. previously initialised digest operation.
  182. The \fIdctx\fR parameter contains a pointer to a previously initialised provider
  183. side context.
  184. \&\fBOSSL_FUNC_digest_update()\fR should digest \fIinl\fR bytes of data at the location pointed to
  185. by \fIin\fR.
  186. \&\fBOSSL_FUNC_digest_update()\fR may be called multiple times for a single digest operation.
  187. .PP
  188. \&\fBOSSL_FUNC_digest_final()\fR generates a digest started through previous \fBOSSL_FUNC_digest_init()\fR
  189. and \fBOSSL_FUNC_digest_update()\fR calls.
  190. The \fIdctx\fR parameter contains a pointer to the provider side context.
  191. The digest should be written to \fI*out\fR and the length of the digest to
  192. \&\fI*outl\fR.
  193. The digest should not exceed \fIoutsz\fR bytes.
  194. .PP
  195. \&\fBOSSL_FUNC_digest_digest()\fR is a "oneshot" digest function.
  196. No provider side digest context is used.
  197. Instead the provider context that was created during provider initialisation is
  198. passed in the \fIprovctx\fR parameter (see \fBprovider\fR\|(7)).
  199. \&\fIinl\fR bytes at \fIin\fR should be digested and the result should be stored at
  200. \&\fIout\fR. The length of the digest should be stored in \fI*outl\fR which should not
  201. exceed \fIoutsz\fR bytes.
  202. .SS "Digest Parameters"
  203. .IX Subsection "Digest Parameters"
  204. See \fBOSSL_PARAM\fR\|(3) for further details on the parameters structure used by
  205. these functions.
  206. .PP
  207. \&\fBOSSL_FUNC_digest_get_params()\fR gets details of the algorithm implementation
  208. and stores them in \fIparams\fR.
  209. .PP
  210. \&\fBOSSL_FUNC_digest_set_ctx_params()\fR sets digest operation parameters for the
  211. provider side digest context \fIdctx\fR to \fIparams\fR.
  212. Any parameter settings are additional to any that were previously set.
  213. Passing NULL for \fIparams\fR should return true.
  214. .PP
  215. \&\fBOSSL_FUNC_digest_get_ctx_params()\fR gets digest operation details details from
  216. the given provider side digest context \fIdctx\fR and stores them in \fIparams\fR.
  217. Passing NULL for \fIparams\fR should return true.
  218. .PP
  219. \&\fBOSSL_FUNC_digest_gettable_params()\fR returns a constant \fBOSSL_PARAM\fR\|(3) array
  220. containing descriptors of the parameters that \fBOSSL_FUNC_digest_get_params()\fR
  221. can handle.
  222. .PP
  223. \&\fBOSSL_FUNC_digest_gettable_ctx_params()\fR and
  224. \&\fBOSSL_FUNC_digest_settable_ctx_params()\fR both return constant
  225. \&\fBOSSL_PARAM\fR\|(3) arrays as descriptors of the parameters that
  226. \&\fBOSSL_FUNC_digest_get_ctx_params()\fR and \fBOSSL_FUNC_digest_set_ctx_params()\fR
  227. can handle, respectively. The array is based on the current state of
  228. the provider side context if \fIdctx\fR is not NULL and on the provider
  229. side algorithm \fIprovctx\fR otherwise.
  230. .PP
  231. Parameters currently recognised by built-in digests with this function
  232. are as follows. Not all parameters are relevant to, or are understood
  233. by all digests:
  234. .IP """blocksize"" (\fBOSSL_DIGEST_PARAM_BLOCK_SIZE\fR) <unsigned integer>" 4
  235. .IX Item """blocksize"" (OSSL_DIGEST_PARAM_BLOCK_SIZE) <unsigned integer>"
  236. The digest block size.
  237. The length of the "blocksize" parameter should not exceed that of a \fBsize_t\fR.
  238. .IP """size"" (\fBOSSL_DIGEST_PARAM_SIZE\fR) <unsigned integer>" 4
  239. .IX Item """size"" (OSSL_DIGEST_PARAM_SIZE) <unsigned integer>"
  240. The digest output size.
  241. The length of the "size" parameter should not exceed that of a \fBsize_t\fR.
  242. .IP """flags"" (\fBOSSL_DIGEST_PARAM_FLAGS\fR) <unsigned integer>" 4
  243. .IX Item """flags"" (OSSL_DIGEST_PARAM_FLAGS) <unsigned integer>"
  244. Diverse flags that describe exceptional behaviour for the digest:
  245. .RS 4
  246. .IP \fBEVP_MD_FLAG_ONESHOT\fR 4
  247. .IX Item "EVP_MD_FLAG_ONESHOT"
  248. This digest method can only handle one block of input.
  249. .IP \fBEVP_MD_FLAG_XOF\fR 4
  250. .IX Item "EVP_MD_FLAG_XOF"
  251. This digest method is an extensible-output function (XOF).
  252. .IP \fBEVP_MD_FLAG_DIGALGID_NULL\fR 4
  253. .IX Item "EVP_MD_FLAG_DIGALGID_NULL"
  254. When setting up a DigestAlgorithmIdentifier, this flag will have the
  255. parameter set to NULL by default. Use this for PKCS#1. \fINote: if
  256. combined with EVP_MD_FLAG_DIGALGID_ABSENT, the latter will override.\fR
  257. .IP \fBEVP_MD_FLAG_DIGALGID_ABSENT\fR 4
  258. .IX Item "EVP_MD_FLAG_DIGALGID_ABSENT"
  259. When setting up a DigestAlgorithmIdentifier, this flag will have the
  260. parameter be left absent by default. \fINote: if combined with
  261. EVP_MD_FLAG_DIGALGID_NULL, the latter will be overridden.\fR
  262. .IP \fBEVP_MD_FLAG_DIGALGID_CUSTOM\fR 4
  263. .IX Item "EVP_MD_FLAG_DIGALGID_CUSTOM"
  264. Custom DigestAlgorithmIdentifier handling via ctrl, with
  265. \&\fBEVP_MD_FLAG_DIGALGID_ABSENT\fR as default. \fINote: if combined with
  266. EVP_MD_FLAG_DIGALGID_NULL, the latter will be overridden.\fR
  267. Currently unused.
  268. .RE
  269. .RS 4
  270. .Sp
  271. The length of the "flags" parameter should equal that of an
  272. \&\fBunsigned long int\fR.
  273. .RE
  274. .SS "Digest Context Parameters"
  275. .IX Subsection "Digest Context Parameters"
  276. \&\fBOSSL_FUNC_digest_set_ctx_params()\fR sets digest parameters associated with the
  277. given provider side digest context \fIdctx\fR to \fIparams\fR.
  278. Any parameter settings are additional to any that were previously set.
  279. See \fBOSSL_PARAM\fR\|(3) for further details on the parameters structure.
  280. .PP
  281. \&\fBOSSL_FUNC_digest_get_ctx_params()\fR gets details of currently set parameters
  282. values associated with the give provider side digest context \fIdctx\fR
  283. and stores them in \fIparams\fR.
  284. See \fBOSSL_PARAM\fR\|(3) for further details on the parameters structure.
  285. .SH "RETURN VALUES"
  286. .IX Header "RETURN VALUES"
  287. \&\fBOSSL_FUNC_digest_newctx()\fR and \fBOSSL_FUNC_digest_dupctx()\fR should return the newly created
  288. provider side digest context, or NULL on failure.
  289. .PP
  290. \&\fBOSSL_FUNC_digest_init()\fR, \fBOSSL_FUNC_digest_update()\fR, \fBOSSL_FUNC_digest_final()\fR, \fBOSSL_FUNC_digest_digest()\fR,
  291. \&\fBOSSL_FUNC_digest_set_params()\fR and \fBOSSL_FUNC_digest_get_params()\fR should return 1 for success or
  292. 0 on error.
  293. .PP
  294. \&\fBOSSL_FUNC_digest_size()\fR should return the digest size.
  295. .PP
  296. \&\fBOSSL_FUNC_digest_block_size()\fR should return the block size of the underlying digest
  297. algorithm.
  298. .SH BUGS
  299. .IX Header "BUGS"
  300. The \fBEVP_Q_digest()\fR, \fBEVP_Digest()\fR and \fBEVP_DigestFinal_ex()\fR API calls do not
  301. expect the digest size to be larger than EVP_MAX_MD_SIZE. Any algorithm which
  302. produces larger digests is unusable with those API calls.
  303. .SH "SEE ALSO"
  304. .IX Header "SEE ALSO"
  305. \&\fBprovider\fR\|(7), \fBOSSL_PROVIDER\-FIPS\fR\|(7), \fBOSSL_PROVIDER\-default\fR\|(7),
  306. \&\fBOSSL_PROVIDER\-legacy\fR\|(7),
  307. \&\fBEVP_MD\-common\fR\|(7), \fBEVP_MD\-BLAKE2\fR\|(7), \fBEVP_MD\-MD2\fR\|(7),
  308. \&\fBEVP_MD\-MD4\fR\|(7), \fBEVP_MD\-MD5\fR\|(7), \fBEVP_MD\-MD5\-SHA1\fR\|(7),
  309. \&\fBEVP_MD\-MDC2\fR\|(7), \fBEVP_MD\-RIPEMD160\fR\|(7), \fBEVP_MD\-SHA1\fR\|(7),
  310. \&\fBEVP_MD\-SHA2\fR\|(7), \fBEVP_MD\-SHA3\fR\|(7), \fBEVP_MD\-KECCAK\fR\|(7)
  311. \&\fBEVP_MD\-SHAKE\fR\|(7), \fBEVP_MD\-SM3\fR\|(7), \fBEVP_MD\-WHIRLPOOL\fR\|(7),
  312. \&\fBEVP_MD\-NULL\fR\|(7),
  313. \&\fBlife_cycle\-digest\fR\|(7), \fBEVP_DigestInit\fR\|(3)
  314. .SH HISTORY
  315. .IX Header "HISTORY"
  316. The provider DIGEST interface was introduced in OpenSSL 3.0.
  317. .SH COPYRIGHT
  318. .IX Header "COPYRIGHT"
  319. Copyright 2019\-2023 The OpenSSL Project Authors. All Rights Reserved.
  320. .PP
  321. Licensed under the Apache License 2.0 (the "License"). You may not use
  322. this file except in compliance with the License. You can obtain a copy
  323. in the file LICENSE in the source distribution or at
  324. <https://www.openssl.org/source/license.html>.