Coverage Report

Created: 2024-05-21 06:52

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