provider_core.c 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780
  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 "internal/core.h"
  25. #include "provider_local.h"
  26. #ifndef FIPS_MODULE
  27. # include <openssl/self_test.h>
  28. #endif
  29. static OSSL_PROVIDER *provider_new(const char *name,
  30. OSSL_provider_init_fn *init_function);
  31. /*-
  32. * Provider Object structure
  33. * =========================
  34. */
  35. typedef struct {
  36. char *name;
  37. char *value;
  38. } INFOPAIR;
  39. DEFINE_STACK_OF(INFOPAIR)
  40. #ifndef FIPS_MODULE
  41. typedef struct {
  42. OSSL_PROVIDER *prov;
  43. int (*create_cb)(const OSSL_CORE_HANDLE *provider, void *cbdata);
  44. int (*remove_cb)(const OSSL_CORE_HANDLE *provider, void *cbdata);
  45. int (*global_props_cb)(const char *props, void *cbdata);
  46. void *cbdata;
  47. } OSSL_PROVIDER_CHILD_CB;
  48. DEFINE_STACK_OF(OSSL_PROVIDER_CHILD_CB)
  49. #endif
  50. struct provider_store_st; /* Forward declaration */
  51. struct ossl_provider_st {
  52. /* Flag bits */
  53. unsigned int flag_initialized:1;
  54. unsigned int flag_activated:1;
  55. unsigned int flag_fallback:1; /* Can be used as fallback */
  56. #ifndef FIPS_MODULE
  57. unsigned int flag_couldbechild:1;
  58. #endif
  59. /* Getting and setting the flags require synchronization */
  60. CRYPTO_RWLOCK *flag_lock;
  61. /* OpenSSL library side data */
  62. CRYPTO_REF_COUNT refcnt;
  63. CRYPTO_RWLOCK *refcnt_lock; /* For the ref counter */
  64. int activatecnt;
  65. char *name;
  66. char *path;
  67. DSO *module;
  68. OSSL_provider_init_fn *init_function;
  69. STACK_OF(INFOPAIR) *parameters;
  70. OSSL_LIB_CTX *libctx; /* The library context this instance is in */
  71. struct provider_store_st *store; /* The store this instance belongs to */
  72. #ifndef FIPS_MODULE
  73. /*
  74. * In the FIPS module inner provider, this isn't needed, since the
  75. * error upcalls are always direct calls to the outer provider.
  76. */
  77. int error_lib; /* ERR library number, one for each provider */
  78. # ifndef OPENSSL_NO_ERR
  79. ERR_STRING_DATA *error_strings; /* Copy of what the provider gives us */
  80. # endif
  81. #endif
  82. /* Provider side functions */
  83. OSSL_FUNC_provider_teardown_fn *teardown;
  84. OSSL_FUNC_provider_gettable_params_fn *gettable_params;
  85. OSSL_FUNC_provider_get_params_fn *get_params;
  86. OSSL_FUNC_provider_get_capabilities_fn *get_capabilities;
  87. OSSL_FUNC_provider_self_test_fn *self_test;
  88. OSSL_FUNC_provider_query_operation_fn *query_operation;
  89. OSSL_FUNC_provider_unquery_operation_fn *unquery_operation;
  90. /*
  91. * Cache of bit to indicate of query_operation() has been called on
  92. * a specific operation or not.
  93. */
  94. unsigned char *operation_bits;
  95. size_t operation_bits_sz;
  96. CRYPTO_RWLOCK *opbits_lock;
  97. #ifndef FIPS_MODULE
  98. /* Whether this provider is the child of some other provider */
  99. const OSSL_CORE_HANDLE *handle;
  100. unsigned int ischild:1;
  101. #endif
  102. /* Provider side data */
  103. void *provctx;
  104. const OSSL_DISPATCH *dispatch;
  105. };
  106. DEFINE_STACK_OF(OSSL_PROVIDER)
  107. static int ossl_provider_cmp(const OSSL_PROVIDER * const *a,
  108. const OSSL_PROVIDER * const *b)
  109. {
  110. return strcmp((*a)->name, (*b)->name);
  111. }
  112. /*-
  113. * Provider Object store
  114. * =====================
  115. *
  116. * The Provider Object store is a library context object, and therefore needs
  117. * an index.
  118. */
  119. struct provider_store_st {
  120. OSSL_LIB_CTX *libctx;
  121. STACK_OF(OSSL_PROVIDER) *providers;
  122. STACK_OF(OSSL_PROVIDER_CHILD_CB) *child_cbs;
  123. CRYPTO_RWLOCK *default_path_lock;
  124. CRYPTO_RWLOCK *lock;
  125. char *default_path;
  126. unsigned int use_fallbacks:1;
  127. unsigned int freeing:1;
  128. };
  129. /*
  130. * provider_deactivate_free() is a wrapper around ossl_provider_deactivate()
  131. * and ossl_provider_free(), called as needed.
  132. * Since this is only called when the provider store is being emptied, we
  133. * don't need to care about any lock.
  134. */
  135. static void provider_deactivate_free(OSSL_PROVIDER *prov)
  136. {
  137. if (prov->flag_activated)
  138. ossl_provider_deactivate(prov);
  139. ossl_provider_free(prov);
  140. }
  141. #ifndef FIPS_MODULE
  142. static void ossl_provider_child_cb_free(OSSL_PROVIDER_CHILD_CB *cb)
  143. {
  144. OPENSSL_free(cb);
  145. }
  146. #endif
  147. static void provider_store_free(void *vstore)
  148. {
  149. struct provider_store_st *store = vstore;
  150. if (store == NULL)
  151. return;
  152. store->freeing = 1;
  153. OPENSSL_free(store->default_path);
  154. sk_OSSL_PROVIDER_pop_free(store->providers, provider_deactivate_free);
  155. #ifndef FIPS_MODULE
  156. sk_OSSL_PROVIDER_CHILD_CB_pop_free(store->child_cbs,
  157. ossl_provider_child_cb_free);
  158. #endif
  159. CRYPTO_THREAD_lock_free(store->default_path_lock);
  160. CRYPTO_THREAD_lock_free(store->lock);
  161. OPENSSL_free(store);
  162. }
  163. static void *provider_store_new(OSSL_LIB_CTX *ctx)
  164. {
  165. struct provider_store_st *store = OPENSSL_zalloc(sizeof(*store));
  166. const struct predefined_providers_st *p = NULL;
  167. if (store == NULL
  168. || (store->providers = sk_OSSL_PROVIDER_new(ossl_provider_cmp)) == NULL
  169. || (store->default_path_lock = CRYPTO_THREAD_lock_new()) == NULL
  170. #ifndef FIPS_MODULE
  171. || (store->child_cbs = sk_OSSL_PROVIDER_CHILD_CB_new_null()) == NULL
  172. #endif
  173. || (store->lock = CRYPTO_THREAD_lock_new()) == NULL) {
  174. provider_store_free(store);
  175. return NULL;
  176. }
  177. store->libctx = ctx;
  178. store->use_fallbacks = 1;
  179. for (p = ossl_predefined_providers; p->name != NULL; p++) {
  180. OSSL_PROVIDER *prov = NULL;
  181. /*
  182. * We use the internal constructor directly here,
  183. * otherwise we get a call loop
  184. */
  185. prov = provider_new(p->name, p->init);
  186. if (prov == NULL
  187. || sk_OSSL_PROVIDER_push(store->providers, prov) == 0) {
  188. ossl_provider_free(prov);
  189. provider_store_free(store);
  190. ERR_raise(ERR_LIB_CRYPTO, ERR_R_INTERNAL_ERROR);
  191. return NULL;
  192. }
  193. prov->libctx = ctx;
  194. prov->store = store;
  195. #ifndef FIPS_MODULE
  196. prov->error_lib = ERR_get_next_error_library();
  197. #endif
  198. if(p->is_fallback)
  199. ossl_provider_set_fallback(prov);
  200. }
  201. return store;
  202. }
  203. static const OSSL_LIB_CTX_METHOD provider_store_method = {
  204. /* Needs to be freed before the child provider data is freed */
  205. OSSL_LIB_CTX_METHOD_PRIORITY_1,
  206. provider_store_new,
  207. provider_store_free,
  208. };
  209. static struct provider_store_st *get_provider_store(OSSL_LIB_CTX *libctx)
  210. {
  211. struct provider_store_st *store = NULL;
  212. store = ossl_lib_ctx_get_data(libctx, OSSL_LIB_CTX_PROVIDER_STORE_INDEX,
  213. &provider_store_method);
  214. if (store == NULL)
  215. ERR_raise(ERR_LIB_CRYPTO, ERR_R_INTERNAL_ERROR);
  216. return store;
  217. }
  218. int ossl_provider_disable_fallback_loading(OSSL_LIB_CTX *libctx)
  219. {
  220. struct provider_store_st *store;
  221. if ((store = get_provider_store(libctx)) != NULL) {
  222. if (!CRYPTO_THREAD_write_lock(store->lock))
  223. return 0;
  224. store->use_fallbacks = 0;
  225. CRYPTO_THREAD_unlock(store->lock);
  226. return 1;
  227. }
  228. return 0;
  229. }
  230. OSSL_PROVIDER *ossl_provider_find(OSSL_LIB_CTX *libctx, const char *name,
  231. int noconfig)
  232. {
  233. struct provider_store_st *store = NULL;
  234. OSSL_PROVIDER *prov = NULL;
  235. if ((store = get_provider_store(libctx)) != NULL) {
  236. OSSL_PROVIDER tmpl = { 0, };
  237. int i;
  238. #ifndef FIPS_MODULE
  239. /*
  240. * Make sure any providers are loaded from config before we try to find
  241. * them.
  242. */
  243. if (!noconfig) {
  244. if (ossl_lib_ctx_is_default(libctx))
  245. OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CONFIG, NULL);
  246. }
  247. #endif
  248. tmpl.name = (char *)name;
  249. if (!CRYPTO_THREAD_read_lock(store->lock))
  250. return NULL;
  251. if ((i = sk_OSSL_PROVIDER_find(store->providers, &tmpl)) == -1
  252. || (prov = sk_OSSL_PROVIDER_value(store->providers, i)) == NULL
  253. || !ossl_provider_up_ref(prov))
  254. prov = NULL;
  255. CRYPTO_THREAD_unlock(store->lock);
  256. }
  257. return prov;
  258. }
  259. /*-
  260. * Provider Object methods
  261. * =======================
  262. */
  263. static OSSL_PROVIDER *provider_new(const char *name,
  264. OSSL_provider_init_fn *init_function)
  265. {
  266. OSSL_PROVIDER *prov = NULL;
  267. if ((prov = OPENSSL_zalloc(sizeof(*prov))) == NULL
  268. #ifndef HAVE_ATOMICS
  269. || (prov->refcnt_lock = CRYPTO_THREAD_lock_new()) == NULL
  270. #endif
  271. || (prov->opbits_lock = CRYPTO_THREAD_lock_new()) == NULL
  272. || (prov->flag_lock = CRYPTO_THREAD_lock_new()) == NULL
  273. || (prov->name = OPENSSL_strdup(name)) == NULL) {
  274. ossl_provider_free(prov);
  275. ERR_raise(ERR_LIB_CRYPTO, ERR_R_MALLOC_FAILURE);
  276. return NULL;
  277. }
  278. prov->refcnt = 1; /* 1 One reference to be returned */
  279. prov->init_function = init_function;
  280. #ifndef FIPS_MODULE
  281. prov->flag_couldbechild = 1;
  282. #endif
  283. return prov;
  284. }
  285. int ossl_provider_up_ref(OSSL_PROVIDER *prov)
  286. {
  287. int ref = 0;
  288. if (CRYPTO_UP_REF(&prov->refcnt, &ref, prov->refcnt_lock) <= 0)
  289. return 0;
  290. #ifndef FIPS_MODULE
  291. if (prov->ischild) {
  292. if (!ossl_provider_up_ref_parent(prov, 0)) {
  293. ossl_provider_free(prov);
  294. return 0;
  295. }
  296. }
  297. #endif
  298. return ref;
  299. }
  300. #ifndef FIPS_MODULE
  301. static int provider_up_ref_intern(OSSL_PROVIDER *prov, int activate)
  302. {
  303. if (activate)
  304. return ossl_provider_activate(prov, 0, 1);
  305. return ossl_provider_up_ref(prov);
  306. }
  307. static int provider_free_intern(OSSL_PROVIDER *prov, int deactivate)
  308. {
  309. if (deactivate)
  310. return ossl_provider_deactivate(prov);
  311. ossl_provider_free(prov);
  312. return 1;
  313. }
  314. #endif
  315. OSSL_PROVIDER *ossl_provider_new(OSSL_LIB_CTX *libctx, const char *name,
  316. OSSL_provider_init_fn *init_function,
  317. int noconfig)
  318. {
  319. struct provider_store_st *store = NULL;
  320. OSSL_PROVIDER *prov = NULL;
  321. if ((store = get_provider_store(libctx)) == NULL)
  322. return NULL;
  323. if ((prov = ossl_provider_find(libctx, name,
  324. noconfig)) != NULL) { /* refcount +1 */
  325. ossl_provider_free(prov); /* refcount -1 */
  326. ERR_raise_data(ERR_LIB_CRYPTO, CRYPTO_R_PROVIDER_ALREADY_EXISTS,
  327. "name=%s", name);
  328. return NULL;
  329. }
  330. /* provider_new() generates an error, so no need here */
  331. if ((prov = provider_new(name, init_function)) == NULL)
  332. return NULL;
  333. if (!CRYPTO_THREAD_write_lock(store->lock))
  334. return NULL;
  335. if (!ossl_provider_up_ref(prov)) { /* +1 One reference for the store */
  336. ossl_provider_free(prov); /* -1 Reference that was to be returned */
  337. prov = NULL;
  338. } else if (sk_OSSL_PROVIDER_push(store->providers, prov) == 0) {
  339. ossl_provider_free(prov); /* -1 Store reference */
  340. ossl_provider_free(prov); /* -1 Reference that was to be returned */
  341. prov = NULL;
  342. } else {
  343. prov->libctx = libctx;
  344. prov->store = store;
  345. #ifndef FIPS_MODULE
  346. prov->error_lib = ERR_get_next_error_library();
  347. #endif
  348. }
  349. CRYPTO_THREAD_unlock(store->lock);
  350. if (prov == NULL)
  351. ERR_raise(ERR_LIB_CRYPTO, ERR_R_MALLOC_FAILURE);
  352. /*
  353. * At this point, the provider is only partially "loaded". To be
  354. * fully "loaded", ossl_provider_activate() must also be called.
  355. */
  356. return prov;
  357. }
  358. static void free_infopair(INFOPAIR *pair)
  359. {
  360. OPENSSL_free(pair->name);
  361. OPENSSL_free(pair->value);
  362. OPENSSL_free(pair);
  363. }
  364. void ossl_provider_free(OSSL_PROVIDER *prov)
  365. {
  366. if (prov != NULL) {
  367. int ref = 0;
  368. CRYPTO_DOWN_REF(&prov->refcnt, &ref, prov->refcnt_lock);
  369. /*
  370. * When the refcount drops to zero, we clean up the provider.
  371. * Note that this also does teardown, which may seem late,
  372. * considering that init happens on first activation. However,
  373. * there may be other structures hanging on to the provider after
  374. * the last deactivation and may therefore need full access to the
  375. * provider's services. Therefore, we deinit late.
  376. */
  377. if (ref == 0) {
  378. if (prov->flag_initialized) {
  379. ossl_provider_teardown(prov);
  380. #ifndef OPENSSL_NO_ERR
  381. # ifndef FIPS_MODULE
  382. if (prov->error_strings != NULL) {
  383. ERR_unload_strings(prov->error_lib, prov->error_strings);
  384. OPENSSL_free(prov->error_strings);
  385. prov->error_strings = NULL;
  386. }
  387. # endif
  388. #endif
  389. OPENSSL_free(prov->operation_bits);
  390. prov->operation_bits = NULL;
  391. prov->operation_bits_sz = 0;
  392. prov->flag_initialized = 0;
  393. }
  394. #ifndef FIPS_MODULE
  395. /*
  396. * We deregister thread handling whether or not the provider was
  397. * initialized. If init was attempted but was not successful then
  398. * the provider may still have registered a thread handler.
  399. */
  400. ossl_init_thread_deregister(prov);
  401. DSO_free(prov->module);
  402. #endif
  403. OPENSSL_free(prov->name);
  404. OPENSSL_free(prov->path);
  405. sk_INFOPAIR_pop_free(prov->parameters, free_infopair);
  406. CRYPTO_THREAD_lock_free(prov->opbits_lock);
  407. CRYPTO_THREAD_lock_free(prov->flag_lock);
  408. #ifndef HAVE_ATOMICS
  409. CRYPTO_THREAD_lock_free(prov->refcnt_lock);
  410. #endif
  411. OPENSSL_free(prov);
  412. }
  413. #ifndef FIPS_MODULE
  414. else if (prov->ischild) {
  415. ossl_provider_free_parent(prov, 0);
  416. }
  417. #endif
  418. }
  419. }
  420. /* Setters */
  421. int ossl_provider_set_module_path(OSSL_PROVIDER *prov, const char *module_path)
  422. {
  423. OPENSSL_free(prov->path);
  424. prov->path = NULL;
  425. if (module_path == NULL)
  426. return 1;
  427. if ((prov->path = OPENSSL_strdup(module_path)) != NULL)
  428. return 1;
  429. ERR_raise(ERR_LIB_CRYPTO, ERR_R_MALLOC_FAILURE);
  430. return 0;
  431. }
  432. int ossl_provider_add_parameter(OSSL_PROVIDER *prov,
  433. const char *name, const char *value)
  434. {
  435. INFOPAIR *pair = NULL;
  436. if ((pair = OPENSSL_zalloc(sizeof(*pair))) != NULL
  437. && (prov->parameters != NULL
  438. || (prov->parameters = sk_INFOPAIR_new_null()) != NULL)
  439. && (pair->name = OPENSSL_strdup(name)) != NULL
  440. && (pair->value = OPENSSL_strdup(value)) != NULL
  441. && sk_INFOPAIR_push(prov->parameters, pair) > 0)
  442. return 1;
  443. if (pair != NULL) {
  444. OPENSSL_free(pair->name);
  445. OPENSSL_free(pair->value);
  446. OPENSSL_free(pair);
  447. }
  448. ERR_raise(ERR_LIB_CRYPTO, ERR_R_MALLOC_FAILURE);
  449. return 0;
  450. }
  451. /*
  452. * Provider activation.
  453. *
  454. * What "activation" means depends on the provider form; for built in
  455. * providers (in the library or the application alike), the provider
  456. * can already be considered to be loaded, all that's needed is to
  457. * initialize it. However, for dynamically loadable provider modules,
  458. * we must first load that module.
  459. *
  460. * Built in modules are distinguished from dynamically loaded modules
  461. * with an already assigned init function.
  462. */
  463. static const OSSL_DISPATCH *core_dispatch; /* Define further down */
  464. int OSSL_PROVIDER_set_default_search_path(OSSL_LIB_CTX *libctx,
  465. const char *path)
  466. {
  467. struct provider_store_st *store;
  468. char *p = NULL;
  469. if (path != NULL) {
  470. p = OPENSSL_strdup(path);
  471. if (p == NULL) {
  472. ERR_raise(ERR_LIB_CRYPTO, ERR_R_MALLOC_FAILURE);
  473. return 0;
  474. }
  475. }
  476. if ((store = get_provider_store(libctx)) != NULL
  477. && CRYPTO_THREAD_write_lock(store->default_path_lock)) {
  478. OPENSSL_free(store->default_path);
  479. store->default_path = p;
  480. CRYPTO_THREAD_unlock(store->default_path_lock);
  481. return 1;
  482. }
  483. OPENSSL_free(p);
  484. return 0;
  485. }
  486. /*
  487. * Internal version that doesn't affect the store flags, and thereby avoid
  488. * locking. Direct callers must remember to set the store flags when
  489. * appropriate.
  490. */
  491. static int provider_init(OSSL_PROVIDER *prov, int flag_lock)
  492. {
  493. const OSSL_DISPATCH *provider_dispatch = NULL;
  494. void *tmp_provctx = NULL; /* safety measure */
  495. #ifndef OPENSSL_NO_ERR
  496. # ifndef FIPS_MODULE
  497. OSSL_FUNC_provider_get_reason_strings_fn *p_get_reason_strings = NULL;
  498. # endif
  499. #endif
  500. int ok = 0;
  501. /*
  502. * The flag lock is used to lock init, not only because the flag is
  503. * checked here and set at the end, but also because this function
  504. * modifies a number of things in the provider structure that this
  505. * function needs to perform under lock anyway.
  506. */
  507. if (flag_lock && !CRYPTO_THREAD_write_lock(prov->flag_lock))
  508. goto end;
  509. if (prov->flag_initialized) {
  510. ok = 1;
  511. goto end;
  512. }
  513. /*
  514. * If the init function isn't set, it indicates that this provider is
  515. * a loadable module.
  516. */
  517. if (prov->init_function == NULL) {
  518. #ifdef FIPS_MODULE
  519. goto end;
  520. #else
  521. if (prov->module == NULL) {
  522. char *allocated_path = NULL;
  523. const char *module_path = NULL;
  524. char *merged_path = NULL;
  525. const char *load_dir = NULL;
  526. char *allocated_load_dir = NULL;
  527. struct provider_store_st *store;
  528. if ((prov->module = DSO_new()) == NULL) {
  529. /* DSO_new() generates an error already */
  530. goto end;
  531. }
  532. if ((store = get_provider_store(prov->libctx)) == NULL
  533. || !CRYPTO_THREAD_read_lock(store->default_path_lock))
  534. goto end;
  535. if (store->default_path != NULL) {
  536. allocated_load_dir = OPENSSL_strdup(store->default_path);
  537. CRYPTO_THREAD_unlock(store->default_path_lock);
  538. if (allocated_load_dir == NULL) {
  539. ERR_raise(ERR_LIB_CRYPTO, ERR_R_MALLOC_FAILURE);
  540. goto end;
  541. }
  542. load_dir = allocated_load_dir;
  543. } else {
  544. CRYPTO_THREAD_unlock(store->default_path_lock);
  545. }
  546. if (load_dir == NULL) {
  547. load_dir = ossl_safe_getenv("OPENSSL_MODULES");
  548. if (load_dir == NULL)
  549. load_dir = MODULESDIR;
  550. }
  551. DSO_ctrl(prov->module, DSO_CTRL_SET_FLAGS,
  552. DSO_FLAG_NAME_TRANSLATION_EXT_ONLY, NULL);
  553. module_path = prov->path;
  554. if (module_path == NULL)
  555. module_path = allocated_path =
  556. DSO_convert_filename(prov->module, prov->name);
  557. if (module_path != NULL)
  558. merged_path = DSO_merge(prov->module, module_path, load_dir);
  559. if (merged_path == NULL
  560. || (DSO_load(prov->module, merged_path, NULL, 0)) == NULL) {
  561. DSO_free(prov->module);
  562. prov->module = NULL;
  563. }
  564. OPENSSL_free(merged_path);
  565. OPENSSL_free(allocated_path);
  566. OPENSSL_free(allocated_load_dir);
  567. }
  568. if (prov->module != NULL)
  569. prov->init_function = (OSSL_provider_init_fn *)
  570. DSO_bind_func(prov->module, "OSSL_provider_init");
  571. #endif
  572. }
  573. /* Call the initialise function for the provider. */
  574. if (prov->init_function == NULL
  575. || !prov->init_function((OSSL_CORE_HANDLE *)prov, core_dispatch,
  576. &provider_dispatch, &tmp_provctx)) {
  577. ERR_raise_data(ERR_LIB_CRYPTO, ERR_R_INIT_FAIL,
  578. "name=%s", prov->name);
  579. goto end;
  580. }
  581. prov->provctx = tmp_provctx;
  582. prov->dispatch = provider_dispatch;
  583. #ifndef FIPS_MODULE
  584. prov->flag_couldbechild = 0;
  585. #endif
  586. for (; provider_dispatch->function_id != 0; provider_dispatch++) {
  587. switch (provider_dispatch->function_id) {
  588. case OSSL_FUNC_PROVIDER_TEARDOWN:
  589. prov->teardown =
  590. OSSL_FUNC_provider_teardown(provider_dispatch);
  591. break;
  592. case OSSL_FUNC_PROVIDER_GETTABLE_PARAMS:
  593. prov->gettable_params =
  594. OSSL_FUNC_provider_gettable_params(provider_dispatch);
  595. break;
  596. case OSSL_FUNC_PROVIDER_GET_PARAMS:
  597. prov->get_params =
  598. OSSL_FUNC_provider_get_params(provider_dispatch);
  599. break;
  600. case OSSL_FUNC_PROVIDER_SELF_TEST:
  601. prov->self_test =
  602. OSSL_FUNC_provider_self_test(provider_dispatch);
  603. break;
  604. case OSSL_FUNC_PROVIDER_GET_CAPABILITIES:
  605. prov->get_capabilities =
  606. OSSL_FUNC_provider_get_capabilities(provider_dispatch);
  607. break;
  608. case OSSL_FUNC_PROVIDER_QUERY_OPERATION:
  609. prov->query_operation =
  610. OSSL_FUNC_provider_query_operation(provider_dispatch);
  611. break;
  612. case OSSL_FUNC_PROVIDER_UNQUERY_OPERATION:
  613. prov->unquery_operation =
  614. OSSL_FUNC_provider_unquery_operation(provider_dispatch);
  615. break;
  616. #ifndef OPENSSL_NO_ERR
  617. # ifndef FIPS_MODULE
  618. case OSSL_FUNC_PROVIDER_GET_REASON_STRINGS:
  619. p_get_reason_strings =
  620. OSSL_FUNC_provider_get_reason_strings(provider_dispatch);
  621. break;
  622. # endif
  623. #endif
  624. }
  625. }
  626. #ifndef OPENSSL_NO_ERR
  627. # ifndef FIPS_MODULE
  628. if (p_get_reason_strings != NULL) {
  629. const OSSL_ITEM *reasonstrings = p_get_reason_strings(prov->provctx);
  630. size_t cnt, cnt2;
  631. /*
  632. * ERR_load_strings() handles ERR_STRING_DATA rather than OSSL_ITEM,
  633. * although they are essentially the same type.
  634. * Furthermore, ERR_load_strings() patches the array's error number
  635. * with the error library number, so we need to make a copy of that
  636. * array either way.
  637. */
  638. cnt = 0;
  639. while (reasonstrings[cnt].id != 0) {
  640. if (ERR_GET_LIB(reasonstrings[cnt].id) != 0)
  641. goto end;
  642. cnt++;
  643. }
  644. cnt++; /* One for the terminating item */
  645. /* Allocate one extra item for the "library" name */
  646. prov->error_strings =
  647. OPENSSL_zalloc(sizeof(ERR_STRING_DATA) * (cnt + 1));
  648. if (prov->error_strings == NULL)
  649. goto end;
  650. /*
  651. * Set the "library" name.
  652. */
  653. prov->error_strings[0].error = ERR_PACK(prov->error_lib, 0, 0);
  654. prov->error_strings[0].string = prov->name;
  655. /*
  656. * Copy reasonstrings item 0..cnt-1 to prov->error_trings positions
  657. * 1..cnt.
  658. */
  659. for (cnt2 = 1; cnt2 <= cnt; cnt2++) {
  660. prov->error_strings[cnt2].error = (int)reasonstrings[cnt2-1].id;
  661. prov->error_strings[cnt2].string = reasonstrings[cnt2-1].ptr;
  662. }
  663. ERR_load_strings(prov->error_lib, prov->error_strings);
  664. }
  665. # endif
  666. #endif
  667. /* With this flag set, this provider has become fully "loaded". */
  668. prov->flag_initialized = 1;
  669. ok = 1;
  670. end:
  671. if (flag_lock)
  672. CRYPTO_THREAD_unlock(prov->flag_lock);
  673. return ok;
  674. }
  675. /*
  676. * Deactivate a provider.
  677. * Return -1 on failure and the activation count on success
  678. */
  679. static int provider_deactivate(OSSL_PROVIDER *prov)
  680. {
  681. int count;
  682. struct provider_store_st *store;
  683. if (!ossl_assert(prov != NULL))
  684. return -1;
  685. store = get_provider_store(prov->libctx);
  686. if (store == NULL)
  687. return -1;
  688. if (!CRYPTO_THREAD_read_lock(store->lock))
  689. return -1;
  690. if (!CRYPTO_THREAD_write_lock(prov->flag_lock)) {
  691. CRYPTO_THREAD_unlock(store->lock);
  692. return -1;
  693. }
  694. #ifndef FIPS_MODULE
  695. if (prov->activatecnt == 2 && prov->ischild) {
  696. /*
  697. * We have had a direct activation in this child libctx so we need to
  698. * now down the ref count in the parent provider.
  699. */
  700. ossl_provider_free_parent(prov, 1);
  701. }
  702. #endif
  703. if ((count = --prov->activatecnt) < 1) {
  704. prov->flag_activated = 0;
  705. #ifndef FIPS_MODULE
  706. {
  707. int i, max = sk_OSSL_PROVIDER_CHILD_CB_num(store->child_cbs);
  708. OSSL_PROVIDER_CHILD_CB *child_cb;
  709. for (i = 0; i < max; i++) {
  710. child_cb = sk_OSSL_PROVIDER_CHILD_CB_value(store->child_cbs, i);
  711. child_cb->remove_cb((OSSL_CORE_HANDLE *)prov, child_cb->cbdata);
  712. }
  713. }
  714. #endif
  715. }
  716. CRYPTO_THREAD_unlock(prov->flag_lock);
  717. CRYPTO_THREAD_unlock(store->lock);
  718. /* We don't deinit here, that's done in ossl_provider_free() */
  719. return count;
  720. }
  721. /*
  722. * Activate a provider.
  723. * Return -1 on failure and the activation count on success
  724. */
  725. static int provider_activate(OSSL_PROVIDER *prov, int lock, int upcalls)
  726. {
  727. int count = -1;
  728. if (provider_init(prov, lock)) {
  729. int ret = 1;
  730. struct provider_store_st *store;
  731. store = get_provider_store(prov->libctx);
  732. if (store == NULL)
  733. return -1;
  734. if (lock && !CRYPTO_THREAD_read_lock(store->lock))
  735. return -1;
  736. if (lock && !CRYPTO_THREAD_write_lock(prov->flag_lock)) {
  737. CRYPTO_THREAD_unlock(store->lock);
  738. return -1;
  739. }
  740. #ifndef FIPS_MODULE
  741. if (prov->ischild && upcalls)
  742. ret = ossl_provider_up_ref_parent(prov, 1);
  743. #endif
  744. if (ret) {
  745. count = ++prov->activatecnt;
  746. prov->flag_activated = 1;
  747. #ifndef FIPS_MODULE
  748. if (prov->activatecnt == 1) {
  749. OSSL_PROVIDER_CHILD_CB *child_cb;
  750. int i, max;
  751. max = sk_OSSL_PROVIDER_CHILD_CB_num(store->child_cbs);
  752. for (i = 0; i < max; i++) {
  753. /*
  754. * This is newly activated (activatecnt == 1), so we need to
  755. * create child providers as necessary.
  756. */
  757. child_cb = sk_OSSL_PROVIDER_CHILD_CB_value(store->child_cbs,
  758. i);
  759. ret &= child_cb->create_cb((OSSL_CORE_HANDLE *)prov,
  760. child_cb->cbdata);
  761. }
  762. }
  763. #endif
  764. }
  765. if (lock) {
  766. CRYPTO_THREAD_unlock(prov->flag_lock);
  767. CRYPTO_THREAD_unlock(store->lock);
  768. }
  769. if (!ret)
  770. return -1;
  771. }
  772. return count;
  773. }
  774. static int provider_flush_store_cache(const OSSL_PROVIDER *prov)
  775. {
  776. struct provider_store_st *store;
  777. int freeing;
  778. if ((store = get_provider_store(prov->libctx)) == NULL)
  779. return 0;
  780. if (!CRYPTO_THREAD_read_lock(store->lock))
  781. return 0;
  782. freeing = store->freeing;
  783. CRYPTO_THREAD_unlock(store->lock);
  784. if (!freeing)
  785. return evp_method_store_flush(prov->libctx);
  786. return 1;
  787. }
  788. int ossl_provider_activate(OSSL_PROVIDER *prov, int retain_fallbacks,
  789. int upcalls)
  790. {
  791. int count;
  792. if (prov == NULL)
  793. return 0;
  794. if ((count = provider_activate(prov, 1, upcalls)) > 0) {
  795. if (!retain_fallbacks) {
  796. if (!CRYPTO_THREAD_write_lock(prov->store->lock)) {
  797. provider_deactivate(prov);
  798. return 0;
  799. }
  800. prov->store->use_fallbacks = 0;
  801. CRYPTO_THREAD_unlock(prov->store->lock);
  802. }
  803. return count == 1 ? provider_flush_store_cache(prov) : 1;
  804. }
  805. return 0;
  806. }
  807. int ossl_provider_deactivate(OSSL_PROVIDER *prov)
  808. {
  809. int count;
  810. if (prov == NULL || (count = provider_deactivate(prov)) < 0)
  811. return 0;
  812. return count == 0 ? provider_flush_store_cache(prov) : 1;
  813. }
  814. void *ossl_provider_ctx(const OSSL_PROVIDER *prov)
  815. {
  816. return prov->provctx;
  817. }
  818. /*
  819. * This function only does something once when store->use_fallbacks == 1,
  820. * and then sets store->use_fallbacks = 0, so the second call and so on is
  821. * effectively a no-op.
  822. */
  823. static void provider_activate_fallbacks(struct provider_store_st *store)
  824. {
  825. int use_fallbacks;
  826. int num_provs;
  827. int activated_fallback_count = 0;
  828. int i;
  829. if (!CRYPTO_THREAD_read_lock(store->lock))
  830. return;
  831. use_fallbacks = store->use_fallbacks;
  832. CRYPTO_THREAD_unlock(store->lock);
  833. if (!use_fallbacks)
  834. return;
  835. if (!CRYPTO_THREAD_write_lock(store->lock))
  836. return;
  837. /* Check again, just in case another thread changed it */
  838. use_fallbacks = store->use_fallbacks;
  839. if (!use_fallbacks) {
  840. CRYPTO_THREAD_unlock(store->lock);
  841. return;
  842. }
  843. num_provs = sk_OSSL_PROVIDER_num(store->providers);
  844. for (i = 0; i < num_provs; i++) {
  845. OSSL_PROVIDER *prov = sk_OSSL_PROVIDER_value(store->providers, i);
  846. if (ossl_provider_up_ref(prov)) {
  847. if (CRYPTO_THREAD_write_lock(prov->flag_lock)) {
  848. if (prov->flag_fallback) {
  849. if (provider_activate(prov, 0, 0) > 0)
  850. activated_fallback_count++;
  851. }
  852. CRYPTO_THREAD_unlock(prov->flag_lock);
  853. }
  854. ossl_provider_free(prov);
  855. }
  856. }
  857. /*
  858. * We assume that all fallbacks have been added to the store before
  859. * any fallback is activated.
  860. */
  861. if (activated_fallback_count > 0)
  862. store->use_fallbacks = 0;
  863. CRYPTO_THREAD_unlock(store->lock);
  864. }
  865. int ossl_provider_doall_activated(OSSL_LIB_CTX *ctx,
  866. int (*cb)(OSSL_PROVIDER *provider,
  867. void *cbdata),
  868. void *cbdata)
  869. {
  870. int ret = 0, curr, max;
  871. struct provider_store_st *store = get_provider_store(ctx);
  872. STACK_OF(OSSL_PROVIDER) *provs = NULL;
  873. #ifndef FIPS_MODULE
  874. /*
  875. * Make sure any providers are loaded from config before we try to use
  876. * them.
  877. */
  878. if (ossl_lib_ctx_is_default(ctx))
  879. OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CONFIG, NULL);
  880. #endif
  881. if (store == NULL)
  882. return 1;
  883. provider_activate_fallbacks(store);
  884. /*
  885. * Under lock, grab a copy of the provider list and up_ref each
  886. * provider so that they don't disappear underneath us.
  887. */
  888. if (!CRYPTO_THREAD_read_lock(store->lock))
  889. return 0;
  890. provs = sk_OSSL_PROVIDER_dup(store->providers);
  891. if (provs == NULL) {
  892. CRYPTO_THREAD_unlock(store->lock);
  893. return 0;
  894. }
  895. max = sk_OSSL_PROVIDER_num(provs);
  896. /*
  897. * We work backwards through the stack so that we can safely delete items
  898. * as we go.
  899. */
  900. for (curr = max - 1; curr >= 0; curr--) {
  901. OSSL_PROVIDER *prov = sk_OSSL_PROVIDER_value(provs, curr);
  902. if (!CRYPTO_THREAD_write_lock(prov->flag_lock))
  903. goto err_unlock;
  904. if (prov->flag_activated) {
  905. if (!ossl_provider_up_ref(prov)){
  906. CRYPTO_THREAD_unlock(prov->flag_lock);
  907. goto err_unlock;
  908. }
  909. /*
  910. * It's already activated, but we up the activated count to ensure
  911. * it remains activated until after we've called the user callback.
  912. */
  913. if (provider_activate(prov, 0, 1) < 0) {
  914. ossl_provider_free(prov);
  915. CRYPTO_THREAD_unlock(prov->flag_lock);
  916. goto err_unlock;
  917. }
  918. } else {
  919. sk_OSSL_PROVIDER_delete(provs, curr);
  920. max--;
  921. }
  922. CRYPTO_THREAD_unlock(prov->flag_lock);
  923. }
  924. CRYPTO_THREAD_unlock(store->lock);
  925. /*
  926. * Now, we sweep through all providers not under lock
  927. */
  928. for (curr = 0; curr < max; curr++) {
  929. OSSL_PROVIDER *prov = sk_OSSL_PROVIDER_value(provs, curr);
  930. if (!cb(prov, cbdata))
  931. goto finish;
  932. }
  933. curr = -1;
  934. ret = 1;
  935. goto finish;
  936. err_unlock:
  937. CRYPTO_THREAD_unlock(store->lock);
  938. finish:
  939. /*
  940. * The pop_free call doesn't do what we want on an error condition. We
  941. * either start from the first item in the stack, or part way through if
  942. * we only processed some of the items.
  943. */
  944. for (curr++; curr < max; curr++) {
  945. OSSL_PROVIDER *prov = sk_OSSL_PROVIDER_value(provs, curr);
  946. provider_deactivate(prov);
  947. ossl_provider_free(prov);
  948. }
  949. sk_OSSL_PROVIDER_free(provs);
  950. return ret;
  951. }
  952. int ossl_provider_available(OSSL_PROVIDER *prov)
  953. {
  954. int ret;
  955. if (prov != NULL) {
  956. provider_activate_fallbacks(prov->store);
  957. if (!CRYPTO_THREAD_read_lock(prov->flag_lock))
  958. return 0;
  959. ret = prov->flag_activated;
  960. CRYPTO_THREAD_unlock(prov->flag_lock);
  961. return ret;
  962. }
  963. return 0;
  964. }
  965. /* Setters of Provider Object data */
  966. int ossl_provider_set_fallback(OSSL_PROVIDER *prov)
  967. {
  968. if (prov == NULL)
  969. return 0;
  970. prov->flag_fallback = 1;
  971. return 1;
  972. }
  973. /* Getters of Provider Object data */
  974. const char *ossl_provider_name(const OSSL_PROVIDER *prov)
  975. {
  976. return prov->name;
  977. }
  978. const DSO *ossl_provider_dso(const OSSL_PROVIDER *prov)
  979. {
  980. return prov->module;
  981. }
  982. const char *ossl_provider_module_name(const OSSL_PROVIDER *prov)
  983. {
  984. #ifdef FIPS_MODULE
  985. return NULL;
  986. #else
  987. return DSO_get_filename(prov->module);
  988. #endif
  989. }
  990. const char *ossl_provider_module_path(const OSSL_PROVIDER *prov)
  991. {
  992. #ifdef FIPS_MODULE
  993. return NULL;
  994. #else
  995. /* FIXME: Ensure it's a full path */
  996. return DSO_get_filename(prov->module);
  997. #endif
  998. }
  999. void *ossl_provider_prov_ctx(const OSSL_PROVIDER *prov)
  1000. {
  1001. if (prov != NULL)
  1002. return prov->provctx;
  1003. return NULL;
  1004. }
  1005. const OSSL_DISPATCH *ossl_provider_get0_dispatch(const OSSL_PROVIDER *prov)
  1006. {
  1007. if (prov != NULL)
  1008. return prov->dispatch;
  1009. return NULL;
  1010. }
  1011. OSSL_LIB_CTX *ossl_provider_libctx(const OSSL_PROVIDER *prov)
  1012. {
  1013. return prov != NULL ? prov->libctx : NULL;
  1014. }
  1015. /* Wrappers around calls to the provider */
  1016. void ossl_provider_teardown(const OSSL_PROVIDER *prov)
  1017. {
  1018. if (prov->teardown != NULL
  1019. #ifndef FIPS_MODULE
  1020. && !prov->ischild
  1021. #endif
  1022. )
  1023. prov->teardown(prov->provctx);
  1024. }
  1025. const OSSL_PARAM *ossl_provider_gettable_params(const OSSL_PROVIDER *prov)
  1026. {
  1027. return prov->gettable_params == NULL
  1028. ? NULL : prov->gettable_params(prov->provctx);
  1029. }
  1030. int ossl_provider_get_params(const OSSL_PROVIDER *prov, OSSL_PARAM params[])
  1031. {
  1032. return prov->get_params == NULL
  1033. ? 0 : prov->get_params(prov->provctx, params);
  1034. }
  1035. int ossl_provider_self_test(const OSSL_PROVIDER *prov)
  1036. {
  1037. int ret;
  1038. if (prov->self_test == NULL)
  1039. return 1;
  1040. ret = prov->self_test(prov->provctx);
  1041. if (ret == 0)
  1042. (void)provider_flush_store_cache(prov);
  1043. return ret;
  1044. }
  1045. int ossl_provider_get_capabilities(const OSSL_PROVIDER *prov,
  1046. const char *capability,
  1047. OSSL_CALLBACK *cb,
  1048. void *arg)
  1049. {
  1050. return prov->get_capabilities == NULL
  1051. ? 1 : prov->get_capabilities(prov->provctx, capability, cb, arg);
  1052. }
  1053. const OSSL_ALGORITHM *ossl_provider_query_operation(const OSSL_PROVIDER *prov,
  1054. int operation_id,
  1055. int *no_cache)
  1056. {
  1057. const OSSL_ALGORITHM *res;
  1058. if (prov->query_operation == NULL)
  1059. return NULL;
  1060. res = prov->query_operation(prov->provctx, operation_id, no_cache);
  1061. #if defined(OPENSSL_NO_CACHED_FETCH)
  1062. /* Forcing the non-caching of queries */
  1063. if (no_cache != NULL)
  1064. *no_cache = 1;
  1065. #endif
  1066. return res;
  1067. }
  1068. void ossl_provider_unquery_operation(const OSSL_PROVIDER *prov,
  1069. int operation_id,
  1070. const OSSL_ALGORITHM *algs)
  1071. {
  1072. if (prov->unquery_operation != NULL)
  1073. prov->unquery_operation(prov->provctx, operation_id, algs);
  1074. }
  1075. int ossl_provider_clear_all_operation_bits(OSSL_LIB_CTX *libctx)
  1076. {
  1077. struct provider_store_st *store;
  1078. OSSL_PROVIDER *provider;
  1079. int i, num, res = 1;
  1080. if ((store = get_provider_store(libctx)) != NULL) {
  1081. if (!CRYPTO_THREAD_read_lock(store->lock))
  1082. return 0;
  1083. num = sk_OSSL_PROVIDER_num(store->providers);
  1084. for (i = 0; i < num; i++) {
  1085. provider = sk_OSSL_PROVIDER_value(store->providers, i);
  1086. if (!CRYPTO_THREAD_write_lock(provider->opbits_lock)) {
  1087. res = 0;
  1088. continue;
  1089. }
  1090. if (provider->operation_bits != NULL)
  1091. memset(provider->operation_bits, 0,
  1092. provider->operation_bits_sz);
  1093. CRYPTO_THREAD_unlock(provider->opbits_lock);
  1094. }
  1095. CRYPTO_THREAD_unlock(store->lock);
  1096. return res;
  1097. }
  1098. return 0;
  1099. }
  1100. int ossl_provider_set_operation_bit(OSSL_PROVIDER *provider, size_t bitnum)
  1101. {
  1102. size_t byte = bitnum / 8;
  1103. unsigned char bit = (1 << (bitnum % 8)) & 0xFF;
  1104. if (!CRYPTO_THREAD_write_lock(provider->opbits_lock))
  1105. return 0;
  1106. if (provider->operation_bits_sz <= byte) {
  1107. unsigned char *tmp = OPENSSL_realloc(provider->operation_bits,
  1108. byte + 1);
  1109. if (tmp == NULL) {
  1110. CRYPTO_THREAD_unlock(provider->opbits_lock);
  1111. ERR_raise(ERR_LIB_CRYPTO, ERR_R_MALLOC_FAILURE);
  1112. return 0;
  1113. }
  1114. provider->operation_bits = tmp;
  1115. memset(provider->operation_bits + provider->operation_bits_sz,
  1116. '\0', byte + 1 - provider->operation_bits_sz);
  1117. provider->operation_bits_sz = byte + 1;
  1118. }
  1119. provider->operation_bits[byte] |= bit;
  1120. CRYPTO_THREAD_unlock(provider->opbits_lock);
  1121. return 1;
  1122. }
  1123. int ossl_provider_test_operation_bit(OSSL_PROVIDER *provider, size_t bitnum,
  1124. int *result)
  1125. {
  1126. size_t byte = bitnum / 8;
  1127. unsigned char bit = (1 << (bitnum % 8)) & 0xFF;
  1128. if (!ossl_assert(result != NULL)) {
  1129. ERR_raise(ERR_LIB_CRYPTO, ERR_R_PASSED_NULL_PARAMETER);
  1130. return 0;
  1131. }
  1132. *result = 0;
  1133. if (!CRYPTO_THREAD_read_lock(provider->opbits_lock))
  1134. return 0;
  1135. if (provider->operation_bits_sz > byte)
  1136. *result = ((provider->operation_bits[byte] & bit) != 0);
  1137. CRYPTO_THREAD_unlock(provider->opbits_lock);
  1138. return 1;
  1139. }
  1140. #ifndef FIPS_MODULE
  1141. const OSSL_CORE_HANDLE *ossl_provider_get_parent(OSSL_PROVIDER *prov)
  1142. {
  1143. return prov->handle;
  1144. }
  1145. int ossl_provider_is_child(const OSSL_PROVIDER *prov)
  1146. {
  1147. return prov->ischild;
  1148. }
  1149. int ossl_provider_set_child(OSSL_PROVIDER *prov, const OSSL_CORE_HANDLE *handle)
  1150. {
  1151. prov->handle = handle;
  1152. prov->ischild = 1;
  1153. return 1;
  1154. }
  1155. int ossl_provider_convert_to_child(OSSL_PROVIDER *prov,
  1156. const OSSL_CORE_HANDLE *handle,
  1157. OSSL_provider_init_fn *init_function)
  1158. {
  1159. int flush = 0;
  1160. if (!CRYPTO_THREAD_write_lock(prov->store->lock))
  1161. return 0;
  1162. if (!CRYPTO_THREAD_write_lock(prov->flag_lock)) {
  1163. CRYPTO_THREAD_unlock(prov->store->lock);
  1164. return 0;
  1165. }
  1166. /*
  1167. * The provider could be in one of three states: (1) Already a child,
  1168. * (2) Not a child (but eligible to be one), or (3) Not a child (not
  1169. * eligible to be one).
  1170. */
  1171. if (prov->flag_couldbechild) {
  1172. ossl_provider_set_child(prov, handle);
  1173. prov->init_function = init_function;
  1174. }
  1175. if (prov->ischild && provider_activate(prov, 0, 0)) {
  1176. flush = 1;
  1177. prov->store->use_fallbacks = 0;
  1178. }
  1179. CRYPTO_THREAD_unlock(prov->flag_lock);
  1180. CRYPTO_THREAD_unlock(prov->store->lock);
  1181. if (flush)
  1182. provider_flush_store_cache(prov);
  1183. /*
  1184. * We report success whether or not the provider was eligible for conversion
  1185. * to a child. If its not elgibile then it has already been loaded as a non
  1186. * child provider and we should keep it like that.
  1187. */
  1188. return 1;
  1189. }
  1190. int ossl_provider_default_props_update(OSSL_LIB_CTX *libctx, const char *props)
  1191. {
  1192. #ifndef FIPS_MODULE
  1193. struct provider_store_st *store = NULL;
  1194. int i, max;
  1195. OSSL_PROVIDER_CHILD_CB *child_cb;
  1196. if ((store = get_provider_store(libctx)) == NULL)
  1197. return 0;
  1198. if (!CRYPTO_THREAD_read_lock(store->lock))
  1199. return 0;
  1200. max = sk_OSSL_PROVIDER_CHILD_CB_num(store->child_cbs);
  1201. for (i = 0; i < max; i++) {
  1202. child_cb = sk_OSSL_PROVIDER_CHILD_CB_value(store->child_cbs, i);
  1203. child_cb->global_props_cb(props, child_cb->cbdata);
  1204. }
  1205. CRYPTO_THREAD_unlock(store->lock);
  1206. #endif
  1207. return 1;
  1208. }
  1209. static int ossl_provider_register_child_cb(const OSSL_CORE_HANDLE *handle,
  1210. int (*create_cb)(
  1211. const OSSL_CORE_HANDLE *provider,
  1212. void *cbdata),
  1213. int (*remove_cb)(
  1214. const OSSL_CORE_HANDLE *provider,
  1215. void *cbdata),
  1216. int (*global_props_cb)(
  1217. const char *props,
  1218. void *cbdata),
  1219. void *cbdata)
  1220. {
  1221. /*
  1222. * This is really an OSSL_PROVIDER that we created and cast to
  1223. * OSSL_CORE_HANDLE originally. Therefore it is safe to cast it back.
  1224. */
  1225. OSSL_PROVIDER *thisprov = (OSSL_PROVIDER *)handle;
  1226. OSSL_PROVIDER *prov;
  1227. OSSL_LIB_CTX *libctx = thisprov->libctx;
  1228. struct provider_store_st *store = NULL;
  1229. int ret = 0, i, max;
  1230. OSSL_PROVIDER_CHILD_CB *child_cb;
  1231. char *propsstr = NULL;
  1232. if ((store = get_provider_store(libctx)) == NULL)
  1233. return 0;
  1234. child_cb = OPENSSL_malloc(sizeof(*child_cb));
  1235. if (child_cb == NULL)
  1236. return 0;
  1237. child_cb->prov = thisprov;
  1238. child_cb->create_cb = create_cb;
  1239. child_cb->remove_cb = remove_cb;
  1240. child_cb->global_props_cb = global_props_cb;
  1241. child_cb->cbdata = cbdata;
  1242. if (!CRYPTO_THREAD_write_lock(store->lock)) {
  1243. OPENSSL_free(child_cb);
  1244. return 0;
  1245. }
  1246. propsstr = evp_get_global_properties_str(libctx, 0);
  1247. if (propsstr != NULL) {
  1248. global_props_cb(propsstr, cbdata);
  1249. OPENSSL_free(propsstr);
  1250. }
  1251. max = sk_OSSL_PROVIDER_num(store->providers);
  1252. for (i = 0; i < max; i++) {
  1253. prov = sk_OSSL_PROVIDER_value(store->providers, i);
  1254. /*
  1255. * We require register_child_cb to be called during a provider init
  1256. * function. The currently initing provider will never be activated yet
  1257. * and we we should not attempt to aquire the flag_lock for it.
  1258. */
  1259. if (prov == thisprov)
  1260. continue;
  1261. if (!CRYPTO_THREAD_read_lock(prov->flag_lock))
  1262. break;
  1263. /*
  1264. * We hold the lock while calling the user callback. This means that the
  1265. * user callback must be short and simple and not do anything likely to
  1266. * cause a deadlock.
  1267. */
  1268. if (prov->flag_activated
  1269. && !create_cb((OSSL_CORE_HANDLE *)prov, cbdata))
  1270. break;
  1271. CRYPTO_THREAD_unlock(prov->flag_lock);
  1272. }
  1273. if (i == max) {
  1274. /* Success */
  1275. ret = sk_OSSL_PROVIDER_CHILD_CB_push(store->child_cbs, child_cb);
  1276. }
  1277. if (i != max || ret <= 0) {
  1278. /* Failed during creation. Remove everything we just added */
  1279. for (; i >= 0; i--) {
  1280. prov = sk_OSSL_PROVIDER_value(store->providers, i);
  1281. remove_cb((OSSL_CORE_HANDLE *)prov, cbdata);
  1282. }
  1283. OPENSSL_free(child_cb);
  1284. ret = 0;
  1285. }
  1286. CRYPTO_THREAD_unlock(store->lock);
  1287. return ret;
  1288. }
  1289. static void ossl_provider_deregister_child_cb(const OSSL_CORE_HANDLE *handle)
  1290. {
  1291. /*
  1292. * This is really an OSSL_PROVIDER that we created and cast to
  1293. * OSSL_CORE_HANDLE originally. Therefore it is safe to cast it back.
  1294. */
  1295. OSSL_PROVIDER *thisprov = (OSSL_PROVIDER *)handle;
  1296. OSSL_LIB_CTX *libctx = thisprov->libctx;
  1297. struct provider_store_st *store = NULL;
  1298. int i, max;
  1299. OSSL_PROVIDER_CHILD_CB *child_cb;
  1300. if ((store = get_provider_store(libctx)) == NULL)
  1301. return;
  1302. if (!CRYPTO_THREAD_write_lock(store->lock))
  1303. return;
  1304. max = sk_OSSL_PROVIDER_CHILD_CB_num(store->child_cbs);
  1305. for (i = 0; i < max; i++) {
  1306. child_cb = sk_OSSL_PROVIDER_CHILD_CB_value(store->child_cbs, i);
  1307. if (child_cb->prov == thisprov) {
  1308. /* Found an entry */
  1309. sk_OSSL_PROVIDER_CHILD_CB_delete(store->child_cbs, i);
  1310. OPENSSL_free(child_cb);
  1311. break;
  1312. }
  1313. }
  1314. CRYPTO_THREAD_unlock(store->lock);
  1315. }
  1316. #endif
  1317. /*-
  1318. * Core functions for the provider
  1319. * ===============================
  1320. *
  1321. * This is the set of functions that the core makes available to the provider
  1322. */
  1323. /*
  1324. * This returns a list of Provider Object parameters with their types, for
  1325. * discovery. We do not expect that many providers will use this, but one
  1326. * never knows.
  1327. */
  1328. static const OSSL_PARAM param_types[] = {
  1329. OSSL_PARAM_DEFN(OSSL_PROV_PARAM_CORE_VERSION, OSSL_PARAM_UTF8_PTR, NULL, 0),
  1330. OSSL_PARAM_DEFN(OSSL_PROV_PARAM_CORE_PROV_NAME, OSSL_PARAM_UTF8_PTR,
  1331. NULL, 0),
  1332. #ifndef FIPS_MODULE
  1333. OSSL_PARAM_DEFN(OSSL_PROV_PARAM_CORE_MODULE_FILENAME, OSSL_PARAM_UTF8_PTR,
  1334. NULL, 0),
  1335. #endif
  1336. OSSL_PARAM_END
  1337. };
  1338. /*
  1339. * Forward declare all the functions that are provided aa dispatch.
  1340. * This ensures that the compiler will complain if they aren't defined
  1341. * with the correct signature.
  1342. */
  1343. static OSSL_FUNC_core_gettable_params_fn core_gettable_params;
  1344. static OSSL_FUNC_core_get_params_fn core_get_params;
  1345. static OSSL_FUNC_core_thread_start_fn core_thread_start;
  1346. static OSSL_FUNC_core_get_libctx_fn core_get_libctx;
  1347. #ifndef FIPS_MODULE
  1348. static OSSL_FUNC_core_new_error_fn core_new_error;
  1349. static OSSL_FUNC_core_set_error_debug_fn core_set_error_debug;
  1350. static OSSL_FUNC_core_vset_error_fn core_vset_error;
  1351. static OSSL_FUNC_core_set_error_mark_fn core_set_error_mark;
  1352. static OSSL_FUNC_core_clear_last_error_mark_fn core_clear_last_error_mark;
  1353. static OSSL_FUNC_core_pop_error_to_mark_fn core_pop_error_to_mark;
  1354. static OSSL_FUNC_core_obj_add_sigid_fn core_obj_add_sigid;
  1355. static OSSL_FUNC_core_obj_create_fn core_obj_create;
  1356. #endif
  1357. static const OSSL_PARAM *core_gettable_params(const OSSL_CORE_HANDLE *handle)
  1358. {
  1359. return param_types;
  1360. }
  1361. static int core_get_params(const OSSL_CORE_HANDLE *handle, OSSL_PARAM params[])
  1362. {
  1363. int i;
  1364. OSSL_PARAM *p;
  1365. /*
  1366. * We created this object originally and we know it is actually an
  1367. * OSSL_PROVIDER *, so the cast is safe
  1368. */
  1369. OSSL_PROVIDER *prov = (OSSL_PROVIDER *)handle;
  1370. if ((p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_CORE_VERSION)) != NULL)
  1371. OSSL_PARAM_set_utf8_ptr(p, OPENSSL_VERSION_STR);
  1372. if ((p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_CORE_PROV_NAME)) != NULL)
  1373. OSSL_PARAM_set_utf8_ptr(p, prov->name);
  1374. #ifndef FIPS_MODULE
  1375. if ((p = OSSL_PARAM_locate(params,
  1376. OSSL_PROV_PARAM_CORE_MODULE_FILENAME)) != NULL)
  1377. OSSL_PARAM_set_utf8_ptr(p, ossl_provider_module_path(prov));
  1378. #endif
  1379. if (prov->parameters == NULL)
  1380. return 1;
  1381. for (i = 0; i < sk_INFOPAIR_num(prov->parameters); i++) {
  1382. INFOPAIR *pair = sk_INFOPAIR_value(prov->parameters, i);
  1383. if ((p = OSSL_PARAM_locate(params, pair->name)) != NULL)
  1384. OSSL_PARAM_set_utf8_ptr(p, pair->value);
  1385. }
  1386. return 1;
  1387. }
  1388. static OPENSSL_CORE_CTX *core_get_libctx(const OSSL_CORE_HANDLE *handle)
  1389. {
  1390. /*
  1391. * We created this object originally and we know it is actually an
  1392. * OSSL_PROVIDER *, so the cast is safe
  1393. */
  1394. OSSL_PROVIDER *prov = (OSSL_PROVIDER *)handle;
  1395. /*
  1396. * Using ossl_provider_libctx would be wrong as that returns
  1397. * NULL for |prov| == NULL and NULL libctx has a special meaning
  1398. * that does not apply here. Here |prov| == NULL can happen only in
  1399. * case of a coding error.
  1400. */
  1401. assert(prov != NULL);
  1402. return (OPENSSL_CORE_CTX *)prov->libctx;
  1403. }
  1404. static int core_thread_start(const OSSL_CORE_HANDLE *handle,
  1405. OSSL_thread_stop_handler_fn handfn,
  1406. void *arg)
  1407. {
  1408. /*
  1409. * We created this object originally and we know it is actually an
  1410. * OSSL_PROVIDER *, so the cast is safe
  1411. */
  1412. OSSL_PROVIDER *prov = (OSSL_PROVIDER *)handle;
  1413. return ossl_init_thread_start(prov, arg, handfn);
  1414. }
  1415. /*
  1416. * The FIPS module inner provider doesn't implement these. They aren't
  1417. * needed there, since the FIPS module upcalls are always the outer provider
  1418. * ones.
  1419. */
  1420. #ifndef FIPS_MODULE
  1421. /*
  1422. * These error functions should use |handle| to select the proper
  1423. * library context to report in the correct error stack if error
  1424. * stacks become tied to the library context.
  1425. * We cannot currently do that since there's no support for it in the
  1426. * ERR subsystem.
  1427. */
  1428. static void core_new_error(const OSSL_CORE_HANDLE *handle)
  1429. {
  1430. ERR_new();
  1431. }
  1432. static void core_set_error_debug(const OSSL_CORE_HANDLE *handle,
  1433. const char *file, int line, const char *func)
  1434. {
  1435. ERR_set_debug(file, line, func);
  1436. }
  1437. static void core_vset_error(const OSSL_CORE_HANDLE *handle,
  1438. uint32_t reason, const char *fmt, va_list args)
  1439. {
  1440. /*
  1441. * We created this object originally and we know it is actually an
  1442. * OSSL_PROVIDER *, so the cast is safe
  1443. */
  1444. OSSL_PROVIDER *prov = (OSSL_PROVIDER *)handle;
  1445. /*
  1446. * If the uppermost 8 bits are non-zero, it's an OpenSSL library
  1447. * error and will be treated as such. Otherwise, it's a new style
  1448. * provider error and will be treated as such.
  1449. */
  1450. if (ERR_GET_LIB(reason) != 0) {
  1451. ERR_vset_error(ERR_GET_LIB(reason), ERR_GET_REASON(reason), fmt, args);
  1452. } else {
  1453. ERR_vset_error(prov->error_lib, (int)reason, fmt, args);
  1454. }
  1455. }
  1456. static int core_set_error_mark(const OSSL_CORE_HANDLE *handle)
  1457. {
  1458. return ERR_set_mark();
  1459. }
  1460. static int core_clear_last_error_mark(const OSSL_CORE_HANDLE *handle)
  1461. {
  1462. return ERR_clear_last_mark();
  1463. }
  1464. static int core_pop_error_to_mark(const OSSL_CORE_HANDLE *handle)
  1465. {
  1466. return ERR_pop_to_mark();
  1467. }
  1468. static int core_obj_add_sigid(const OSSL_CORE_HANDLE *prov,
  1469. const char *sign_name, const char *digest_name,
  1470. const char *pkey_name)
  1471. {
  1472. int sign_nid = OBJ_txt2nid(sign_name);
  1473. int digest_nid = OBJ_txt2nid(digest_name);
  1474. int pkey_nid = OBJ_txt2nid(pkey_name);
  1475. if (sign_nid == NID_undef)
  1476. return 0;
  1477. /*
  1478. * Check if it already exists. This is a success if so (even if we don't
  1479. * have nids for the digest/pkey)
  1480. */
  1481. if (OBJ_find_sigid_algs(sign_nid, NULL, NULL))
  1482. return 1;
  1483. if (digest_nid == NID_undef
  1484. || pkey_nid == NID_undef)
  1485. return 0;
  1486. return OBJ_add_sigid(sign_nid, digest_nid, pkey_nid);
  1487. }
  1488. static int core_obj_create(const OSSL_CORE_HANDLE *prov, const char *oid,
  1489. const char *sn, const char *ln)
  1490. {
  1491. /* Check if it already exists and create it if not */
  1492. return OBJ_txt2nid(oid) != NID_undef
  1493. || OBJ_create(oid, sn, ln) != NID_undef;
  1494. }
  1495. #endif /* FIPS_MODULE */
  1496. /*
  1497. * Functions provided by the core.
  1498. */
  1499. static const OSSL_DISPATCH core_dispatch_[] = {
  1500. { OSSL_FUNC_CORE_GETTABLE_PARAMS, (void (*)(void))core_gettable_params },
  1501. { OSSL_FUNC_CORE_GET_PARAMS, (void (*)(void))core_get_params },
  1502. { OSSL_FUNC_CORE_GET_LIBCTX, (void (*)(void))core_get_libctx },
  1503. { OSSL_FUNC_CORE_THREAD_START, (void (*)(void))core_thread_start },
  1504. #ifndef FIPS_MODULE
  1505. { OSSL_FUNC_CORE_NEW_ERROR, (void (*)(void))core_new_error },
  1506. { OSSL_FUNC_CORE_SET_ERROR_DEBUG, (void (*)(void))core_set_error_debug },
  1507. { OSSL_FUNC_CORE_VSET_ERROR, (void (*)(void))core_vset_error },
  1508. { OSSL_FUNC_CORE_SET_ERROR_MARK, (void (*)(void))core_set_error_mark },
  1509. { OSSL_FUNC_CORE_CLEAR_LAST_ERROR_MARK,
  1510. (void (*)(void))core_clear_last_error_mark },
  1511. { OSSL_FUNC_CORE_POP_ERROR_TO_MARK, (void (*)(void))core_pop_error_to_mark },
  1512. { OSSL_FUNC_BIO_NEW_FILE, (void (*)(void))ossl_core_bio_new_file },
  1513. { OSSL_FUNC_BIO_NEW_MEMBUF, (void (*)(void))ossl_core_bio_new_mem_buf },
  1514. { OSSL_FUNC_BIO_READ_EX, (void (*)(void))ossl_core_bio_read_ex },
  1515. { OSSL_FUNC_BIO_WRITE_EX, (void (*)(void))ossl_core_bio_write_ex },
  1516. { OSSL_FUNC_BIO_GETS, (void (*)(void))ossl_core_bio_gets },
  1517. { OSSL_FUNC_BIO_PUTS, (void (*)(void))ossl_core_bio_puts },
  1518. { OSSL_FUNC_BIO_CTRL, (void (*)(void))ossl_core_bio_ctrl },
  1519. { OSSL_FUNC_BIO_UP_REF, (void (*)(void))ossl_core_bio_up_ref },
  1520. { OSSL_FUNC_BIO_FREE, (void (*)(void))ossl_core_bio_free },
  1521. { OSSL_FUNC_BIO_VPRINTF, (void (*)(void))ossl_core_bio_vprintf },
  1522. { OSSL_FUNC_BIO_VSNPRINTF, (void (*)(void))BIO_vsnprintf },
  1523. { OSSL_FUNC_SELF_TEST_CB, (void (*)(void))OSSL_SELF_TEST_get_callback },
  1524. { OSSL_FUNC_GET_ENTROPY, (void (*)(void))ossl_rand_get_entropy },
  1525. { OSSL_FUNC_CLEANUP_ENTROPY, (void (*)(void))ossl_rand_cleanup_entropy },
  1526. { OSSL_FUNC_GET_NONCE, (void (*)(void))ossl_rand_get_nonce },
  1527. { OSSL_FUNC_CLEANUP_NONCE, (void (*)(void))ossl_rand_cleanup_nonce },
  1528. #endif
  1529. { OSSL_FUNC_CRYPTO_MALLOC, (void (*)(void))CRYPTO_malloc },
  1530. { OSSL_FUNC_CRYPTO_ZALLOC, (void (*)(void))CRYPTO_zalloc },
  1531. { OSSL_FUNC_CRYPTO_FREE, (void (*)(void))CRYPTO_free },
  1532. { OSSL_FUNC_CRYPTO_CLEAR_FREE, (void (*)(void))CRYPTO_clear_free },
  1533. { OSSL_FUNC_CRYPTO_REALLOC, (void (*)(void))CRYPTO_realloc },
  1534. { OSSL_FUNC_CRYPTO_CLEAR_REALLOC, (void (*)(void))CRYPTO_clear_realloc },
  1535. { OSSL_FUNC_CRYPTO_SECURE_MALLOC, (void (*)(void))CRYPTO_secure_malloc },
  1536. { OSSL_FUNC_CRYPTO_SECURE_ZALLOC, (void (*)(void))CRYPTO_secure_zalloc },
  1537. { OSSL_FUNC_CRYPTO_SECURE_FREE, (void (*)(void))CRYPTO_secure_free },
  1538. { OSSL_FUNC_CRYPTO_SECURE_CLEAR_FREE,
  1539. (void (*)(void))CRYPTO_secure_clear_free },
  1540. { OSSL_FUNC_CRYPTO_SECURE_ALLOCATED,
  1541. (void (*)(void))CRYPTO_secure_allocated },
  1542. { OSSL_FUNC_OPENSSL_CLEANSE, (void (*)(void))OPENSSL_cleanse },
  1543. #ifndef FIPS_MODULE
  1544. { OSSL_FUNC_PROVIDER_REGISTER_CHILD_CB,
  1545. (void (*)(void))ossl_provider_register_child_cb },
  1546. { OSSL_FUNC_PROVIDER_DEREGISTER_CHILD_CB,
  1547. (void (*)(void))ossl_provider_deregister_child_cb },
  1548. { OSSL_FUNC_PROVIDER_NAME,
  1549. (void (*)(void))OSSL_PROVIDER_get0_name },
  1550. { OSSL_FUNC_PROVIDER_GET0_PROVIDER_CTX,
  1551. (void (*)(void))OSSL_PROVIDER_get0_provider_ctx },
  1552. { OSSL_FUNC_PROVIDER_GET0_DISPATCH,
  1553. (void (*)(void))OSSL_PROVIDER_get0_dispatch },
  1554. { OSSL_FUNC_PROVIDER_UP_REF,
  1555. (void (*)(void))provider_up_ref_intern },
  1556. { OSSL_FUNC_PROVIDER_FREE,
  1557. (void (*)(void))provider_free_intern },
  1558. { OSSL_FUNC_CORE_OBJ_ADD_SIGID, (void (*)(void))core_obj_add_sigid },
  1559. { OSSL_FUNC_CORE_OBJ_CREATE, (void (*)(void))core_obj_create },
  1560. #endif
  1561. { 0, NULL }
  1562. };
  1563. static const OSSL_DISPATCH *core_dispatch = core_dispatch_;