context.c 16 KB

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