evp_fetch.c 21 KB

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