evp_fetch.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. /*
  2. * Copyright 2019-2024 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. * Note that there is a corner case here, in which, if a user
  278. * passes a name of the form name1:name2:..., then the construction
  279. * will create a method against all names, but the lookup will fail
  280. * as ossl_namemap_name2num treats the name string as a single name
  281. * rather than introducing new features where in the EVP_<obj>_fetch
  282. * parses the string and queries for each, return an error.
  283. */
  284. if (name_id == 0)
  285. name_id = ossl_namemap_name2num(namemap, name);
  286. if (name_id == 0) {
  287. ERR_raise_data(ERR_LIB_EVP, ERR_R_FETCH_FAILED,
  288. "Algorithm %s cannot be found", name);
  289. free_method(method);
  290. method = NULL;
  291. } else {
  292. meth_id = evp_method_id(name_id, operation_id);
  293. if (meth_id != 0)
  294. ossl_method_store_cache_set(store, prov, meth_id, propq,
  295. method, up_ref_method, free_method);
  296. }
  297. }
  298. /*
  299. * If we never were in the constructor, the algorithm to be fetched
  300. * is unsupported.
  301. */
  302. unsupported = !methdata->flag_construct_error_occurred;
  303. }
  304. if ((name_id != 0 || name != NULL) && method == NULL) {
  305. int code = unsupported ? ERR_R_UNSUPPORTED : ERR_R_FETCH_FAILED;
  306. if (name == NULL)
  307. name = ossl_namemap_num2name(namemap, name_id, 0);
  308. ERR_raise_data(ERR_LIB_EVP, code,
  309. "%s, Algorithm (%s : %d), Properties (%s)",
  310. ossl_lib_ctx_get_descriptor(methdata->libctx),
  311. name == NULL ? "<null>" : name, name_id,
  312. properties == NULL ? "<null>" : properties);
  313. }
  314. return method;
  315. }
  316. void *evp_generic_fetch(OSSL_LIB_CTX *libctx, int operation_id,
  317. const char *name, const char *properties,
  318. void *(*new_method)(int name_id,
  319. const OSSL_ALGORITHM *algodef,
  320. OSSL_PROVIDER *prov),
  321. int (*up_ref_method)(void *),
  322. void (*free_method)(void *))
  323. {
  324. struct evp_method_data_st methdata;
  325. void *method;
  326. methdata.libctx = libctx;
  327. methdata.tmp_store = NULL;
  328. method = inner_evp_generic_fetch(&methdata, NULL, operation_id,
  329. name, properties,
  330. new_method, up_ref_method, free_method);
  331. dealloc_tmp_evp_method_store(methdata.tmp_store);
  332. return method;
  333. }
  334. /*
  335. * evp_generic_fetch_from_prov() is special, and only returns methods from
  336. * the given provider.
  337. * This is meant to be used when one method needs to fetch an associated
  338. * method.
  339. */
  340. void *evp_generic_fetch_from_prov(OSSL_PROVIDER *prov, int operation_id,
  341. const char *name, const char *properties,
  342. void *(*new_method)(int name_id,
  343. const OSSL_ALGORITHM *algodef,
  344. OSSL_PROVIDER *prov),
  345. int (*up_ref_method)(void *),
  346. void (*free_method)(void *))
  347. {
  348. struct evp_method_data_st methdata;
  349. void *method;
  350. methdata.libctx = ossl_provider_libctx(prov);
  351. methdata.tmp_store = NULL;
  352. method = inner_evp_generic_fetch(&methdata, prov, operation_id,
  353. name, properties,
  354. new_method, up_ref_method, free_method);
  355. dealloc_tmp_evp_method_store(methdata.tmp_store);
  356. return method;
  357. }
  358. int evp_method_store_cache_flush(OSSL_LIB_CTX *libctx)
  359. {
  360. OSSL_METHOD_STORE *store = get_evp_method_store(libctx);
  361. if (store != NULL)
  362. return ossl_method_store_cache_flush_all(store);
  363. return 1;
  364. }
  365. int evp_method_store_remove_all_provided(const OSSL_PROVIDER *prov)
  366. {
  367. OSSL_LIB_CTX *libctx = ossl_provider_libctx(prov);
  368. OSSL_METHOD_STORE *store = get_evp_method_store(libctx);
  369. if (store != NULL)
  370. return ossl_method_store_remove_all_provided(store, prov);
  371. return 1;
  372. }
  373. static int evp_set_parsed_default_properties(OSSL_LIB_CTX *libctx,
  374. OSSL_PROPERTY_LIST *def_prop,
  375. int loadconfig,
  376. int mirrored)
  377. {
  378. OSSL_METHOD_STORE *store = get_evp_method_store(libctx);
  379. OSSL_PROPERTY_LIST **plp = ossl_ctx_global_properties(libctx, loadconfig);
  380. if (plp != NULL && store != NULL) {
  381. int ret;
  382. #ifndef FIPS_MODULE
  383. char *propstr = NULL;
  384. size_t strsz;
  385. if (mirrored) {
  386. if (ossl_global_properties_no_mirrored(libctx))
  387. return 0;
  388. } else {
  389. /*
  390. * These properties have been explicitly set on this libctx, so
  391. * don't allow any mirroring from a parent libctx.
  392. */
  393. ossl_global_properties_stop_mirroring(libctx);
  394. }
  395. strsz = ossl_property_list_to_string(libctx, def_prop, NULL, 0);
  396. if (strsz > 0)
  397. propstr = OPENSSL_malloc(strsz);
  398. if (propstr == NULL) {
  399. ERR_raise(ERR_LIB_EVP, ERR_R_INTERNAL_ERROR);
  400. return 0;
  401. }
  402. if (ossl_property_list_to_string(libctx, def_prop, propstr,
  403. strsz) == 0) {
  404. OPENSSL_free(propstr);
  405. ERR_raise(ERR_LIB_EVP, ERR_R_INTERNAL_ERROR);
  406. return 0;
  407. }
  408. ossl_provider_default_props_update(libctx, propstr);
  409. OPENSSL_free(propstr);
  410. #endif
  411. ossl_property_free(*plp);
  412. *plp = def_prop;
  413. ret = ossl_method_store_cache_flush_all(store);
  414. #ifndef FIPS_MODULE
  415. ossl_decoder_cache_flush(libctx);
  416. #endif
  417. return ret;
  418. }
  419. ERR_raise(ERR_LIB_EVP, ERR_R_INTERNAL_ERROR);
  420. return 0;
  421. }
  422. int evp_set_default_properties_int(OSSL_LIB_CTX *libctx, const char *propq,
  423. int loadconfig, int mirrored)
  424. {
  425. OSSL_PROPERTY_LIST *pl = NULL;
  426. if (propq != NULL && (pl = ossl_parse_query(libctx, propq, 1)) == NULL) {
  427. ERR_raise(ERR_LIB_EVP, EVP_R_DEFAULT_QUERY_PARSE_ERROR);
  428. return 0;
  429. }
  430. if (!evp_set_parsed_default_properties(libctx, pl, loadconfig, mirrored)) {
  431. ossl_property_free(pl);
  432. return 0;
  433. }
  434. return 1;
  435. }
  436. int EVP_set_default_properties(OSSL_LIB_CTX *libctx, const char *propq)
  437. {
  438. return evp_set_default_properties_int(libctx, propq, 1, 0);
  439. }
  440. static int evp_default_properties_merge(OSSL_LIB_CTX *libctx, const char *propq,
  441. int loadconfig)
  442. {
  443. OSSL_PROPERTY_LIST **plp = ossl_ctx_global_properties(libctx, loadconfig);
  444. OSSL_PROPERTY_LIST *pl1, *pl2;
  445. if (propq == NULL)
  446. return 1;
  447. if (plp == NULL || *plp == NULL)
  448. return evp_set_default_properties_int(libctx, propq, 0, 0);
  449. if ((pl1 = ossl_parse_query(libctx, propq, 1)) == NULL) {
  450. ERR_raise(ERR_LIB_EVP, EVP_R_DEFAULT_QUERY_PARSE_ERROR);
  451. return 0;
  452. }
  453. pl2 = ossl_property_merge(pl1, *plp);
  454. ossl_property_free(pl1);
  455. if (pl2 == NULL) {
  456. ERR_raise(ERR_LIB_EVP, ERR_R_CRYPTO_LIB);
  457. return 0;
  458. }
  459. if (!evp_set_parsed_default_properties(libctx, pl2, 0, 0)) {
  460. ossl_property_free(pl2);
  461. return 0;
  462. }
  463. return 1;
  464. }
  465. static int evp_default_property_is_enabled(OSSL_LIB_CTX *libctx,
  466. const char *prop_name)
  467. {
  468. OSSL_PROPERTY_LIST **plp = ossl_ctx_global_properties(libctx, 1);
  469. return plp != NULL && ossl_property_is_enabled(libctx, prop_name, *plp);
  470. }
  471. int EVP_default_properties_is_fips_enabled(OSSL_LIB_CTX *libctx)
  472. {
  473. return evp_default_property_is_enabled(libctx, "fips");
  474. }
  475. int evp_default_properties_enable_fips_int(OSSL_LIB_CTX *libctx, int enable,
  476. int loadconfig)
  477. {
  478. const char *query = (enable != 0) ? "fips=yes" : "-fips";
  479. return evp_default_properties_merge(libctx, query, loadconfig);
  480. }
  481. int EVP_default_properties_enable_fips(OSSL_LIB_CTX *libctx, int enable)
  482. {
  483. return evp_default_properties_enable_fips_int(libctx, enable, 1);
  484. }
  485. char *evp_get_global_properties_str(OSSL_LIB_CTX *libctx, int loadconfig)
  486. {
  487. OSSL_PROPERTY_LIST **plp = ossl_ctx_global_properties(libctx, loadconfig);
  488. char *propstr = NULL;
  489. size_t sz;
  490. if (plp == NULL)
  491. return OPENSSL_strdup("");
  492. sz = ossl_property_list_to_string(libctx, *plp, NULL, 0);
  493. if (sz == 0) {
  494. ERR_raise(ERR_LIB_EVP, ERR_R_INTERNAL_ERROR);
  495. return NULL;
  496. }
  497. propstr = OPENSSL_malloc(sz);
  498. if (propstr == NULL)
  499. return NULL;
  500. if (ossl_property_list_to_string(libctx, *plp, propstr, sz) == 0) {
  501. ERR_raise(ERR_LIB_EVP, ERR_R_INTERNAL_ERROR);
  502. OPENSSL_free(propstr);
  503. return NULL;
  504. }
  505. return propstr;
  506. }
  507. struct filter_data_st {
  508. int operation_id;
  509. void (*user_fn)(void *method, void *arg);
  510. void *user_arg;
  511. };
  512. static void filter_on_operation_id(int id, void *method, void *arg)
  513. {
  514. struct filter_data_st *data = arg;
  515. if ((id & METHOD_ID_OPERATION_MASK) == data->operation_id)
  516. data->user_fn(method, data->user_arg);
  517. }
  518. void evp_generic_do_all(OSSL_LIB_CTX *libctx, int operation_id,
  519. void (*user_fn)(void *method, void *arg),
  520. void *user_arg,
  521. void *(*new_method)(int name_id,
  522. const OSSL_ALGORITHM *algodef,
  523. OSSL_PROVIDER *prov),
  524. int (*up_ref_method)(void *),
  525. void (*free_method)(void *))
  526. {
  527. struct evp_method_data_st methdata;
  528. struct filter_data_st data;
  529. methdata.libctx = libctx;
  530. methdata.tmp_store = NULL;
  531. (void)inner_evp_generic_fetch(&methdata, NULL, operation_id, NULL, NULL,
  532. new_method, up_ref_method, free_method);
  533. data.operation_id = operation_id;
  534. data.user_fn = user_fn;
  535. data.user_arg = user_arg;
  536. if (methdata.tmp_store != NULL)
  537. ossl_method_store_do_all(methdata.tmp_store, &filter_on_operation_id,
  538. &data);
  539. ossl_method_store_do_all(get_evp_method_store(libctx),
  540. &filter_on_operation_id, &data);
  541. dealloc_tmp_evp_method_store(methdata.tmp_store);
  542. }
  543. int evp_is_a(OSSL_PROVIDER *prov, int number,
  544. const char *legacy_name, const char *name)
  545. {
  546. /*
  547. * For a |prov| that is NULL, the library context will be NULL
  548. */
  549. OSSL_LIB_CTX *libctx = ossl_provider_libctx(prov);
  550. OSSL_NAMEMAP *namemap = ossl_namemap_stored(libctx);
  551. if (prov == NULL)
  552. number = ossl_namemap_name2num(namemap, legacy_name);
  553. return ossl_namemap_name2num(namemap, name) == number;
  554. }
  555. int evp_names_do_all(OSSL_PROVIDER *prov, int number,
  556. void (*fn)(const char *name, void *data),
  557. void *data)
  558. {
  559. OSSL_LIB_CTX *libctx = ossl_provider_libctx(prov);
  560. OSSL_NAMEMAP *namemap = ossl_namemap_stored(libctx);
  561. return ossl_namemap_doall_names(namemap, number, fn, data);
  562. }