Coverage Report

Created: 2024-11-21 07:03

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