provider_core.c 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263
  1. /*
  2. * Copyright 2019-2021 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 <assert.h>
  10. #include <openssl/core.h>
  11. #include <openssl/core_dispatch.h>
  12. #include <openssl/core_names.h>
  13. #include <openssl/provider.h>
  14. #include <openssl/params.h>
  15. #include <openssl/opensslv.h>
  16. #include "crypto/cryptlib.h"
  17. #include "crypto/evp.h" /* evp_method_store_flush */
  18. #include "crypto/rand.h"
  19. #include "internal/nelem.h"
  20. #include "internal/thread_once.h"
  21. #include "internal/provider.h"
  22. #include "internal/refcount.h"
  23. #include "internal/bio.h"
  24. #include "provider_local.h"
  25. #ifndef FIPS_MODULE
  26. # include <openssl/self_test.h>
  27. #endif
  28. static OSSL_PROVIDER *provider_new(const char *name,
  29. OSSL_provider_init_fn *init_function);
  30. /*-
  31. * Provider Object structure
  32. * =========================
  33. */
  34. typedef struct {
  35. char *name;
  36. char *value;
  37. } INFOPAIR;
  38. DEFINE_STACK_OF(INFOPAIR)
  39. struct provider_store_st; /* Forward declaration */
  40. struct ossl_provider_st {
  41. /* Flag bits */
  42. unsigned int flag_initialized:1;
  43. unsigned int flag_activated:1;
  44. unsigned int flag_fallback:1; /* Can be used as fallback */
  45. unsigned int flag_activated_as_fallback:1;
  46. /* Getting and setting the flags require synchronization */
  47. CRYPTO_RWLOCK *flag_lock;
  48. /* OpenSSL library side data */
  49. CRYPTO_REF_COUNT refcnt;
  50. CRYPTO_RWLOCK *refcnt_lock; /* For the ref counter */
  51. CRYPTO_REF_COUNT activatecnt;
  52. CRYPTO_RWLOCK *activatecnt_lock; /* For the activate counter */
  53. char *name;
  54. char *path;
  55. DSO *module;
  56. OSSL_provider_init_fn *init_function;
  57. STACK_OF(INFOPAIR) *parameters;
  58. OSSL_LIB_CTX *libctx; /* The library context this instance is in */
  59. struct provider_store_st *store; /* The store this instance belongs to */
  60. #ifndef FIPS_MODULE
  61. /*
  62. * In the FIPS module inner provider, this isn't needed, since the
  63. * error upcalls are always direct calls to the outer provider.
  64. */
  65. int error_lib; /* ERR library number, one for each provider */
  66. # ifndef OPENSSL_NO_ERR
  67. ERR_STRING_DATA *error_strings; /* Copy of what the provider gives us */
  68. # endif
  69. #endif
  70. /* Provider side functions */
  71. OSSL_FUNC_provider_teardown_fn *teardown;
  72. OSSL_FUNC_provider_gettable_params_fn *gettable_params;
  73. OSSL_FUNC_provider_get_params_fn *get_params;
  74. OSSL_FUNC_provider_get_capabilities_fn *get_capabilities;
  75. OSSL_FUNC_provider_self_test_fn *self_test;
  76. OSSL_FUNC_provider_query_operation_fn *query_operation;
  77. OSSL_FUNC_provider_unquery_operation_fn *unquery_operation;
  78. /*
  79. * Cache of bit to indicate of query_operation() has been called on
  80. * a specific operation or not.
  81. */
  82. unsigned char *operation_bits;
  83. size_t operation_bits_sz;
  84. CRYPTO_RWLOCK *opbits_lock;
  85. /* Provider side data */
  86. void *provctx;
  87. };
  88. DEFINE_STACK_OF(OSSL_PROVIDER)
  89. static int ossl_provider_cmp(const OSSL_PROVIDER * const *a,
  90. const OSSL_PROVIDER * const *b)
  91. {
  92. return strcmp((*a)->name, (*b)->name);
  93. }
  94. /*-
  95. * Provider Object store
  96. * =====================
  97. *
  98. * The Provider Object store is a library context object, and therefore needs
  99. * an index.
  100. */
  101. struct provider_store_st {
  102. STACK_OF(OSSL_PROVIDER) *providers;
  103. CRYPTO_RWLOCK *default_path_lock;
  104. CRYPTO_RWLOCK *lock;
  105. char *default_path;
  106. unsigned int use_fallbacks:1;
  107. };
  108. /*
  109. * provider_deactivate_free() is a wrapper around ossl_provider_deactivate()
  110. * and ossl_provider_free(), called as needed.
  111. * Since this is only called when the provider store is being emptied, we
  112. * don't need to care about any lock.
  113. */
  114. static void provider_deactivate_free(OSSL_PROVIDER *prov)
  115. {
  116. if (prov->flag_activated)
  117. ossl_provider_deactivate(prov);
  118. ossl_provider_free(prov);
  119. }
  120. static void provider_store_free(void *vstore)
  121. {
  122. struct provider_store_st *store = vstore;
  123. if (store == NULL)
  124. return;
  125. OPENSSL_free(store->default_path);
  126. sk_OSSL_PROVIDER_pop_free(store->providers, provider_deactivate_free);
  127. CRYPTO_THREAD_lock_free(store->default_path_lock);
  128. CRYPTO_THREAD_lock_free(store->lock);
  129. OPENSSL_free(store);
  130. }
  131. static void *provider_store_new(OSSL_LIB_CTX *ctx)
  132. {
  133. struct provider_store_st *store = OPENSSL_zalloc(sizeof(*store));
  134. const struct predefined_providers_st *p = NULL;
  135. if (store == NULL
  136. || (store->providers = sk_OSSL_PROVIDER_new(ossl_provider_cmp)) == NULL
  137. || (store->default_path_lock = CRYPTO_THREAD_lock_new()) == NULL
  138. || (store->lock = CRYPTO_THREAD_lock_new()) == NULL) {
  139. provider_store_free(store);
  140. return NULL;
  141. }
  142. store->use_fallbacks = 1;
  143. for (p = ossl_predefined_providers; p->name != NULL; p++) {
  144. OSSL_PROVIDER *prov = NULL;
  145. /*
  146. * We use the internal constructor directly here,
  147. * otherwise we get a call loop
  148. */
  149. prov = provider_new(p->name, p->init);
  150. if (prov == NULL
  151. || sk_OSSL_PROVIDER_push(store->providers, prov) == 0) {
  152. ossl_provider_free(prov);
  153. provider_store_free(store);
  154. ERR_raise(ERR_LIB_CRYPTO, ERR_R_INTERNAL_ERROR);
  155. return NULL;
  156. }
  157. prov->libctx = ctx;
  158. prov->store = store;
  159. #ifndef FIPS_MODULE
  160. prov->error_lib = ERR_get_next_error_library();
  161. #endif
  162. if(p->is_fallback)
  163. ossl_provider_set_fallback(prov);
  164. }
  165. return store;
  166. }
  167. static const OSSL_LIB_CTX_METHOD provider_store_method = {
  168. provider_store_new,
  169. provider_store_free,
  170. };
  171. static struct provider_store_st *get_provider_store(OSSL_LIB_CTX *libctx)
  172. {
  173. struct provider_store_st *store = NULL;
  174. store = ossl_lib_ctx_get_data(libctx, OSSL_LIB_CTX_PROVIDER_STORE_INDEX,
  175. &provider_store_method);
  176. if (store == NULL)
  177. ERR_raise(ERR_LIB_CRYPTO, ERR_R_INTERNAL_ERROR);
  178. return store;
  179. }
  180. int ossl_provider_disable_fallback_loading(OSSL_LIB_CTX *libctx)
  181. {
  182. struct provider_store_st *store;
  183. if ((store = get_provider_store(libctx)) != NULL) {
  184. if (!CRYPTO_THREAD_write_lock(store->lock))
  185. return 0;
  186. store->use_fallbacks = 0;
  187. CRYPTO_THREAD_unlock(store->lock);
  188. return 1;
  189. }
  190. return 0;
  191. }
  192. OSSL_PROVIDER *ossl_provider_find(OSSL_LIB_CTX *libctx, const char *name,
  193. int noconfig)
  194. {
  195. struct provider_store_st *store = NULL;
  196. OSSL_PROVIDER *prov = NULL;
  197. if ((store = get_provider_store(libctx)) != NULL) {
  198. OSSL_PROVIDER tmpl = { 0, };
  199. int i;
  200. #ifndef FIPS_MODULE
  201. /*
  202. * Make sure any providers are loaded from config before we try to find
  203. * them.
  204. */
  205. if (!noconfig)
  206. OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CONFIG, NULL);
  207. #endif
  208. tmpl.name = (char *)name;
  209. if (!CRYPTO_THREAD_write_lock(store->lock))
  210. return NULL;
  211. if ((i = sk_OSSL_PROVIDER_find(store->providers, &tmpl)) == -1
  212. || (prov = sk_OSSL_PROVIDER_value(store->providers, i)) == NULL
  213. || !ossl_provider_up_ref(prov))
  214. prov = NULL;
  215. CRYPTO_THREAD_unlock(store->lock);
  216. }
  217. return prov;
  218. }
  219. /*-
  220. * Provider Object methods
  221. * =======================
  222. */
  223. static OSSL_PROVIDER *provider_new(const char *name,
  224. OSSL_provider_init_fn *init_function)
  225. {
  226. OSSL_PROVIDER *prov = NULL;
  227. if ((prov = OPENSSL_zalloc(sizeof(*prov))) == NULL
  228. #ifndef HAVE_ATOMICS
  229. || (prov->refcnt_lock = CRYPTO_THREAD_lock_new()) == NULL
  230. || (prov->activatecnt_lock = CRYPTO_THREAD_lock_new()) == NULL
  231. #endif
  232. || !ossl_provider_up_ref(prov) /* +1 One reference to be returned */
  233. || (prov->opbits_lock = CRYPTO_THREAD_lock_new()) == NULL
  234. || (prov->flag_lock = CRYPTO_THREAD_lock_new()) == NULL
  235. || (prov->name = OPENSSL_strdup(name)) == NULL) {
  236. ossl_provider_free(prov);
  237. ERR_raise(ERR_LIB_CRYPTO, ERR_R_MALLOC_FAILURE);
  238. return NULL;
  239. }
  240. prov->init_function = init_function;
  241. return prov;
  242. }
  243. int ossl_provider_up_ref(OSSL_PROVIDER *prov)
  244. {
  245. int ref = 0;
  246. if (CRYPTO_UP_REF(&prov->refcnt, &ref, prov->refcnt_lock) <= 0)
  247. return 0;
  248. return ref;
  249. }
  250. OSSL_PROVIDER *ossl_provider_new(OSSL_LIB_CTX *libctx, const char *name,
  251. OSSL_provider_init_fn *init_function,
  252. int noconfig)
  253. {
  254. struct provider_store_st *store = NULL;
  255. OSSL_PROVIDER *prov = NULL;
  256. if ((store = get_provider_store(libctx)) == NULL)
  257. return NULL;
  258. if ((prov = ossl_provider_find(libctx, name,
  259. noconfig)) != NULL) { /* refcount +1 */
  260. ossl_provider_free(prov); /* refcount -1 */
  261. ERR_raise_data(ERR_LIB_CRYPTO, CRYPTO_R_PROVIDER_ALREADY_EXISTS,
  262. "name=%s", name);
  263. return NULL;
  264. }
  265. /* provider_new() generates an error, so no need here */
  266. if ((prov = provider_new(name, init_function)) == NULL)
  267. return NULL;
  268. if (!CRYPTO_THREAD_write_lock(store->lock))
  269. return NULL;
  270. if (!ossl_provider_up_ref(prov)) { /* +1 One reference for the store */
  271. ossl_provider_free(prov); /* -1 Reference that was to be returned */
  272. prov = NULL;
  273. } else if (sk_OSSL_PROVIDER_push(store->providers, prov) == 0) {
  274. ossl_provider_free(prov); /* -1 Store reference */
  275. ossl_provider_free(prov); /* -1 Reference that was to be returned */
  276. prov = NULL;
  277. } else {
  278. prov->libctx = libctx;
  279. prov->store = store;
  280. #ifndef FIPS_MODULE
  281. prov->error_lib = ERR_get_next_error_library();
  282. #endif
  283. }
  284. CRYPTO_THREAD_unlock(store->lock);
  285. if (prov == NULL)
  286. ERR_raise(ERR_LIB_CRYPTO, ERR_R_MALLOC_FAILURE);
  287. /*
  288. * At this point, the provider is only partially "loaded". To be
  289. * fully "loaded", ossl_provider_activate() must also be called.
  290. */
  291. return prov;
  292. }
  293. static void free_infopair(INFOPAIR *pair)
  294. {
  295. OPENSSL_free(pair->name);
  296. OPENSSL_free(pair->value);
  297. OPENSSL_free(pair);
  298. }
  299. void ossl_provider_free(OSSL_PROVIDER *prov)
  300. {
  301. if (prov != NULL) {
  302. int ref = 0;
  303. CRYPTO_DOWN_REF(&prov->refcnt, &ref, prov->refcnt_lock);
  304. /*
  305. * When the refcount drops to zero, we clean up the provider.
  306. * Note that this also does teardown, which may seem late,
  307. * considering that init happens on first activation. However,
  308. * there may be other structures hanging on to the provider after
  309. * the last deactivation and may therefore need full access to the
  310. * provider's services. Therefore, we deinit late.
  311. */
  312. if (ref == 0) {
  313. if (prov->flag_initialized) {
  314. if (prov->teardown != NULL)
  315. prov->teardown(prov->provctx);
  316. #ifndef OPENSSL_NO_ERR
  317. # ifndef FIPS_MODULE
  318. if (prov->error_strings != NULL) {
  319. ERR_unload_strings(prov->error_lib, prov->error_strings);
  320. OPENSSL_free(prov->error_strings);
  321. prov->error_strings = NULL;
  322. }
  323. # endif
  324. #endif
  325. OPENSSL_free(prov->operation_bits);
  326. prov->operation_bits = NULL;
  327. prov->operation_bits_sz = 0;
  328. prov->flag_initialized = 0;
  329. }
  330. #ifndef FIPS_MODULE
  331. /*
  332. * We deregister thread handling whether or not the provider was
  333. * initialized. If init was attempted but was not successful then
  334. * the provider may still have registered a thread handler.
  335. */
  336. ossl_init_thread_deregister(prov);
  337. DSO_free(prov->module);
  338. #endif
  339. OPENSSL_free(prov->name);
  340. OPENSSL_free(prov->path);
  341. sk_INFOPAIR_pop_free(prov->parameters, free_infopair);
  342. CRYPTO_THREAD_lock_free(prov->opbits_lock);
  343. CRYPTO_THREAD_lock_free(prov->flag_lock);
  344. #ifndef HAVE_ATOMICS
  345. CRYPTO_THREAD_lock_free(prov->refcnt_lock);
  346. CRYPTO_THREAD_lock_free(prov->activatecnt_lock);
  347. #endif
  348. OPENSSL_free(prov);
  349. }
  350. }
  351. }
  352. /* Setters */
  353. int ossl_provider_set_module_path(OSSL_PROVIDER *prov, const char *module_path)
  354. {
  355. OPENSSL_free(prov->path);
  356. if (module_path == NULL)
  357. return 1;
  358. if ((prov->path = OPENSSL_strdup(module_path)) != NULL)
  359. return 1;
  360. ERR_raise(ERR_LIB_CRYPTO, ERR_R_MALLOC_FAILURE);
  361. return 0;
  362. }
  363. int ossl_provider_add_parameter(OSSL_PROVIDER *prov,
  364. const char *name, const char *value)
  365. {
  366. INFOPAIR *pair = NULL;
  367. if ((pair = OPENSSL_zalloc(sizeof(*pair))) != NULL
  368. && (prov->parameters != NULL
  369. || (prov->parameters = sk_INFOPAIR_new_null()) != NULL)
  370. && (pair->name = OPENSSL_strdup(name)) != NULL
  371. && (pair->value = OPENSSL_strdup(value)) != NULL
  372. && sk_INFOPAIR_push(prov->parameters, pair) > 0)
  373. return 1;
  374. if (pair != NULL) {
  375. OPENSSL_free(pair->name);
  376. OPENSSL_free(pair->value);
  377. OPENSSL_free(pair);
  378. }
  379. ERR_raise(ERR_LIB_CRYPTO, ERR_R_MALLOC_FAILURE);
  380. return 0;
  381. }
  382. /*
  383. * Provider activation.
  384. *
  385. * What "activation" means depends on the provider form; for built in
  386. * providers (in the library or the application alike), the provider
  387. * can already be considered to be loaded, all that's needed is to
  388. * initialize it. However, for dynamically loadable provider modules,
  389. * we must first load that module.
  390. *
  391. * Built in modules are distinguished from dynamically loaded modules
  392. * with an already assigned init function.
  393. */
  394. static const OSSL_DISPATCH *core_dispatch; /* Define further down */
  395. int OSSL_PROVIDER_set_default_search_path(OSSL_LIB_CTX *libctx,
  396. const char *path)
  397. {
  398. struct provider_store_st *store;
  399. char *p = NULL;
  400. if (path != NULL) {
  401. p = OPENSSL_strdup(path);
  402. if (p == NULL) {
  403. ERR_raise(ERR_LIB_CRYPTO, ERR_R_MALLOC_FAILURE);
  404. return 0;
  405. }
  406. }
  407. if ((store = get_provider_store(libctx)) != NULL
  408. && CRYPTO_THREAD_write_lock(store->default_path_lock)) {
  409. OPENSSL_free(store->default_path);
  410. store->default_path = p;
  411. CRYPTO_THREAD_unlock(store->default_path_lock);
  412. return 1;
  413. }
  414. OPENSSL_free(p);
  415. return 0;
  416. }
  417. /*
  418. * Internal version that doesn't affect the store flags, and thereby avoid
  419. * locking. Direct callers must remember to set the store flags when
  420. * appropriate.
  421. */
  422. static int provider_init(OSSL_PROVIDER *prov)
  423. {
  424. const OSSL_DISPATCH *provider_dispatch = NULL;
  425. void *tmp_provctx = NULL; /* safety measure */
  426. #ifndef OPENSSL_NO_ERR
  427. # ifndef FIPS_MODULE
  428. OSSL_FUNC_provider_get_reason_strings_fn *p_get_reason_strings = NULL;
  429. # endif
  430. #endif
  431. int ok = 0;
  432. /*
  433. * The flag lock is used to lock init, not only because the flag is
  434. * checked here and set at the end, but also because this function
  435. * modifies a number of things in the provider structure that this
  436. * function needs to perform under lock anyway.
  437. */
  438. if (!CRYPTO_THREAD_write_lock(prov->flag_lock))
  439. goto end;
  440. if (prov->flag_initialized) {
  441. ok = 1;
  442. goto end;
  443. }
  444. /*
  445. * If the init function isn't set, it indicates that this provider is
  446. * a loadable module.
  447. */
  448. if (prov->init_function == NULL) {
  449. #ifdef FIPS_MODULE
  450. goto end;
  451. #else
  452. if (prov->module == NULL) {
  453. char *allocated_path = NULL;
  454. const char *module_path = NULL;
  455. char *merged_path = NULL;
  456. const char *load_dir = NULL;
  457. char *allocated_load_dir = NULL;
  458. struct provider_store_st *store;
  459. if ((prov->module = DSO_new()) == NULL) {
  460. /* DSO_new() generates an error already */
  461. goto end;
  462. }
  463. if ((store = get_provider_store(prov->libctx)) == NULL
  464. || !CRYPTO_THREAD_read_lock(store->default_path_lock))
  465. goto end;
  466. if (store->default_path != NULL) {
  467. allocated_load_dir = OPENSSL_strdup(store->default_path);
  468. CRYPTO_THREAD_unlock(store->default_path_lock);
  469. if (allocated_load_dir == NULL) {
  470. ERR_raise(ERR_LIB_CRYPTO, ERR_R_MALLOC_FAILURE);
  471. goto end;
  472. }
  473. load_dir = allocated_load_dir;
  474. } else {
  475. CRYPTO_THREAD_unlock(store->default_path_lock);
  476. }
  477. if (load_dir == NULL) {
  478. load_dir = ossl_safe_getenv("OPENSSL_MODULES");
  479. if (load_dir == NULL)
  480. load_dir = MODULESDIR;
  481. }
  482. DSO_ctrl(prov->module, DSO_CTRL_SET_FLAGS,
  483. DSO_FLAG_NAME_TRANSLATION_EXT_ONLY, NULL);
  484. module_path = prov->path;
  485. if (module_path == NULL)
  486. module_path = allocated_path =
  487. DSO_convert_filename(prov->module, prov->name);
  488. if (module_path != NULL)
  489. merged_path = DSO_merge(prov->module, module_path, load_dir);
  490. if (merged_path == NULL
  491. || (DSO_load(prov->module, merged_path, NULL, 0)) == NULL) {
  492. DSO_free(prov->module);
  493. prov->module = NULL;
  494. }
  495. OPENSSL_free(merged_path);
  496. OPENSSL_free(allocated_path);
  497. OPENSSL_free(allocated_load_dir);
  498. }
  499. if (prov->module != NULL)
  500. prov->init_function = (OSSL_provider_init_fn *)
  501. DSO_bind_func(prov->module, "OSSL_provider_init");
  502. #endif
  503. }
  504. /* Call the initialise function for the provider. */
  505. if (prov->init_function == NULL
  506. || !prov->init_function((OSSL_CORE_HANDLE *)prov, core_dispatch,
  507. &provider_dispatch, &tmp_provctx)) {
  508. ERR_raise_data(ERR_LIB_CRYPTO, ERR_R_INIT_FAIL,
  509. "name=%s", prov->name);
  510. goto end;
  511. }
  512. prov->provctx = tmp_provctx;
  513. for (; provider_dispatch->function_id != 0; provider_dispatch++) {
  514. switch (provider_dispatch->function_id) {
  515. case OSSL_FUNC_PROVIDER_TEARDOWN:
  516. prov->teardown =
  517. OSSL_FUNC_provider_teardown(provider_dispatch);
  518. break;
  519. case OSSL_FUNC_PROVIDER_GETTABLE_PARAMS:
  520. prov->gettable_params =
  521. OSSL_FUNC_provider_gettable_params(provider_dispatch);
  522. break;
  523. case OSSL_FUNC_PROVIDER_GET_PARAMS:
  524. prov->get_params =
  525. OSSL_FUNC_provider_get_params(provider_dispatch);
  526. break;
  527. case OSSL_FUNC_PROVIDER_SELF_TEST:
  528. prov->self_test =
  529. OSSL_FUNC_provider_self_test(provider_dispatch);
  530. break;
  531. case OSSL_FUNC_PROVIDER_GET_CAPABILITIES:
  532. prov->get_capabilities =
  533. OSSL_FUNC_provider_get_capabilities(provider_dispatch);
  534. break;
  535. case OSSL_FUNC_PROVIDER_QUERY_OPERATION:
  536. prov->query_operation =
  537. OSSL_FUNC_provider_query_operation(provider_dispatch);
  538. break;
  539. case OSSL_FUNC_PROVIDER_UNQUERY_OPERATION:
  540. prov->unquery_operation =
  541. OSSL_FUNC_provider_unquery_operation(provider_dispatch);
  542. break;
  543. #ifndef OPENSSL_NO_ERR
  544. # ifndef FIPS_MODULE
  545. case OSSL_FUNC_PROVIDER_GET_REASON_STRINGS:
  546. p_get_reason_strings =
  547. OSSL_FUNC_provider_get_reason_strings(provider_dispatch);
  548. break;
  549. # endif
  550. #endif
  551. }
  552. }
  553. #ifndef OPENSSL_NO_ERR
  554. # ifndef FIPS_MODULE
  555. if (p_get_reason_strings != NULL) {
  556. const OSSL_ITEM *reasonstrings = p_get_reason_strings(prov->provctx);
  557. size_t cnt, cnt2;
  558. /*
  559. * ERR_load_strings() handles ERR_STRING_DATA rather than OSSL_ITEM,
  560. * although they are essentially the same type.
  561. * Furthermore, ERR_load_strings() patches the array's error number
  562. * with the error library number, so we need to make a copy of that
  563. * array either way.
  564. */
  565. cnt = 0;
  566. while (reasonstrings[cnt].id != 0) {
  567. if (ERR_GET_LIB(reasonstrings[cnt].id) != 0)
  568. goto end;
  569. cnt++;
  570. }
  571. cnt++; /* One for the terminating item */
  572. /* Allocate one extra item for the "library" name */
  573. prov->error_strings =
  574. OPENSSL_zalloc(sizeof(ERR_STRING_DATA) * (cnt + 1));
  575. if (prov->error_strings == NULL)
  576. goto end;
  577. /*
  578. * Set the "library" name.
  579. */
  580. prov->error_strings[0].error = ERR_PACK(prov->error_lib, 0, 0);
  581. prov->error_strings[0].string = prov->name;
  582. /*
  583. * Copy reasonstrings item 0..cnt-1 to prov->error_trings positions
  584. * 1..cnt.
  585. */
  586. for (cnt2 = 1; cnt2 <= cnt; cnt2++) {
  587. prov->error_strings[cnt2].error = (int)reasonstrings[cnt2-1].id;
  588. prov->error_strings[cnt2].string = reasonstrings[cnt2-1].ptr;
  589. }
  590. ERR_load_strings(prov->error_lib, prov->error_strings);
  591. }
  592. # endif
  593. #endif
  594. /* With this flag set, this provider has become fully "loaded". */
  595. prov->flag_initialized = 1;
  596. ok = 1;
  597. end:
  598. CRYPTO_THREAD_unlock(prov->flag_lock);
  599. return ok;
  600. }
  601. static int provider_deactivate(OSSL_PROVIDER *prov)
  602. {
  603. int ref = 0;
  604. if (!ossl_assert(prov != NULL))
  605. return 0;
  606. if (CRYPTO_DOWN_REF(&prov->activatecnt, &ref, prov->activatecnt_lock) <= 0)
  607. return 0;
  608. if (ref < 1) {
  609. if (!CRYPTO_THREAD_write_lock(prov->flag_lock))
  610. return 0;
  611. prov->flag_activated = 0;
  612. CRYPTO_THREAD_unlock(prov->flag_lock);
  613. }
  614. /* We don't deinit here, that's done in ossl_provider_free() */
  615. return 1;
  616. }
  617. static int provider_activate(OSSL_PROVIDER *prov)
  618. {
  619. int ref = 0;
  620. if (CRYPTO_UP_REF(&prov->activatecnt, &ref, prov->activatecnt_lock) <= 0)
  621. return 0;
  622. if (provider_init(prov)) {
  623. if (!CRYPTO_THREAD_write_lock(prov->flag_lock))
  624. return 0;
  625. prov->flag_activated = 1;
  626. CRYPTO_THREAD_unlock(prov->flag_lock);
  627. return 1;
  628. }
  629. provider_deactivate(prov);
  630. return 0;
  631. }
  632. int ossl_provider_activate(OSSL_PROVIDER *prov, int retain_fallbacks)
  633. {
  634. if (prov == NULL)
  635. return 0;
  636. if (provider_activate(prov)) {
  637. if (!retain_fallbacks) {
  638. if (!CRYPTO_THREAD_write_lock(prov->store->lock)) {
  639. provider_deactivate(prov);
  640. return 0;
  641. }
  642. prov->store->use_fallbacks = 0;
  643. CRYPTO_THREAD_unlock(prov->store->lock);
  644. }
  645. return 1;
  646. }
  647. return 0;
  648. }
  649. int ossl_provider_deactivate(OSSL_PROVIDER *prov)
  650. {
  651. if (prov == NULL)
  652. return 0;
  653. return provider_deactivate(prov);
  654. }
  655. void *ossl_provider_ctx(const OSSL_PROVIDER *prov)
  656. {
  657. return prov->provctx;
  658. }
  659. /*
  660. * This function only does something once when store->use_fallbacks == 1,
  661. * and then sets store->use_fallbacks = 0, so the second call and so on is
  662. * effectively a no-op.
  663. */
  664. static void provider_activate_fallbacks(struct provider_store_st *store)
  665. {
  666. int use_fallbacks;
  667. int num_provs;
  668. int activated_fallback_count = 0;
  669. int i;
  670. if (!CRYPTO_THREAD_read_lock(store->lock))
  671. return;
  672. use_fallbacks = store->use_fallbacks;
  673. CRYPTO_THREAD_unlock(store->lock);
  674. if (!use_fallbacks)
  675. return;
  676. if (!CRYPTO_THREAD_write_lock(store->lock))
  677. return;
  678. /* Check again, just in case another thread changed it */
  679. use_fallbacks = store->use_fallbacks;
  680. if (!use_fallbacks) {
  681. CRYPTO_THREAD_unlock(store->lock);
  682. return;
  683. }
  684. num_provs = sk_OSSL_PROVIDER_num(store->providers);
  685. for (i = 0; i < num_provs; i++) {
  686. OSSL_PROVIDER *prov = sk_OSSL_PROVIDER_value(store->providers, i);
  687. if (ossl_provider_up_ref(prov)) {
  688. if (prov->flag_fallback) {
  689. if (provider_activate(prov)) {
  690. prov->flag_activated_as_fallback = 1;
  691. activated_fallback_count++;
  692. }
  693. }
  694. ossl_provider_free(prov);
  695. }
  696. }
  697. /*
  698. * We assume that all fallbacks have been added to the store before
  699. * any fallback is activated.
  700. * TODO: We may have to reconsider this, IF we find ourselves adding
  701. * fallbacks after any previous fallback has been activated.
  702. */
  703. if (activated_fallback_count > 0)
  704. store->use_fallbacks = 0;
  705. CRYPTO_THREAD_unlock(store->lock);
  706. }
  707. int ossl_provider_doall_activated(OSSL_LIB_CTX *ctx,
  708. int (*cb)(OSSL_PROVIDER *provider,
  709. void *cbdata),
  710. void *cbdata)
  711. {
  712. int ret = 0, i, j;
  713. struct provider_store_st *store = get_provider_store(ctx);
  714. STACK_OF(OSSL_PROVIDER) *provs = NULL;
  715. #ifndef FIPS_MODULE
  716. /*
  717. * Make sure any providers are loaded from config before we try to use
  718. * them.
  719. */
  720. OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CONFIG, NULL);
  721. #endif
  722. if (store == NULL)
  723. return 1;
  724. provider_activate_fallbacks(store);
  725. /*
  726. * Under lock, grab a copy of the provider list and up_ref each
  727. * provider so that they don't disappear underneath us.
  728. */
  729. if (!CRYPTO_THREAD_read_lock(store->lock))
  730. return 0;
  731. provs = sk_OSSL_PROVIDER_dup(store->providers);
  732. if (provs == NULL) {
  733. CRYPTO_THREAD_unlock(store->lock);
  734. return 0;
  735. }
  736. j = sk_OSSL_PROVIDER_num(provs);
  737. for (i = 0; i < j; i++)
  738. if (!ossl_provider_up_ref(sk_OSSL_PROVIDER_value(provs, i)))
  739. goto err_unlock;
  740. CRYPTO_THREAD_unlock(store->lock);
  741. /*
  742. * Now, we sweep through all providers not under lock
  743. */
  744. for (j = 0; j < i; j++) {
  745. OSSL_PROVIDER *prov = sk_OSSL_PROVIDER_value(provs, j);
  746. if (prov->flag_activated && !cb(prov, cbdata))
  747. goto finish;
  748. }
  749. ret = 1;
  750. goto finish;
  751. err_unlock:
  752. CRYPTO_THREAD_unlock(store->lock);
  753. finish:
  754. /* The pop_free call doesn't do what we want on an error condition */
  755. for (j = 0; j < i; j++)
  756. ossl_provider_free(sk_OSSL_PROVIDER_value(provs, j));
  757. sk_OSSL_PROVIDER_free(provs);
  758. return ret;
  759. }
  760. int ossl_provider_available(OSSL_PROVIDER *prov)
  761. {
  762. if (prov != NULL) {
  763. provider_activate_fallbacks(prov->store);
  764. return prov->flag_activated;
  765. }
  766. return 0;
  767. }
  768. /* Setters of Provider Object data */
  769. int ossl_provider_set_fallback(OSSL_PROVIDER *prov)
  770. {
  771. if (prov == NULL)
  772. return 0;
  773. prov->flag_fallback = 1;
  774. return 1;
  775. }
  776. /* Getters of Provider Object data */
  777. const char *ossl_provider_name(const OSSL_PROVIDER *prov)
  778. {
  779. return prov->name;
  780. }
  781. const DSO *ossl_provider_dso(const OSSL_PROVIDER *prov)
  782. {
  783. return prov->module;
  784. }
  785. const char *ossl_provider_module_name(const OSSL_PROVIDER *prov)
  786. {
  787. #ifdef FIPS_MODULE
  788. return NULL;
  789. #else
  790. return DSO_get_filename(prov->module);
  791. #endif
  792. }
  793. const char *ossl_provider_module_path(const OSSL_PROVIDER *prov)
  794. {
  795. #ifdef FIPS_MODULE
  796. return NULL;
  797. #else
  798. /* FIXME: Ensure it's a full path */
  799. return DSO_get_filename(prov->module);
  800. #endif
  801. }
  802. void *ossl_provider_prov_ctx(const OSSL_PROVIDER *prov)
  803. {
  804. if (prov != NULL)
  805. return prov->provctx;
  806. return NULL;
  807. }
  808. OSSL_LIB_CTX *ossl_provider_libctx(const OSSL_PROVIDER *prov)
  809. {
  810. return prov != NULL ? prov->libctx : NULL;
  811. }
  812. /* Wrappers around calls to the provider */
  813. void ossl_provider_teardown(const OSSL_PROVIDER *prov)
  814. {
  815. if (prov->teardown != NULL)
  816. prov->teardown(prov->provctx);
  817. }
  818. const OSSL_PARAM *ossl_provider_gettable_params(const OSSL_PROVIDER *prov)
  819. {
  820. return prov->gettable_params == NULL
  821. ? NULL : prov->gettable_params(prov->provctx);
  822. }
  823. int ossl_provider_get_params(const OSSL_PROVIDER *prov, OSSL_PARAM params[])
  824. {
  825. return prov->get_params == NULL
  826. ? 0 : prov->get_params(prov->provctx, params);
  827. }
  828. int ossl_provider_self_test(const OSSL_PROVIDER *prov)
  829. {
  830. int ret;
  831. if (prov->self_test == NULL)
  832. return 1;
  833. ret = prov->self_test(prov->provctx);
  834. if (ret == 0)
  835. (void)evp_method_store_flush(ossl_provider_libctx(prov));
  836. return ret;
  837. }
  838. int ossl_provider_get_capabilities(const OSSL_PROVIDER *prov,
  839. const char *capability,
  840. OSSL_CALLBACK *cb,
  841. void *arg)
  842. {
  843. return prov->get_capabilities == NULL
  844. ? 1 : prov->get_capabilities(prov->provctx, capability, cb, arg);
  845. }
  846. const OSSL_ALGORITHM *ossl_provider_query_operation(const OSSL_PROVIDER *prov,
  847. int operation_id,
  848. int *no_cache)
  849. {
  850. const OSSL_ALGORITHM *res;
  851. if (prov->query_operation == NULL)
  852. return NULL;
  853. res = prov->query_operation(prov->provctx, operation_id, no_cache);
  854. #if defined(OPENSSL_NO_CACHED_FETCH)
  855. /* Forcing the non-caching of queries */
  856. if (no_cache != NULL)
  857. *no_cache = 1;
  858. #endif
  859. return res;
  860. }
  861. void ossl_provider_unquery_operation(const OSSL_PROVIDER *prov,
  862. int operation_id,
  863. const OSSL_ALGORITHM *algs)
  864. {
  865. if (prov->unquery_operation != NULL)
  866. prov->unquery_operation(prov->provctx, operation_id, algs);
  867. }
  868. int ossl_provider_set_operation_bit(OSSL_PROVIDER *provider, size_t bitnum)
  869. {
  870. size_t byte = bitnum / 8;
  871. unsigned char bit = (1 << (bitnum % 8)) & 0xFF;
  872. if (!CRYPTO_THREAD_write_lock(provider->opbits_lock))
  873. return 0;
  874. if (provider->operation_bits_sz <= byte) {
  875. unsigned char *tmp = OPENSSL_realloc(provider->operation_bits,
  876. byte + 1);
  877. if (tmp == NULL) {
  878. CRYPTO_THREAD_unlock(provider->opbits_lock);
  879. ERR_raise(ERR_LIB_CRYPTO, ERR_R_MALLOC_FAILURE);
  880. return 0;
  881. }
  882. provider->operation_bits = tmp;
  883. memset(provider->operation_bits + provider->operation_bits_sz,
  884. '\0', byte + 1 - provider->operation_bits_sz);
  885. provider->operation_bits_sz = byte + 1;
  886. }
  887. provider->operation_bits[byte] |= bit;
  888. CRYPTO_THREAD_unlock(provider->opbits_lock);
  889. return 1;
  890. }
  891. int ossl_provider_test_operation_bit(OSSL_PROVIDER *provider, size_t bitnum,
  892. int *result)
  893. {
  894. size_t byte = bitnum / 8;
  895. unsigned char bit = (1 << (bitnum % 8)) & 0xFF;
  896. if (!ossl_assert(result != NULL)) {
  897. ERR_raise(ERR_LIB_CRYPTO, ERR_R_PASSED_NULL_PARAMETER);
  898. return 0;
  899. }
  900. *result = 0;
  901. if (!CRYPTO_THREAD_read_lock(provider->opbits_lock))
  902. return 0;
  903. if (provider->operation_bits_sz > byte)
  904. *result = ((provider->operation_bits[byte] & bit) != 0);
  905. CRYPTO_THREAD_unlock(provider->opbits_lock);
  906. return 1;
  907. }
  908. /*-
  909. * Core functions for the provider
  910. * ===============================
  911. *
  912. * This is the set of functions that the core makes available to the provider
  913. */
  914. /*
  915. * This returns a list of Provider Object parameters with their types, for
  916. * discovery. We do not expect that many providers will use this, but one
  917. * never knows.
  918. */
  919. static const OSSL_PARAM param_types[] = {
  920. OSSL_PARAM_DEFN(OSSL_PROV_PARAM_CORE_VERSION, OSSL_PARAM_UTF8_PTR, NULL, 0),
  921. OSSL_PARAM_DEFN(OSSL_PROV_PARAM_CORE_PROV_NAME, OSSL_PARAM_UTF8_PTR,
  922. NULL, 0),
  923. #ifndef FIPS_MODULE
  924. OSSL_PARAM_DEFN(OSSL_PROV_PARAM_CORE_MODULE_FILENAME, OSSL_PARAM_UTF8_PTR,
  925. NULL, 0),
  926. #endif
  927. OSSL_PARAM_END
  928. };
  929. /*
  930. * Forward declare all the functions that are provided aa dispatch.
  931. * This ensures that the compiler will complain if they aren't defined
  932. * with the correct signature.
  933. */
  934. static OSSL_FUNC_core_gettable_params_fn core_gettable_params;
  935. static OSSL_FUNC_core_get_params_fn core_get_params;
  936. static OSSL_FUNC_core_thread_start_fn core_thread_start;
  937. static OSSL_FUNC_core_get_libctx_fn core_get_libctx;
  938. #ifndef FIPS_MODULE
  939. static OSSL_FUNC_core_new_error_fn core_new_error;
  940. static OSSL_FUNC_core_set_error_debug_fn core_set_error_debug;
  941. static OSSL_FUNC_core_vset_error_fn core_vset_error;
  942. static OSSL_FUNC_core_set_error_mark_fn core_set_error_mark;
  943. static OSSL_FUNC_core_clear_last_error_mark_fn core_clear_last_error_mark;
  944. static OSSL_FUNC_core_pop_error_to_mark_fn core_pop_error_to_mark;
  945. #endif
  946. static const OSSL_PARAM *core_gettable_params(const OSSL_CORE_HANDLE *handle)
  947. {
  948. return param_types;
  949. }
  950. static int core_get_params(const OSSL_CORE_HANDLE *handle, OSSL_PARAM params[])
  951. {
  952. int i;
  953. OSSL_PARAM *p;
  954. /*
  955. * We created this object originally and we know it is actually an
  956. * OSSL_PROVIDER *, so the cast is safe
  957. */
  958. OSSL_PROVIDER *prov = (OSSL_PROVIDER *)handle;
  959. if ((p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_CORE_VERSION)) != NULL)
  960. OSSL_PARAM_set_utf8_ptr(p, OPENSSL_VERSION_STR);
  961. if ((p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_CORE_PROV_NAME)) != NULL)
  962. OSSL_PARAM_set_utf8_ptr(p, prov->name);
  963. #ifndef FIPS_MODULE
  964. if ((p = OSSL_PARAM_locate(params,
  965. OSSL_PROV_PARAM_CORE_MODULE_FILENAME)) != NULL)
  966. OSSL_PARAM_set_utf8_ptr(p, ossl_provider_module_path(prov));
  967. #endif
  968. if (prov->parameters == NULL)
  969. return 1;
  970. for (i = 0; i < sk_INFOPAIR_num(prov->parameters); i++) {
  971. INFOPAIR *pair = sk_INFOPAIR_value(prov->parameters, i);
  972. if ((p = OSSL_PARAM_locate(params, pair->name)) != NULL)
  973. OSSL_PARAM_set_utf8_ptr(p, pair->value);
  974. }
  975. return 1;
  976. }
  977. static OPENSSL_CORE_CTX *core_get_libctx(const OSSL_CORE_HANDLE *handle)
  978. {
  979. /*
  980. * We created this object originally and we know it is actually an
  981. * OSSL_PROVIDER *, so the cast is safe
  982. */
  983. OSSL_PROVIDER *prov = (OSSL_PROVIDER *)handle;
  984. /*
  985. * Using ossl_provider_libctx would be wrong as that returns
  986. * NULL for |prov| == NULL and NULL libctx has a special meaning
  987. * that does not apply here. Here |prov| == NULL can happen only in
  988. * case of a coding error.
  989. */
  990. assert(prov != NULL);
  991. return (OPENSSL_CORE_CTX *)prov->libctx;
  992. }
  993. static int core_thread_start(const OSSL_CORE_HANDLE *handle,
  994. OSSL_thread_stop_handler_fn handfn)
  995. {
  996. /*
  997. * We created this object originally and we know it is actually an
  998. * OSSL_PROVIDER *, so the cast is safe
  999. */
  1000. OSSL_PROVIDER *prov = (OSSL_PROVIDER *)handle;
  1001. return ossl_init_thread_start(prov, prov->provctx, handfn);
  1002. }
  1003. /*
  1004. * The FIPS module inner provider doesn't implement these. They aren't
  1005. * needed there, since the FIPS module upcalls are always the outer provider
  1006. * ones.
  1007. */
  1008. #ifndef FIPS_MODULE
  1009. /*
  1010. * These error functions should use |handle| to select the proper
  1011. * library context to report in the correct error stack if error
  1012. * stacks become tied to the library context.
  1013. * We cannot currently do that since there's no support for it in the
  1014. * ERR subsystem.
  1015. */
  1016. static void core_new_error(const OSSL_CORE_HANDLE *handle)
  1017. {
  1018. ERR_new();
  1019. }
  1020. static void core_set_error_debug(const OSSL_CORE_HANDLE *handle,
  1021. const char *file, int line, const char *func)
  1022. {
  1023. ERR_set_debug(file, line, func);
  1024. }
  1025. static void core_vset_error(const OSSL_CORE_HANDLE *handle,
  1026. uint32_t reason, const char *fmt, va_list args)
  1027. {
  1028. /*
  1029. * We created this object originally and we know it is actually an
  1030. * OSSL_PROVIDER *, so the cast is safe
  1031. */
  1032. OSSL_PROVIDER *prov = (OSSL_PROVIDER *)handle;
  1033. /*
  1034. * If the uppermost 8 bits are non-zero, it's an OpenSSL library
  1035. * error and will be treated as such. Otherwise, it's a new style
  1036. * provider error and will be treated as such.
  1037. */
  1038. if (ERR_GET_LIB(reason) != 0) {
  1039. ERR_vset_error(ERR_GET_LIB(reason), ERR_GET_REASON(reason), fmt, args);
  1040. } else {
  1041. ERR_vset_error(prov->error_lib, (int)reason, fmt, args);
  1042. }
  1043. }
  1044. static int core_set_error_mark(const OSSL_CORE_HANDLE *handle)
  1045. {
  1046. return ERR_set_mark();
  1047. }
  1048. static int core_clear_last_error_mark(const OSSL_CORE_HANDLE *handle)
  1049. {
  1050. return ERR_clear_last_mark();
  1051. }
  1052. static int core_pop_error_to_mark(const OSSL_CORE_HANDLE *handle)
  1053. {
  1054. return ERR_pop_to_mark();
  1055. }
  1056. #endif /* FIPS_MODULE */
  1057. /*
  1058. * Functions provided by the core.
  1059. */
  1060. static const OSSL_DISPATCH core_dispatch_[] = {
  1061. { OSSL_FUNC_CORE_GETTABLE_PARAMS, (void (*)(void))core_gettable_params },
  1062. { OSSL_FUNC_CORE_GET_PARAMS, (void (*)(void))core_get_params },
  1063. { OSSL_FUNC_CORE_GET_LIBCTX, (void (*)(void))core_get_libctx },
  1064. { OSSL_FUNC_CORE_THREAD_START, (void (*)(void))core_thread_start },
  1065. #ifndef FIPS_MODULE
  1066. { OSSL_FUNC_CORE_NEW_ERROR, (void (*)(void))core_new_error },
  1067. { OSSL_FUNC_CORE_SET_ERROR_DEBUG, (void (*)(void))core_set_error_debug },
  1068. { OSSL_FUNC_CORE_VSET_ERROR, (void (*)(void))core_vset_error },
  1069. { OSSL_FUNC_CORE_SET_ERROR_MARK, (void (*)(void))core_set_error_mark },
  1070. { OSSL_FUNC_CORE_CLEAR_LAST_ERROR_MARK,
  1071. (void (*)(void))core_clear_last_error_mark },
  1072. { OSSL_FUNC_CORE_POP_ERROR_TO_MARK, (void (*)(void))core_pop_error_to_mark },
  1073. { OSSL_FUNC_BIO_NEW_FILE, (void (*)(void))ossl_core_bio_new_file },
  1074. { OSSL_FUNC_BIO_NEW_MEMBUF, (void (*)(void))ossl_core_bio_new_mem_buf },
  1075. { OSSL_FUNC_BIO_READ_EX, (void (*)(void))ossl_core_bio_read_ex },
  1076. { OSSL_FUNC_BIO_WRITE_EX, (void (*)(void))ossl_core_bio_write_ex },
  1077. { OSSL_FUNC_BIO_GETS, (void (*)(void))ossl_core_bio_gets },
  1078. { OSSL_FUNC_BIO_PUTS, (void (*)(void))ossl_core_bio_puts },
  1079. { OSSL_FUNC_BIO_CTRL, (void (*)(void))ossl_core_bio_ctrl },
  1080. { OSSL_FUNC_BIO_UP_REF, (void (*)(void))ossl_core_bio_up_ref },
  1081. { OSSL_FUNC_BIO_FREE, (void (*)(void))ossl_core_bio_free },
  1082. { OSSL_FUNC_BIO_VPRINTF, (void (*)(void))ossl_core_bio_vprintf },
  1083. { OSSL_FUNC_BIO_VSNPRINTF, (void (*)(void))BIO_vsnprintf },
  1084. { OSSL_FUNC_SELF_TEST_CB, (void (*)(void))OSSL_SELF_TEST_get_callback },
  1085. { OSSL_FUNC_GET_ENTROPY, (void (*)(void))ossl_rand_get_entropy },
  1086. { OSSL_FUNC_CLEANUP_ENTROPY, (void (*)(void))ossl_rand_cleanup_entropy },
  1087. { OSSL_FUNC_GET_NONCE, (void (*)(void))ossl_rand_get_nonce },
  1088. { OSSL_FUNC_CLEANUP_NONCE, (void (*)(void))ossl_rand_cleanup_nonce },
  1089. #endif
  1090. { OSSL_FUNC_CRYPTO_MALLOC, (void (*)(void))CRYPTO_malloc },
  1091. { OSSL_FUNC_CRYPTO_ZALLOC, (void (*)(void))CRYPTO_zalloc },
  1092. { OSSL_FUNC_CRYPTO_FREE, (void (*)(void))CRYPTO_free },
  1093. { OSSL_FUNC_CRYPTO_CLEAR_FREE, (void (*)(void))CRYPTO_clear_free },
  1094. { OSSL_FUNC_CRYPTO_REALLOC, (void (*)(void))CRYPTO_realloc },
  1095. { OSSL_FUNC_CRYPTO_CLEAR_REALLOC, (void (*)(void))CRYPTO_clear_realloc },
  1096. { OSSL_FUNC_CRYPTO_SECURE_MALLOC, (void (*)(void))CRYPTO_secure_malloc },
  1097. { OSSL_FUNC_CRYPTO_SECURE_ZALLOC, (void (*)(void))CRYPTO_secure_zalloc },
  1098. { OSSL_FUNC_CRYPTO_SECURE_FREE, (void (*)(void))CRYPTO_secure_free },
  1099. { OSSL_FUNC_CRYPTO_SECURE_CLEAR_FREE,
  1100. (void (*)(void))CRYPTO_secure_clear_free },
  1101. { OSSL_FUNC_CRYPTO_SECURE_ALLOCATED,
  1102. (void (*)(void))CRYPTO_secure_allocated },
  1103. { OSSL_FUNC_OPENSSL_CLEANSE, (void (*)(void))OPENSSL_cleanse },
  1104. { 0, NULL }
  1105. };
  1106. static const OSSL_DISPATCH *core_dispatch = core_dispatch_;