context.c 17 KB

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