evp_fetch.c 22 KB

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