Coverage Report

Created: 2025-08-28 07:07

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