]>
Commit | Line | Data |
---|---|---|
c13d2ab4 | 1 | /* |
33388b44 | 2 | * Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved. |
c13d2ab4 RL |
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 | ||
10 | #include <stddef.h> | |
50cd4768 | 11 | #include <openssl/types.h> |
c13d2ab4 RL |
12 | #include <openssl/evp.h> |
13 | #include <openssl/core.h> | |
14 | #include "internal/cryptlib.h" | |
15 | #include "internal/thread_once.h" | |
c13d2ab4 RL |
16 | #include "internal/property.h" |
17 | #include "internal/core.h" | |
f7c16d48 | 18 | #include "internal/provider.h" |
baff732d | 19 | #include "internal/namemap.h" |
04cb5ec0 | 20 | #include "internal/property.h" |
706457b7 DMSP |
21 | #include "crypto/evp.h" /* evp_local.h needs it */ |
22 | #include "evp_local.h" | |
c13d2ab4 | 23 | |
695d195b RL |
24 | #define NAME_SEPARATOR ':' |
25 | ||
181ea366 | 26 | static void evp_method_store_free(void *vstore) |
c13d2ab4 RL |
27 | { |
28 | ossl_method_store_free(vstore); | |
29 | } | |
30 | ||
181ea366 | 31 | static void *evp_method_store_new(OPENSSL_CTX *ctx) |
c13d2ab4 | 32 | { |
1aedc35f | 33 | return ossl_method_store_new(ctx); |
c13d2ab4 RL |
34 | } |
35 | ||
36 | ||
181ea366 RL |
37 | static const OPENSSL_CTX_METHOD evp_method_store_method = { |
38 | evp_method_store_new, | |
39 | evp_method_store_free, | |
c13d2ab4 RL |
40 | }; |
41 | ||
c13d2ab4 | 42 | /* Data to be passed through ossl_method_construct() */ |
181ea366 | 43 | struct evp_method_data_st { |
baff732d | 44 | OPENSSL_CTX *libctx; |
c13d2ab4 | 45 | OSSL_METHOD_CONSTRUCT_METHOD *mcm; |
181ea366 RL |
46 | int operation_id; /* For get_evp_method_from_store() */ |
47 | int name_id; /* For get_evp_method_from_store() */ | |
48 | const char *names; /* For get_evp_method_from_store() */ | |
49 | const char *propquery; /* For get_evp_method_from_store() */ | |
f7c16d48 | 50 | void *(*method_from_dispatch)(int name_id, const OSSL_DISPATCH *, |
0ddf74bf | 51 | OSSL_PROVIDER *); |
c13d2ab4 RL |
52 | int (*refcnt_up_method)(void *method); |
53 | void (*destruct_method)(void *method); | |
54 | }; | |
55 | ||
56 | /* | |
57 | * Generic routines to fetch / create EVP methods with ossl_method_construct() | |
58 | */ | |
181ea366 | 59 | static void *alloc_tmp_evp_method_store(OPENSSL_CTX *ctx) |
c13d2ab4 | 60 | { |
1aedc35f | 61 | return ossl_method_store_new(ctx); |
c13d2ab4 RL |
62 | } |
63 | ||
181ea366 | 64 | static void dealloc_tmp_evp_method_store(void *store) |
c13d2ab4 RL |
65 | { |
66 | if (store != NULL) | |
67 | ossl_method_store_free(store); | |
68 | } | |
69 | ||
181ea366 | 70 | static OSSL_METHOD_STORE *get_evp_method_store(OPENSSL_CTX *libctx) |
c13d2ab4 | 71 | { |
181ea366 RL |
72 | return openssl_ctx_get_data(libctx, OPENSSL_CTX_EVP_METHOD_STORE_INDEX, |
73 | &evp_method_store_method); | |
c13d2ab4 RL |
74 | } |
75 | ||
2ccb1b4e | 76 | /* |
64f849f4 DMSP |
77 | * To identify the method in the EVP method store, we mix the name identity |
78 | * with the operation identity, under the assumption that we don't have more | |
181ea366 | 79 | * than 2^24 names or more than 2^8 operation types. |
2ccb1b4e RL |
80 | * |
81 | * The resulting identity is a 32-bit integer, composed like this: | |
82 | * | |
83 | * +---------24 bits--------+-8 bits-+ | |
84 | * | name identity | op id | | |
85 | * +------------------------+--------+ | |
86 | */ | |
b418980c | 87 | static uint32_t evp_method_id(int name_id, unsigned int operation_id) |
2ccb1b4e | 88 | { |
64f849f4 DMSP |
89 | if (!ossl_assert(name_id > 0 && name_id < (1 << 24)) |
90 | || !ossl_assert(operation_id > 0 && operation_id < (1 << 8))) | |
2ccb1b4e RL |
91 | return 0; |
92 | return ((name_id << 8) & 0xFFFFFF00) | (operation_id & 0x000000FF); | |
93 | } | |
94 | ||
181ea366 RL |
95 | static void *get_evp_method_from_store(OPENSSL_CTX *libctx, void *store, |
96 | void *data) | |
c13d2ab4 | 97 | { |
181ea366 | 98 | struct evp_method_data_st *methdata = data; |
c13d2ab4 | 99 | void *method = NULL; |
f7c16d48 RL |
100 | int name_id; |
101 | uint32_t meth_id; | |
c13d2ab4 | 102 | |
f7c16d48 | 103 | /* |
181ea366 RL |
104 | * get_evp_method_from_store() is only called to try and get the method |
105 | * that evp_generic_fetch() is asking for, and the operation id as well | |
106 | * as the name or name id are passed via methdata. | |
f7c16d48 RL |
107 | */ |
108 | if ((name_id = methdata->name_id) == 0) { | |
109 | OSSL_NAMEMAP *namemap = ossl_namemap_stored(libctx); | |
695d195b RL |
110 | const char *names = methdata->names; |
111 | const char *q = strchr(names, NAME_SEPARATOR); | |
112 | size_t l = (q == NULL ? strlen(names) : (size_t)(q - names)); | |
f7c16d48 RL |
113 | |
114 | if (namemap == 0) | |
115 | return NULL; | |
695d195b | 116 | name_id = ossl_namemap_name2num_n(namemap, names, l); |
f7c16d48 RL |
117 | } |
118 | ||
119 | if (name_id == 0 | |
b418980c | 120 | || (meth_id = evp_method_id(name_id, methdata->operation_id)) == 0) |
c13d2ab4 RL |
121 | return NULL; |
122 | ||
f7c16d48 | 123 | if (store == NULL |
181ea366 | 124 | && (store = get_evp_method_store(libctx)) == NULL) |
2e49c054 RL |
125 | return NULL; |
126 | ||
bdbf2df2 P |
127 | if (!ossl_method_store_fetch(store, meth_id, methdata->propquery, |
128 | &method)) | |
129 | return NULL; | |
c13d2ab4 RL |
130 | return method; |
131 | } | |
132 | ||
181ea366 RL |
133 | static int put_evp_method_in_store(OPENSSL_CTX *libctx, void *store, |
134 | void *method, const OSSL_PROVIDER *prov, | |
135 | int operation_id, const char *names, | |
136 | const char *propdef, void *data) | |
c13d2ab4 | 137 | { |
181ea366 | 138 | struct evp_method_data_st *methdata = data; |
2e49c054 | 139 | OSSL_NAMEMAP *namemap; |
f7c16d48 RL |
140 | int name_id; |
141 | uint32_t meth_id; | |
695d195b | 142 | size_t l = 0; |
dc46e3dd | 143 | |
f7c16d48 | 144 | /* |
181ea366 RL |
145 | * put_evp_method_in_store() is only called with an EVP method that was |
146 | * successfully created by construct_method() below, which means that | |
147 | * all the names should already be stored in the namemap with the same | |
148 | * numeric identity, so just use the first to get that identity. | |
f7c16d48 | 149 | */ |
695d195b RL |
150 | if (names != NULL) { |
151 | const char *q = strchr(names, NAME_SEPARATOR); | |
152 | ||
153 | l = (q == NULL ? strlen(names) : (size_t)(q - names)); | |
154 | } | |
155 | ||
f7c16d48 | 156 | if ((namemap = ossl_namemap_stored(libctx)) == NULL |
695d195b | 157 | || (name_id = ossl_namemap_name2num_n(namemap, names, l)) == 0 |
b418980c | 158 | || (meth_id = evp_method_id(name_id, operation_id)) == 0) |
dc46e3dd | 159 | return 0; |
c13d2ab4 RL |
160 | |
161 | if (store == NULL | |
181ea366 | 162 | && (store = get_evp_method_store(libctx)) == NULL) |
c13d2ab4 RL |
163 | return 0; |
164 | ||
f7c16d48 | 165 | return ossl_method_store_add(store, prov, meth_id, propdef, method, |
b1d40ddf RL |
166 | methdata->refcnt_up_method, |
167 | methdata->destruct_method); | |
c13d2ab4 RL |
168 | } |
169 | ||
f7c16d48 RL |
170 | /* |
171 | * The core fetching functionality passes the name of the implementation. | |
172 | * This function is responsible to getting an identity number for it. | |
173 | */ | |
36fa4d8a | 174 | static void *construct_evp_method(const OSSL_ALGORITHM *algodef, |
181ea366 | 175 | OSSL_PROVIDER *prov, void *data) |
c13d2ab4 | 176 | { |
f7c16d48 | 177 | /* |
181ea366 | 178 | * This function is only called if get_evp_method_from_store() returned |
f7c16d48 RL |
179 | * NULL, so it's safe to say that of all the spots to create a new |
180 | * namemap entry, this is it. Should the name already exist there, we | |
3d83c735 RL |
181 | * know that ossl_namemap_add_name() will return its corresponding |
182 | * number. | |
f7c16d48 | 183 | */ |
181ea366 | 184 | struct evp_method_data_st *methdata = data; |
f7c16d48 RL |
185 | OPENSSL_CTX *libctx = ossl_provider_library_context(prov); |
186 | OSSL_NAMEMAP *namemap = ossl_namemap_stored(libctx); | |
36fa4d8a | 187 | const char *names = algodef->algorithm_names; |
3d83c735 | 188 | int name_id = ossl_namemap_add_names(namemap, 0, names, NAME_SEPARATOR); |
c13d2ab4 | 189 | |
695d195b RL |
190 | if (name_id == 0) |
191 | return NULL; | |
36fa4d8a RL |
192 | return methdata->method_from_dispatch(name_id, algodef->implementation, |
193 | prov); | |
c13d2ab4 RL |
194 | } |
195 | ||
181ea366 | 196 | static void destruct_evp_method(void *method, void *data) |
c13d2ab4 | 197 | { |
181ea366 | 198 | struct evp_method_data_st *methdata = data; |
c13d2ab4 RL |
199 | |
200 | methdata->destruct_method(method); | |
201 | } | |
202 | ||
181ea366 RL |
203 | static void * |
204 | inner_evp_generic_fetch(OPENSSL_CTX *libctx, int operation_id, | |
205 | int name_id, const char *name, | |
206 | const char *properties, | |
207 | void *(*new_method)(int name_id, | |
208 | const OSSL_DISPATCH *fns, | |
0ddf74bf | 209 | OSSL_PROVIDER *prov), |
181ea366 RL |
210 | int (*up_ref_method)(void *), |
211 | void (*free_method)(void *)) | |
c13d2ab4 | 212 | { |
181ea366 | 213 | OSSL_METHOD_STORE *store = get_evp_method_store(libctx); |
437ad983 | 214 | OSSL_NAMEMAP *namemap = ossl_namemap_stored(libctx); |
f7c16d48 | 215 | uint32_t meth_id = 0; |
c13d2ab4 RL |
216 | void *method = NULL; |
217 | ||
baff732d | 218 | if (store == NULL || namemap == NULL) |
e019da7b RL |
219 | return NULL; |
220 | ||
2ccb1b4e RL |
221 | /* |
222 | * If there's ever an operation_id == 0 passed, we have an internal | |
223 | * programming error. | |
224 | */ | |
225 | if (!ossl_assert(operation_id > 0)) | |
226 | return NULL; | |
227 | ||
228 | /* | |
f7c16d48 RL |
229 | * If we have been passed neither a name_id or a name, we have an |
230 | * internal programming error. | |
231 | */ | |
232 | if (!ossl_assert(name_id != 0 || name != NULL)) | |
233 | return NULL; | |
234 | ||
235 | /* If we haven't received a name id yet, try to get one for the name */ | |
236 | if (name_id == 0) | |
237 | name_id = ossl_namemap_name2num(namemap, name); | |
238 | ||
239 | /* | |
181ea366 | 240 | * If we have a name id, calculate a method id with evp_method_id(). |
f7c16d48 | 241 | * |
181ea366 RL |
242 | * evp_method_id returns 0 if we have too many operations (more than |
243 | * about 2^8) or too many names (more than about 2^24). In that case, | |
244 | * we can't create any new method. | |
2ccb1b4e | 245 | */ |
b418980c | 246 | if (name_id != 0 && (meth_id = evp_method_id(name_id, operation_id)) == 0) |
2ccb1b4e RL |
247 | return NULL; |
248 | ||
f7c16d48 RL |
249 | if (meth_id == 0 |
250 | || !ossl_method_store_cache_get(store, meth_id, properties, &method)) { | |
c13d2ab4 | 251 | OSSL_METHOD_CONSTRUCT_METHOD mcm = { |
181ea366 RL |
252 | alloc_tmp_evp_method_store, |
253 | dealloc_tmp_evp_method_store, | |
254 | get_evp_method_from_store, | |
255 | put_evp_method_in_store, | |
256 | construct_evp_method, | |
257 | destruct_evp_method | |
c13d2ab4 | 258 | }; |
181ea366 | 259 | struct evp_method_data_st mcmdata; |
c13d2ab4 | 260 | |
c13d2ab4 | 261 | mcmdata.mcm = &mcm; |
baff732d | 262 | mcmdata.libctx = libctx; |
f7c16d48 RL |
263 | mcmdata.operation_id = operation_id; |
264 | mcmdata.name_id = name_id; | |
695d195b | 265 | mcmdata.names = name; |
f7c16d48 | 266 | mcmdata.propquery = properties; |
c13d2ab4 | 267 | mcmdata.method_from_dispatch = new_method; |
7c95390e | 268 | mcmdata.refcnt_up_method = up_ref_method; |
c13d2ab4 | 269 | mcmdata.destruct_method = free_method; |
f7c16d48 RL |
270 | if ((method = ossl_method_construct(libctx, operation_id, |
271 | 0 /* !force_cache */, | |
08607613 | 272 | &mcm, &mcmdata)) != NULL) { |
2ccb1b4e RL |
273 | /* |
274 | * If construction did create a method for us, we know that | |
181ea366 RL |
275 | * there is a correct name_id and meth_id, since those have |
276 | * already been calculated in get_evp_method_from_store() and | |
277 | * put_evp_method_in_store() above. | |
2ccb1b4e | 278 | */ |
f7c16d48 RL |
279 | if (name_id == 0) |
280 | name_id = ossl_namemap_name2num(namemap, name); | |
b418980c | 281 | meth_id = evp_method_id(name_id, operation_id); |
bdbf2df2 P |
282 | ossl_method_store_cache_set(store, meth_id, properties, method, |
283 | up_ref_method, free_method); | |
2ccb1b4e | 284 | } |
c13d2ab4 RL |
285 | } |
286 | ||
287 | return method; | |
288 | } | |
cb929645 | 289 | |
cfbd76c1 RL |
290 | #ifndef FIPS_MODULE |
291 | static const char *libctx_descriptor(OPENSSL_CTX *libctx) | |
292 | { | |
293 | if (openssl_ctx_is_global_default(libctx)) | |
294 | return "Global default library context"; | |
295 | if (openssl_ctx_is_default(libctx)) | |
296 | return "Thread-local default library context"; | |
297 | return "Non-default library context"; | |
298 | } | |
299 | #endif | |
300 | ||
f7c16d48 RL |
301 | void *evp_generic_fetch(OPENSSL_CTX *libctx, int operation_id, |
302 | const char *name, const char *properties, | |
303 | void *(*new_method)(int name_id, | |
304 | const OSSL_DISPATCH *fns, | |
0ddf74bf | 305 | OSSL_PROVIDER *prov), |
f7c16d48 RL |
306 | int (*up_ref_method)(void *), |
307 | void (*free_method)(void *)) | |
308 | { | |
6b1e5fa4 MC |
309 | void *ret = inner_evp_generic_fetch(libctx, |
310 | operation_id, 0, name, properties, | |
311 | new_method, up_ref_method, free_method); | |
312 | ||
313 | if (ret == NULL) { | |
314 | int code = EVP_R_FETCH_FAILED; | |
315 | ||
f844f9eb | 316 | #ifdef FIPS_MODULE |
6b1e5fa4 MC |
317 | ERR_raise(ERR_LIB_EVP, code); |
318 | #else | |
319 | ERR_raise_data(ERR_LIB_EVP, code, | |
320 | "%s, Algorithm (%s), Properties (%s)", | |
cfbd76c1 | 321 | libctx_descriptor(libctx), |
6b1e5fa4 MC |
322 | name = NULL ? "<null>" : name, |
323 | properties == NULL ? "<null>" : properties); | |
324 | #endif | |
325 | } | |
326 | return ret; | |
f7c16d48 RL |
327 | } |
328 | ||
329 | /* | |
330 | * evp_generic_fetch_by_number() is special, and only returns methods for | |
331 | * already known names, i.e. it refuses to work if no name_id can be found | |
332 | * (it's considered an internal programming error). | |
333 | * This is meant to be used when one method needs to fetch an associated | |
334 | * other method. | |
335 | */ | |
336 | void *evp_generic_fetch_by_number(OPENSSL_CTX *libctx, int operation_id, | |
337 | int name_id, const char *properties, | |
338 | void *(*new_method)(int name_id, | |
339 | const OSSL_DISPATCH *fns, | |
0ddf74bf | 340 | OSSL_PROVIDER *prov), |
f7c16d48 RL |
341 | int (*up_ref_method)(void *), |
342 | void (*free_method)(void *)) | |
343 | { | |
6b1e5fa4 MC |
344 | void *ret = inner_evp_generic_fetch(libctx, |
345 | operation_id, name_id, NULL, | |
346 | properties, new_method, up_ref_method, | |
347 | free_method); | |
348 | ||
349 | if (ret == NULL) { | |
350 | int code = EVP_R_FETCH_FAILED; | |
351 | ||
f844f9eb | 352 | #ifdef FIPS_MODULE |
6b1e5fa4 MC |
353 | ERR_raise(ERR_LIB_EVP, code); |
354 | #else | |
355 | { | |
356 | OSSL_NAMEMAP *namemap = ossl_namemap_stored(libctx); | |
357 | const char *name = (namemap == NULL) | |
358 | ? NULL | |
359 | : ossl_namemap_num2name(namemap, name_id, 0); | |
360 | ||
361 | ERR_raise_data(ERR_LIB_EVP, code, | |
362 | "%s, Algorithm (%s), Properties (%s)", | |
cfbd76c1 | 363 | libctx_descriptor(libctx), |
6b1e5fa4 MC |
364 | name = NULL ? "<null>" : name, |
365 | properties == NULL ? "<null>" : properties); | |
366 | } | |
367 | #endif | |
368 | } | |
369 | return ret; | |
f7c16d48 RL |
370 | } |
371 | ||
04cb5ec0 SL |
372 | void evp_method_store_flush(OPENSSL_CTX *libctx) |
373 | { | |
374 | OSSL_METHOD_STORE *store = get_evp_method_store(libctx); | |
375 | ||
376 | if (store != NULL) | |
377 | ossl_method_store_flush_cache(store, 1); | |
378 | } | |
379 | ||
e6c54619 MC |
380 | static int evp_set_parsed_default_properties(OPENSSL_CTX *libctx, |
381 | OSSL_PROPERTY_LIST *def_prop, | |
382 | int loadconfig) | |
cb929645 | 383 | { |
181ea366 | 384 | OSSL_METHOD_STORE *store = get_evp_method_store(libctx); |
e6c54619 | 385 | OSSL_PROPERTY_LIST **plp = ossl_ctx_global_properties(libctx, loadconfig); |
f9e504e8 P |
386 | |
387 | if (plp != NULL) { | |
388 | ossl_property_free(*plp); | |
389 | *plp = def_prop; | |
390 | if (store != NULL) | |
04cb5ec0 | 391 | ossl_method_store_flush_cache(store, 0); |
f9e504e8 P |
392 | return 1; |
393 | } | |
e0624f0d | 394 | EVPerr(0, ERR_R_INTERNAL_ERROR); |
cb929645 RL |
395 | return 0; |
396 | } | |
3d96a51c | 397 | |
e6c54619 MC |
398 | int evp_set_default_properties_int(OPENSSL_CTX *libctx, const char *propq, |
399 | int loadconfig) | |
f9e504e8 P |
400 | { |
401 | OSSL_PROPERTY_LIST *pl = NULL; | |
402 | ||
403 | if (propq != NULL && (pl = ossl_parse_query(libctx, propq)) == NULL) { | |
404 | EVPerr(0, EVP_R_DEFAULT_QUERY_PARSE_ERROR); | |
405 | return 0; | |
406 | } | |
e6c54619 | 407 | return evp_set_parsed_default_properties(libctx, pl, loadconfig); |
f9e504e8 P |
408 | } |
409 | ||
e6c54619 MC |
410 | int EVP_set_default_properties(OPENSSL_CTX *libctx, const char *propq) |
411 | { | |
412 | return evp_set_default_properties_int(libctx, propq, 1); | |
413 | } | |
e0624f0d SL |
414 | |
415 | static int evp_default_properties_merge(OPENSSL_CTX *libctx, const char *propq) | |
416 | { | |
e6c54619 | 417 | OSSL_PROPERTY_LIST **plp = ossl_ctx_global_properties(libctx, 1); |
f9e504e8 P |
418 | OSSL_PROPERTY_LIST *pl1, *pl2; |
419 | ||
420 | if (propq == NULL) | |
421 | return 1; | |
422 | if (plp == NULL || *plp == NULL) | |
423 | return EVP_set_default_properties(libctx, propq); | |
424 | if ((pl1 = ossl_parse_query(libctx, propq)) == NULL) { | |
425 | EVPerr(0, EVP_R_DEFAULT_QUERY_PARSE_ERROR); | |
426 | return 0; | |
427 | } | |
428 | pl2 = ossl_property_merge(pl1, *plp); | |
429 | ossl_property_free(pl1); | |
430 | if (pl2 == NULL) { | |
431 | EVPerr(0, ERR_R_MALLOC_FAILURE); | |
432 | return 0; | |
433 | } | |
e6c54619 | 434 | return evp_set_parsed_default_properties(libctx, pl2, 0); |
e0624f0d SL |
435 | } |
436 | ||
437 | static int evp_default_property_is_enabled(OPENSSL_CTX *libctx, | |
438 | const char *prop_name) | |
439 | { | |
e6c54619 | 440 | OSSL_PROPERTY_LIST **plp = ossl_ctx_global_properties(libctx, 1); |
e0624f0d | 441 | |
f9e504e8 | 442 | return plp != NULL && ossl_property_is_enabled(libctx, prop_name, *plp); |
e0624f0d SL |
443 | } |
444 | ||
445 | int EVP_default_properties_is_fips_enabled(OPENSSL_CTX *libctx) | |
446 | { | |
447 | return evp_default_property_is_enabled(libctx, "fips"); | |
448 | } | |
449 | ||
450 | int EVP_default_properties_enable_fips(OPENSSL_CTX *libctx, int enable) | |
451 | { | |
452 | const char *query = (enable != 0) ? "fips=yes" : "-fips"; | |
453 | ||
454 | return evp_default_properties_merge(libctx, query); | |
455 | } | |
456 | ||
457 | ||
3d96a51c RL |
458 | struct do_all_data_st { |
459 | void (*user_fn)(void *method, void *arg); | |
460 | void *user_arg; | |
f7c16d48 | 461 | void *(*new_method)(const int name_id, const OSSL_DISPATCH *fns, |
0ddf74bf | 462 | OSSL_PROVIDER *prov); |
3d96a51c RL |
463 | void (*free_method)(void *); |
464 | }; | |
465 | ||
466 | static void do_one(OSSL_PROVIDER *provider, const OSSL_ALGORITHM *algo, | |
467 | int no_store, void *vdata) | |
468 | { | |
469 | struct do_all_data_st *data = vdata; | |
f7c16d48 RL |
470 | OPENSSL_CTX *libctx = ossl_provider_library_context(provider); |
471 | OSSL_NAMEMAP *namemap = ossl_namemap_stored(libctx); | |
3d83c735 RL |
472 | int name_id = ossl_namemap_add_names(namemap, 0, algo->algorithm_names, |
473 | NAME_SEPARATOR); | |
f7c16d48 RL |
474 | void *method = NULL; |
475 | ||
476 | if (name_id != 0) | |
0ddf74bf | 477 | method = data->new_method(name_id, algo->implementation, provider); |
3d96a51c RL |
478 | |
479 | if (method != NULL) { | |
480 | data->user_fn(method, data->user_arg); | |
481 | data->free_method(method); | |
482 | } | |
483 | } | |
484 | ||
485 | void evp_generic_do_all(OPENSSL_CTX *libctx, int operation_id, | |
486 | void (*user_fn)(void *method, void *arg), | |
487 | void *user_arg, | |
f7c16d48 | 488 | void *(*new_method)(int name_id, |
3d96a51c | 489 | const OSSL_DISPATCH *fns, |
0ddf74bf | 490 | OSSL_PROVIDER *prov), |
3d96a51c RL |
491 | void (*free_method)(void *)) |
492 | { | |
493 | struct do_all_data_st data; | |
494 | ||
495 | data.new_method = new_method; | |
496 | data.free_method = free_method; | |
497 | data.user_fn = user_fn; | |
498 | data.user_arg = user_arg; | |
5a29b628 RL |
499 | |
500 | /* | |
501 | * No pre- or post-condition for this call, as this only creates methods | |
502 | * temporarly and then promptly destroys them. | |
503 | */ | |
504 | ossl_algorithm_do_all(libctx, operation_id, NULL, NULL, do_one, NULL, | |
505 | &data); | |
3d96a51c | 506 | } |
f7c16d48 | 507 | |
3f7ce7f1 | 508 | const char *evp_first_name(const OSSL_PROVIDER *prov, int name_id) |
f7c16d48 RL |
509 | { |
510 | OPENSSL_CTX *libctx = ossl_provider_library_context(prov); | |
511 | OSSL_NAMEMAP *namemap = ossl_namemap_stored(libctx); | |
512 | ||
513 | return ossl_namemap_num2name(namemap, name_id, 0); | |
514 | } | |
7cfa1717 | 515 | |
e4a1d023 RL |
516 | int evp_is_a(OSSL_PROVIDER *prov, int number, |
517 | const char *legacy_name, const char *name) | |
7cfa1717 | 518 | { |
e4a1d023 RL |
519 | /* |
520 | * For a |prov| that is NULL, the library context will be NULL | |
521 | */ | |
7cfa1717 RL |
522 | OPENSSL_CTX *libctx = ossl_provider_library_context(prov); |
523 | OSSL_NAMEMAP *namemap = ossl_namemap_stored(libctx); | |
524 | ||
e4a1d023 RL |
525 | if (prov == NULL) |
526 | number = ossl_namemap_name2num(namemap, legacy_name); | |
7cfa1717 RL |
527 | return ossl_namemap_name2num(namemap, name) == number; |
528 | } | |
32040838 | 529 | |
f651c727 RL |
530 | void evp_names_do_all(OSSL_PROVIDER *prov, int number, |
531 | void (*fn)(const char *name, void *data), | |
532 | void *data) | |
32040838 RL |
533 | { |
534 | OPENSSL_CTX *libctx = ossl_provider_library_context(prov); | |
535 | OSSL_NAMEMAP *namemap = ossl_namemap_stored(libctx); | |
536 | ||
537 | ossl_namemap_doall_names(namemap, number, fn, data); | |
538 | } |