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