]>
Commit | Line | Data |
---|---|---|
567db2c1 RL |
1 | =pod |
2 | ||
3 | =head1 NAME | |
4 | ||
03888233 RL |
5 | EVP_MAC, EVP_MAC_fetch, EVP_MAC_up_ref, EVP_MAC_free, EVP_MAC_is_a, |
6 | EVP_MAC_number, EVP_MAC_name, EVP_MAC_names_do_all, EVP_MAC_description, | |
7dd0f299 | 7 | EVP_MAC_provider, EVP_MAC_get_params, EVP_MAC_gettable_params, |
865adf97 MC |
8 | EVP_MAC_CTX, EVP_MAC_CTX_new, EVP_MAC_CTX_free, EVP_MAC_CTX_dup, |
9 | EVP_MAC_CTX_mac, EVP_MAC_CTX_get_params, EVP_MAC_CTX_set_params, | |
90a2576b | 10 | EVP_MAC_CTX_get_mac_size, EVP_MAC_init, EVP_MAC_update, EVP_MAC_final, |
41f7ecf3 | 11 | EVP_MAC_gettable_ctx_params, EVP_MAC_settable_ctx_params, |
8dd233bb | 12 | EVP_MAC_CTX_gettable_params, EVP_MAC_CTX_settable_params, |
251e610c | 13 | EVP_MAC_do_all_provided - EVP MAC routines |
567db2c1 RL |
14 | |
15 | =head1 SYNOPSIS | |
16 | ||
17 | #include <openssl/evp.h> | |
18 | ||
19 | typedef struct evp_mac_st EVP_MAC; | |
20 | typedef struct evp_mac_ctx_st EVP_MAC_CTX; | |
21 | ||
b4250010 | 22 | EVP_MAC *EVP_MAC_fetch(OSSL_LIB_CTX *libctx, const char *algorithm, |
e74bd290 RL |
23 | const char *properties); |
24 | int EVP_MAC_up_ref(EVP_MAC *mac); | |
25 | void EVP_MAC_free(EVP_MAC *mac); | |
7cfa1717 | 26 | int EVP_MAC_is_a(const EVP_MAC *mac, const char *name); |
506cb0f6 | 27 | int EVP_MAC_number(const EVP_MAC *mac); |
c9452d74 | 28 | const char *EVP_MAC_name(const EVP_MAC *mac); |
d84f5515 MC |
29 | int EVP_MAC_names_do_all(const EVP_MAC *mac, |
30 | void (*fn)(const char *name, void *data), | |
31 | void *data); | |
03888233 | 32 | const char *EVP_MAC_description(const EVP_MAC *mac); |
7dd0f299 | 33 | const OSSL_PROVIDER *EVP_MAC_provider(const EVP_MAC *mac); |
e74bd290 RL |
34 | int EVP_MAC_get_params(EVP_MAC *mac, OSSL_PARAM params[]); |
35 | ||
865adf97 MC |
36 | EVP_MAC_CTX *EVP_MAC_CTX_new(EVP_MAC *mac); |
37 | void EVP_MAC_CTX_free(EVP_MAC_CTX *ctx); | |
38 | EVP_MAC_CTX *EVP_MAC_CTX_dup(const EVP_MAC_CTX *src); | |
39 | EVP_MAC *EVP_MAC_CTX_mac(EVP_MAC_CTX *ctx); | |
40 | int EVP_MAC_CTX_get_params(EVP_MAC_CTX *ctx, OSSL_PARAM params[]); | |
41 | int EVP_MAC_CTX_set_params(EVP_MAC_CTX *ctx, const OSSL_PARAM params[]); | |
e74bd290 | 42 | |
90a2576b | 43 | size_t EVP_MAC_CTX_get_mac_size(EVP_MAC_CTX *ctx); |
afa44486 P |
44 | int EVP_MAC_init(EVP_MAC_CTX *ctx, const unsigned char *key, size_t keylen, |
45 | const OSSL_PARAM params[]); | |
567db2c1 | 46 | int EVP_MAC_update(EVP_MAC_CTX *ctx, const unsigned char *data, size_t datalen); |
e74bd290 RL |
47 | int EVP_MAC_final(EVP_MAC_CTX *ctx, |
48 | unsigned char *out, size_t *outl, size_t outsize); | |
49 | ||
50 | const OSSL_PARAM *EVP_MAC_gettable_params(const EVP_MAC *mac); | |
41f7ecf3 P |
51 | const OSSL_PARAM *EVP_MAC_gettable_ctx_params(const EVP_MAC *mac); |
52 | const OSSL_PARAM *EVP_MAC_settable_ctx_params(const EVP_MAC *mac); | |
8dd233bb P |
53 | const OSSL_PARAM *EVP_MAC_CTX_gettable_params(EVP_MAC_CTX *ctx); |
54 | const OSSL_PARAM *EVP_MAC_CTX_settable_params(EVP_MAC_CTX *ctx); | |
567db2c1 | 55 | |
b4250010 | 56 | void EVP_MAC_do_all_provided(OSSL_LIB_CTX *libctx, |
251e610c RL |
57 | void (*fn)(EVP_MAC *mac, void *arg), |
58 | void *arg); | |
d1cafb08 | 59 | |
567db2c1 RL |
60 | =head1 DESCRIPTION |
61 | ||
62 | These types and functions help the application to calculate MACs of | |
63 | different types and with different underlying algorithms if there are | |
64 | any. | |
65 | ||
66 | MACs are a bit complex insofar that some of them use other algorithms | |
67 | for actual computation. HMAC uses a digest, and CMAC uses a cipher. | |
68 | Therefore, there are sometimes two contexts to keep track of, one for | |
69 | the MAC algorithm itself and one for the underlying computation | |
70 | algorithm if there is one. | |
71 | ||
72 | To make things less ambiguous, this manual talks about a "context" or | |
73 | "MAC context", which is to denote the MAC level context, and about a | |
74 | "underlying context", or "computation context", which is to denote the | |
75 | context for the underlying computation algorithm if there is one. | |
76 | ||
77 | =head2 Types | |
78 | ||
79 | B<EVP_MAC> is a type that holds the implementation of a MAC. | |
80 | ||
81 | B<EVP_MAC_CTX> is a context type that holds internal MAC information | |
82 | as well as a reference to a computation context, for those MACs that | |
83 | rely on an underlying computation algorithm. | |
84 | ||
e74bd290 RL |
85 | =head2 Algorithm implementation fetching |
86 | ||
87 | EVP_MAC_fetch() fetches an implementation of a MAC I<algorithm>, given | |
88 | a library context I<libctx> and a set of I<properties>. | |
89 | See L<provider(7)/Fetching algorithms> for further information. | |
90 | ||
b8086652 SL |
91 | See L<OSSL_PROVIDER-default(7)/Message Authentication Code (MAC)> for the list |
92 | of algorithms supported by the default provider. | |
93 | ||
e74bd290 RL |
94 | The returned value must eventually be freed with |
95 | L<EVP_MAC_free(3)>. | |
96 | ||
97 | EVP_MAC_up_ref() increments the reference count of an already fetched | |
98 | MAC. | |
99 | ||
100 | EVP_MAC_free() frees a fetched algorithm. | |
101 | NULL is a valid parameter, for which this function is a no-op. | |
102 | ||
567db2c1 RL |
103 | =head2 Context manipulation functions |
104 | ||
865adf97 | 105 | EVP_MAC_CTX_new() creates a new context for the MAC type I<mac>. |
567db2c1 RL |
106 | The created context can then be used with most other functions |
107 | described here. | |
108 | ||
865adf97 | 109 | EVP_MAC_CTX_free() frees the contents of the context, including an |
567db2c1 | 110 | underlying context if there is one, as well as the context itself. |
e74bd290 | 111 | NULL is a valid parameter, for which this function is a no-op. |
567db2c1 | 112 | |
865adf97 | 113 | EVP_MAC_CTX_dup() duplicates the I<src> context and returns a newly allocated |
be5fc053 | 114 | context. |
567db2c1 | 115 | |
865adf97 | 116 | EVP_MAC_CTX_mac() returns the B<EVP_MAC> associated with the context |
e74bd290 | 117 | I<ctx>. |
567db2c1 RL |
118 | |
119 | =head2 Computing functions | |
120 | ||
121 | EVP_MAC_init() sets up the underlying context with information given | |
afa44486 P |
122 | via the I<key> and I<params> arguments. The MAC I<key> has a length of |
123 | I<keylen> and the parameters in I<params> are processed before setting | |
124 | the key. If I<key> is NULL, the key must be set via params either | |
125 | as part of this call or separately using EVP_MAC_CTX_set_params(). | |
126 | This should be called before calling EVP_MAC_update() and EVP_MAC_final(). | |
567db2c1 | 127 | |
e74bd290 | 128 | EVP_MAC_update() adds I<datalen> bytes from I<data> to the MAC input. |
567db2c1 RL |
129 | |
130 | EVP_MAC_final() does the final computation and stores the result in | |
e74bd290 RL |
131 | the memory pointed at by I<out> of size I<outsize>, and sets the number |
132 | of bytes written in I<*outl> at. | |
ee2161e8 | 133 | If I<out> is NULL or I<outsize> is too small, then no computation |
e74bd290 | 134 | is made. |
567db2c1 | 135 | To figure out what the output length will be and allocate space for it |
ee2161e8 | 136 | dynamically, simply call with I<out> being NULL and I<outl> |
567db2c1 | 137 | pointing at a valid location, then allocate space and make a second |
e74bd290 RL |
138 | call with I<out> pointing at the allocated space. |
139 | ||
140 | EVP_MAC_get_params() retrieves details about the implementation | |
141 | I<mac>. | |
142 | The set of parameters given with I<params> determine exactly what | |
143 | parameters should be retrieved. | |
144 | Note that a parameter that is unknown in the underlying context is | |
145 | simply ignored. | |
146 | ||
865adf97 | 147 | EVP_MAC_CTX_get_params() retrieves chosen parameters, given the |
e74bd290 RL |
148 | context I<ctx> and its underlying context. |
149 | The set of parameters given with I<params> determine exactly what | |
150 | parameters should be retrieved. | |
151 | Note that a parameter that is unknown in the underlying context is | |
152 | simply ignored. | |
153 | ||
865adf97 | 154 | EVP_MAC_CTX_set_params() passes chosen parameters to the underlying |
e74bd290 RL |
155 | context, given a context I<ctx>. |
156 | The set of parameters given with I<params> determine exactly what | |
157 | parameters are passed down. | |
158 | Note that a parameter that is unknown in the underlying context is | |
159 | simply ignored. | |
160 | Also, what happens when a needed parameter isn't passed down is | |
161 | defined by the implementation. | |
162 | ||
8dd233bb P |
163 | EVP_MAC_gettable_params() returns an B<OSSL_PARAM> array that describes |
164 | the retrievable and settable parameters. EVP_MAC_gettable_params() | |
165 | returns parameters that can be used with EVP_MAC_get_params(). | |
166 | See L<OSSL_PARAM(3)> for the use of B<OSSL_PARAM> as a parameter descriptor. | |
167 | ||
168 | EVP_MAC_gettable_ctx_params() and EVP_MAC_CTX_gettable_params() | |
169 | return constant B<OSSL_PARAM> arrays that describe the retrievable | |
170 | parameters that can be used with EVP_MAC_CTX_get_params(). | |
171 | EVP_MAC_gettable_ctx_params() returns the parameters that can be retrieved | |
172 | from the algorithm, whereas EVP_MAC_CTX_gettable_params() returns | |
173 | the parameters that can be retrieved in the context's current state. | |
174 | See L<OSSL_PARAM(3)> for the use of B<OSSL_PARAM> as a parameter descriptor. | |
175 | ||
176 | EVP_MAC_settable_ctx_params() and EVP_MAC_CTX_settable_params() return | |
177 | constant B<OSSL_PARAM> arrays that describe the settable parameters that | |
178 | can be used with EVP_MAC_CTX_set_params(). EVP_MAC_settable_ctx_params() | |
179 | returns the parameters that can be retrieved from the algorithm, | |
180 | whereas EVP_MAC_CTX_settable_params() returns the parameters that can | |
181 | be retrieved in the context's current state. See L<OSSL_PARAM(3)> | |
182 | for the use of B<OSSL_PARAM> as a parameter descriptor. | |
567db2c1 RL |
183 | |
184 | =head2 Information functions | |
185 | ||
90a2576b | 186 | EVP_MAC_CTX_get_mac_size() returns the MAC output size for the given context. |
567db2c1 | 187 | |
7cfa1717 RL |
188 | EVP_MAC_is_a() checks if the given I<mac> is an implementation of an |
189 | algorithm that's identifiable with I<name>. | |
190 | ||
7dd0f299 RL |
191 | EVP_MAC_provider() returns the provider that holds the implementation |
192 | of the given I<mac>. | |
193 | ||
251e610c | 194 | EVP_MAC_do_all_provided() traverses all MAC implemented by all activated |
d1cafb08 RL |
195 | providers in the given library context I<libctx>, and for each of the |
196 | implementations, calls the given function I<fn> with the implementation method | |
197 | and the given I<arg> as argument. | |
198 | ||
506cb0f6 RL |
199 | EVP_MAC_number() returns the internal dynamic number assigned to |
200 | I<mac>. | |
201 | ||
c9452d74 P |
202 | EVP_MAC_name() return the name of the given MAC. For fetched MACs |
203 | with multiple names, only one of them is returned; it's | |
204 | recommended to use EVP_MAC_names_do_all() instead. | |
205 | ||
f651c727 RL |
206 | EVP_MAC_names_do_all() traverses all names for I<mac>, and calls |
207 | I<fn> with each name and I<data>. | |
208 | ||
03888233 RL |
209 | EVP_MAC_description() returns a description of the I<mac>, meant for display |
210 | and human consumption. The description is at the discretion of the mac | |
211 | implementation. | |
212 | ||
b1cabee8 | 213 | =head1 PARAMETERS |
567db2c1 | 214 | |
e592dbde RL |
215 | Parameters are identified by name as strings, and have an expected |
216 | data type and maximum size. | |
217 | OpenSSL has a set of macros for parameter names it expects to see in | |
218 | its own MAC implementations. | |
219 | Here, we show all three, the OpenSSL macro for the parameter name, the | |
220 | name in string form, and a type description. | |
221 | ||
e74bd290 | 222 | The standard parameter names are: |
567db2c1 RL |
223 | |
224 | =over 4 | |
225 | ||
0c452a51 | 226 | =item "key" (B<OSSL_MAC_PARAM_KEY>) <octet string> |
567db2c1 | 227 | |
e74bd290 | 228 | Its value is the MAC key as an array of bytes. |
567db2c1 RL |
229 | |
230 | For MACs that use an underlying computation algorithm, the algorithm | |
e74bd290 | 231 | must be set first, see parameter names "algorithm" below. |
afc580b9 | 232 | |
0c452a51 | 233 | =item "iv" (B<OSSL_MAC_PARAM_IV>) <octet string> |
afc580b9 | 234 | |
e74bd290 | 235 | Some MAC implementations require an IV, this parameter sets the IV. |
6e624a64 | 236 | |
0c452a51 | 237 | =item "custom" (B<OSSL_MAC_PARAM_CUSTOM>) <octet string> |
6e624a64 | 238 | |
13b3cd7b | 239 | Some MAC implementations (KMAC, BLAKE2) accept a Customization String, |
e74bd290 RL |
240 | this parameter sets the Customization String. The default value is the |
241 | empty string. | |
6e624a64 | 242 | |
0c452a51 | 243 | =item "salt" (B<OSSL_MAC_PARAM_SALT>) <octet string> |
13b3cd7b AS |
244 | |
245 | This option is used by BLAKE2 MAC. | |
246 | ||
0c452a51 | 247 | =item "xof" (B<OSSL_MAC_PARAM_XOF>) <integer> |
6e624a64 | 248 | |
e74bd290 | 249 | It's a simple flag, the value 0 or 1 are expected. |
6e624a64 SL |
250 | |
251 | This option is used by KMAC. | |
252 | ||
36978c19 | 253 | =item "digest-noinit" (B<OSSL_MAC_PARAM_DIGEST_NOINIT>) <integer> |
567db2c1 | 254 | |
36978c19 SL |
255 | A simple flag to set the MAC digest to not initialise the |
256 | implementation specific data. The value 0 or 1 is expected. | |
257 | ||
258 | This option is used by HMAC. | |
259 | ||
260 | =item "digest-oneshot" (B<OSSL_MAC_PARAM_DIGEST_ONESHOT>) <integer> | |
261 | ||
262 | A simple flag to set the MAC digest to be a oneshot operation. | |
263 | The value 0 or 1 is expected. | |
264 | ||
265 | This option is used by HMAC. | |
567db2c1 | 266 | |
0c452a51 | 267 | =item "properties" (B<OSSL_MAC_PARAM_PROPERTIES>) <UTF8 string> |
567db2c1 | 268 | |
0c452a51 | 269 | =item "digest" (B<OSSL_MAC_PARAM_DIGEST>) <UTF8 string> |
567db2c1 | 270 | |
0c452a51 | 271 | =item "cipher" (B<OSSL_MAC_PARAM_CIPHER>) <UTF8 string> |
e74bd290 | 272 | |
f3b8d77f | 273 | For MAC implementations that use an underlying computation cipher or |
9bd9c440 | 274 | digest, these parameters set what the algorithm should be. |
567db2c1 | 275 | |
9bd9c440 | 276 | The value is always the name of the intended algorithm, |
f3b8d77f | 277 | or the properties. |
567db2c1 | 278 | |
e74bd290 RL |
279 | Note that not all algorithms may support all digests. |
280 | HMAC does not support variable output length digests such as SHAKE128 | |
281 | or SHAKE256. | |
567db2c1 | 282 | |
0c452a51 | 283 | =item "size" (B<OSSL_MAC_PARAM_SIZE>) <unsigned integer> |
567db2c1 RL |
284 | |
285 | For MAC implementations that support it, set the output size that | |
286 | EVP_MAC_final() should produce. | |
1aa01009 P |
287 | The allowed sizes vary between MAC implementations, but must never exceed |
288 | what can be given with a B<size_t>. | |
567db2c1 | 289 | |
820d87bc MC |
290 | =item "tls-data-size" (B<OSSL_MAC_PARAM_TLS_DATA_SIZE>) <unsigned integer> |
291 | ||
292 | This parameter is only supported by HMAC. If set then special handling is | |
293 | activated for calculating the MAC of a received mac-then-encrypt TLS record | |
294 | where variable length record padding has been used (as in the case of CBC mode | |
295 | ciphersuites). The value represents the total length of the record that is | |
296 | having the MAC calculated including the received MAC and the record padding. | |
297 | ||
298 | When used EVP_MAC_update must be called precisely twice. The first time with | |
299 | the 13 bytes of TLS "header" data, and the second time with the entire record | |
300 | including the MAC itself and any padding. The entire record length must equal | |
301 | the value passed in the "tls-data-size" parameter. The length passed in the | |
302 | B<datalen> parameter to EVP_MAC_update() should be equal to the length of the | |
303 | record after the MAC and any padding has been removed. | |
304 | ||
567db2c1 RL |
305 | =back |
306 | ||
e74bd290 | 307 | All these parameters should be used before the calls to any of |
567db2c1 RL |
308 | EVP_MAC_init(), EVP_MAC_update() and EVP_MAC_final() for a full |
309 | computation. | |
310 | Anything else may give undefined results. | |
311 | ||
10b63e97 P |
312 | =head1 NOTES |
313 | ||
314 | The MAC life-cycle is described in L<life_cycle-mac(7)>. In the future, | |
315 | the transitions described there will be enforced. When this is done, it will | |
316 | not be considered a breaking change to the API. | |
317 | ||
318 | ||
e74bd290 | 319 | =head1 RETURN VALUES |
567db2c1 | 320 | |
e74bd290 RL |
321 | EVP_MAC_fetch() returns a pointer to a newly fetched EVP_MAC, or |
322 | NULL if allocation failed. | |
567db2c1 | 323 | |
e74bd290 RL |
324 | EVP_MAC_up_ref() returns 1 on success, 0 on error. |
325 | ||
d84f5515 MC |
326 | EVP_MAC_names_do_all() returns 1 if the callback was called for all names. A |
327 | return value of 0 means that the callback was not called for any names. | |
328 | ||
e74bd290 RL |
329 | EVP_MAC_free() returns nothing at all. |
330 | ||
7cfa1717 RL |
331 | EVP_MAC_is_a() returns 1 if the given method can be identified with |
332 | the given name, otherwise 0. | |
333 | ||
c9452d74 P |
334 | EVP_MAC_name() returns a name of the MAC, or NULL on error. |
335 | ||
7dd0f299 RL |
336 | EVP_MAC_provider() returns a pointer to the provider for the MAC, or |
337 | NULL on error. | |
338 | ||
865adf97 | 339 | EVP_MAC_CTX_new() and EVP_MAC_CTX_dup() return a pointer to a newly |
e74bd290 | 340 | created EVP_MAC_CTX, or NULL if allocation failed. |
567db2c1 | 341 | |
865adf97 | 342 | EVP_MAC_CTX_free() returns nothing at all. |
567db2c1 | 343 | |
865adf97 | 344 | EVP_MAC_CTX_get_params() and EVP_MAC_CTX_set_params() return 1 on |
e74bd290 | 345 | success, 0 on error. |
567db2c1 | 346 | |
e74bd290 RL |
347 | EVP_MAC_init(), EVP_MAC_update(), and EVP_MAC_final() return 1 on success, 0 |
348 | on error. | |
567db2c1 | 349 | |
90a2576b | 350 | EVP_MAC_CTX_get_mac_size() returns the expected output size, or 0 if it isn't set. |
567db2c1 RL |
351 | If it isn't set, a call to EVP_MAC_init() should get it set. |
352 | ||
251e610c | 353 | EVP_MAC_do_all_provided() returns nothing at all. |
567db2c1 | 354 | |
cda77422 | 355 | =head1 EXAMPLES |
567db2c1 RL |
356 | |
357 | #include <stdlib.h> | |
358 | #include <stdio.h> | |
359 | #include <string.h> | |
360 | #include <stdarg.h> | |
361 | #include <unistd.h> | |
362 | ||
363 | #include <openssl/evp.h> | |
364 | #include <openssl/err.h> | |
e74bd290 | 365 | #include <openssl/params.h> |
567db2c1 RL |
366 | |
367 | int main() { | |
e74bd290 RL |
368 | EVP_MAC *mac = EVP_MAC_fetch(NULL, getenv("MY_MAC"), NULL); |
369 | const char *cipher = getenv("MY_MAC_CIPHER"); | |
370 | const char *digest = getenv("MY_MAC_DIGEST"); | |
567db2c1 RL |
371 | const char *key = getenv("MY_KEY"); |
372 | EVP_MAC_CTX *ctx = NULL; | |
373 | ||
374 | unsigned char buf[4096]; | |
d5b170a2 | 375 | size_t read_l; |
567db2c1 RL |
376 | size_t final_l; |
377 | ||
378 | size_t i; | |
379 | ||
afa44486 | 380 | OSSL_PARAM params[3]; |
e74bd290 RL |
381 | size_t params_n = 0; |
382 | ||
383 | if (cipher != NULL) | |
384 | params[params_n++] = | |
d5b170a2 | 385 | OSSL_PARAM_construct_utf8_string("cipher", (char*)cipher, 0); |
e74bd290 RL |
386 | if (digest != NULL) |
387 | params[params_n++] = | |
d5b170a2 | 388 | OSSL_PARAM_construct_utf8_string("digest", (char*)digest, 0); |
e74bd290 RL |
389 | params[params_n] = OSSL_PARAM_construct_end(); |
390 | ||
567db2c1 RL |
391 | if (mac == NULL |
392 | || key == NULL | |
865adf97 | 393 | || (ctx = EVP_MAC_CTX_new(mac)) == NULL |
afa44486 P |
394 | || !EVP_MAC_init(ctx, (const unsigned char *)key, strlen(key), |
395 | params)) | |
567db2c1 RL |
396 | goto err; |
397 | ||
38e6c490 | 398 | while ( (read_l = read(STDIN_FILENO, buf, sizeof(buf))) > 0) { |
567db2c1 RL |
399 | if (!EVP_MAC_update(ctx, buf, read_l)) |
400 | goto err; | |
401 | } | |
402 | ||
d5b170a2 | 403 | if (!EVP_MAC_final(ctx, buf, &final_l, sizeof(buf))) |
567db2c1 RL |
404 | goto err; |
405 | ||
406 | printf("Result: "); | |
407 | for (i = 0; i < final_l; i++) | |
408 | printf("%02X", buf[i]); | |
409 | printf("\n"); | |
410 | ||
865adf97 | 411 | EVP_MAC_CTX_free(ctx); |
e74bd290 | 412 | EVP_MAC_free(mac); |
567db2c1 RL |
413 | exit(0); |
414 | ||
415 | err: | |
865adf97 | 416 | EVP_MAC_CTX_free(ctx); |
e74bd290 | 417 | EVP_MAC_free(mac); |
567db2c1 RL |
418 | fprintf(stderr, "Something went wrong\n"); |
419 | ERR_print_errors_fp(stderr); | |
420 | exit (1); | |
421 | } | |
422 | ||
423 | A run of this program, called with correct environment variables, can | |
424 | look like this: | |
425 | ||
426 | $ MY_MAC=cmac MY_KEY=secret0123456789 MY_MAC_CIPHER=aes-128-cbc \ | |
427 | LD_LIBRARY_PATH=. ./foo < foo.c | |
38e6c490 | 428 | Result: C5C06683CD9DDEF904D754505C560A4E |
567db2c1 RL |
429 | |
430 | (in this example, that program was stored in F<foo.c> and compiled to | |
431 | F<./foo>) | |
432 | ||
433 | =head1 SEE ALSO | |
434 | ||
e74bd290 RL |
435 | L<property(7)> |
436 | L<OSSL_PARAM(3)>, | |
d7cea0b8 RS |
437 | L<EVP_MAC-BLAKE2(7)>, |
438 | L<EVP_MAC-CMAC(7)>, | |
439 | L<EVP_MAC-GMAC(7)>, | |
440 | L<EVP_MAC-HMAC(7)>, | |
441 | L<EVP_MAC-KMAC(7)>, | |
442 | L<EVP_MAC-Siphash(7)>, | |
10b63e97 P |
443 | L<EVP_MAC-Poly1305(7)>, |
444 | L<provider-mac(7)>, | |
445 | L<life_cycle-mac(7)> | |
567db2c1 | 446 | |
be5fc053 KR |
447 | =head1 HISTORY |
448 | ||
4674aaf4 | 449 | These functions were added in OpenSSL 3.0. |
be5fc053 | 450 | |
567db2c1 RL |
451 | =head1 COPYRIGHT |
452 | ||
a28d06f3 | 453 | Copyright 2018-2021 The OpenSSL Project Authors. All Rights Reserved. |
567db2c1 | 454 | |
4746f25a | 455 | Licensed under the Apache License 2.0 (the "License"). You may not use |
567db2c1 RL |
456 | this file except in compliance with the License. You can obtain a copy |
457 | in the file LICENSE in the source distribution or at | |
458 | L<https://www.openssl.org/source/license.html>. | |
459 | ||
460 | =cut |