Coverage Report

Created: 2025-12-31 06:58

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