context.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  1. /*
  2. * Copyright 2019-2025 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 "crypto/cryptlib.h"
  10. #include <openssl/conf.h>
  11. #include "internal/thread_once.h"
  12. #include "internal/property.h"
  13. #include "internal/core.h"
  14. #include "internal/bio.h"
  15. #include "internal/provider.h"
  16. #include "crypto/decoder.h"
  17. #include "crypto/context.h"
  18. struct ossl_lib_ctx_st {
  19. CRYPTO_RWLOCK *lock, *rand_crngt_lock;
  20. OSSL_EX_DATA_GLOBAL global;
  21. void *property_string_data;
  22. void *evp_method_store;
  23. void *provider_store;
  24. void *namemap;
  25. void *property_defns;
  26. void *global_properties;
  27. void *drbg;
  28. void *drbg_nonce;
  29. CRYPTO_THREAD_LOCAL rcu_local_key;
  30. #ifndef FIPS_MODULE
  31. void *provider_conf;
  32. void *bio_core;
  33. void *child_provider;
  34. OSSL_METHOD_STORE *decoder_store;
  35. void *decoder_cache;
  36. OSSL_METHOD_STORE *encoder_store;
  37. OSSL_METHOD_STORE *store_loader_store;
  38. void *self_test_cb;
  39. #endif
  40. #if defined(OPENSSL_THREADS)
  41. void *threads;
  42. #endif
  43. void *rand_crngt;
  44. #ifdef FIPS_MODULE
  45. void *thread_event_handler;
  46. void *fips_prov;
  47. #endif
  48. unsigned int ischild:1;
  49. };
  50. int ossl_lib_ctx_write_lock(OSSL_LIB_CTX *ctx)
  51. {
  52. if ((ctx = ossl_lib_ctx_get_concrete(ctx)) == NULL)
  53. return 0;
  54. return CRYPTO_THREAD_write_lock(ctx->lock);
  55. }
  56. int ossl_lib_ctx_read_lock(OSSL_LIB_CTX *ctx)
  57. {
  58. if ((ctx = ossl_lib_ctx_get_concrete(ctx)) == NULL)
  59. return 0;
  60. return CRYPTO_THREAD_read_lock(ctx->lock);
  61. }
  62. int ossl_lib_ctx_unlock(OSSL_LIB_CTX *ctx)
  63. {
  64. if ((ctx = ossl_lib_ctx_get_concrete(ctx)) == NULL)
  65. return 0;
  66. return CRYPTO_THREAD_unlock(ctx->lock);
  67. }
  68. int ossl_lib_ctx_is_child(OSSL_LIB_CTX *ctx)
  69. {
  70. ctx = ossl_lib_ctx_get_concrete(ctx);
  71. if (ctx == NULL)
  72. return 0;
  73. return ctx->ischild;
  74. }
  75. static void context_deinit_objs(OSSL_LIB_CTX *ctx);
  76. static int context_init(OSSL_LIB_CTX *ctx)
  77. {
  78. int exdata_done = 0;
  79. if (!CRYPTO_THREAD_init_local(&ctx->rcu_local_key, NULL))
  80. return 0;
  81. ctx->lock = CRYPTO_THREAD_lock_new();
  82. if (ctx->lock == NULL)
  83. goto err;
  84. ctx->rand_crngt_lock = CRYPTO_THREAD_lock_new();
  85. if (ctx->rand_crngt_lock == NULL)
  86. goto err;
  87. /* Initialize ex_data. */
  88. if (!ossl_do_ex_data_init(ctx))
  89. goto err;
  90. exdata_done = 1;
  91. /* P2. We want evp_method_store to be cleaned up before the provider store */
  92. ctx->evp_method_store = ossl_method_store_new(ctx);
  93. if (ctx->evp_method_store == NULL)
  94. goto err;
  95. #ifndef FIPS_MODULE
  96. /* P2. Must be freed before the provider store is freed */
  97. ctx->provider_conf = ossl_prov_conf_ctx_new(ctx);
  98. if (ctx->provider_conf == NULL)
  99. goto err;
  100. #endif
  101. /* P2. */
  102. ctx->drbg = ossl_rand_ctx_new(ctx);
  103. if (ctx->drbg == NULL)
  104. goto err;
  105. #ifndef FIPS_MODULE
  106. /*
  107. * P2. We want decoder_store/decoder_cache to be cleaned up before the
  108. * provider store
  109. */
  110. ctx->decoder_store = ossl_method_store_new(ctx);
  111. if (ctx->decoder_store == NULL)
  112. goto err;
  113. ctx->decoder_cache = ossl_decoder_cache_new(ctx);
  114. if (ctx->decoder_cache == NULL)
  115. goto err;
  116. /* P2. We want encoder_store to be cleaned up before the provider store */
  117. ctx->encoder_store = ossl_method_store_new(ctx);
  118. if (ctx->encoder_store == NULL)
  119. goto err;
  120. /* P2. We want loader_store to be cleaned up before the provider store */
  121. ctx->store_loader_store = ossl_method_store_new(ctx);
  122. if (ctx->store_loader_store == NULL)
  123. goto err;
  124. #endif
  125. /* P1. Needs to be freed before the child provider data is freed */
  126. ctx->provider_store = ossl_provider_store_new(ctx);
  127. if (ctx->provider_store == NULL)
  128. goto err;
  129. /* Default priority. */
  130. ctx->property_string_data = ossl_property_string_data_new(ctx);
  131. if (ctx->property_string_data == NULL)
  132. goto err;
  133. ctx->namemap = ossl_stored_namemap_new(ctx);
  134. if (ctx->namemap == NULL)
  135. goto err;
  136. ctx->property_defns = ossl_property_defns_new(ctx);
  137. if (ctx->property_defns == NULL)
  138. goto err;
  139. ctx->global_properties = ossl_ctx_global_properties_new(ctx);
  140. if (ctx->global_properties == NULL)
  141. goto err;
  142. #ifndef FIPS_MODULE
  143. ctx->bio_core = ossl_bio_core_globals_new(ctx);
  144. if (ctx->bio_core == NULL)
  145. goto err;
  146. #endif
  147. ctx->drbg_nonce = ossl_prov_drbg_nonce_ctx_new(ctx);
  148. if (ctx->drbg_nonce == NULL)
  149. goto err;
  150. #ifndef FIPS_MODULE
  151. ctx->self_test_cb = ossl_self_test_set_callback_new(ctx);
  152. if (ctx->self_test_cb == NULL)
  153. goto err;
  154. #endif
  155. #ifdef FIPS_MODULE
  156. ctx->thread_event_handler = ossl_thread_event_ctx_new(ctx);
  157. if (ctx->thread_event_handler == NULL)
  158. goto err;
  159. ctx->fips_prov = ossl_fips_prov_ossl_ctx_new(ctx);
  160. if (ctx->fips_prov == NULL)
  161. goto err;
  162. #endif
  163. #ifndef OPENSSL_NO_THREAD_POOL
  164. ctx->threads = ossl_threads_ctx_new(ctx);
  165. if (ctx->threads == NULL)
  166. goto err;
  167. #endif
  168. /* Low priority. */
  169. #ifndef FIPS_MODULE
  170. ctx->child_provider = ossl_child_prov_ctx_new(ctx);
  171. if (ctx->child_provider == NULL)
  172. goto err;
  173. #endif
  174. /* Everything depends on properties, so we also pre-initialise that */
  175. if (!ossl_property_parse_init(ctx))
  176. goto err;
  177. return 1;
  178. err:
  179. context_deinit_objs(ctx);
  180. if (exdata_done)
  181. ossl_crypto_cleanup_all_ex_data_int(ctx);
  182. CRYPTO_THREAD_lock_free(ctx->rand_crngt_lock);
  183. CRYPTO_THREAD_lock_free(ctx->lock);
  184. CRYPTO_THREAD_cleanup_local(&ctx->rcu_local_key);
  185. memset(ctx, '\0', sizeof(*ctx));
  186. return 0;
  187. }
  188. static void context_deinit_objs(OSSL_LIB_CTX *ctx)
  189. {
  190. /* P2. We want evp_method_store to be cleaned up before the provider store */
  191. if (ctx->evp_method_store != NULL) {
  192. ossl_method_store_free(ctx->evp_method_store);
  193. ctx->evp_method_store = NULL;
  194. }
  195. /* P2. */
  196. if (ctx->drbg != NULL) {
  197. ossl_rand_ctx_free(ctx->drbg);
  198. ctx->drbg = NULL;
  199. }
  200. #ifndef FIPS_MODULE
  201. /* P2. */
  202. if (ctx->provider_conf != NULL) {
  203. ossl_prov_conf_ctx_free(ctx->provider_conf);
  204. ctx->provider_conf = NULL;
  205. }
  206. /*
  207. * P2. We want decoder_store/decoder_cache to be cleaned up before the
  208. * provider store
  209. */
  210. if (ctx->decoder_store != NULL) {
  211. ossl_method_store_free(ctx->decoder_store);
  212. ctx->decoder_store = NULL;
  213. }
  214. if (ctx->decoder_cache != NULL) {
  215. ossl_decoder_cache_free(ctx->decoder_cache);
  216. ctx->decoder_cache = NULL;
  217. }
  218. /* P2. We want encoder_store to be cleaned up before the provider store */
  219. if (ctx->encoder_store != NULL) {
  220. ossl_method_store_free(ctx->encoder_store);
  221. ctx->encoder_store = NULL;
  222. }
  223. /* P2. We want loader_store to be cleaned up before the provider store */
  224. if (ctx->store_loader_store != NULL) {
  225. ossl_method_store_free(ctx->store_loader_store);
  226. ctx->store_loader_store = NULL;
  227. }
  228. #endif
  229. /* P1. Needs to be freed before the child provider data is freed */
  230. if (ctx->provider_store != NULL) {
  231. ossl_provider_store_free(ctx->provider_store);
  232. ctx->provider_store = NULL;
  233. }
  234. /* Default priority. */
  235. if (ctx->property_string_data != NULL) {
  236. ossl_property_string_data_free(ctx->property_string_data);
  237. ctx->property_string_data = NULL;
  238. }
  239. if (ctx->namemap != NULL) {
  240. ossl_stored_namemap_free(ctx->namemap);
  241. ctx->namemap = NULL;
  242. }
  243. if (ctx->property_defns != NULL) {
  244. ossl_property_defns_free(ctx->property_defns);
  245. ctx->property_defns = NULL;
  246. }
  247. if (ctx->global_properties != NULL) {
  248. ossl_ctx_global_properties_free(ctx->global_properties);
  249. ctx->global_properties = NULL;
  250. }
  251. #ifndef FIPS_MODULE
  252. if (ctx->bio_core != NULL) {
  253. ossl_bio_core_globals_free(ctx->bio_core);
  254. ctx->bio_core = NULL;
  255. }
  256. #endif
  257. if (ctx->drbg_nonce != NULL) {
  258. ossl_prov_drbg_nonce_ctx_free(ctx->drbg_nonce);
  259. ctx->drbg_nonce = NULL;
  260. }
  261. #ifndef FIPS_MODULE
  262. if (ctx->self_test_cb != NULL) {
  263. ossl_self_test_set_callback_free(ctx->self_test_cb);
  264. ctx->self_test_cb = NULL;
  265. }
  266. #endif
  267. if (ctx->rand_crngt != NULL) {
  268. ossl_rand_crng_ctx_free(ctx->rand_crngt);
  269. ctx->rand_crngt = NULL;
  270. }
  271. #ifdef FIPS_MODULE
  272. if (ctx->thread_event_handler != NULL) {
  273. ossl_thread_event_ctx_free(ctx->thread_event_handler);
  274. ctx->thread_event_handler = NULL;
  275. }
  276. if (ctx->fips_prov != NULL) {
  277. ossl_fips_prov_ossl_ctx_free(ctx->fips_prov);
  278. ctx->fips_prov = NULL;
  279. }
  280. #endif
  281. #ifndef OPENSSL_NO_THREAD_POOL
  282. if (ctx->threads != NULL) {
  283. ossl_threads_ctx_free(ctx->threads);
  284. ctx->threads = NULL;
  285. }
  286. #endif
  287. /* Low priority. */
  288. #ifndef FIPS_MODULE
  289. if (ctx->child_provider != NULL) {
  290. ossl_child_prov_ctx_free(ctx->child_provider);
  291. ctx->child_provider = NULL;
  292. }
  293. #endif
  294. }
  295. static int context_deinit(OSSL_LIB_CTX *ctx)
  296. {
  297. if (ctx == NULL)
  298. return 1;
  299. ossl_ctx_thread_stop(ctx);
  300. context_deinit_objs(ctx);
  301. ossl_crypto_cleanup_all_ex_data_int(ctx);
  302. CRYPTO_THREAD_lock_free(ctx->rand_crngt_lock);
  303. CRYPTO_THREAD_lock_free(ctx->lock);
  304. ctx->rand_crngt_lock = NULL;
  305. ctx->lock = NULL;
  306. CRYPTO_THREAD_cleanup_local(&ctx->rcu_local_key);
  307. return 1;
  308. }
  309. #ifndef FIPS_MODULE
  310. /* The default default context */
  311. static OSSL_LIB_CTX default_context_int;
  312. static CRYPTO_ONCE default_context_init = CRYPTO_ONCE_STATIC_INIT;
  313. static CRYPTO_THREAD_LOCAL default_context_thread_local;
  314. static int default_context_inited = 0;
  315. DEFINE_RUN_ONCE_STATIC(default_context_do_init)
  316. {
  317. if (!CRYPTO_THREAD_init_local(&default_context_thread_local, NULL))
  318. goto err;
  319. if (!context_init(&default_context_int))
  320. goto deinit_thread;
  321. default_context_inited = 1;
  322. return 1;
  323. deinit_thread:
  324. CRYPTO_THREAD_cleanup_local(&default_context_thread_local);
  325. err:
  326. return 0;
  327. }
  328. void ossl_lib_ctx_default_deinit(void)
  329. {
  330. if (!default_context_inited)
  331. return;
  332. context_deinit(&default_context_int);
  333. CRYPTO_THREAD_cleanup_local(&default_context_thread_local);
  334. default_context_inited = 0;
  335. }
  336. static OSSL_LIB_CTX *get_thread_default_context(void)
  337. {
  338. if (!RUN_ONCE(&default_context_init, default_context_do_init))
  339. return NULL;
  340. return CRYPTO_THREAD_get_local(&default_context_thread_local);
  341. }
  342. static OSSL_LIB_CTX *get_default_context(void)
  343. {
  344. OSSL_LIB_CTX *current_defctx = get_thread_default_context();
  345. if (current_defctx == NULL && default_context_inited)
  346. current_defctx = &default_context_int;
  347. return current_defctx;
  348. }
  349. static int set_default_context(OSSL_LIB_CTX *defctx)
  350. {
  351. if (defctx == &default_context_int)
  352. defctx = NULL;
  353. return CRYPTO_THREAD_set_local(&default_context_thread_local, defctx);
  354. }
  355. #endif
  356. OSSL_LIB_CTX *OSSL_LIB_CTX_new(void)
  357. {
  358. OSSL_LIB_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx));
  359. if (ctx != NULL && !context_init(ctx)) {
  360. OPENSSL_free(ctx);
  361. ctx = NULL;
  362. }
  363. return ctx;
  364. }
  365. #ifndef FIPS_MODULE
  366. OSSL_LIB_CTX *OSSL_LIB_CTX_new_from_dispatch(const OSSL_CORE_HANDLE *handle,
  367. const OSSL_DISPATCH *in)
  368. {
  369. OSSL_LIB_CTX *ctx = OSSL_LIB_CTX_new();
  370. if (ctx == NULL)
  371. return NULL;
  372. if (!ossl_bio_init_core(ctx, in)) {
  373. OSSL_LIB_CTX_free(ctx);
  374. return NULL;
  375. }
  376. return ctx;
  377. }
  378. OSSL_LIB_CTX *OSSL_LIB_CTX_new_child(const OSSL_CORE_HANDLE *handle,
  379. const OSSL_DISPATCH *in)
  380. {
  381. OSSL_LIB_CTX *ctx = OSSL_LIB_CTX_new_from_dispatch(handle, in);
  382. if (ctx == NULL)
  383. return NULL;
  384. if (!ossl_provider_init_as_child(ctx, handle, in)) {
  385. OSSL_LIB_CTX_free(ctx);
  386. return NULL;
  387. }
  388. ctx->ischild = 1;
  389. return ctx;
  390. }
  391. int OSSL_LIB_CTX_load_config(OSSL_LIB_CTX *ctx, const char *config_file)
  392. {
  393. return CONF_modules_load_file_ex(ctx, config_file, NULL, 0) > 0;
  394. }
  395. #endif
  396. void OSSL_LIB_CTX_free(OSSL_LIB_CTX *ctx)
  397. {
  398. if (ctx == NULL || ossl_lib_ctx_is_default(ctx))
  399. return;
  400. #ifndef FIPS_MODULE
  401. if (ctx->ischild)
  402. ossl_provider_deinit_child(ctx);
  403. #endif
  404. context_deinit(ctx);
  405. OPENSSL_free(ctx);
  406. }
  407. #ifndef FIPS_MODULE
  408. OSSL_LIB_CTX *OSSL_LIB_CTX_get0_global_default(void)
  409. {
  410. if (!RUN_ONCE(&default_context_init, default_context_do_init))
  411. return NULL;
  412. return &default_context_int;
  413. }
  414. OSSL_LIB_CTX *OSSL_LIB_CTX_set0_default(OSSL_LIB_CTX *libctx)
  415. {
  416. OSSL_LIB_CTX *current_defctx;
  417. if ((current_defctx = get_default_context()) != NULL) {
  418. if (libctx != NULL)
  419. set_default_context(libctx);
  420. return current_defctx;
  421. }
  422. return NULL;
  423. }
  424. void ossl_release_default_drbg_ctx(void)
  425. {
  426. /* early release of the DRBG in global default libctx */
  427. if (default_context_int.drbg != NULL) {
  428. ossl_rand_ctx_free(default_context_int.drbg);
  429. default_context_int.drbg = NULL;
  430. }
  431. }
  432. #endif
  433. OSSL_LIB_CTX *ossl_lib_ctx_get_concrete(OSSL_LIB_CTX *ctx)
  434. {
  435. #ifndef FIPS_MODULE
  436. if (ctx == NULL)
  437. return get_default_context();
  438. #endif
  439. return ctx;
  440. }
  441. int ossl_lib_ctx_is_default(OSSL_LIB_CTX *ctx)
  442. {
  443. #ifndef FIPS_MODULE
  444. if (ctx == NULL || ctx == get_default_context())
  445. return 1;
  446. #endif
  447. return 0;
  448. }
  449. int ossl_lib_ctx_is_global_default(OSSL_LIB_CTX *ctx)
  450. {
  451. #ifndef FIPS_MODULE
  452. if (ossl_lib_ctx_get_concrete(ctx) == &default_context_int)
  453. return 1;
  454. #endif
  455. return 0;
  456. }
  457. void *ossl_lib_ctx_get_data(OSSL_LIB_CTX *ctx, int index)
  458. {
  459. void *p;
  460. ctx = ossl_lib_ctx_get_concrete(ctx);
  461. if (ctx == NULL)
  462. return NULL;
  463. switch (index) {
  464. case OSSL_LIB_CTX_PROPERTY_STRING_INDEX:
  465. return ctx->property_string_data;
  466. case OSSL_LIB_CTX_EVP_METHOD_STORE_INDEX:
  467. return ctx->evp_method_store;
  468. case OSSL_LIB_CTX_PROVIDER_STORE_INDEX:
  469. return ctx->provider_store;
  470. case OSSL_LIB_CTX_NAMEMAP_INDEX:
  471. return ctx->namemap;
  472. case OSSL_LIB_CTX_PROPERTY_DEFN_INDEX:
  473. return ctx->property_defns;
  474. case OSSL_LIB_CTX_GLOBAL_PROPERTIES:
  475. return ctx->global_properties;
  476. case OSSL_LIB_CTX_DRBG_INDEX:
  477. return ctx->drbg;
  478. case OSSL_LIB_CTX_DRBG_NONCE_INDEX:
  479. return ctx->drbg_nonce;
  480. #ifndef FIPS_MODULE
  481. case OSSL_LIB_CTX_PROVIDER_CONF_INDEX:
  482. return ctx->provider_conf;
  483. case OSSL_LIB_CTX_BIO_CORE_INDEX:
  484. return ctx->bio_core;
  485. case OSSL_LIB_CTX_CHILD_PROVIDER_INDEX:
  486. return ctx->child_provider;
  487. case OSSL_LIB_CTX_DECODER_STORE_INDEX:
  488. return ctx->decoder_store;
  489. case OSSL_LIB_CTX_DECODER_CACHE_INDEX:
  490. return ctx->decoder_cache;
  491. case OSSL_LIB_CTX_ENCODER_STORE_INDEX:
  492. return ctx->encoder_store;
  493. case OSSL_LIB_CTX_STORE_LOADER_STORE_INDEX:
  494. return ctx->store_loader_store;
  495. case OSSL_LIB_CTX_SELF_TEST_CB_INDEX:
  496. return ctx->self_test_cb;
  497. #endif
  498. #ifndef OPENSSL_NO_THREAD_POOL
  499. case OSSL_LIB_CTX_THREAD_INDEX:
  500. return ctx->threads;
  501. #endif
  502. case OSSL_LIB_CTX_RAND_CRNGT_INDEX: {
  503. /*
  504. * rand_crngt must be lazily initialized because it calls into
  505. * libctx, so must not be called from context_init, else a deadlock
  506. * will occur.
  507. *
  508. * We use a separate lock because code called by the instantiation
  509. * of rand_crngt is liable to try and take the libctx lock.
  510. */
  511. if (CRYPTO_THREAD_read_lock(ctx->rand_crngt_lock) != 1)
  512. return NULL;
  513. if (ctx->rand_crngt == NULL) {
  514. CRYPTO_THREAD_unlock(ctx->rand_crngt_lock);
  515. if (CRYPTO_THREAD_write_lock(ctx->rand_crngt_lock) != 1)
  516. return NULL;
  517. if (ctx->rand_crngt == NULL)
  518. ctx->rand_crngt = ossl_rand_crng_ctx_new(ctx);
  519. }
  520. p = ctx->rand_crngt;
  521. CRYPTO_THREAD_unlock(ctx->rand_crngt_lock);
  522. return p;
  523. }
  524. #ifdef FIPS_MODULE
  525. case OSSL_LIB_CTX_THREAD_EVENT_HANDLER_INDEX:
  526. return ctx->thread_event_handler;
  527. case OSSL_LIB_CTX_FIPS_PROV_INDEX:
  528. return ctx->fips_prov;
  529. #endif
  530. default:
  531. return NULL;
  532. }
  533. }
  534. OSSL_EX_DATA_GLOBAL *ossl_lib_ctx_get_ex_data_global(OSSL_LIB_CTX *ctx)
  535. {
  536. ctx = ossl_lib_ctx_get_concrete(ctx);
  537. if (ctx == NULL)
  538. return NULL;
  539. return &ctx->global;
  540. }
  541. const char *ossl_lib_ctx_get_descriptor(OSSL_LIB_CTX *libctx)
  542. {
  543. #ifdef FIPS_MODULE
  544. return "FIPS internal library context";
  545. #else
  546. if (ossl_lib_ctx_is_global_default(libctx))
  547. return "Global default library context";
  548. if (ossl_lib_ctx_is_default(libctx))
  549. return "Thread-local default library context";
  550. return "Non-default library context";
  551. #endif
  552. }
  553. CRYPTO_THREAD_LOCAL *ossl_lib_ctx_get_rcukey(OSSL_LIB_CTX *libctx)
  554. {
  555. libctx = ossl_lib_ctx_get_concrete(libctx);
  556. if (libctx == NULL)
  557. return NULL;
  558. return &libctx->rcu_local_key;
  559. }