Coverage Report

Created: 2026-02-22 06:10

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