Debian Codegraph @

upstream/debian-unstable/man3/EVP_MAC.3ssl

raw
1 .\" -*- mode: troff; coding: utf-8 -*-
2 .\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45)
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 "EVP_MAC 3SSL"
58 .TH EVP_MAC 3SSL 2026-04-07 3.6.2 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 EVP_MAC, EVP_MAC_fetch, EVP_MAC_up_ref, EVP_MAC_free, EVP_MAC_is_a,
65 EVP_MAC_get0_name, EVP_MAC_names_do_all, EVP_MAC_get0_description,
66 EVP_MAC_get0_provider, EVP_MAC_get_params, EVP_MAC_gettable_params,
67 EVP_MAC_CTX, EVP_MAC_CTX_new, EVP_MAC_CTX_free, EVP_MAC_CTX_dup,
68 EVP_MAC_CTX_get0_mac, EVP_MAC_CTX_get_params, EVP_MAC_CTX_set_params,
69 EVP_MAC_CTX_get_mac_size, EVP_MAC_CTX_get_block_size, EVP_Q_mac,
70 EVP_MAC_init, EVP_MAC_init_SKEY, EVP_MAC_update, EVP_MAC_final, EVP_MAC_finalXOF,
71 EVP_MAC_gettable_ctx_params, EVP_MAC_settable_ctx_params,
72 EVP_MAC_CTX_gettable_params, EVP_MAC_CTX_settable_params,
73 EVP_MAC_do_all_provided \- EVP MAC routines
74 .SH SYNOPSIS
75 .IX Header "SYNOPSIS"
76 .Vb 1
77 \& #include <openssl/evp.h>
78 \&
79 \& typedef struct evp_mac_st EVP_MAC;
80 \& typedef struct evp_mac_ctx_st EVP_MAC_CTX;
81 \&
82 \& EVP_MAC *EVP_MAC_fetch(OSSL_LIB_CTX *libctx, const char *algorithm,
83 \& const char *properties);
84 \& int EVP_MAC_up_ref(EVP_MAC *mac);
85 \& void EVP_MAC_free(EVP_MAC *mac);
86 \& int EVP_MAC_is_a(const EVP_MAC *mac, const char *name);
87 \& const char *EVP_MAC_get0_name(const EVP_MAC *mac);
88 \& int EVP_MAC_names_do_all(const EVP_MAC *mac,
89 \& void (*fn)(const char *name, void *data),
90 \& void *data);
91 \& const char *EVP_MAC_get0_description(const EVP_MAC *mac);
92 \& const OSSL_PROVIDER *EVP_MAC_get0_provider(const EVP_MAC *mac);
93 \& int EVP_MAC_get_params(EVP_MAC *mac, OSSL_PARAM params[]);
94 \&
95 \& EVP_MAC_CTX *EVP_MAC_CTX_new(EVP_MAC *mac);
96 \& void EVP_MAC_CTX_free(EVP_MAC_CTX *ctx);
97 \& EVP_MAC_CTX *EVP_MAC_CTX_dup(const EVP_MAC_CTX *src);
98 \& EVP_MAC *EVP_MAC_CTX_get0_mac(EVP_MAC_CTX *ctx);
99 \& int EVP_MAC_CTX_get_params(EVP_MAC_CTX *ctx, OSSL_PARAM params[]);
100 \& int EVP_MAC_CTX_set_params(EVP_MAC_CTX *ctx, const OSSL_PARAM params[]);
101 \&
102 \& size_t EVP_MAC_CTX_get_mac_size(EVP_MAC_CTX *ctx);
103 \& size_t EVP_MAC_CTX_get_block_size(EVP_MAC_CTX *ctx);
104 \& unsigned char *EVP_Q_mac(OSSL_LIB_CTX *libctx, const char *name, const char *propq,
105 \& const char *subalg, const OSSL_PARAM *params,
106 \& const void *key, size_t keylen,
107 \& const unsigned char *data, size_t datalen,
108 \& unsigned char *out, size_t outsize, size_t *outlen);
109 \& int EVP_MAC_init(EVP_MAC_CTX *ctx, const unsigned char *key, size_t keylen,
110 \& const OSSL_PARAM params[]);
111 \& int EVP_MAC_init_SKEY(EVP_MAC_CTX *ctx, EVP_SKEY *skey, const OSSL_PARAM params[]);
112 \& int EVP_MAC_update(EVP_MAC_CTX *ctx, const unsigned char *data, size_t datalen);
113 \& int EVP_MAC_final(EVP_MAC_CTX *ctx,
114 \& unsigned char *out, size_t *outl, size_t outsize);
115 \& int EVP_MAC_finalXOF(EVP_MAC_CTX *ctx, unsigned char *out, size_t outsize);
116 \&
117 \& const OSSL_PARAM *EVP_MAC_gettable_params(const EVP_MAC *mac);
118 \& const OSSL_PARAM *EVP_MAC_gettable_ctx_params(const EVP_MAC *mac);
119 \& const OSSL_PARAM *EVP_MAC_settable_ctx_params(const EVP_MAC *mac);
120 \& const OSSL_PARAM *EVP_MAC_CTX_gettable_params(EVP_MAC_CTX *ctx);
121 \& const OSSL_PARAM *EVP_MAC_CTX_settable_params(EVP_MAC_CTX *ctx);
122 \&
123 \& void EVP_MAC_do_all_provided(OSSL_LIB_CTX *libctx,
124 \& void (*fn)(EVP_MAC *mac, void *arg),
125 \& void *arg);
126 .Ve
127 .SH DESCRIPTION
128 .IX Header "DESCRIPTION"
129 These types and functions help the application to calculate MACs of
130 different types and with different underlying algorithms if there are
131 any.
132 .PP
133 MACs are a bit complex insofar that some of them use other algorithms
134 for actual computation. HMAC uses a digest, and CMAC uses a cipher.
135 Therefore, there are sometimes two contexts to keep track of, one for
136 the MAC algorithm itself and one for the underlying computation
137 algorithm if there is one.
138 .PP
139 To make things less ambiguous, this manual talks about a "context" or
140 "MAC context", which is to denote the MAC level context, and about a
141 "underlying context", or "computation context", which is to denote the
142 context for the underlying computation algorithm if there is one.
143 .SS Types
144 .IX Subsection "Types"
145 \&\fBEVP_MAC\fR is a type that holds the implementation of a MAC.
146 .PP
147 \&\fBEVP_MAC_CTX\fR is a context type that holds internal MAC information
148 as well as a reference to a computation context, for those MACs that
149 rely on an underlying computation algorithm.
150 .SS "Algorithm implementation fetching"
151 .IX Subsection "Algorithm implementation fetching"
152 \&\fBEVP_MAC_fetch()\fR fetches an implementation of a MAC \fIalgorithm\fR, given
153 a library context \fIlibctx\fR and a set of \fIproperties\fR.
154 See "ALGORITHM FETCHING" in \fBcrypto\fR\|(7) for further information.
155 .PP
156 See "Message Authentication Code (MAC)" in \fBOSSL_PROVIDER\-default\fR\|(7) for the list
157 of algorithms supported by the default provider.
158 .PP
159 The returned value must eventually be freed with
160 \&\fBEVP_MAC_free\fR\|(3).
161 .PP
162 \&\fBEVP_MAC_up_ref()\fR increments the reference count of an already fetched
163 MAC.
164 .PP
165 \&\fBEVP_MAC_free()\fR frees a fetched algorithm.
166 NULL is a valid parameter, for which this function is a no-op.
167 .SS "Context manipulation functions"
168 .IX Subsection "Context manipulation functions"
169 \&\fBEVP_MAC_CTX_new()\fR creates a new context for the MAC type \fImac\fR.
170 The created context can then be used with most other functions
171 described here.
172 .PP
173 \&\fBEVP_MAC_CTX_free()\fR frees the contents of the context, including an
174 underlying context if there is one, as well as the context itself.
175 NULL is a valid parameter, for which this function is a no-op.
176 .PP
177 \&\fBEVP_MAC_CTX_dup()\fR duplicates the \fIsrc\fR context and returns a newly allocated
178 context.
179 .PP
180 \&\fBEVP_MAC_CTX_get0_mac()\fR returns the \fBEVP_MAC\fR associated with the context
181 \&\fIctx\fR.
182 .SS "Computing functions"
183 .IX Subsection "Computing functions"
184 \&\fBEVP_Q_mac()\fR computes the message authentication code
185 of \fIdata\fR with length \fIdatalen\fR
186 using the MAC algorithm \fIname\fR and the key \fIkey\fR with length \fIkeylen\fR.
187 The MAC algorithm is fetched using any given \fIlibctx\fR and property query
188 string \fIpropq\fR. It takes parameters \fIsubalg\fR and further \fIparams\fR,
189 both of which may be NULL if not needed.
190 If \fIout\fR is not NULL, it places the result in the memory pointed at by \fIout\fR,
191 but only if \fIoutsize\fR is sufficient (otherwise no computation is made).
192 If \fIout\fR is NULL, it allocates and uses a buffer of suitable length,
193 which will be returned on success and must be freed by the caller.
194 In either case, also on error,
195 it assigns the number of bytes written to \fI*outlen\fR unless \fIoutlen\fR is NULL.
196 .PP
197 \&\fBEVP_MAC_init()\fR sets up the underlying context \fIctx\fR with information given
198 via the \fIkey\fR and \fIparams\fR arguments. The MAC \fIkey\fR has a length of
199 \&\fIkeylen\fR and the parameters in \fIparams\fR are processed before setting
200 the key. If \fIkey\fR is NULL, the key must be set via \fIparams\fR either
201 as part of this call or separately using \fBEVP_MAC_CTX_set_params()\fR.
202 Providing non-NULL \fIparams\fR to this function is equivalent to calling
203 \&\fBEVP_MAC_CTX_set_params()\fR with those \fIparams\fR for the same \fIctx\fR beforehand.
204 Note: There are additional requirements for some MAC algorithms during
205 re-initalization (i.e. calling \fBEVP_MAC_init()\fR on an EVP_MAC after \fBEVP_MAC_final()\fR
206 has been called on the same object). See the NOTES section below.
207 .PP
208 \&\fBEVP_MAC_init()\fR should be called before \fBEVP_MAC_update()\fR and \fBEVP_MAC_final()\fR.
209 .PP
210 \&\fBEVP_MAC_init_SKEY()\fR is similar to \fBEVP_MAC_init()\fR but it accepts an opaque
211 \&\fBEVP_SKEY\fR object as a key.
212 .PP
213 \&\fBEVP_MAC_update()\fR adds \fIdatalen\fR bytes from \fIdata\fR to the MAC input.
214 .PP
215 \&\fBEVP_MAC_final()\fR does the final computation and stores the result in
216 the memory pointed at by \fIout\fR of size \fIoutsize\fR, and sets the number
217 of bytes written in \fI*outl\fR at.
218 If \fIout\fR is NULL or \fIoutsize\fR is too small, then no computation
219 is made.
220 To figure out what the output length will be and allocate space for it
221 dynamically, simply call with \fIout\fR being NULL and \fIoutl\fR
222 pointing at a valid location, then allocate space and make a second
223 call with \fIout\fR pointing at the allocated space.
224 .PP
225 \&\fBEVP_MAC_finalXOF()\fR does the final computation for an XOF based MAC and stores
226 the result in the memory pointed at by \fIout\fR of size \fIoutsize\fR.
227 .PP
228 \&\fBEVP_MAC_get_params()\fR retrieves details about the implementation
229 \&\fImac\fR.
230 The set of parameters given with \fIparams\fR determine exactly what
231 parameters should be retrieved.
232 Note that a parameter that is unknown in the underlying context is
233 simply ignored.
234 .PP
235 \&\fBEVP_MAC_CTX_get_params()\fR retrieves chosen parameters, given the
236 context \fIctx\fR and its underlying context.
237 The set of parameters given with \fIparams\fR determine exactly what
238 parameters should be retrieved.
239 Note that a parameter that is unknown in the underlying context is
240 simply ignored.
241 .PP
242 \&\fBEVP_MAC_CTX_set_params()\fR passes chosen parameters to the underlying
243 context, given a context \fIctx\fR.
244 The set of parameters given with \fIparams\fR determine exactly what
245 parameters are passed down.
246 If \fIparams\fR are NULL, the underlying context should do nothing and return 1.
247 Note that a parameter that is unknown in the underlying context is
248 simply ignored.
249 Also, what happens when a needed parameter isn't passed down is
250 defined by the implementation.
251 .PP
252 \&\fBEVP_MAC_gettable_params()\fR returns an \fBOSSL_PARAM\fR\|(3) array that describes
253 the retrievable and settable parameters. \fBEVP_MAC_gettable_params()\fR
254 returns parameters that can be used with \fBEVP_MAC_get_params()\fR.
255 .PP
256 \&\fBEVP_MAC_gettable_ctx_params()\fR and \fBEVP_MAC_CTX_gettable_params()\fR
257 return constant \fBOSSL_PARAM\fR\|(3) arrays that describe the retrievable
258 parameters that can be used with \fBEVP_MAC_CTX_get_params()\fR.
259 \&\fBEVP_MAC_gettable_ctx_params()\fR returns the parameters that can be retrieved
260 from the algorithm, whereas \fBEVP_MAC_CTX_gettable_params()\fR returns
261 the parameters that can be retrieved in the context's current state.
262 .PP
263 \&\fBEVP_MAC_settable_ctx_params()\fR and \fBEVP_MAC_CTX_settable_params()\fR return
264 constant \fBOSSL_PARAM\fR\|(3) arrays that describe the settable parameters that
265 can be used with \fBEVP_MAC_CTX_set_params()\fR. \fBEVP_MAC_settable_ctx_params()\fR
266 returns the parameters that can be retrieved from the algorithm,
267 whereas \fBEVP_MAC_CTX_settable_params()\fR returns the parameters that can
268 be retrieved in the context's current state.
269 .SS "Information functions"
270 .IX Subsection "Information functions"
271 \&\fBEVP_MAC_CTX_get_mac_size()\fR returns the MAC output size for the given context.
272 .PP
273 \&\fBEVP_MAC_CTX_get_block_size()\fR returns the MAC block size for the given context.
274 Not all MAC algorithms support this.
275 .PP
276 \&\fBEVP_MAC_is_a()\fR checks if the given \fImac\fR is an implementation of an
277 algorithm that's identifiable with \fIname\fR.
278 .PP
279 \&\fBEVP_MAC_get0_provider()\fR returns the provider that holds the implementation
280 of the given \fImac\fR.
281 .PP
282 \&\fBEVP_MAC_do_all_provided()\fR traverses all MAC implemented by all activated
283 providers in the given library context \fIlibctx\fR, and for each of the
284 implementations, calls the given function \fIfn\fR with the implementation method
285 and the given \fIarg\fR as argument.
286 .PP
287 \&\fBEVP_MAC_get0_name()\fR return the name of the given MAC. For fetched MACs
288 with multiple names, only one of them is returned; it's
289 recommended to use \fBEVP_MAC_names_do_all()\fR instead.
290 .PP
291 \&\fBEVP_MAC_names_do_all()\fR traverses all names for \fImac\fR, and calls
292 \&\fIfn\fR with each name and \fIdata\fR.
293 .PP
294 \&\fBEVP_MAC_get0_description()\fR returns a description of the \fImac\fR, meant
295 for display and human consumption. The description is at the discretion
296 of the mac implementation.
297 .SH PARAMETERS
298 .IX Header "PARAMETERS"
299 Parameters are identified by name as strings, and have an expected
300 data type and maximum size.
301 OpenSSL has a set of macros for parameter names it expects to see in
302 its own MAC implementations.
303 Here, we show all three, the OpenSSL macro for the parameter name, the
304 name in string form, and a type description.
305 .PP
306 The standard parameter names are:
307 .IP """key"" (\fBOSSL_MAC_PARAM_KEY\fR) <octet string>" 4
308 .IX Item """key"" (OSSL_MAC_PARAM_KEY) <octet string>"
309 Its value is the MAC key as an array of bytes.
310 .Sp
311 For MACs that use an underlying computation algorithm, the algorithm
312 must be set first, see parameter names "algorithm" below.
313 .IP """iv"" (\fBOSSL_MAC_PARAM_IV\fR) <octet string>" 4
314 .IX Item """iv"" (OSSL_MAC_PARAM_IV) <octet string>"
315 Some MAC implementations (GMAC) require an IV, this parameter sets the IV.
316 .IP """custom"" (\fBOSSL_MAC_PARAM_CUSTOM\fR) <octet string>" 4
317 .IX Item """custom"" (OSSL_MAC_PARAM_CUSTOM) <octet string>"
318 Some MAC implementations (KMAC, BLAKE2) accept a Customization String,
319 this parameter sets the Customization String. The default value is the
320 empty string.
321 .IP """salt"" (\fBOSSL_MAC_PARAM_SALT\fR) <octet string>" 4
322 .IX Item """salt"" (OSSL_MAC_PARAM_SALT) <octet string>"
323 This option is used by BLAKE2 MAC.
324 .IP """xof"" (\fBOSSL_MAC_PARAM_XOF\fR) <integer>" 4
325 .IX Item """xof"" (OSSL_MAC_PARAM_XOF) <integer>"
326 It's a simple flag, the value 0 or 1 are expected.
327 .Sp
328 This option is used by KMAC.
329 .IP """digest-noinit"" (\fBOSSL_MAC_PARAM_DIGEST_NOINIT\fR) <integer>" 4
330 .IX Item """digest-noinit"" (OSSL_MAC_PARAM_DIGEST_NOINIT) <integer>"
331 A simple flag to set the MAC digest to not initialise the
332 implementation specific data. The value 0 or 1 is expected.
333 .Sp
334 This option is deprecated and will be removed in a future release.
335 The option may be set, but is ignored.
336 .IP """digest-oneshot"" (\fBOSSL_MAC_PARAM_DIGEST_ONESHOT\fR) <integer>" 4
337 .IX Item """digest-oneshot"" (OSSL_MAC_PARAM_DIGEST_ONESHOT) <integer>"
338 A simple flag to set the MAC digest to be a oneshot operation.
339 The value 0 or 1 is expected.
340 .Sp
341 This option is deprecated and will be removed in a future release.
342 The option may be set, but is ignored.
343 .IP """properties"" (\fBOSSL_MAC_PARAM_PROPERTIES\fR) <UTF8 string>" 4
344 .IX Item """properties"" (OSSL_MAC_PARAM_PROPERTIES) <UTF8 string>"
345 .PD 0
346 .IP """digest"" (\fBOSSL_MAC_PARAM_DIGEST\fR) <UTF8 string>" 4
347 .IX Item """digest"" (OSSL_MAC_PARAM_DIGEST) <UTF8 string>"
348 .IP """cipher"" (\fBOSSL_MAC_PARAM_CIPHER\fR) <UTF8 string>" 4
349 .IX Item """cipher"" (OSSL_MAC_PARAM_CIPHER) <UTF8 string>"
350 .PD
351 For MAC implementations that use an underlying computation cipher or
352 digest, these parameters set what the algorithm should be.
353 .Sp
354 The value is always the name of the intended algorithm,
355 or the properties.
356 .Sp
357 Note that not all algorithms may support all digests.
358 HMAC does not support variable output length digests such as SHAKE128
359 or SHAKE256.
360 .IP """size"" (\fBOSSL_MAC_PARAM_SIZE\fR) <unsigned integer>" 4
361 .IX Item """size"" (OSSL_MAC_PARAM_SIZE) <unsigned integer>"
362 For MAC implementations that support it, set the output size that
363 \&\fBEVP_MAC_final()\fR should produce.
364 The allowed sizes vary between MAC implementations, but must never exceed
365 what can be given with a \fBsize_t\fR.
366 .IP """tls-data-size"" (\fBOSSL_MAC_PARAM_TLS_DATA_SIZE\fR) <unsigned integer>" 4
367 .IX Item """tls-data-size"" (OSSL_MAC_PARAM_TLS_DATA_SIZE) <unsigned integer>"
368 This parameter is only supported by HMAC. If set then special handling is
369 activated for calculating the MAC of a received mac-then-encrypt TLS record
370 where variable length record padding has been used (as in the case of CBC mode
371 ciphersuites). The value represents the total length of the record that is
372 having the MAC calculated including the received MAC and the record padding.
373 .Sp
374 When used EVP_MAC_update must be called precisely twice. The first time with
375 the 13 bytes of TLS "header" data, and the second time with the entire record
376 including the MAC itself and any padding. The entire record length must equal
377 the value passed in the "tls-data-size" parameter. The length passed in the
378 \&\fBdatalen\fR parameter to \fBEVP_MAC_update()\fR should be equal to the length of the
379 record after the MAC and any padding has been removed.
380 .PP
381 All these parameters should be used before the calls to any of
382 \&\fBEVP_MAC_init()\fR, \fBEVP_MAC_update()\fR and \fBEVP_MAC_final()\fR for a full
383 computation.
384 Anything else may give undefined results.
385 .SH NOTES
386 .IX Header "NOTES"
387 The MAC life-cycle is described in \fBlife_cycle\-mac\fR\|(7). In the future,
388 the transitions described there will be enforced. When this is done, it will
389 not be considered a breaking change to the API.
390 .PP
391 The usage of the parameter names "custom", "iv" and "salt" correspond to
392 the names used in the standard where the algorithm was defined.
393 .PP
394 Some MAC algorithms store internal state that cannot be extracted during
395 re-initalization. For example GMAC cannot extract an \fBIV\fR from the
396 underlying CIPHER context, and so calling \fBEVP_MAC_init()\fR on an EVP_MAC object
397 after \fBEVP_MAC_final()\fR has been called cannot reset its cipher state to what it
398 was when the \fBIV\fR was initially generated. For such instances, an
399 \&\fBOSSL_MAC_PARAM_IV\fR parameter must be passed with each call to \fBEVP_MAC_init()\fR.
400 .SH "RETURN VALUES"
401 .IX Header "RETURN VALUES"
402 \&\fBEVP_MAC_fetch()\fR returns a pointer to a newly fetched \fBEVP_MAC\fR, or
403 NULL if allocation failed.
404 .PP
405 \&\fBEVP_MAC_up_ref()\fR returns 1 on success, 0 on error.
406 .PP
407 \&\fBEVP_MAC_names_do_all()\fR returns 1 if the callback was called for all names. A
408 return value of 0 means that the callback was not called for any names.
409 .PP
410 \&\fBEVP_MAC_free()\fR returns nothing at all.
411 .PP
412 \&\fBEVP_MAC_is_a()\fR returns 1 if the given method can be identified with
413 the given name, otherwise 0.
414 .PP
415 \&\fBEVP_MAC_get0_name()\fR returns a name of the MAC, or NULL on error.
416 .PP
417 \&\fBEVP_MAC_get0_provider()\fR returns a pointer to the provider for the MAC, or
418 NULL on error.
419 .PP
420 \&\fBEVP_MAC_CTX_new()\fR and \fBEVP_MAC_CTX_dup()\fR return a pointer to a newly
421 created EVP_MAC_CTX, or NULL if allocation failed.
422 .PP
423 \&\fBEVP_MAC_CTX_free()\fR returns nothing at all.
424 .PP
425 \&\fBEVP_MAC_CTX_get_params()\fR and \fBEVP_MAC_CTX_set_params()\fR return 1 on
426 success, 0 on error.
427 .PP
428 \&\fBEVP_Q_mac()\fR returns a pointer to the computed MAC value, or NULL on error.
429 .PP
430 \&\fBEVP_MAC_init()\fR, \fBEVP_MAC_init_SKEY()\fR, \fBEVP_MAC_update()\fR, \fBEVP_MAC_final()\fR, and
431 \&\fBEVP_MAC_finalXOF()\fR return 1 on success, 0 on error.
432 .PP
433 \&\fBEVP_MAC_CTX_get_mac_size()\fR returns the expected output size, or 0 if it isn't
434 set. If it isn't set, a call to \fBEVP_MAC_init()\fR will set it.
435 .PP
436 \&\fBEVP_MAC_CTX_get_block_size()\fR returns the block size, or 0 if it isn't set.
437 If it isn't set, a call to \fBEVP_MAC_init()\fR will set it.
438 .PP
439 \&\fBEVP_MAC_do_all_provided()\fR returns nothing at all.
440 .SH EXAMPLES
441 .IX Header "EXAMPLES"
442 .Vb 5
443 \& #include <stdlib.h>
444 \& #include <stdio.h>
445 \& #include <string.h>
446 \& #include <stdarg.h>
447 \& #include <unistd.h>
448 \&
449 \& #include <openssl/evp.h>
450 \& #include <openssl/err.h>
451 \& #include <openssl/params.h>
452 \&
453 \& int main() {
454 \& EVP_MAC *mac = EVP_MAC_fetch(NULL, getenv("MY_MAC"), NULL);
455 \& const char *cipher = getenv("MY_MAC_CIPHER");
456 \& const char *digest = getenv("MY_MAC_DIGEST");
457 \& const char *key = getenv("MY_KEY");
458 \& EVP_MAC_CTX *ctx = NULL;
459 \&
460 \& unsigned char buf[4096];
461 \& size_t read_l;
462 \& size_t final_l;
463 \&
464 \& size_t i;
465 \&
466 \& OSSL_PARAM params[3];
467 \& size_t params_n = 0;
468 \&
469 \& if (cipher != NULL)
470 \& params[params_n++] =
471 \& OSSL_PARAM_construct_utf8_string("cipher", (char*)cipher, 0);
472 \& if (digest != NULL)
473 \& params[params_n++] =
474 \& OSSL_PARAM_construct_utf8_string("digest", (char*)digest, 0);
475 \& params[params_n] = OSSL_PARAM_construct_end();
476 \&
477 \& if (mac == NULL
478 \& || key == NULL
479 \& || (ctx = EVP_MAC_CTX_new(mac)) == NULL
480 \& || !EVP_MAC_init(ctx, (const unsigned char *)key, strlen(key),
481 \& params))
482 \& goto err;
483 \&
484 \& while ( (read_l = read(STDIN_FILENO, buf, sizeof(buf))) > 0) {
485 \& if (!EVP_MAC_update(ctx, buf, read_l))
486 \& goto err;
487 \& }
488 \&
489 \& if (!EVP_MAC_final(ctx, buf, &final_l, sizeof(buf)))
490 \& goto err;
491 \&
492 \& printf("Result: ");
493 \& for (i = 0; i < final_l; i++)
494 \& printf("%02X", buf[i]);
495 \& printf("\en");
496 \&
497 \& EVP_MAC_CTX_free(ctx);
498 \& EVP_MAC_free(mac);
499 \& exit(0);
500 \&
501 \& err:
502 \& EVP_MAC_CTX_free(ctx);
503 \& EVP_MAC_free(mac);
504 \& fprintf(stderr, "Something went wrong\en");
505 \& ERR_print_errors_fp(stderr);
506 \& exit (1);
507 \& }
508 .Ve
509 .PP
510 A run of this program, called with correct environment variables, can
511 look like this:
512 .PP
513 .Vb 3
514 \& $ MY_MAC=cmac MY_KEY=secret0123456789 MY_MAC_CIPHER=aes\-128\-cbc \e
515 \& LD_LIBRARY_PATH=. ./foo < foo.c
516 \& Result: C5C06683CD9DDEF904D754505C560A4E
517 .Ve
518 .PP
519 (in this example, that program was stored in \fIfoo.c\fR and compiled to
520 \&\fI./foo\fR)
521 .SH "SEE ALSO"
522 .IX Header "SEE ALSO"
523 \&\fBproperty\fR\|(7)
524 \&\fBOSSL_PARAM\fR\|(3),
525 \&\fBEVP_MAC\-BLAKE2\fR\|(7),
526 \&\fBEVP_MAC\-CMAC\fR\|(7),
527 \&\fBEVP_MAC\-GMAC\fR\|(7),
528 \&\fBEVP_MAC\-HMAC\fR\|(7),
529 \&\fBEVP_MAC\-KMAC\fR\|(7),
530 \&\fBEVP_MAC\-Siphash\fR\|(7),
531 \&\fBEVP_MAC\-Poly1305\fR\|(7),
532 \&\fBprovider\-mac\fR\|(7),
533 \&\fBlife_cycle\-mac\fR\|(7)
534 .SH HISTORY
535 .IX Header "HISTORY"
536 These functions were added in OpenSSL 3.0.
537 .PP
538 The \fBEVP_MAC_init_SKEY()\fR function was added in OpenSSL 3.5.
539 .SH COPYRIGHT
540 .IX Header "COPYRIGHT"
541 Copyright 2018\-2025 The OpenSSL Project Authors. All Rights Reserved.
542 .PP
543 Licensed under the Apache License 2.0 (the "License"). You may not use
544 this file except in compliance with the License. You can obtain a copy
545 in the file LICENSE in the source distribution or at
546 <https://www.openssl.org/source/license.html>.