]>
Commit | Line | Data |
---|---|---|
e538294f MC |
1 | /* |
2 | * Copyright 2020 The OpenSSL Project Authors. All Rights Reserved. | |
3 | * | |
4 | * Licensed under the Apache License 2.0 (the "License"). You may not use | |
5 | * this file except in compliance with the License. You can obtain a copy | |
6 | * in the file LICENSE in the source distribution or at | |
7 | * https://www.openssl.org/source/license.html | |
8 | */ | |
9 | ||
2ef9a7ac MC |
10 | /* We need to use some engine deprecated APIs */ |
11 | #define OPENSSL_SUPPRESS_DEPRECATED | |
12 | ||
e538294f MC |
13 | #include <string.h> |
14 | #include <openssl/core_dispatch.h> | |
15 | #include <openssl/core_names.h> | |
16 | #include <openssl/params.h> | |
17 | #include <openssl/err.h> | |
18 | #include <openssl/evp.h> | |
19 | #include "openssl/param_build.h" | |
20 | #include "internal/param_build_set.h" | |
21 | #include "prov/implementations.h" | |
22 | #include "prov/providercommon.h" | |
23 | #include "prov/provider_ctx.h" | |
24 | #include "prov/macsignature.h" | |
a540ef90 | 25 | #include "e_os.h" /* strcasecmp */ |
e538294f MC |
26 | |
27 | static OSSL_FUNC_keymgmt_new_fn mac_new; | |
28 | static OSSL_FUNC_keymgmt_free_fn mac_free; | |
29 | static OSSL_FUNC_keymgmt_gen_init_fn mac_gen_init; | |
30 | static OSSL_FUNC_keymgmt_gen_fn mac_gen; | |
31 | static OSSL_FUNC_keymgmt_gen_cleanup_fn mac_gen_cleanup; | |
422cbcee P |
32 | static OSSL_FUNC_keymgmt_gen_set_params_fn mac_gen_set_params; |
33 | static OSSL_FUNC_keymgmt_gen_settable_params_fn mac_gen_settable_params; | |
e538294f MC |
34 | static OSSL_FUNC_keymgmt_get_params_fn mac_get_params; |
35 | static OSSL_FUNC_keymgmt_gettable_params_fn mac_gettable_params; | |
36 | static OSSL_FUNC_keymgmt_set_params_fn mac_set_params; | |
37 | static OSSL_FUNC_keymgmt_settable_params_fn mac_settable_params; | |
38 | static OSSL_FUNC_keymgmt_has_fn mac_has; | |
39 | static OSSL_FUNC_keymgmt_match_fn mac_match; | |
40 | static OSSL_FUNC_keymgmt_import_fn mac_import; | |
41 | static OSSL_FUNC_keymgmt_import_types_fn mac_imexport_types; | |
42 | static OSSL_FUNC_keymgmt_export_fn mac_export; | |
43 | static OSSL_FUNC_keymgmt_export_types_fn mac_imexport_types; | |
44 | ||
422cbcee P |
45 | static OSSL_FUNC_keymgmt_new_fn mac_new_cmac; |
46 | static OSSL_FUNC_keymgmt_gettable_params_fn cmac_gettable_params; | |
47 | static OSSL_FUNC_keymgmt_import_types_fn cmac_imexport_types; | |
48 | static OSSL_FUNC_keymgmt_export_types_fn cmac_imexport_types; | |
49 | static OSSL_FUNC_keymgmt_gen_set_params_fn cmac_gen_set_params; | |
50 | static OSSL_FUNC_keymgmt_gen_settable_params_fn cmac_gen_settable_params; | |
51 | ||
e538294f | 52 | struct mac_gen_ctx { |
b4250010 | 53 | OSSL_LIB_CTX *libctx; |
e538294f MC |
54 | int selection; |
55 | unsigned char *priv_key; | |
56 | size_t priv_key_len; | |
2ef9a7ac | 57 | PROV_CIPHER cipher; |
e538294f MC |
58 | }; |
59 | ||
b4250010 | 60 | MAC_KEY *mac_key_new(OSSL_LIB_CTX *libctx, int cmac) |
e538294f | 61 | { |
422cbcee P |
62 | MAC_KEY *mackey; |
63 | ||
64 | if (!ossl_prov_is_running()) | |
65 | return NULL; | |
e538294f | 66 | |
422cbcee | 67 | mackey = OPENSSL_zalloc(sizeof(*mackey)); |
e538294f MC |
68 | if (mackey == NULL) |
69 | return NULL; | |
70 | ||
71 | mackey->lock = CRYPTO_THREAD_lock_new(); | |
72 | if (mackey->lock == NULL) { | |
73 | OPENSSL_free(mackey); | |
74 | return NULL; | |
75 | } | |
76 | mackey->libctx = libctx; | |
77 | mackey->refcnt = 1; | |
a540ef90 | 78 | mackey->cmac = cmac; |
e538294f MC |
79 | |
80 | return mackey; | |
81 | } | |
82 | ||
83 | void mac_key_free(MAC_KEY *mackey) | |
84 | { | |
85 | int ref = 0; | |
86 | ||
87 | if (mackey == NULL) | |
88 | return; | |
89 | ||
90 | CRYPTO_DOWN_REF(&mackey->refcnt, &ref, mackey->lock); | |
91 | if (ref > 0) | |
92 | return; | |
93 | ||
94 | OPENSSL_secure_clear_free(mackey->priv_key, mackey->priv_key_len); | |
2ef9a7ac MC |
95 | OPENSSL_free(mackey->properties); |
96 | ossl_prov_cipher_reset(&mackey->cipher); | |
e538294f MC |
97 | CRYPTO_THREAD_lock_free(mackey->lock); |
98 | OPENSSL_free(mackey); | |
99 | } | |
100 | ||
101 | int mac_key_up_ref(MAC_KEY *mackey) | |
102 | { | |
103 | int ref = 0; | |
104 | ||
422cbcee P |
105 | /* This is effectively doing a new operation on the MAC_KEY and should be |
106 | * adequately guarded again modules' error states. However, both current | |
107 | * calls here are guarded propery in signature/mac_legacy.c. Thus, it | |
108 | * could be removed here. The concern is that something in the future | |
109 | * might call this function without adequate guards. It's a cheap call, | |
110 | * it seems best to leave it even though it is currently redundant. | |
111 | */ | |
112 | if (!ossl_prov_is_running()) | |
113 | return 0; | |
114 | ||
e538294f MC |
115 | CRYPTO_UP_REF(&mackey->refcnt, &ref, mackey->lock); |
116 | return 1; | |
117 | } | |
118 | ||
119 | static void *mac_new(void *provctx) | |
120 | { | |
a829b735 | 121 | return mac_key_new(PROV_LIBCTX_OF(provctx), 0); |
a540ef90 MC |
122 | } |
123 | ||
124 | static void *mac_new_cmac(void *provctx) | |
125 | { | |
a829b735 | 126 | return mac_key_new(PROV_LIBCTX_OF(provctx), 1); |
e538294f MC |
127 | } |
128 | ||
129 | static void mac_free(void *mackey) | |
130 | { | |
131 | mac_key_free(mackey); | |
132 | } | |
133 | ||
3d914185 | 134 | static int mac_has(const void *keydata, int selection) |
e538294f | 135 | { |
3d914185 | 136 | const MAC_KEY *key = keydata; |
e538294f MC |
137 | int ok = 0; |
138 | ||
422cbcee | 139 | if (ossl_prov_is_running() && key != NULL) { |
e538294f MC |
140 | /* |
141 | * MAC keys always have all the parameters they need (i.e. none). | |
142 | * Therefore we always return with 1, if asked about parameters. | |
143 | * Similarly for public keys. | |
144 | */ | |
145 | ok = 1; | |
146 | ||
147 | if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0) | |
148 | ok = key->priv_key != NULL; | |
149 | } | |
150 | return ok; | |
151 | } | |
152 | ||
153 | static int mac_match(const void *keydata1, const void *keydata2, int selection) | |
154 | { | |
155 | const MAC_KEY *key1 = keydata1; | |
156 | const MAC_KEY *key2 = keydata2; | |
157 | int ok = 1; | |
158 | ||
422cbcee P |
159 | if (!ossl_prov_is_running()) |
160 | return 0; | |
161 | ||
e538294f MC |
162 | if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0) { |
163 | if ((key1->priv_key == NULL && key2->priv_key != NULL) | |
164 | || (key1->priv_key != NULL && key2->priv_key == NULL) | |
a540ef90 | 165 | || key1->priv_key_len != key2->priv_key_len |
2ef9a7ac MC |
166 | || (key1->cipher.cipher == NULL && key2->cipher.cipher != NULL) |
167 | || (key1->cipher.cipher != NULL && key2->cipher.cipher == NULL)) | |
e538294f MC |
168 | ok = 0; |
169 | else | |
170 | ok = ok && (key1->priv_key == NULL /* implies key2->privkey == NULL */ | |
171 | || CRYPTO_memcmp(key1->priv_key, key2->priv_key, | |
172 | key1->priv_key_len) == 0); | |
2ef9a7ac MC |
173 | if (key1->cipher.cipher != NULL) |
174 | ok = ok && EVP_CIPHER_is_a(key1->cipher.cipher, | |
175 | EVP_CIPHER_name(key2->cipher.cipher)); | |
e538294f MC |
176 | } |
177 | return ok; | |
178 | } | |
179 | ||
180 | static int mac_key_fromdata(MAC_KEY *key, const OSSL_PARAM params[]) | |
181 | { | |
182 | const OSSL_PARAM *p; | |
183 | ||
184 | p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_PRIV_KEY); | |
185 | if (p != NULL) { | |
186 | if (p->data_type != OSSL_PARAM_OCTET_STRING) { | |
187 | ERR_raise(ERR_LIB_PROV, ERR_R_PASSED_INVALID_ARGUMENT); | |
188 | return 0; | |
189 | } | |
190 | OPENSSL_secure_clear_free(key->priv_key, key->priv_key_len); | |
191 | key->priv_key = OPENSSL_secure_malloc(p->data_size); | |
192 | if (key->priv_key == NULL) { | |
193 | ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE); | |
194 | return 0; | |
195 | } | |
196 | memcpy(key->priv_key, p->data, p->data_size); | |
197 | key->priv_key_len = p->data_size; | |
a540ef90 | 198 | } |
e538294f | 199 | |
2ef9a7ac MC |
200 | p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_PROPERTIES); |
201 | if (p != NULL) { | |
202 | if (p->data_type != OSSL_PARAM_UTF8_STRING) { | |
203 | ERR_raise(ERR_LIB_PROV, ERR_R_PASSED_INVALID_ARGUMENT); | |
204 | return 0; | |
a540ef90 | 205 | } |
2ef9a7ac MC |
206 | OPENSSL_free(key->properties); |
207 | key->properties = OPENSSL_strdup(p->data); | |
208 | if (key->properties == NULL) { | |
209 | ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE); | |
210 | return 0; | |
a540ef90 | 211 | } |
e538294f | 212 | } |
a540ef90 | 213 | |
2ef9a7ac MC |
214 | if (key->cmac && !ossl_prov_cipher_load_from_params(&key->cipher, params, |
215 | key->libctx)) { | |
216 | ERR_raise(ERR_LIB_PROV, ERR_R_PASSED_INVALID_ARGUMENT); | |
217 | return 0; | |
218 | } | |
219 | ||
220 | if (key->priv_key != NULL) | |
a540ef90 MC |
221 | return 1; |
222 | ||
e538294f MC |
223 | return 0; |
224 | } | |
225 | ||
226 | static int mac_import(void *keydata, int selection, const OSSL_PARAM params[]) | |
227 | { | |
228 | MAC_KEY *key = keydata; | |
229 | ||
422cbcee | 230 | if (!ossl_prov_is_running() || key == NULL) |
e538294f MC |
231 | return 0; |
232 | ||
233 | if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) == 0) | |
234 | return 0; | |
235 | ||
236 | return mac_key_fromdata(key, params); | |
237 | } | |
238 | ||
239 | static int key_to_params(MAC_KEY *key, OSSL_PARAM_BLD *tmpl, | |
240 | OSSL_PARAM params[]) | |
241 | { | |
242 | if (key == NULL) | |
243 | return 0; | |
244 | ||
245 | if (key->priv_key != NULL | |
246 | && !ossl_param_build_set_octet_string(tmpl, params, | |
247 | OSSL_PKEY_PARAM_PRIV_KEY, | |
248 | key->priv_key, key->priv_key_len)) | |
249 | return 0; | |
250 | ||
2ef9a7ac | 251 | if (key->cipher.cipher != NULL |
a540ef90 MC |
252 | && !ossl_param_build_set_utf8_string(tmpl, params, |
253 | OSSL_PKEY_PARAM_CIPHER, | |
2ef9a7ac | 254 | EVP_CIPHER_name(key->cipher.cipher))) |
a540ef90 MC |
255 | return 0; |
256 | ||
2ef9a7ac MC |
257 | #if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODULE) |
258 | if (key->cipher.engine != NULL | |
a540ef90 MC |
259 | && !ossl_param_build_set_utf8_string(tmpl, params, |
260 | OSSL_PKEY_PARAM_ENGINE, | |
2ef9a7ac | 261 | ENGINE_get_id(key->cipher.engine))) |
a540ef90 | 262 | return 0; |
2ef9a7ac | 263 | #endif |
a540ef90 | 264 | |
e538294f MC |
265 | return 1; |
266 | } | |
267 | ||
268 | static int mac_export(void *keydata, int selection, OSSL_CALLBACK *param_cb, | |
269 | void *cbarg) | |
270 | { | |
271 | MAC_KEY *key = keydata; | |
272 | OSSL_PARAM_BLD *tmpl; | |
273 | OSSL_PARAM *params = NULL; | |
274 | int ret = 0; | |
275 | ||
422cbcee | 276 | if (!ossl_prov_is_running() || key == NULL) |
e538294f MC |
277 | return 0; |
278 | ||
279 | tmpl = OSSL_PARAM_BLD_new(); | |
280 | if (tmpl == NULL) | |
281 | return 0; | |
282 | ||
283 | if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0 | |
284 | && !key_to_params(key, tmpl, NULL)) | |
285 | goto err; | |
286 | ||
287 | params = OSSL_PARAM_BLD_to_param(tmpl); | |
288 | if (params == NULL) | |
289 | goto err; | |
290 | ||
291 | ret = param_cb(params, cbarg); | |
292 | OSSL_PARAM_BLD_free_params(params); | |
293 | err: | |
294 | OSSL_PARAM_BLD_free(tmpl); | |
295 | return ret; | |
296 | } | |
297 | ||
298 | static const OSSL_PARAM mac_key_types[] = { | |
299 | OSSL_PARAM_octet_string(OSSL_PKEY_PARAM_PRIV_KEY, NULL, 0), | |
2ef9a7ac | 300 | OSSL_PARAM_utf8_string(OSSL_PKEY_PARAM_PROPERTIES, NULL, 0), |
e538294f MC |
301 | OSSL_PARAM_END |
302 | }; | |
303 | static const OSSL_PARAM *mac_imexport_types(int selection) | |
304 | { | |
305 | if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0) | |
306 | return mac_key_types; | |
307 | return NULL; | |
308 | } | |
309 | ||
a540ef90 MC |
310 | static const OSSL_PARAM cmac_key_types[] = { |
311 | OSSL_PARAM_octet_string(OSSL_PKEY_PARAM_PRIV_KEY, NULL, 0), | |
312 | OSSL_PARAM_utf8_string(OSSL_PKEY_PARAM_CIPHER, NULL, 0), | |
313 | OSSL_PARAM_utf8_string(OSSL_PKEY_PARAM_ENGINE, NULL, 0), | |
2ef9a7ac | 314 | OSSL_PARAM_utf8_string(OSSL_PKEY_PARAM_PROPERTIES, NULL, 0), |
a540ef90 MC |
315 | OSSL_PARAM_END |
316 | }; | |
317 | static const OSSL_PARAM *cmac_imexport_types(int selection) | |
318 | { | |
319 | if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0) | |
320 | return cmac_key_types; | |
321 | return NULL; | |
322 | } | |
323 | ||
e538294f MC |
324 | static int mac_get_params(void *key, OSSL_PARAM params[]) |
325 | { | |
326 | return key_to_params(key, NULL, params); | |
327 | } | |
328 | ||
329 | static const OSSL_PARAM *mac_gettable_params(void *provctx) | |
330 | { | |
331 | static const OSSL_PARAM gettable_params[] = { | |
332 | OSSL_PARAM_octet_string(OSSL_PKEY_PARAM_PRIV_KEY, NULL, 0), | |
333 | OSSL_PARAM_END | |
334 | }; | |
335 | return gettable_params; | |
336 | } | |
337 | ||
a540ef90 MC |
338 | static const OSSL_PARAM *cmac_gettable_params(void *provctx) |
339 | { | |
340 | static const OSSL_PARAM gettable_params[] = { | |
341 | OSSL_PARAM_octet_string(OSSL_PKEY_PARAM_PRIV_KEY, NULL, 0), | |
342 | OSSL_PARAM_utf8_string(OSSL_PKEY_PARAM_CIPHER, NULL, 0), | |
343 | OSSL_PARAM_utf8_string(OSSL_PKEY_PARAM_ENGINE, NULL, 0), | |
344 | OSSL_PARAM_END | |
345 | }; | |
346 | return gettable_params; | |
347 | } | |
348 | ||
e538294f MC |
349 | static int mac_set_params(void *keydata, const OSSL_PARAM params[]) |
350 | { | |
351 | MAC_KEY *key = keydata; | |
352 | const OSSL_PARAM *p; | |
353 | ||
354 | if (key == NULL) | |
355 | return 0; | |
356 | ||
357 | p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_PRIV_KEY); | |
358 | if (p != NULL) | |
359 | return mac_key_fromdata(key, params); | |
360 | ||
361 | return 1; | |
362 | } | |
363 | ||
364 | static const OSSL_PARAM *mac_settable_params(void *provctx) | |
365 | { | |
366 | static const OSSL_PARAM settable_params[] = { | |
367 | OSSL_PARAM_octet_string(OSSL_PKEY_PARAM_PRIV_KEY, NULL, 0), | |
368 | OSSL_PARAM_END | |
369 | }; | |
370 | return settable_params; | |
371 | } | |
372 | ||
373 | static void *mac_gen_init(void *provctx, int selection) | |
374 | { | |
a829b735 | 375 | OSSL_LIB_CTX *libctx = PROV_LIBCTX_OF(provctx); |
e538294f MC |
376 | struct mac_gen_ctx *gctx = NULL; |
377 | ||
422cbcee P |
378 | if (!ossl_prov_is_running()) |
379 | return NULL; | |
380 | ||
a540ef90 | 381 | if ((gctx = OPENSSL_zalloc(sizeof(*gctx))) != NULL) { |
e538294f MC |
382 | gctx->libctx = libctx; |
383 | gctx->selection = selection; | |
384 | } | |
385 | return gctx; | |
386 | } | |
387 | ||
e538294f MC |
388 | static int mac_gen_set_params(void *genctx, const OSSL_PARAM params[]) |
389 | { | |
390 | struct mac_gen_ctx *gctx = genctx; | |
391 | const OSSL_PARAM *p; | |
392 | ||
393 | if (gctx == NULL) | |
394 | return 0; | |
395 | ||
396 | p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_PRIV_KEY); | |
397 | if (p != NULL) { | |
398 | if (p->data_type != OSSL_PARAM_OCTET_STRING) { | |
399 | ERR_raise(ERR_LIB_PROV, ERR_R_PASSED_INVALID_ARGUMENT); | |
400 | return 0; | |
401 | } | |
402 | gctx->priv_key = OPENSSL_secure_malloc(p->data_size); | |
403 | if (gctx->priv_key == NULL) { | |
404 | ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE); | |
405 | return 0; | |
406 | } | |
407 | memcpy(gctx->priv_key, p->data, p->data_size); | |
408 | gctx->priv_key_len = p->data_size; | |
409 | } | |
410 | ||
411 | return 1; | |
412 | } | |
413 | ||
a540ef90 MC |
414 | static int cmac_gen_set_params(void *genctx, const OSSL_PARAM params[]) |
415 | { | |
416 | struct mac_gen_ctx *gctx = genctx; | |
a540ef90 MC |
417 | |
418 | if (!mac_gen_set_params(genctx, params)) | |
419 | return 0; | |
420 | ||
2ef9a7ac MC |
421 | if (!ossl_prov_cipher_load_from_params(&gctx->cipher, params, |
422 | gctx->libctx)) { | |
423 | ERR_raise(ERR_LIB_PROV, ERR_R_PASSED_INVALID_ARGUMENT); | |
424 | return 0; | |
a540ef90 MC |
425 | } |
426 | ||
427 | return 1; | |
428 | } | |
429 | ||
e538294f MC |
430 | static const OSSL_PARAM *mac_gen_settable_params(void *provctx) |
431 | { | |
432 | static OSSL_PARAM settable[] = { | |
433 | OSSL_PARAM_octet_string(OSSL_PKEY_PARAM_PRIV_KEY, NULL, 0), | |
434 | OSSL_PARAM_END | |
435 | }; | |
436 | return settable; | |
437 | } | |
438 | ||
a540ef90 MC |
439 | static const OSSL_PARAM *cmac_gen_settable_params(void *provctx) |
440 | { | |
441 | static OSSL_PARAM settable[] = { | |
442 | OSSL_PARAM_octet_string(OSSL_PKEY_PARAM_PRIV_KEY, NULL, 0), | |
443 | OSSL_PARAM_utf8_string(OSSL_PKEY_PARAM_CIPHER, NULL, 0), | |
444 | OSSL_PARAM_END | |
445 | }; | |
446 | return settable; | |
447 | } | |
448 | ||
e538294f MC |
449 | static void *mac_gen(void *genctx, OSSL_CALLBACK *cb, void *cbarg) |
450 | { | |
451 | struct mac_gen_ctx *gctx = genctx; | |
452 | MAC_KEY *key; | |
453 | ||
422cbcee | 454 | if (!ossl_prov_is_running() || gctx == NULL) |
e538294f MC |
455 | return NULL; |
456 | ||
a540ef90 | 457 | if ((key = mac_key_new(gctx->libctx, 0)) == NULL) { |
e538294f MC |
458 | ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE); |
459 | return NULL; | |
460 | } | |
461 | ||
462 | /* If we're doing parameter generation then we just return a blank key */ | |
463 | if ((gctx->selection & OSSL_KEYMGMT_SELECT_KEYPAIR) == 0) | |
464 | return key; | |
465 | ||
466 | if (gctx->priv_key == NULL) { | |
467 | ERR_raise(ERR_LIB_PROV, EVP_R_INVALID_KEY); | |
468 | mac_key_free(key); | |
469 | return NULL; | |
470 | } | |
471 | ||
472 | /* | |
473 | * This is horrible but required for backwards compatibility. We don't | |
474 | * actually do real key generation at all. We simply copy the key that was | |
475 | * previously set in the gctx. Hopefully at some point in the future all | |
476 | * of this can be removed and we will only support the EVP_KDF APIs. | |
477 | */ | |
2ef9a7ac MC |
478 | if (!ossl_prov_cipher_copy(&key->cipher, &gctx->cipher)) { |
479 | ERR_raise(ERR_LIB_PROV, ERR_R_INTERNAL_ERROR); | |
480 | return NULL; | |
481 | } | |
482 | ossl_prov_cipher_reset(&gctx->cipher); | |
e538294f MC |
483 | key->priv_key = gctx->priv_key; |
484 | key->priv_key_len = gctx->priv_key_len; | |
485 | gctx->priv_key_len = 0; | |
486 | gctx->priv_key = NULL; | |
487 | ||
488 | return key; | |
489 | } | |
490 | ||
491 | static void mac_gen_cleanup(void *genctx) | |
492 | { | |
493 | struct mac_gen_ctx *gctx = genctx; | |
494 | ||
495 | OPENSSL_secure_clear_free(gctx->priv_key, gctx->priv_key_len); | |
2ef9a7ac | 496 | ossl_prov_cipher_reset(&gctx->cipher); |
e538294f MC |
497 | OPENSSL_free(gctx); |
498 | } | |
499 | ||
1be63951 | 500 | const OSSL_DISPATCH ossl_mac_legacy_keymgmt_functions[] = { |
e538294f MC |
501 | { OSSL_FUNC_KEYMGMT_NEW, (void (*)(void))mac_new }, |
502 | { OSSL_FUNC_KEYMGMT_FREE, (void (*)(void))mac_free }, | |
503 | { OSSL_FUNC_KEYMGMT_GET_PARAMS, (void (*) (void))mac_get_params }, | |
504 | { OSSL_FUNC_KEYMGMT_GETTABLE_PARAMS, (void (*) (void))mac_gettable_params }, | |
505 | { OSSL_FUNC_KEYMGMT_SET_PARAMS, (void (*) (void))mac_set_params }, | |
506 | { OSSL_FUNC_KEYMGMT_SETTABLE_PARAMS, (void (*) (void))mac_settable_params }, | |
507 | { OSSL_FUNC_KEYMGMT_HAS, (void (*)(void))mac_has }, | |
508 | { OSSL_FUNC_KEYMGMT_MATCH, (void (*)(void))mac_match }, | |
509 | { OSSL_FUNC_KEYMGMT_IMPORT, (void (*)(void))mac_import }, | |
510 | { OSSL_FUNC_KEYMGMT_IMPORT_TYPES, (void (*)(void))mac_imexport_types }, | |
511 | { OSSL_FUNC_KEYMGMT_EXPORT, (void (*)(void))mac_export }, | |
512 | { OSSL_FUNC_KEYMGMT_EXPORT_TYPES, (void (*)(void))mac_imexport_types }, | |
513 | { OSSL_FUNC_KEYMGMT_GEN_INIT, (void (*)(void))mac_gen_init }, | |
514 | { OSSL_FUNC_KEYMGMT_GEN_SET_PARAMS, (void (*)(void))mac_gen_set_params }, | |
515 | { OSSL_FUNC_KEYMGMT_GEN_SETTABLE_PARAMS, | |
516 | (void (*)(void))mac_gen_settable_params }, | |
517 | { OSSL_FUNC_KEYMGMT_GEN, (void (*)(void))mac_gen }, | |
518 | { OSSL_FUNC_KEYMGMT_GEN_CLEANUP, (void (*)(void))mac_gen_cleanup }, | |
519 | { 0, NULL } | |
520 | }; | |
a540ef90 | 521 | |
1be63951 | 522 | const OSSL_DISPATCH ossl_cossl_mac_legacy_keymgmt_functions[] = { |
a540ef90 MC |
523 | { OSSL_FUNC_KEYMGMT_NEW, (void (*)(void))mac_new_cmac }, |
524 | { OSSL_FUNC_KEYMGMT_FREE, (void (*)(void))mac_free }, | |
525 | { OSSL_FUNC_KEYMGMT_GET_PARAMS, (void (*) (void))mac_get_params }, | |
526 | { OSSL_FUNC_KEYMGMT_GETTABLE_PARAMS, (void (*) (void))cmac_gettable_params }, | |
527 | { OSSL_FUNC_KEYMGMT_SET_PARAMS, (void (*) (void))mac_set_params }, | |
528 | { OSSL_FUNC_KEYMGMT_SETTABLE_PARAMS, (void (*) (void))mac_settable_params }, | |
529 | { OSSL_FUNC_KEYMGMT_HAS, (void (*)(void))mac_has }, | |
530 | { OSSL_FUNC_KEYMGMT_MATCH, (void (*)(void))mac_match }, | |
531 | { OSSL_FUNC_KEYMGMT_IMPORT, (void (*)(void))mac_import }, | |
532 | { OSSL_FUNC_KEYMGMT_IMPORT_TYPES, (void (*)(void))cmac_imexport_types }, | |
533 | { OSSL_FUNC_KEYMGMT_EXPORT, (void (*)(void))mac_export }, | |
534 | { OSSL_FUNC_KEYMGMT_EXPORT_TYPES, (void (*)(void))cmac_imexport_types }, | |
535 | { OSSL_FUNC_KEYMGMT_GEN_INIT, (void (*)(void))mac_gen_init }, | |
536 | { OSSL_FUNC_KEYMGMT_GEN_SET_PARAMS, (void (*)(void))cmac_gen_set_params }, | |
537 | { OSSL_FUNC_KEYMGMT_GEN_SETTABLE_PARAMS, | |
538 | (void (*)(void))cmac_gen_settable_params }, | |
539 | { OSSL_FUNC_KEYMGMT_GEN, (void (*)(void))mac_gen }, | |
540 | { OSSL_FUNC_KEYMGMT_GEN_CLEANUP, (void (*)(void))mac_gen_cleanup }, | |
541 | { 0, NULL } | |
542 | }; | |
422cbcee | 543 |