evp_fetch.c 22 KB

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