provider_core.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. /*
  2. * Copyright 2019 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 <openssl/core.h>
  10. #include <openssl/core_numbers.h>
  11. #include <openssl/params.h>
  12. #include <openssl/opensslv.h>
  13. #include "internal/cryptlib.h"
  14. #include "internal/nelem.h"
  15. #include "internal/thread_once.h"
  16. #include "internal/provider.h"
  17. #include "internal/refcount.h"
  18. #include "provider_local.h"
  19. static OSSL_PROVIDER *provider_new(const char *name,
  20. OSSL_provider_init_fn *init_function);
  21. /*-
  22. * Provider Object structure
  23. * =========================
  24. */
  25. typedef struct {
  26. char *name;
  27. char *value;
  28. } INFOPAIR;
  29. DEFINE_STACK_OF(INFOPAIR)
  30. struct provider_store_st; /* Forward declaration */
  31. struct ossl_provider_st {
  32. /* Flag bits */
  33. unsigned int flag_initialized:1;
  34. unsigned int flag_fallback:1;
  35. /* OpenSSL library side data */
  36. CRYPTO_REF_COUNT refcnt;
  37. CRYPTO_RWLOCK *refcnt_lock; /* For the ref counter */
  38. char *name;
  39. char *path;
  40. DSO *module;
  41. OSSL_provider_init_fn *init_function;
  42. STACK_OF(INFOPAIR) *parameters;
  43. OPENSSL_CTX *libctx; /* The library context this instance is in */
  44. struct provider_store_st *store; /* The store this instance belongs to */
  45. /* Provider side functions */
  46. OSSL_provider_teardown_fn *teardown;
  47. OSSL_provider_get_param_types_fn *get_param_types;
  48. OSSL_provider_get_params_fn *get_params;
  49. OSSL_provider_query_operation_fn *query_operation;
  50. /* Provider side data */
  51. void *provctx;
  52. };
  53. DEFINE_STACK_OF(OSSL_PROVIDER)
  54. static int ossl_provider_cmp(const OSSL_PROVIDER * const *a,
  55. const OSSL_PROVIDER * const *b)
  56. {
  57. return strcmp((*a)->name, (*b)->name);
  58. }
  59. /*-
  60. * Provider Object store
  61. * =====================
  62. *
  63. * The Provider Object store is a library context object, and therefore needs
  64. * an index.
  65. */
  66. struct provider_store_st {
  67. STACK_OF(OSSL_PROVIDER) *providers;
  68. CRYPTO_RWLOCK *lock;
  69. unsigned int use_fallbacks:1;
  70. };
  71. static void provider_store_free(void *vstore)
  72. {
  73. struct provider_store_st *store = vstore;
  74. if (store == NULL)
  75. return;
  76. sk_OSSL_PROVIDER_pop_free(store->providers, ossl_provider_free);
  77. CRYPTO_THREAD_lock_free(store->lock);
  78. OPENSSL_free(store);
  79. }
  80. static void *provider_store_new(OPENSSL_CTX *ctx)
  81. {
  82. struct provider_store_st *store = OPENSSL_zalloc(sizeof(*store));
  83. const struct predefined_providers_st *p = NULL;
  84. if (store == NULL
  85. || (store->providers = sk_OSSL_PROVIDER_new(ossl_provider_cmp)) == NULL
  86. || (store->lock = CRYPTO_THREAD_lock_new()) == NULL) {
  87. provider_store_free(store);
  88. return NULL;
  89. }
  90. store->use_fallbacks = 1;
  91. for (p = predefined_providers; p->name != NULL; p++) {
  92. OSSL_PROVIDER *prov = NULL;
  93. /*
  94. * We use the internal constructor directly here,
  95. * otherwise we get a call loop
  96. */
  97. prov = provider_new(p->name, p->init);
  98. if (prov == NULL
  99. || sk_OSSL_PROVIDER_push(store->providers, prov) == 0) {
  100. ossl_provider_free(prov);
  101. provider_store_free(store);
  102. CRYPTOerr(CRYPTO_F_PROVIDER_STORE_NEW, ERR_R_INTERNAL_ERROR);
  103. return NULL;
  104. }
  105. prov->libctx = ctx;
  106. prov->store = store;
  107. if(p->is_fallback)
  108. ossl_provider_set_fallback(prov);
  109. }
  110. return store;
  111. }
  112. static const OPENSSL_CTX_METHOD provider_store_method = {
  113. provider_store_new,
  114. provider_store_free,
  115. };
  116. static struct provider_store_st *get_provider_store(OPENSSL_CTX *libctx)
  117. {
  118. struct provider_store_st *store = NULL;
  119. store = openssl_ctx_get_data(libctx, OPENSSL_CTX_PROVIDER_STORE_INDEX,
  120. &provider_store_method);
  121. if (store == NULL)
  122. CRYPTOerr(CRYPTO_F_GET_PROVIDER_STORE, ERR_R_INTERNAL_ERROR);
  123. return store;
  124. }
  125. OSSL_PROVIDER *ossl_provider_find(OPENSSL_CTX *libctx, const char *name)
  126. {
  127. struct provider_store_st *store = NULL;
  128. OSSL_PROVIDER *prov = NULL;
  129. if ((store = get_provider_store(libctx)) != NULL) {
  130. OSSL_PROVIDER tmpl = { 0, };
  131. int i;
  132. tmpl.name = (char *)name;
  133. CRYPTO_THREAD_write_lock(store->lock);
  134. if ((i = sk_OSSL_PROVIDER_find(store->providers, &tmpl)) == -1
  135. || (prov = sk_OSSL_PROVIDER_value(store->providers, i)) == NULL
  136. || !ossl_provider_upref(prov))
  137. prov = NULL;
  138. CRYPTO_THREAD_unlock(store->lock);
  139. }
  140. return prov;
  141. }
  142. /*-
  143. * Provider Object methods
  144. * =======================
  145. */
  146. static OSSL_PROVIDER *provider_new(const char *name,
  147. OSSL_provider_init_fn *init_function)
  148. {
  149. OSSL_PROVIDER *prov = NULL;
  150. if ((prov = OPENSSL_zalloc(sizeof(*prov))) == NULL
  151. #ifndef HAVE_ATOMICS
  152. || (prov->refcnt_lock = CRYPTO_THREAD_lock_new()) == NULL
  153. #endif
  154. || !ossl_provider_upref(prov) /* +1 One reference to be returned */
  155. || (prov->name = OPENSSL_strdup(name)) == NULL) {
  156. ossl_provider_free(prov);
  157. CRYPTOerr(CRYPTO_F_PROVIDER_NEW, ERR_R_MALLOC_FAILURE);
  158. return NULL;
  159. }
  160. prov->init_function = init_function;
  161. return prov;
  162. }
  163. int ossl_provider_upref(OSSL_PROVIDER *prov)
  164. {
  165. int ref = 0;
  166. if (CRYPTO_UP_REF(&prov->refcnt, &ref, prov->refcnt_lock) <= 0)
  167. return 0;
  168. return ref;
  169. }
  170. OSSL_PROVIDER *ossl_provider_new(OPENSSL_CTX *libctx, const char *name,
  171. OSSL_provider_init_fn *init_function)
  172. {
  173. struct provider_store_st *store = NULL;
  174. OSSL_PROVIDER *prov = NULL;
  175. if ((store = get_provider_store(libctx)) == NULL)
  176. return NULL;
  177. if ((prov = ossl_provider_find(libctx, name)) != NULL) { /* refcount +1 */
  178. ossl_provider_free(prov); /* refcount -1 */
  179. CRYPTOerr(CRYPTO_F_OSSL_PROVIDER_NEW,
  180. CRYPTO_R_PROVIDER_ALREADY_EXISTS);
  181. ERR_add_error_data(2, "name=", name);
  182. return NULL;
  183. }
  184. /* provider_new() generates an error, so no need here */
  185. if ((prov = provider_new(name, init_function)) == NULL)
  186. return NULL;
  187. CRYPTO_THREAD_write_lock(store->lock);
  188. if (!ossl_provider_upref(prov)) { /* +1 One reference for the store */
  189. ossl_provider_free(prov); /* -1 Reference that was to be returned */
  190. prov = NULL;
  191. } else if (sk_OSSL_PROVIDER_push(store->providers, prov) == 0) {
  192. ossl_provider_free(prov); /* -1 Store reference */
  193. ossl_provider_free(prov); /* -1 Reference that was to be returned */
  194. prov = NULL;
  195. } else {
  196. prov->libctx = libctx;
  197. prov->store = store;
  198. }
  199. CRYPTO_THREAD_unlock(store->lock);
  200. if (prov == NULL)
  201. CRYPTOerr(CRYPTO_F_OSSL_PROVIDER_NEW, ERR_R_MALLOC_FAILURE);
  202. /*
  203. * At this point, the provider is only partially "loaded". To be
  204. * fully "loaded", ossl_provider_activate() must also be called.
  205. */
  206. return prov;
  207. }
  208. static void free_infopair(INFOPAIR *pair)
  209. {
  210. OPENSSL_free(pair->name);
  211. OPENSSL_free(pair->value);
  212. OPENSSL_free(pair);
  213. }
  214. void ossl_provider_free(OSSL_PROVIDER *prov)
  215. {
  216. if (prov != NULL) {
  217. int ref = 0;
  218. CRYPTO_DOWN_REF(&prov->refcnt, &ref, prov->refcnt_lock);
  219. /*
  220. * When the refcount drops below two, the store is the only
  221. * possible reference, or it has already been taken away from
  222. * the store (this may happen if a provider was activated
  223. * because it's a fallback, but isn't currently used)
  224. * When that happens, the provider is inactivated.
  225. */
  226. if (ref < 2 && prov->flag_initialized) {
  227. if (prov->teardown != NULL)
  228. prov->teardown(prov->provctx);
  229. prov->flag_initialized = 0;
  230. }
  231. /*
  232. * When the refcount drops to zero, it has been taken out of
  233. * the store. All we have to do here is clean it out.
  234. */
  235. if (ref == 0) {
  236. #ifndef FIPS_MODE
  237. DSO_free(prov->module);
  238. #endif
  239. OPENSSL_free(prov->name);
  240. OPENSSL_free(prov->path);
  241. sk_INFOPAIR_pop_free(prov->parameters, free_infopair);
  242. #ifndef HAVE_ATOMICS
  243. CRYPTO_THREAD_lock_free(prov->refcnt_lock);
  244. #endif
  245. OPENSSL_free(prov);
  246. }
  247. }
  248. }
  249. /* Setters */
  250. int ossl_provider_set_module_path(OSSL_PROVIDER *prov, const char *module_path)
  251. {
  252. OPENSSL_free(prov->path);
  253. if (module_path == NULL)
  254. return 1;
  255. if ((prov->path = OPENSSL_strdup(module_path)) != NULL)
  256. return 1;
  257. CRYPTOerr(CRYPTO_F_OSSL_PROVIDER_SET_MODULE_PATH, ERR_R_MALLOC_FAILURE);
  258. return 0;
  259. }
  260. int ossl_provider_add_parameter(OSSL_PROVIDER *prov,
  261. const char *name, const char *value)
  262. {
  263. INFOPAIR *pair = NULL;
  264. if ((pair = OPENSSL_zalloc(sizeof(*pair))) != NULL
  265. && (prov->parameters != NULL
  266. || (prov->parameters = sk_INFOPAIR_new_null()) != NULL)
  267. && (pair->name = OPENSSL_strdup(name)) != NULL
  268. && (pair->value = OPENSSL_strdup(value)) != NULL
  269. && sk_INFOPAIR_push(prov->parameters, pair) > 0)
  270. return 1;
  271. if (pair != NULL) {
  272. OPENSSL_free(pair->name);
  273. OPENSSL_free(pair->value);
  274. OPENSSL_free(pair);
  275. }
  276. CRYPTOerr(CRYPTO_F_OSSL_PROVIDER_ADD_PARAMETER, ERR_R_MALLOC_FAILURE);
  277. return 0;
  278. }
  279. /*
  280. * Provider activation.
  281. *
  282. * What "activation" means depends on the provider form; for built in
  283. * providers (in the library or the application alike), the provider
  284. * can already be considered to be loaded, all that's needed is to
  285. * initialize it. However, for dynamically loadable provider modules,
  286. * we must first load that module.
  287. *
  288. * Built in modules are distinguished from dynamically loaded modules
  289. * with an already assigned init function.
  290. */
  291. static const OSSL_DISPATCH *core_dispatch; /* Define further down */
  292. /*
  293. * Internal version that doesn't affect the store flags, and thereby avoid
  294. * locking. Direct callers must remember to set the store flags when
  295. * appropriate.
  296. */
  297. static int provider_activate(OSSL_PROVIDER *prov)
  298. {
  299. const OSSL_DISPATCH *provider_dispatch = NULL;
  300. if (prov->flag_initialized)
  301. return 1;
  302. /*
  303. * If the init function isn't set, it indicates that this provider is
  304. * a loadable module.
  305. */
  306. if (prov->init_function == NULL) {
  307. #ifdef FIPS_MODE
  308. return 0;
  309. #else
  310. if (prov->module == NULL) {
  311. char *allocated_path = NULL;
  312. const char *module_path = NULL;
  313. char *merged_path = NULL;
  314. const char *load_dir = ossl_safe_getenv("OPENSSL_MODULES");
  315. if ((prov->module = DSO_new()) == NULL) {
  316. /* DSO_new() generates an error already */
  317. return 0;
  318. }
  319. if (load_dir == NULL)
  320. load_dir = MODULESDIR;
  321. DSO_ctrl(prov->module, DSO_CTRL_SET_FLAGS,
  322. DSO_FLAG_NAME_TRANSLATION_EXT_ONLY, NULL);
  323. module_path = prov->path;
  324. if (module_path == NULL)
  325. module_path = allocated_path =
  326. DSO_convert_filename(prov->module, prov->name);
  327. if (module_path != NULL)
  328. merged_path = DSO_merge(prov->module, module_path, load_dir);
  329. if (merged_path == NULL
  330. || (DSO_load(prov->module, merged_path, NULL, 0)) == NULL) {
  331. DSO_free(prov->module);
  332. prov->module = NULL;
  333. }
  334. OPENSSL_free(merged_path);
  335. OPENSSL_free(allocated_path);
  336. }
  337. if (prov->module != NULL)
  338. prov->init_function = (OSSL_provider_init_fn *)
  339. DSO_bind_func(prov->module, "OSSL_provider_init");
  340. #endif
  341. }
  342. /* Call the initialise function for the provider. */
  343. if (prov->init_function == NULL
  344. || !prov->init_function(prov, core_dispatch, &provider_dispatch,
  345. &prov->provctx)) {
  346. CRYPTOerr(CRYPTO_F_PROVIDER_ACTIVATE, ERR_R_INIT_FAIL);
  347. ERR_add_error_data(2, "name=", prov->name);
  348. #ifndef FIPS_MODE
  349. DSO_free(prov->module);
  350. prov->module = NULL;
  351. #endif
  352. return 0;
  353. }
  354. for (; provider_dispatch->function_id != 0; provider_dispatch++) {
  355. switch (provider_dispatch->function_id) {
  356. case OSSL_FUNC_PROVIDER_TEARDOWN:
  357. prov->teardown =
  358. OSSL_get_provider_teardown(provider_dispatch);
  359. break;
  360. case OSSL_FUNC_PROVIDER_GET_PARAM_TYPES:
  361. prov->get_param_types =
  362. OSSL_get_provider_get_param_types(provider_dispatch);
  363. break;
  364. case OSSL_FUNC_PROVIDER_GET_PARAMS:
  365. prov->get_params =
  366. OSSL_get_provider_get_params(provider_dispatch);
  367. break;
  368. case OSSL_FUNC_PROVIDER_QUERY_OPERATION:
  369. prov->query_operation =
  370. OSSL_get_provider_query_operation(provider_dispatch);
  371. break;
  372. }
  373. }
  374. /* With this flag set, this provider has become fully "loaded". */
  375. prov->flag_initialized = 1;
  376. return 1;
  377. }
  378. int ossl_provider_activate(OSSL_PROVIDER *prov)
  379. {
  380. if (provider_activate(prov)) {
  381. CRYPTO_THREAD_write_lock(prov->store->lock);
  382. prov->store->use_fallbacks = 0;
  383. CRYPTO_THREAD_unlock(prov->store->lock);
  384. return 1;
  385. }
  386. return 0;
  387. }
  388. void *ossl_provider_ctx(const OSSL_PROVIDER *prov)
  389. {
  390. return prov->provctx;
  391. }
  392. static int provider_forall_loaded(struct provider_store_st *store,
  393. int *found_activated,
  394. int (*cb)(OSSL_PROVIDER *provider,
  395. void *cbdata),
  396. void *cbdata)
  397. {
  398. int i;
  399. int ret = 1;
  400. int num_provs = sk_OSSL_PROVIDER_num(store->providers);
  401. if (found_activated != NULL)
  402. *found_activated = 0;
  403. for (i = 0; i < num_provs; i++) {
  404. OSSL_PROVIDER *prov =
  405. sk_OSSL_PROVIDER_value(store->providers, i);
  406. if (prov->flag_initialized) {
  407. if (found_activated != NULL)
  408. *found_activated = 1;
  409. if (!(ret = cb(prov, cbdata)))
  410. break;
  411. }
  412. }
  413. return ret;
  414. }
  415. int ossl_provider_forall_loaded(OPENSSL_CTX *ctx,
  416. int (*cb)(OSSL_PROVIDER *provider,
  417. void *cbdata),
  418. void *cbdata)
  419. {
  420. int ret = 1;
  421. int i;
  422. struct provider_store_st *store = get_provider_store(ctx);
  423. if (store != NULL) {
  424. int found_activated = 0;
  425. CRYPTO_THREAD_read_lock(store->lock);
  426. ret = provider_forall_loaded(store, &found_activated, cb, cbdata);
  427. /*
  428. * If there's nothing activated ever in this store, try to activate
  429. * all fallbacks.
  430. */
  431. if (!found_activated && store->use_fallbacks) {
  432. int num_provs = sk_OSSL_PROVIDER_num(store->providers);
  433. int activated_fallback_count = 0;
  434. for (i = 0; i < num_provs; i++) {
  435. OSSL_PROVIDER *prov =
  436. sk_OSSL_PROVIDER_value(store->providers, i);
  437. /*
  438. * Note that we don't care if the activation succeeds or
  439. * not. If it doesn't succeed, then the next loop will
  440. * fail anyway.
  441. */
  442. if (prov->flag_fallback) {
  443. activated_fallback_count++;
  444. provider_activate(prov);
  445. }
  446. }
  447. if (activated_fallback_count > 0) {
  448. /*
  449. * We assume that all fallbacks have been added to the store
  450. * before any fallback is activated.
  451. * TODO: We may have to reconsider this, IF we find ourselves
  452. * adding fallbacks after any previous fallback has been
  453. * activated.
  454. */
  455. store->use_fallbacks = 0;
  456. /*
  457. * Now that we've activated available fallbacks, try a
  458. * second sweep
  459. */
  460. ret = provider_forall_loaded(store, NULL, cb, cbdata);
  461. }
  462. }
  463. CRYPTO_THREAD_unlock(store->lock);
  464. }
  465. return ret;
  466. }
  467. /* Setters of Provider Object data */
  468. int ossl_provider_set_fallback(OSSL_PROVIDER *prov)
  469. {
  470. if (prov == NULL)
  471. return 0;
  472. prov->flag_fallback = 1;
  473. return 1;
  474. }
  475. /* Getters of Provider Object data */
  476. const char *ossl_provider_name(const OSSL_PROVIDER *prov)
  477. {
  478. return prov->name;
  479. }
  480. const DSO *ossl_provider_dso(const OSSL_PROVIDER *prov)
  481. {
  482. return prov->module;
  483. }
  484. const char *ossl_provider_module_name(const OSSL_PROVIDER *prov)
  485. {
  486. #ifdef FIPS_MODE
  487. return NULL;
  488. #else
  489. return DSO_get_filename(prov->module);
  490. #endif
  491. }
  492. const char *ossl_provider_module_path(const OSSL_PROVIDER *prov)
  493. {
  494. #ifdef FIPS_MODE
  495. return NULL;
  496. #else
  497. /* FIXME: Ensure it's a full path */
  498. return DSO_get_filename(prov->module);
  499. #endif
  500. }
  501. /* Wrappers around calls to the provider */
  502. void ossl_provider_teardown(const OSSL_PROVIDER *prov)
  503. {
  504. if (prov->teardown != NULL)
  505. prov->teardown(prov->provctx);
  506. }
  507. const OSSL_ITEM *ossl_provider_get_param_types(const OSSL_PROVIDER *prov)
  508. {
  509. return prov->get_param_types == NULL
  510. ? NULL : prov->get_param_types(prov->provctx);
  511. }
  512. int ossl_provider_get_params(const OSSL_PROVIDER *prov,
  513. const OSSL_PARAM params[])
  514. {
  515. return prov->get_params == NULL
  516. ? 0 : prov->get_params(prov->provctx, params);
  517. }
  518. const OSSL_ALGORITHM *ossl_provider_query_operation(const OSSL_PROVIDER *prov,
  519. int operation_id,
  520. int *no_cache)
  521. {
  522. return prov->query_operation(prov->provctx, operation_id, no_cache);
  523. }
  524. /*-
  525. * Core functions for the provider
  526. * ===============================
  527. *
  528. * This is the set of functions that the core makes available to the provider
  529. */
  530. /*
  531. * This returns a list of Provider Object parameters with their types, for
  532. * discovery. We do not expect that many providers will use this, but one
  533. * never knows.
  534. */
  535. static const OSSL_ITEM param_types[] = {
  536. { OSSL_PARAM_UTF8_PTR, "openssl-version" },
  537. { OSSL_PARAM_UTF8_PTR, "provider-name" },
  538. { 0, NULL }
  539. };
  540. static const OSSL_ITEM *core_get_param_types(const OSSL_PROVIDER *prov)
  541. {
  542. return param_types;
  543. }
  544. static int core_get_params(const OSSL_PROVIDER *prov, const OSSL_PARAM params[])
  545. {
  546. int i;
  547. const OSSL_PARAM *p;
  548. if ((p = OSSL_PARAM_locate(params, "openssl-version")) != NULL)
  549. OSSL_PARAM_set_utf8_ptr(p, OPENSSL_VERSION_STR);
  550. if ((p = OSSL_PARAM_locate(params, "provider-name")) != NULL)
  551. OSSL_PARAM_set_utf8_ptr(p, prov->name);
  552. if (prov->parameters == NULL)
  553. return 1;
  554. for (i = 0; i < sk_INFOPAIR_num(prov->parameters); i++) {
  555. INFOPAIR *pair = sk_INFOPAIR_value(prov->parameters, i);
  556. if ((p = OSSL_PARAM_locate(params, pair->name)) != NULL)
  557. OSSL_PARAM_set_utf8_ptr(p, pair->value);
  558. }
  559. return 1;
  560. }
  561. static OSSL_core_get_library_context_fn core_get_libctx; /* Check */
  562. static OPENSSL_CTX *core_get_libctx(const OSSL_PROVIDER *prov)
  563. {
  564. return prov->libctx;
  565. }
  566. static const OSSL_DISPATCH core_dispatch_[] = {
  567. { OSSL_FUNC_CORE_GET_PARAM_TYPES, (void (*)(void))core_get_param_types },
  568. { OSSL_FUNC_CORE_GET_PARAMS, (void (*)(void))core_get_params },
  569. { OSSL_FUNC_CORE_GET_LIBRARY_CONTEXT, (void (*)(void))core_get_libctx },
  570. { OSSL_FUNC_CORE_PUT_ERROR, (void (*)(void))ERR_put_error },
  571. { OSSL_FUNC_CORE_ADD_ERROR_VDATA, (void (*)(void))ERR_add_error_vdata },
  572. { 0, NULL }
  573. };
  574. static const OSSL_DISPATCH *core_dispatch = core_dispatch_;