EVP_MAC.3ossl 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. .\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42)
  2. .\"
  3. .\" Standard preamble:
  4. .\" ========================================================================
  5. .de Sp \" Vertical space (when we can't use .PP)
  6. .if t .sp .5v
  7. .if n .sp
  8. ..
  9. .de Vb \" Begin verbatim text
  10. .ft CW
  11. .nf
  12. .ne \\$1
  13. ..
  14. .de Ve \" End verbatim text
  15. .ft R
  16. .fi
  17. ..
  18. .\" Set up some character translations and predefined strings. \*(-- will
  19. .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
  20. .\" double quote, and \*(R" will give a right double quote. \*(C+ will
  21. .\" give a nicer C++. Capital omega is used to do unbreakable dashes and
  22. .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
  23. .\" nothing in troff, for use with C<>.
  24. .tr \(*W-
  25. .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
  26. .ie n \{\
  27. . ds -- \(*W-
  28. . ds PI pi
  29. . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
  30. . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
  31. . ds L" ""
  32. . ds R" ""
  33. . ds C` ""
  34. . ds C' ""
  35. 'br\}
  36. .el\{\
  37. . ds -- \|\(em\|
  38. . ds PI \(*p
  39. . ds L" ``
  40. . ds R" ''
  41. . ds C`
  42. . ds C'
  43. 'br\}
  44. .\"
  45. .\" Escape single quotes in literal strings from groff's Unicode transform.
  46. .ie \n(.g .ds Aq \(aq
  47. .el .ds Aq '
  48. .\"
  49. .\" If the F register is >0, we'll generate index entries on stderr for
  50. .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
  51. .\" entries marked with X<> in POD. Of course, you'll have to process the
  52. .\" output yourself in some meaningful fashion.
  53. .\"
  54. .\" Avoid warning from groff about undefined register 'F'.
  55. .de IX
  56. ..
  57. .nr rF 0
  58. .if \n(.g .if rF .nr rF 1
  59. .if (\n(rF:(\n(.g==0)) \{\
  60. . if \nF \{\
  61. . de IX
  62. . tm Index:\\$1\t\\n%\t"\\$2"
  63. ..
  64. . if !\nF==2 \{\
  65. . nr % 0
  66. . nr F 2
  67. . \}
  68. . \}
  69. .\}
  70. .rr rF
  71. .\"
  72. .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
  73. .\" Fear. Run. Save yourself. No user-serviceable parts.
  74. . \" fudge factors for nroff and troff
  75. .if n \{\
  76. . ds #H 0
  77. . ds #V .8m
  78. . ds #F .3m
  79. . ds #[ \f1
  80. . ds #] \fP
  81. .\}
  82. .if t \{\
  83. . ds #H ((1u-(\\\\n(.fu%2u))*.13m)
  84. . ds #V .6m
  85. . ds #F 0
  86. . ds #[ \&
  87. . ds #] \&
  88. .\}
  89. . \" simple accents for nroff and troff
  90. .if n \{\
  91. . ds ' \&
  92. . ds ` \&
  93. . ds ^ \&
  94. . ds , \&
  95. . ds ~ ~
  96. . ds /
  97. .\}
  98. .if t \{\
  99. . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
  100. . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
  101. . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
  102. . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
  103. . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
  104. . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
  105. .\}
  106. . \" troff and (daisy-wheel) nroff accents
  107. .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
  108. .ds 8 \h'\*(#H'\(*b\h'-\*(#H'
  109. .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
  110. .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
  111. .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
  112. .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
  113. .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
  114. .ds ae a\h'-(\w'a'u*4/10)'e
  115. .ds Ae A\h'-(\w'A'u*4/10)'E
  116. . \" corrections for vroff
  117. .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
  118. .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
  119. . \" for low resolution devices (crt and lpr)
  120. .if \n(.H>23 .if \n(.V>19 \
  121. \{\
  122. . ds : e
  123. . ds 8 ss
  124. . ds o a
  125. . ds d- d\h'-1'\(ga
  126. . ds D- D\h'-1'\(hy
  127. . ds th \o'bp'
  128. . ds Th \o'LP'
  129. . ds ae ae
  130. . ds Ae AE
  131. .\}
  132. .rm #[ #] #H #V #F C
  133. .\" ========================================================================
  134. .\"
  135. .IX Title "EVP_MAC 3ossl"
  136. .TH EVP_MAC 3ossl "2024-09-03" "3.3.2" "OpenSSL"
  137. .\" For nroff, turn off justification. Always turn off hyphenation; it makes
  138. .\" way too many mistakes in technical documents.
  139. .if n .ad l
  140. .nh
  141. .SH "NAME"
  142. EVP_MAC, EVP_MAC_fetch, EVP_MAC_up_ref, EVP_MAC_free, EVP_MAC_is_a,
  143. EVP_MAC_get0_name, EVP_MAC_names_do_all, EVP_MAC_get0_description,
  144. EVP_MAC_get0_provider, EVP_MAC_get_params, EVP_MAC_gettable_params,
  145. EVP_MAC_CTX, EVP_MAC_CTX_new, EVP_MAC_CTX_free, EVP_MAC_CTX_dup,
  146. EVP_MAC_CTX_get0_mac, EVP_MAC_CTX_get_params, EVP_MAC_CTX_set_params,
  147. EVP_MAC_CTX_get_mac_size, EVP_MAC_CTX_get_block_size, EVP_Q_mac,
  148. EVP_MAC_init, EVP_MAC_update, EVP_MAC_final, EVP_MAC_finalXOF,
  149. EVP_MAC_gettable_ctx_params, EVP_MAC_settable_ctx_params,
  150. EVP_MAC_CTX_gettable_params, EVP_MAC_CTX_settable_params,
  151. EVP_MAC_do_all_provided \- EVP MAC routines
  152. .SH "SYNOPSIS"
  153. .IX Header "SYNOPSIS"
  154. .Vb 1
  155. \& #include <openssl/evp.h>
  156. \&
  157. \& typedef struct evp_mac_st EVP_MAC;
  158. \& typedef struct evp_mac_ctx_st EVP_MAC_CTX;
  159. \&
  160. \& EVP_MAC *EVP_MAC_fetch(OSSL_LIB_CTX *libctx, const char *algorithm,
  161. \& const char *properties);
  162. \& int EVP_MAC_up_ref(EVP_MAC *mac);
  163. \& void EVP_MAC_free(EVP_MAC *mac);
  164. \& int EVP_MAC_is_a(const EVP_MAC *mac, const char *name);
  165. \& const char *EVP_MAC_get0_name(const EVP_MAC *mac);
  166. \& int EVP_MAC_names_do_all(const EVP_MAC *mac,
  167. \& void (*fn)(const char *name, void *data),
  168. \& void *data);
  169. \& const char *EVP_MAC_get0_description(const EVP_MAC *mac);
  170. \& const OSSL_PROVIDER *EVP_MAC_get0_provider(const EVP_MAC *mac);
  171. \& int EVP_MAC_get_params(EVP_MAC *mac, OSSL_PARAM params[]);
  172. \&
  173. \& EVP_MAC_CTX *EVP_MAC_CTX_new(EVP_MAC *mac);
  174. \& void EVP_MAC_CTX_free(EVP_MAC_CTX *ctx);
  175. \& EVP_MAC_CTX *EVP_MAC_CTX_dup(const EVP_MAC_CTX *src);
  176. \& EVP_MAC *EVP_MAC_CTX_get0_mac(EVP_MAC_CTX *ctx);
  177. \& int EVP_MAC_CTX_get_params(EVP_MAC_CTX *ctx, OSSL_PARAM params[]);
  178. \& int EVP_MAC_CTX_set_params(EVP_MAC_CTX *ctx, const OSSL_PARAM params[]);
  179. \&
  180. \& size_t EVP_MAC_CTX_get_mac_size(EVP_MAC_CTX *ctx);
  181. \& size_t EVP_MAC_CTX_get_block_size(EVP_MAC_CTX *ctx);
  182. \& unsigned char *EVP_Q_mac(OSSL_LIB_CTX *libctx, const char *name, const char *propq,
  183. \& const char *subalg, const OSSL_PARAM *params,
  184. \& const void *key, size_t keylen,
  185. \& const unsigned char *data, size_t datalen,
  186. \& unsigned char *out, size_t outsize, size_t *outlen);
  187. \& int EVP_MAC_init(EVP_MAC_CTX *ctx, const unsigned char *key, size_t keylen,
  188. \& const OSSL_PARAM params[]);
  189. \& int EVP_MAC_update(EVP_MAC_CTX *ctx, const unsigned char *data, size_t datalen);
  190. \& int EVP_MAC_final(EVP_MAC_CTX *ctx,
  191. \& unsigned char *out, size_t *outl, size_t outsize);
  192. \& int EVP_MAC_finalXOF(EVP_MAC_CTX *ctx, unsigned char *out, size_t outsize);
  193. \&
  194. \& const OSSL_PARAM *EVP_MAC_gettable_params(const EVP_MAC *mac);
  195. \& const OSSL_PARAM *EVP_MAC_gettable_ctx_params(const EVP_MAC *mac);
  196. \& const OSSL_PARAM *EVP_MAC_settable_ctx_params(const EVP_MAC *mac);
  197. \& const OSSL_PARAM *EVP_MAC_CTX_gettable_params(EVP_MAC_CTX *ctx);
  198. \& const OSSL_PARAM *EVP_MAC_CTX_settable_params(EVP_MAC_CTX *ctx);
  199. \&
  200. \& void EVP_MAC_do_all_provided(OSSL_LIB_CTX *libctx,
  201. \& void (*fn)(EVP_MAC *mac, void *arg),
  202. \& void *arg);
  203. .Ve
  204. .SH "DESCRIPTION"
  205. .IX Header "DESCRIPTION"
  206. These types and functions help the application to calculate MACs of
  207. different types and with different underlying algorithms if there are
  208. any.
  209. .PP
  210. MACs are a bit complex insofar that some of them use other algorithms
  211. for actual computation. \s-1HMAC\s0 uses a digest, and \s-1CMAC\s0 uses a cipher.
  212. Therefore, there are sometimes two contexts to keep track of, one for
  213. the \s-1MAC\s0 algorithm itself and one for the underlying computation
  214. algorithm if there is one.
  215. .PP
  216. To make things less ambiguous, this manual talks about a \*(L"context\*(R" or
  217. \&\*(L"\s-1MAC\s0 context\*(R", which is to denote the \s-1MAC\s0 level context, and about a
  218. \&\*(L"underlying context\*(R", or \*(L"computation context\*(R", which is to denote the
  219. context for the underlying computation algorithm if there is one.
  220. .SS "Types"
  221. .IX Subsection "Types"
  222. \&\fB\s-1EVP_MAC\s0\fR is a type that holds the implementation of a \s-1MAC.\s0
  223. .PP
  224. \&\fB\s-1EVP_MAC_CTX\s0\fR is a context type that holds internal \s-1MAC\s0 information
  225. as well as a reference to a computation context, for those MACs that
  226. rely on an underlying computation algorithm.
  227. .SS "Algorithm implementation fetching"
  228. .IX Subsection "Algorithm implementation fetching"
  229. \&\fBEVP_MAC_fetch()\fR fetches an implementation of a \s-1MAC\s0 \fIalgorithm\fR, given
  230. a library context \fIlibctx\fR and a set of \fIproperties\fR.
  231. See \*(L"\s-1ALGORITHM FETCHING\*(R"\s0 in \fBcrypto\fR\|(7) for further information.
  232. .PP
  233. See \*(L"Message Authentication Code (\s-1MAC\s0)\*(R" in \fBOSSL_PROVIDER\-default\fR\|(7) for the list
  234. of algorithms supported by the default provider.
  235. .PP
  236. The returned value must eventually be freed with
  237. \&\fBEVP_MAC_free\fR\|(3).
  238. .PP
  239. \&\fBEVP_MAC_up_ref()\fR increments the reference count of an already fetched
  240. \&\s-1MAC.\s0
  241. .PP
  242. \&\fBEVP_MAC_free()\fR frees a fetched algorithm.
  243. \&\s-1NULL\s0 is a valid parameter, for which this function is a no-op.
  244. .SS "Context manipulation functions"
  245. .IX Subsection "Context manipulation functions"
  246. \&\fBEVP_MAC_CTX_new()\fR creates a new context for the \s-1MAC\s0 type \fImac\fR.
  247. The created context can then be used with most other functions
  248. described here.
  249. .PP
  250. \&\fBEVP_MAC_CTX_free()\fR frees the contents of the context, including an
  251. underlying context if there is one, as well as the context itself.
  252. \&\s-1NULL\s0 is a valid parameter, for which this function is a no-op.
  253. .PP
  254. \&\fBEVP_MAC_CTX_dup()\fR duplicates the \fIsrc\fR context and returns a newly allocated
  255. context.
  256. .PP
  257. \&\fBEVP_MAC_CTX_get0_mac()\fR returns the \fB\s-1EVP_MAC\s0\fR associated with the context
  258. \&\fIctx\fR.
  259. .SS "Computing functions"
  260. .IX Subsection "Computing functions"
  261. \&\fBEVP_Q_mac()\fR computes the message authentication code
  262. of \fIdata\fR with length \fIdatalen\fR
  263. using the \s-1MAC\s0 algorithm \fIname\fR and the key \fIkey\fR with length \fIkeylen\fR.
  264. The \s-1MAC\s0 algorithm is fetched using any given \fIlibctx\fR and property query
  265. string \fIpropq\fR. It takes parameters \fIsubalg\fR and further \fIparams\fR,
  266. both of which may be \s-1NULL\s0 if not needed.
  267. If \fIout\fR is not \s-1NULL,\s0 it places the result in the memory pointed at by \fIout\fR,
  268. but only if \fIoutsize\fR is sufficient (otherwise no computation is made).
  269. If \fIout\fR is \s-1NULL,\s0 it allocates and uses a buffer of suitable length,
  270. which will be returned on success and must be freed by the caller.
  271. In either case, also on error,
  272. it assigns the number of bytes written to \fI*outlen\fR unless \fIoutlen\fR is \s-1NULL.\s0
  273. .PP
  274. \&\fBEVP_MAC_init()\fR sets up the underlying context \fIctx\fR with information given
  275. via the \fIkey\fR and \fIparams\fR arguments. The \s-1MAC\s0 \fIkey\fR has a length of
  276. \&\fIkeylen\fR and the parameters in \fIparams\fR are processed before setting
  277. the key. If \fIkey\fR is \s-1NULL,\s0 the key must be set via \fIparams\fR either
  278. as part of this call or separately using \fBEVP_MAC_CTX_set_params()\fR.
  279. Providing non-NULL \fIparams\fR to this function is equivalent to calling
  280. \&\fBEVP_MAC_CTX_set_params()\fR with those \fIparams\fR for the same \fIctx\fR beforehand.
  281. Note: There are additional requirements for some \s-1MAC\s0 algorithms during
  282. re-initalization (i.e. calling \fBEVP_MAC_init()\fR on an \s-1EVP_MAC\s0 after \fBEVP_MAC_final()\fR
  283. has been called on the same object). See the \s-1NOTES\s0 section below.
  284. .PP
  285. \&\fBEVP_MAC_init()\fR should be called before \fBEVP_MAC_update()\fR and \fBEVP_MAC_final()\fR.
  286. .PP
  287. \&\fBEVP_MAC_update()\fR adds \fIdatalen\fR bytes from \fIdata\fR to the \s-1MAC\s0 input.
  288. .PP
  289. \&\fBEVP_MAC_final()\fR does the final computation and stores the result in
  290. the memory pointed at by \fIout\fR of size \fIoutsize\fR, and sets the number
  291. of bytes written in \fI*outl\fR at.
  292. If \fIout\fR is \s-1NULL\s0 or \fIoutsize\fR is too small, then no computation
  293. is made.
  294. To figure out what the output length will be and allocate space for it
  295. dynamically, simply call with \fIout\fR being \s-1NULL\s0 and \fIoutl\fR
  296. pointing at a valid location, then allocate space and make a second
  297. call with \fIout\fR pointing at the allocated space.
  298. .PP
  299. \&\fBEVP_MAC_finalXOF()\fR does the final computation for an \s-1XOF\s0 based \s-1MAC\s0 and stores
  300. the result in the memory pointed at by \fIout\fR of size \fIoutsize\fR.
  301. .PP
  302. \&\fBEVP_MAC_get_params()\fR retrieves details about the implementation
  303. \&\fImac\fR.
  304. The set of parameters given with \fIparams\fR determine exactly what
  305. parameters should be retrieved.
  306. Note that a parameter that is unknown in the underlying context is
  307. simply ignored.
  308. .PP
  309. \&\fBEVP_MAC_CTX_get_params()\fR retrieves chosen parameters, given the
  310. context \fIctx\fR and its underlying context.
  311. The set of parameters given with \fIparams\fR determine exactly what
  312. parameters should be retrieved.
  313. Note that a parameter that is unknown in the underlying context is
  314. simply ignored.
  315. .PP
  316. \&\fBEVP_MAC_CTX_set_params()\fR passes chosen parameters to the underlying
  317. context, given a context \fIctx\fR.
  318. The set of parameters given with \fIparams\fR determine exactly what
  319. parameters are passed down.
  320. If \fIparams\fR are \s-1NULL,\s0 the underlying context should do nothing and return 1.
  321. Note that a parameter that is unknown in the underlying context is
  322. simply ignored.
  323. Also, what happens when a needed parameter isn't passed down is
  324. defined by the implementation.
  325. .PP
  326. \&\fBEVP_MAC_gettable_params()\fR returns an \s-1\fBOSSL_PARAM\s0\fR\|(3) array that describes
  327. the retrievable and settable parameters. \fBEVP_MAC_gettable_params()\fR
  328. returns parameters that can be used with \fBEVP_MAC_get_params()\fR.
  329. .PP
  330. \&\fBEVP_MAC_gettable_ctx_params()\fR and \fBEVP_MAC_CTX_gettable_params()\fR
  331. return constant \s-1\fBOSSL_PARAM\s0\fR\|(3) arrays that describe the retrievable
  332. parameters that can be used with \fBEVP_MAC_CTX_get_params()\fR.
  333. \&\fBEVP_MAC_gettable_ctx_params()\fR returns the parameters that can be retrieved
  334. from the algorithm, whereas \fBEVP_MAC_CTX_gettable_params()\fR returns
  335. the parameters that can be retrieved in the context's current state.
  336. .PP
  337. \&\fBEVP_MAC_settable_ctx_params()\fR and \fBEVP_MAC_CTX_settable_params()\fR return
  338. constant \s-1\fBOSSL_PARAM\s0\fR\|(3) arrays that describe the settable parameters that
  339. can be used with \fBEVP_MAC_CTX_set_params()\fR. \fBEVP_MAC_settable_ctx_params()\fR
  340. returns the parameters that can be retrieved from the algorithm,
  341. whereas \fBEVP_MAC_CTX_settable_params()\fR returns the parameters that can
  342. be retrieved in the context's current state.
  343. .SS "Information functions"
  344. .IX Subsection "Information functions"
  345. \&\fBEVP_MAC_CTX_get_mac_size()\fR returns the \s-1MAC\s0 output size for the given context.
  346. .PP
  347. \&\fBEVP_MAC_CTX_get_block_size()\fR returns the \s-1MAC\s0 block size for the given context.
  348. Not all \s-1MAC\s0 algorithms support this.
  349. .PP
  350. \&\fBEVP_MAC_is_a()\fR checks if the given \fImac\fR is an implementation of an
  351. algorithm that's identifiable with \fIname\fR.
  352. .PP
  353. \&\fBEVP_MAC_get0_provider()\fR returns the provider that holds the implementation
  354. of the given \fImac\fR.
  355. .PP
  356. \&\fBEVP_MAC_do_all_provided()\fR traverses all \s-1MAC\s0 implemented by all activated
  357. providers in the given library context \fIlibctx\fR, and for each of the
  358. implementations, calls the given function \fIfn\fR with the implementation method
  359. and the given \fIarg\fR as argument.
  360. .PP
  361. \&\fBEVP_MAC_get0_name()\fR return the name of the given \s-1MAC.\s0 For fetched MACs
  362. with multiple names, only one of them is returned; it's
  363. recommended to use \fBEVP_MAC_names_do_all()\fR instead.
  364. .PP
  365. \&\fBEVP_MAC_names_do_all()\fR traverses all names for \fImac\fR, and calls
  366. \&\fIfn\fR with each name and \fIdata\fR.
  367. .PP
  368. \&\fBEVP_MAC_get0_description()\fR returns a description of the \fImac\fR, meant
  369. for display and human consumption. The description is at the discretion
  370. of the mac implementation.
  371. .SH "PARAMETERS"
  372. .IX Header "PARAMETERS"
  373. Parameters are identified by name as strings, and have an expected
  374. data type and maximum size.
  375. OpenSSL has a set of macros for parameter names it expects to see in
  376. its own \s-1MAC\s0 implementations.
  377. Here, we show all three, the OpenSSL macro for the parameter name, the
  378. name in string form, and a type description.
  379. .PP
  380. The standard parameter names are:
  381. .ie n .IP """key"" (\fB\s-1OSSL_MAC_PARAM_KEY\s0\fR) <octet string>" 4
  382. .el .IP "``key'' (\fB\s-1OSSL_MAC_PARAM_KEY\s0\fR) <octet string>" 4
  383. .IX Item "key (OSSL_MAC_PARAM_KEY) <octet string>"
  384. Its value is the \s-1MAC\s0 key as an array of bytes.
  385. .Sp
  386. For MACs that use an underlying computation algorithm, the algorithm
  387. must be set first, see parameter names \*(L"algorithm\*(R" below.
  388. .ie n .IP """iv"" (\fB\s-1OSSL_MAC_PARAM_IV\s0\fR) <octet string>" 4
  389. .el .IP "``iv'' (\fB\s-1OSSL_MAC_PARAM_IV\s0\fR) <octet string>" 4
  390. .IX Item "iv (OSSL_MAC_PARAM_IV) <octet string>"
  391. Some \s-1MAC\s0 implementations (\s-1GMAC\s0) require an \s-1IV,\s0 this parameter sets the \s-1IV.\s0
  392. .ie n .IP """custom"" (\fB\s-1OSSL_MAC_PARAM_CUSTOM\s0\fR) <octet string>" 4
  393. .el .IP "``custom'' (\fB\s-1OSSL_MAC_PARAM_CUSTOM\s0\fR) <octet string>" 4
  394. .IX Item "custom (OSSL_MAC_PARAM_CUSTOM) <octet string>"
  395. Some \s-1MAC\s0 implementations (\s-1KMAC, BLAKE2\s0) accept a Customization String,
  396. this parameter sets the Customization String. The default value is the
  397. empty string.
  398. .ie n .IP """salt"" (\fB\s-1OSSL_MAC_PARAM_SALT\s0\fR) <octet string>" 4
  399. .el .IP "``salt'' (\fB\s-1OSSL_MAC_PARAM_SALT\s0\fR) <octet string>" 4
  400. .IX Item "salt (OSSL_MAC_PARAM_SALT) <octet string>"
  401. This option is used by \s-1BLAKE2 MAC.\s0
  402. .ie n .IP """xof"" (\fB\s-1OSSL_MAC_PARAM_XOF\s0\fR) <integer>" 4
  403. .el .IP "``xof'' (\fB\s-1OSSL_MAC_PARAM_XOF\s0\fR) <integer>" 4
  404. .IX Item "xof (OSSL_MAC_PARAM_XOF) <integer>"
  405. It's a simple flag, the value 0 or 1 are expected.
  406. .Sp
  407. This option is used by \s-1KMAC.\s0
  408. .ie n .IP """digest-noinit"" (\fB\s-1OSSL_MAC_PARAM_DIGEST_NOINIT\s0\fR) <integer>" 4
  409. .el .IP "``digest-noinit'' (\fB\s-1OSSL_MAC_PARAM_DIGEST_NOINIT\s0\fR) <integer>" 4
  410. .IX Item "digest-noinit (OSSL_MAC_PARAM_DIGEST_NOINIT) <integer>"
  411. A simple flag to set the \s-1MAC\s0 digest to not initialise the
  412. implementation specific data. The value 0 or 1 is expected.
  413. .Sp
  414. This option is deprecated and will be removed in a future release.
  415. The option may be set, but is ignored.
  416. .ie n .IP """digest-oneshot"" (\fB\s-1OSSL_MAC_PARAM_DIGEST_ONESHOT\s0\fR) <integer>" 4
  417. .el .IP "``digest-oneshot'' (\fB\s-1OSSL_MAC_PARAM_DIGEST_ONESHOT\s0\fR) <integer>" 4
  418. .IX Item "digest-oneshot (OSSL_MAC_PARAM_DIGEST_ONESHOT) <integer>"
  419. A simple flag to set the \s-1MAC\s0 digest to be a oneshot operation.
  420. The value 0 or 1 is expected.
  421. .Sp
  422. This option is deprecated and will be removed in a future release.
  423. The option may be set, but is ignored.
  424. .ie n .IP """properties"" (\fB\s-1OSSL_MAC_PARAM_PROPERTIES\s0\fR) <\s-1UTF8\s0 string>" 4
  425. .el .IP "``properties'' (\fB\s-1OSSL_MAC_PARAM_PROPERTIES\s0\fR) <\s-1UTF8\s0 string>" 4
  426. .IX Item "properties (OSSL_MAC_PARAM_PROPERTIES) <UTF8 string>"
  427. .PD 0
  428. .ie n .IP """digest"" (\fB\s-1OSSL_MAC_PARAM_DIGEST\s0\fR) <\s-1UTF8\s0 string>" 4
  429. .el .IP "``digest'' (\fB\s-1OSSL_MAC_PARAM_DIGEST\s0\fR) <\s-1UTF8\s0 string>" 4
  430. .IX Item "digest (OSSL_MAC_PARAM_DIGEST) <UTF8 string>"
  431. .ie n .IP """cipher"" (\fB\s-1OSSL_MAC_PARAM_CIPHER\s0\fR) <\s-1UTF8\s0 string>" 4
  432. .el .IP "``cipher'' (\fB\s-1OSSL_MAC_PARAM_CIPHER\s0\fR) <\s-1UTF8\s0 string>" 4
  433. .IX Item "cipher (OSSL_MAC_PARAM_CIPHER) <UTF8 string>"
  434. .PD
  435. For \s-1MAC\s0 implementations that use an underlying computation cipher or
  436. digest, these parameters set what the algorithm should be.
  437. .Sp
  438. The value is always the name of the intended algorithm,
  439. or the properties.
  440. .Sp
  441. Note that not all algorithms may support all digests.
  442. \&\s-1HMAC\s0 does not support variable output length digests such as \s-1SHAKE128\s0
  443. or \s-1SHAKE256.\s0
  444. .ie n .IP """size"" (\fB\s-1OSSL_MAC_PARAM_SIZE\s0\fR) <unsigned integer>" 4
  445. .el .IP "``size'' (\fB\s-1OSSL_MAC_PARAM_SIZE\s0\fR) <unsigned integer>" 4
  446. .IX Item "size (OSSL_MAC_PARAM_SIZE) <unsigned integer>"
  447. For \s-1MAC\s0 implementations that support it, set the output size that
  448. \&\fBEVP_MAC_final()\fR should produce.
  449. The allowed sizes vary between \s-1MAC\s0 implementations, but must never exceed
  450. what can be given with a \fBsize_t\fR.
  451. .ie n .IP """tls-data-size"" (\fB\s-1OSSL_MAC_PARAM_TLS_DATA_SIZE\s0\fR) <unsigned integer>" 4
  452. .el .IP "``tls-data-size'' (\fB\s-1OSSL_MAC_PARAM_TLS_DATA_SIZE\s0\fR) <unsigned integer>" 4
  453. .IX Item "tls-data-size (OSSL_MAC_PARAM_TLS_DATA_SIZE) <unsigned integer>"
  454. This parameter is only supported by \s-1HMAC.\s0 If set then special handling is
  455. activated for calculating the \s-1MAC\s0 of a received mac-then-encrypt \s-1TLS\s0 record
  456. where variable length record padding has been used (as in the case of \s-1CBC\s0 mode
  457. ciphersuites). The value represents the total length of the record that is
  458. having the \s-1MAC\s0 calculated including the received \s-1MAC\s0 and the record padding.
  459. .Sp
  460. When used EVP_MAC_update must be called precisely twice. The first time with
  461. the 13 bytes of \s-1TLS\s0 \*(L"header\*(R" data, and the second time with the entire record
  462. including the \s-1MAC\s0 itself and any padding. The entire record length must equal
  463. the value passed in the \*(L"tls-data-size\*(R" parameter. The length passed in the
  464. \&\fBdatalen\fR parameter to \fBEVP_MAC_update()\fR should be equal to the length of the
  465. record after the \s-1MAC\s0 and any padding has been removed.
  466. .PP
  467. All these parameters should be used before the calls to any of
  468. \&\fBEVP_MAC_init()\fR, \fBEVP_MAC_update()\fR and \fBEVP_MAC_final()\fR for a full
  469. computation.
  470. Anything else may give undefined results.
  471. .SH "NOTES"
  472. .IX Header "NOTES"
  473. The \s-1MAC\s0 life-cycle is described in \fBlife_cycle\-mac\fR\|(7). In the future,
  474. the transitions described there will be enforced. When this is done, it will
  475. not be considered a breaking change to the \s-1API.\s0
  476. .PP
  477. The usage of the parameter names \*(L"custom\*(R", \*(L"iv\*(R" and \*(L"salt\*(R" correspond to
  478. the names used in the standard where the algorithm was defined.
  479. .PP
  480. Some \s-1MAC\s0 algorithms store internal state that cannot be extracted during
  481. re-initalization. For example \s-1GMAC\s0 cannot extract an \fB\s-1IV\s0\fR from the
  482. underlying \s-1CIPHER\s0 context, and so calling \fBEVP_MAC_init()\fR on an \s-1EVP_MAC\s0 object
  483. after \fBEVP_MAC_final()\fR has been called cannot reset its cipher state to what it
  484. was when the \fB\s-1IV\s0\fR was initially generated. For such instances, an
  485. \&\fB\s-1OSSL_MAC_PARAM_IV\s0\fR parameter must be passed with each call to \fBEVP_MAC_init()\fR.
  486. .SH "RETURN VALUES"
  487. .IX Header "RETURN VALUES"
  488. \&\fBEVP_MAC_fetch()\fR returns a pointer to a newly fetched \fB\s-1EVP_MAC\s0\fR, or
  489. \&\s-1NULL\s0 if allocation failed.
  490. .PP
  491. \&\fBEVP_MAC_up_ref()\fR returns 1 on success, 0 on error.
  492. .PP
  493. \&\fBEVP_MAC_names_do_all()\fR returns 1 if the callback was called for all names. A
  494. return value of 0 means that the callback was not called for any names.
  495. .PP
  496. \&\fBEVP_MAC_free()\fR returns nothing at all.
  497. .PP
  498. \&\fBEVP_MAC_is_a()\fR returns 1 if the given method can be identified with
  499. the given name, otherwise 0.
  500. .PP
  501. \&\fBEVP_MAC_get0_name()\fR returns a name of the \s-1MAC,\s0 or \s-1NULL\s0 on error.
  502. .PP
  503. \&\fBEVP_MAC_get0_provider()\fR returns a pointer to the provider for the \s-1MAC,\s0 or
  504. \&\s-1NULL\s0 on error.
  505. .PP
  506. \&\fBEVP_MAC_CTX_new()\fR and \fBEVP_MAC_CTX_dup()\fR return a pointer to a newly
  507. created \s-1EVP_MAC_CTX,\s0 or \s-1NULL\s0 if allocation failed.
  508. .PP
  509. \&\fBEVP_MAC_CTX_free()\fR returns nothing at all.
  510. .PP
  511. \&\fBEVP_MAC_CTX_get_params()\fR and \fBEVP_MAC_CTX_set_params()\fR return 1 on
  512. success, 0 on error.
  513. .PP
  514. \&\fBEVP_Q_mac()\fR returns a pointer to the computed \s-1MAC\s0 value, or \s-1NULL\s0 on error.
  515. .PP
  516. \&\fBEVP_MAC_init()\fR, \fBEVP_MAC_update()\fR, \fBEVP_MAC_final()\fR, and \fBEVP_MAC_finalXOF()\fR
  517. return 1 on success, 0 on error.
  518. .PP
  519. \&\fBEVP_MAC_CTX_get_mac_size()\fR returns the expected output size, or 0 if it isn't
  520. set. If it isn't set, a call to \fBEVP_MAC_init()\fR will set it.
  521. .PP
  522. \&\fBEVP_MAC_CTX_get_block_size()\fR returns the block size, or 0 if it isn't set.
  523. If it isn't set, a call to \fBEVP_MAC_init()\fR will set it.
  524. .PP
  525. \&\fBEVP_MAC_do_all_provided()\fR returns nothing at all.
  526. .SH "EXAMPLES"
  527. .IX Header "EXAMPLES"
  528. .Vb 5
  529. \& #include <stdlib.h>
  530. \& #include <stdio.h>
  531. \& #include <string.h>
  532. \& #include <stdarg.h>
  533. \& #include <unistd.h>
  534. \&
  535. \& #include <openssl/evp.h>
  536. \& #include <openssl/err.h>
  537. \& #include <openssl/params.h>
  538. \&
  539. \& int main() {
  540. \& EVP_MAC *mac = EVP_MAC_fetch(NULL, getenv("MY_MAC"), NULL);
  541. \& const char *cipher = getenv("MY_MAC_CIPHER");
  542. \& const char *digest = getenv("MY_MAC_DIGEST");
  543. \& const char *key = getenv("MY_KEY");
  544. \& EVP_MAC_CTX *ctx = NULL;
  545. \&
  546. \& unsigned char buf[4096];
  547. \& size_t read_l;
  548. \& size_t final_l;
  549. \&
  550. \& size_t i;
  551. \&
  552. \& OSSL_PARAM params[3];
  553. \& size_t params_n = 0;
  554. \&
  555. \& if (cipher != NULL)
  556. \& params[params_n++] =
  557. \& OSSL_PARAM_construct_utf8_string("cipher", (char*)cipher, 0);
  558. \& if (digest != NULL)
  559. \& params[params_n++] =
  560. \& OSSL_PARAM_construct_utf8_string("digest", (char*)digest, 0);
  561. \& params[params_n] = OSSL_PARAM_construct_end();
  562. \&
  563. \& if (mac == NULL
  564. \& || key == NULL
  565. \& || (ctx = EVP_MAC_CTX_new(mac)) == NULL
  566. \& || !EVP_MAC_init(ctx, (const unsigned char *)key, strlen(key),
  567. \& params))
  568. \& goto err;
  569. \&
  570. \& while ( (read_l = read(STDIN_FILENO, buf, sizeof(buf))) > 0) {
  571. \& if (!EVP_MAC_update(ctx, buf, read_l))
  572. \& goto err;
  573. \& }
  574. \&
  575. \& if (!EVP_MAC_final(ctx, buf, &final_l, sizeof(buf)))
  576. \& goto err;
  577. \&
  578. \& printf("Result: ");
  579. \& for (i = 0; i < final_l; i++)
  580. \& printf("%02X", buf[i]);
  581. \& printf("\en");
  582. \&
  583. \& EVP_MAC_CTX_free(ctx);
  584. \& EVP_MAC_free(mac);
  585. \& exit(0);
  586. \&
  587. \& err:
  588. \& EVP_MAC_CTX_free(ctx);
  589. \& EVP_MAC_free(mac);
  590. \& fprintf(stderr, "Something went wrong\en");
  591. \& ERR_print_errors_fp(stderr);
  592. \& exit (1);
  593. \& }
  594. .Ve
  595. .PP
  596. A run of this program, called with correct environment variables, can
  597. look like this:
  598. .PP
  599. .Vb 3
  600. \& $ MY_MAC=cmac MY_KEY=secret0123456789 MY_MAC_CIPHER=aes\-128\-cbc \e
  601. \& LD_LIBRARY_PATH=. ./foo < foo.c
  602. \& Result: C5C06683CD9DDEF904D754505C560A4E
  603. .Ve
  604. .PP
  605. (in this example, that program was stored in \fIfoo.c\fR and compiled to
  606. \&\fI./foo\fR)
  607. .SH "SEE ALSO"
  608. .IX Header "SEE ALSO"
  609. \&\fBproperty\fR\|(7)
  610. \&\s-1\fBOSSL_PARAM\s0\fR\|(3),
  611. \&\s-1\fBEVP_MAC\-BLAKE2\s0\fR\|(7),
  612. \&\s-1\fBEVP_MAC\-CMAC\s0\fR\|(7),
  613. \&\s-1\fBEVP_MAC\-GMAC\s0\fR\|(7),
  614. \&\s-1\fBEVP_MAC\-HMAC\s0\fR\|(7),
  615. \&\s-1\fBEVP_MAC\-KMAC\s0\fR\|(7),
  616. \&\fBEVP_MAC\-Siphash\fR\|(7),
  617. \&\fBEVP_MAC\-Poly1305\fR\|(7),
  618. \&\fBprovider\-mac\fR\|(7),
  619. \&\fBlife_cycle\-mac\fR\|(7)
  620. .SH "HISTORY"
  621. .IX Header "HISTORY"
  622. These functions were added in OpenSSL 3.0.
  623. .SH "COPYRIGHT"
  624. .IX Header "COPYRIGHT"
  625. Copyright 2018\-2024 The OpenSSL Project Authors. All Rights Reserved.
  626. .PP
  627. Licensed under the Apache License 2.0 (the \*(L"License\*(R"). You may not use
  628. this file except in compliance with the License. You can obtain a copy
  629. in the file \s-1LICENSE\s0 in the source distribution or at
  630. <https://www.openssl.org/source/license.html>.