provider-mac.7ossl 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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-MAC 7ossl"
  58. .TH PROVIDER-MAC 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\-mac \- The mac 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. \& * None of these are actual functions, but are displayed like this for
  73. \& * the function signatures for functions that are offered as function
  74. \& * pointers in OSSL_DISPATCH arrays.
  75. \& */
  76. \&
  77. \& /* Context management */
  78. \& void *OSSL_FUNC_mac_newctx(void *provctx);
  79. \& void OSSL_FUNC_mac_freectx(void *mctx);
  80. \& void *OSSL_FUNC_mac_dupctx(void *src);
  81. \&
  82. \& /* Encryption/decryption */
  83. \& int OSSL_FUNC_mac_init(void *mctx, unsigned char *key, size_t keylen,
  84. \& const OSSL_PARAM params[]);
  85. \& int OSSL_FUNC_mac_update(void *mctx, const unsigned char *in, size_t inl);
  86. \& int OSSL_FUNC_mac_final(void *mctx, unsigned char *out, size_t *outl, size_t outsize);
  87. \&
  88. \& /* MAC parameter descriptors */
  89. \& const OSSL_PARAM *OSSL_FUNC_mac_gettable_params(void *provctx);
  90. \& const OSSL_PARAM *OSSL_FUNC_mac_gettable_ctx_params(void *mctx, void *provctx);
  91. \& const OSSL_PARAM *OSSL_FUNC_mac_settable_ctx_params(void *mctx, void *provctx);
  92. \&
  93. \& /* MAC parameters */
  94. \& int OSSL_FUNC_mac_get_params(OSSL_PARAM params[]);
  95. \& int OSSL_FUNC_mac_get_ctx_params(void *mctx, OSSL_PARAM params[]);
  96. \& int OSSL_FUNC_mac_set_ctx_params(void *mctx, const OSSL_PARAM params[]);
  97. .Ve
  98. .SH DESCRIPTION
  99. .IX Header "DESCRIPTION"
  100. This documentation is primarily aimed at provider authors. See \fBprovider\fR\|(7)
  101. for further information.
  102. .PP
  103. The MAC operation enables providers to implement mac algorithms and make
  104. them available to applications via the API functions \fBEVP_MAC_init\fR\|(3),
  105. \&\fBEVP_MAC_update\fR\|(3) and \fBEVP_MAC_final\fR\|(3).
  106. .PP
  107. All "functions" mentioned here are passed as function pointers between
  108. \&\fIlibcrypto\fR and the provider in \fBOSSL_DISPATCH\fR\|(3) arrays via
  109. \&\fBOSSL_ALGORITHM\fR\|(3) arrays that are returned by the provider's
  110. \&\fBprovider_query_operation()\fR function
  111. (see "Provider Functions" in \fBprovider\-base\fR\|(7)).
  112. .PP
  113. All these "functions" have a corresponding function type definition
  114. named \fBOSSL_FUNC_{name}_fn\fR, and a helper function to retrieve the
  115. function pointer from an \fBOSSL_DISPATCH\fR\|(3) element named
  116. \&\fBOSSL_FUNC_{name}\fR.
  117. For example, the "function" \fBOSSL_FUNC_mac_newctx()\fR has these:
  118. .PP
  119. .Vb 3
  120. \& typedef void *(OSSL_FUNC_mac_newctx_fn)(void *provctx);
  121. \& static ossl_inline OSSL_FUNC_mac_newctx_fn
  122. \& OSSL_FUNC_mac_newctx(const OSSL_DISPATCH *opf);
  123. .Ve
  124. .PP
  125. \&\fBOSSL_DISPATCH\fR\|(3) arrays are indexed by numbers that are provided as
  126. macros in \fBopenssl\-core_dispatch.h\fR\|(7), as follows:
  127. .PP
  128. .Vb 3
  129. \& OSSL_FUNC_mac_newctx OSSL_FUNC_MAC_NEWCTX
  130. \& OSSL_FUNC_mac_freectx OSSL_FUNC_MAC_FREECTX
  131. \& OSSL_FUNC_mac_dupctx OSSL_FUNC_MAC_DUPCTX
  132. \&
  133. \& OSSL_FUNC_mac_init OSSL_FUNC_MAC_INIT
  134. \& OSSL_FUNC_mac_update OSSL_FUNC_MAC_UPDATE
  135. \& OSSL_FUNC_mac_final OSSL_FUNC_MAC_FINAL
  136. \&
  137. \& OSSL_FUNC_mac_get_params OSSL_FUNC_MAC_GET_PARAMS
  138. \& OSSL_FUNC_mac_get_ctx_params OSSL_FUNC_MAC_GET_CTX_PARAMS
  139. \& OSSL_FUNC_mac_set_ctx_params OSSL_FUNC_MAC_SET_CTX_PARAMS
  140. \&
  141. \& OSSL_FUNC_mac_gettable_params OSSL_FUNC_MAC_GETTABLE_PARAMS
  142. \& OSSL_FUNC_mac_gettable_ctx_params OSSL_FUNC_MAC_GETTABLE_CTX_PARAMS
  143. \& OSSL_FUNC_mac_settable_ctx_params OSSL_FUNC_MAC_SETTABLE_CTX_PARAMS
  144. .Ve
  145. .PP
  146. A mac algorithm implementation may not implement all of these functions.
  147. In order to be a consistent set of functions, at least the following functions
  148. must be implemented: \fBOSSL_FUNC_mac_newctx()\fR, \fBOSSL_FUNC_mac_freectx()\fR, \fBOSSL_FUNC_mac_init()\fR,
  149. \&\fBOSSL_FUNC_mac_update()\fR, \fBOSSL_FUNC_mac_final()\fR.
  150. All other functions are optional.
  151. .SS "Context Management Functions"
  152. .IX Subsection "Context Management Functions"
  153. \&\fBOSSL_FUNC_mac_newctx()\fR should create and return a pointer to a provider side
  154. structure for holding context information during a mac operation.
  155. A pointer to this context will be passed back in a number of the other mac
  156. operation function calls.
  157. The parameter \fIprovctx\fR is the provider context generated during provider
  158. initialisation (see \fBprovider\fR\|(7)).
  159. .PP
  160. \&\fBOSSL_FUNC_mac_freectx()\fR is passed a pointer to the provider side mac context in
  161. the \fImctx\fR parameter.
  162. If it receives NULL as \fImctx\fR value, it should not do anything other than
  163. return.
  164. This function should free any resources associated with that context.
  165. .PP
  166. \&\fBOSSL_FUNC_mac_dupctx()\fR should duplicate the provider side mac context in the
  167. \&\fImctx\fR parameter and return the duplicate copy.
  168. .SS "Encryption/Decryption Functions"
  169. .IX Subsection "Encryption/Decryption Functions"
  170. \&\fBOSSL_FUNC_mac_init()\fR initialises a mac operation given a newly created provider
  171. side mac context in the \fImctx\fR parameter. The \fIparams\fR are set before setting
  172. the MAC \fIkey\fR of \fIkeylen\fR bytes.
  173. .PP
  174. \&\fBOSSL_FUNC_mac_update()\fR is called to supply data for MAC computation of a previously
  175. initialised mac operation.
  176. The \fImctx\fR parameter contains a pointer to a previously initialised provider
  177. side context.
  178. \&\fBOSSL_FUNC_mac_update()\fR may be called multiple times for a single mac operation.
  179. .PP
  180. \&\fBOSSL_FUNC_mac_final()\fR completes the MAC computation started through previous
  181. \&\fBOSSL_FUNC_mac_init()\fR and \fBOSSL_FUNC_mac_update()\fR calls.
  182. The \fImctx\fR parameter contains a pointer to the provider side context.
  183. The resulting MAC should be written to \fIout\fR and the amount of data written
  184. to \fI*outl\fR, which should not exceed \fIoutsize\fR bytes.
  185. The same expectations apply to \fIoutsize\fR as documented for
  186. \&\fBEVP_MAC_final\fR\|(3).
  187. .SS "Mac Parameters"
  188. .IX Subsection "Mac Parameters"
  189. See \fBOSSL_PARAM\fR\|(3) for further details on the parameters structure used by
  190. these functions.
  191. .PP
  192. \&\fBOSSL_FUNC_mac_get_params()\fR gets details of parameter values associated with the
  193. provider algorithm and stores them in \fIparams\fR.
  194. .PP
  195. \&\fBOSSL_FUNC_mac_set_ctx_params()\fR sets mac parameters associated with the given
  196. provider side mac context \fImctx\fR to \fIparams\fR.
  197. Any parameter settings are additional to any that were previously set.
  198. Passing NULL for \fIparams\fR should return true.
  199. .PP
  200. \&\fBOSSL_FUNC_mac_get_ctx_params()\fR gets details of currently set parameter values
  201. associated with the given provider side mac context \fImctx\fR and stores them
  202. in \fIparams\fR.
  203. Passing NULL for \fIparams\fR should return true.
  204. .PP
  205. \&\fBOSSL_FUNC_mac_gettable_params()\fR, \fBOSSL_FUNC_mac_gettable_ctx_params()\fR,
  206. and \fBOSSL_FUNC_mac_settable_ctx_params()\fR all return constant \fBOSSL_PARAM\fR\|(3)
  207. arrays as descriptors of the parameters that \fBOSSL_FUNC_mac_get_params()\fR,
  208. \&\fBOSSL_FUNC_mac_get_ctx_params()\fR, and \fBOSSL_FUNC_mac_set_ctx_params()\fR
  209. can handle, respectively. \fBOSSL_FUNC_mac_gettable_ctx_params()\fR and
  210. \&\fBOSSL_FUNC_mac_settable_ctx_params()\fR will return the parameters associated
  211. with the provider side context \fImctx\fR in its current state if it is
  212. not NULL. Otherwise, they return the parameters associated with the
  213. provider side algorithm \fIprovctx\fR.
  214. .PP
  215. All MAC implementations are expected to handle the following parameters:
  216. .IP "with \fBOSSL_FUNC_set_ctx_params()\fR:" 4
  217. .IX Item "with OSSL_FUNC_set_ctx_params():"
  218. .RS 4
  219. .PD 0
  220. .IP """key"" (\fBOSSL_MAC_PARAM_KEY\fR) <octet string>" 4
  221. .IX Item """key"" (OSSL_MAC_PARAM_KEY) <octet string>"
  222. .PD
  223. Sets the key in the associated MAC ctx. This is identical to passing a \fIkey\fR
  224. argument to the \fBOSSL_FUNC_mac_init()\fR function.
  225. .RE
  226. .RS 4
  227. .RE
  228. .IP "with \fBOSSL_FUNC_get_params()\fR:" 4
  229. .IX Item "with OSSL_FUNC_get_params():"
  230. .RS 4
  231. .PD 0
  232. .IP """size"" (\fBOSSL_MAC_PARAM_SIZE\fR) <integer>" 4
  233. .IX Item """size"" (OSSL_MAC_PARAM_SIZE) <integer>"
  234. .PD
  235. Can be used to get the default MAC size (which might be the only allowable
  236. MAC size for the implementation).
  237. .Sp
  238. Note that some implementations allow setting the size that the resulting MAC
  239. should have as well, see the documentation of the implementation.
  240. .RE
  241. .RS 4
  242. .IP """size"" (\fBOSSL_MAC_PARAM_BLOCK_SIZE\fR) <integer>" 4
  243. .IX Item """size"" (OSSL_MAC_PARAM_BLOCK_SIZE) <integer>"
  244. Can be used to get the MAC block size (if supported by the algorithm).
  245. .RE
  246. .RS 4
  247. .RE
  248. .PP
  249. The OpenSSL FIPS provider may support the following parameters:
  250. .IP """fips-indicator"" (\fBOSSL_MAC_PARAM_FIPS_APPROVED_INDICATOR\fR) <int>" 4
  251. .IX Item """fips-indicator"" (OSSL_MAC_PARAM_FIPS_APPROVED_INDICATOR) <int>"
  252. A getter that returns 1 if the operation is FIPS approved, or 0 otherwise.
  253. This may be used after calling the final function. It may return 0 if
  254. either "no-short-mac" or "key-check" are set to 0.
  255. .IP """no-short-mac"" (\fBOSSL_MAC_PARAM_FIPS_NO_SHORT_MAC\fR) <integer>" 4
  256. .IX Item """no-short-mac"" (OSSL_MAC_PARAM_FIPS_NO_SHORT_MAC) <integer>"
  257. If required this parameter should be set early via an init function.
  258. The default value of 1 causes an error when too short MAC output is
  259. asked for. Setting this to 0 will ignore the error and set the approved
  260. "fips-indicator" to 0.
  261. This option breaks FIPS compliance if it causes the approved "fips-indicator"
  262. to return 0.
  263. .IP """key-check"" (\fBOSSL_MAC_PARAM_FIPS_KEY_CHECK\fR) <integer>" 4
  264. .IX Item """key-check"" (OSSL_MAC_PARAM_FIPS_KEY_CHECK) <integer>"
  265. If required this parameter should be set before OSSL_FUNC_mac_init.
  266. The default value of 1 causes an error when small key sizes are
  267. asked for. Setting this to 0 will ignore the error and set the approved
  268. "fips-indicator" to 0.
  269. This option breaks FIPS compliance if it causes the approved "fips-indicator"
  270. to return 0.
  271. .SH NOTES
  272. .IX Header "NOTES"
  273. The MAC life-cycle is described in \fBlife_cycle\-rand\fR\|(7). Providers should
  274. ensure that the various transitions listed there are supported. At some point
  275. the EVP layer will begin enforcing the listed transitions.
  276. .SH "RETURN VALUES"
  277. .IX Header "RETURN VALUES"
  278. \&\fBOSSL_FUNC_mac_newctx()\fR and \fBOSSL_FUNC_mac_dupctx()\fR should return the newly created
  279. provider side mac context, or NULL on failure.
  280. .PP
  281. \&\fBOSSL_FUNC_mac_init()\fR, \fBOSSL_FUNC_mac_update()\fR, \fBOSSL_FUNC_mac_final()\fR, \fBOSSL_FUNC_mac_get_params()\fR,
  282. \&\fBOSSL_FUNC_mac_get_ctx_params()\fR and \fBOSSL_FUNC_mac_set_ctx_params()\fR should return 1 for
  283. success or 0 on error.
  284. .PP
  285. \&\fBOSSL_FUNC_mac_gettable_params()\fR, \fBOSSL_FUNC_mac_gettable_ctx_params()\fR and
  286. \&\fBOSSL_FUNC_mac_settable_ctx_params()\fR should return a constant \fBOSSL_PARAM\fR\|(3)
  287. array, or NULL if none is offered.
  288. .SH "SEE ALSO"
  289. .IX Header "SEE ALSO"
  290. \&\fBprovider\fR\|(7),
  291. \&\fBEVP_MAC\-BLAKE2\fR\|(7), \fBEVP_MAC\-CMAC\fR\|(7), \fBEVP_MAC\-GMAC\fR\|(7),
  292. \&\fBEVP_MAC\-HMAC\fR\|(7), \fBEVP_MAC\-KMAC\fR\|(7), \fBEVP_MAC\-Poly1305\fR\|(7),
  293. \&\fBEVP_MAC\-Siphash\fR\|(7),
  294. \&\fBlife_cycle\-mac\fR\|(7), \fBEVP_MAC\fR\|(3)
  295. .SH HISTORY
  296. .IX Header "HISTORY"
  297. The provider MAC interface was introduced in OpenSSL 3.0.
  298. The parameters "no-short-mac" and "fips-indicator" were added in OpenSSL 3.4.
  299. .SH COPYRIGHT
  300. .IX Header "COPYRIGHT"
  301. Copyright 2019\-2024 The OpenSSL Project Authors. All Rights Reserved.
  302. .PP
  303. Licensed under the Apache License 2.0 (the "License"). You may not use
  304. this file except in compliance with the License. You can obtain a copy
  305. in the file LICENSE in the source distribution or at
  306. <https://www.openssl.org/source/license.html>.