provider_core.c 20 KB

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