context.c 17 KB

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