Coverage Report

Created: 2023-06-08 06:41

/src/openssl/crypto/evp/evp_fetch.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 2019-2022 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 <stddef.h>
11
#include <openssl/types.h>
12
#include <openssl/evp.h>
13
#include <openssl/core.h>
14
#include "internal/cryptlib.h"
15
#include "internal/thread_once.h"
16
#include "internal/property.h"
17
#include "internal/core.h"
18
#include "internal/provider.h"
19
#include "internal/namemap.h"
20
#include "crypto/evp.h"    /* evp_local.h needs it */
21
#include "evp_local.h"
22
23
81.4k
#define NAME_SEPARATOR ':'
24
25
/* Data to be passed through ossl_method_construct() */
26
struct evp_method_data_st {
27
    OSSL_LIB_CTX *libctx;
28
    int operation_id;            /* For get_evp_method_from_store() */
29
    int name_id;                 /* For get_evp_method_from_store() */
30
    const char *names;           /* For get_evp_method_from_store() */
31
    const char *propquery;       /* For get_evp_method_from_store() */
32
33
    OSSL_METHOD_STORE *tmp_store; /* For get_tmp_evp_method_store() */
34
35
    unsigned int flag_construct_error_occurred : 1;
36
37
    void *(*method_from_algorithm)(int name_id, const OSSL_ALGORITHM *,
38
                                   OSSL_PROVIDER *);
39
    int (*refcnt_up_method)(void *method);
40
    void (*destruct_method)(void *method);
41
};
42
43
/*
44
 * Generic routines to fetch / create EVP methods with ossl_method_construct()
45
 */
46
static void *get_tmp_evp_method_store(void *data)
47
0
{
48
0
    struct evp_method_data_st *methdata = data;
49
50
0
    if (methdata->tmp_store == NULL)
51
0
        methdata->tmp_store = ossl_method_store_new(methdata->libctx);
52
0
    return methdata->tmp_store;
53
0
}
54
55
 static void dealloc_tmp_evp_method_store(void *store)
56
949k
{
57
949k
    if (store != NULL)
58
0
        ossl_method_store_free(store);
59
949k
}
60
61
static OSSL_METHOD_STORE *get_evp_method_store(OSSL_LIB_CTX *libctx)
62
1.48M
{
63
1.48M
    return ossl_lib_ctx_get_data(libctx, OSSL_LIB_CTX_EVP_METHOD_STORE_INDEX);
64
1.48M
}
65
66
static int reserve_evp_method_store(void *store, void *data)
67
245k
{
68
245k
    struct evp_method_data_st *methdata = data;
69
70
245k
    if (store == NULL
71
245k
        && (store = get_evp_method_store(methdata->libctx)) == NULL)
72
0
        return 0;
73
74
245k
    return ossl_method_lock_store(store);
75
245k
}
76
77
static int unreserve_evp_method_store(void *store, void *data)
78
245k
{
79
245k
    struct evp_method_data_st *methdata = data;
80
81
245k
    if (store == NULL
82
245k
        && (store = get_evp_method_store(methdata->libctx)) == NULL)
83
0
        return 0;
84
85
245k
    return ossl_method_unlock_store(store);
86
245k
}
87
88
/*
89
 * To identify the method in the EVP method store, we mix the name identity
90
 * with the operation identity, under the assumption that we don't have more
91
 * than 2^23 names or more than 2^8 operation types.
92
 *
93
 * The resulting identity is a 31-bit integer, composed like this:
94
 *
95
 * +---------23 bits--------+-8 bits-+
96
 * |      name identity     | op id  |
97
 * +------------------------+--------+
98
 *
99
 * We limit this composite number to 31 bits, thus leaving the top uint32_t
100
 * bit always zero, to avoid negative sign extension when downshifting after
101
 * this number happens to be passed to an int (which happens as soon as it's
102
 * passed to ossl_method_store_cache_set(), and it's in that form that it
103
 * gets passed along to filter_on_operation_id(), defined further down.
104
 */
105
1.97M
#define METHOD_ID_OPERATION_MASK        0x000000FF
106
#define METHOD_ID_OPERATION_MAX         ((1 << 8) - 1)
107
900k
#define METHOD_ID_NAME_MASK             0x7FFFFF00
108
900k
#define METHOD_ID_NAME_OFFSET           8
109
#define METHOD_ID_NAME_MAX              ((1 << 23) - 1)
110
static uint32_t evp_method_id(int name_id, unsigned int operation_id)
111
900k
{
112
900k
    if (!ossl_assert(name_id > 0 && name_id <= METHOD_ID_NAME_MAX)
113
900k
        || !ossl_assert(operation_id > 0
114
900k
                        && operation_id <= METHOD_ID_OPERATION_MAX))
115
0
        return 0;
116
900k
    return (((name_id << METHOD_ID_NAME_OFFSET) & METHOD_ID_NAME_MASK)
117
900k
            | (operation_id & METHOD_ID_OPERATION_MASK));
118
900k
}
119
120
static void *get_evp_method_from_store(void *store, const OSSL_PROVIDER **prov,
121
                                       void *data)
122
122k
{
123
122k
    struct evp_method_data_st *methdata = data;
124
122k
    void *method = NULL;
125
122k
    int name_id;
126
122k
    uint32_t meth_id;
127
128
    /*
129
     * get_evp_method_from_store() is only called to try and get the method
130
     * that evp_generic_fetch() is asking for, and the operation id as well
131
     * as the name or name id are passed via methdata.
132
     */
133
122k
    if ((name_id = methdata->name_id) == 0 && methdata->names != NULL) {
134
80.9k
        OSSL_NAMEMAP *namemap = ossl_namemap_stored(methdata->libctx);
135
80.9k
        const char *names = methdata->names;
136
80.9k
        const char *q = strchr(names, NAME_SEPARATOR);
137
80.9k
        size_t l = (q == NULL ? strlen(names) : (size_t)(q - names));
138
139
80.9k
        if (namemap == 0)
140
0
            return NULL;
141
80.9k
        name_id = ossl_namemap_name2num_n(namemap, names, l);
142
80.9k
    }
143
144
122k
    if (name_id == 0
145
122k
        || (meth_id = evp_method_id(name_id, methdata->operation_id)) == 0)
146
85.7k
        return NULL;
147
148
36.8k
    if (store == NULL
149
36.8k
        && (store = get_evp_method_store(methdata->libctx)) == NULL)
150
0
        return NULL;
151
152
36.8k
    if (!ossl_method_store_fetch(store, meth_id, methdata->propquery, prov,
153
36.8k
                                 &method))
154
36.8k
        return NULL;
155
47
    return method;
156
36.8k
}
157
158
static int put_evp_method_in_store(void *store, void *method,
159
                                   const OSSL_PROVIDER *prov,
160
                                   const char *names, const char *propdef,
161
                                   void *data)
162
224
{
163
224
    struct evp_method_data_st *methdata = data;
164
224
    OSSL_NAMEMAP *namemap;
165
224
    int name_id;
166
224
    uint32_t meth_id;
167
224
    size_t l = 0;
168
169
    /*
170
     * put_evp_method_in_store() is only called with an EVP method that was
171
     * successfully created by construct_method() below, which means that
172
     * all the names should already be stored in the namemap with the same
173
     * numeric identity, so just use the first to get that identity.
174
     */
175
224
    if (names != NULL) {
176
224
        const char *q = strchr(names, NAME_SEPARATOR);
177
178
224
        l = (q == NULL ? strlen(names) : (size_t)(q - names));
179
224
    }
180
181
224
    if ((namemap = ossl_namemap_stored(methdata->libctx)) == NULL
182
224
        || (name_id = ossl_namemap_name2num_n(namemap, names, l)) == 0
183
224
        || (meth_id = evp_method_id(name_id, methdata->operation_id)) == 0)
184
0
        return 0;
185
186
224
    if (store == NULL
187
224
        && (store = get_evp_method_store(methdata->libctx)) == NULL)
188
0
        return 0;
189
190
224
    return ossl_method_store_add(store, prov, meth_id, propdef, method,
191
224
                                 methdata->refcnt_up_method,
192
224
                                 methdata->destruct_method);
193
224
}
194
195
/*
196
 * The core fetching functionality passes the name of the implementation.
197
 * This function is responsible to getting an identity number for it.
198
 */
199
static void *construct_evp_method(const OSSL_ALGORITHM *algodef,
200
                                  OSSL_PROVIDER *prov, void *data)
201
224
{
202
    /*
203
     * This function is only called if get_evp_method_from_store() returned
204
     * NULL, so it's safe to say that of all the spots to create a new
205
     * namemap entry, this is it.  Should the name already exist there, we
206
     * know that ossl_namemap_add_name() will return its corresponding
207
     * number.
208
     */
209
224
    struct evp_method_data_st *methdata = data;
210
224
    OSSL_LIB_CTX *libctx = ossl_provider_libctx(prov);
211
224
    OSSL_NAMEMAP *namemap = ossl_namemap_stored(libctx);
212
224
    const char *names = algodef->algorithm_names;
213
224
    int name_id = ossl_namemap_add_names(namemap, 0, names, NAME_SEPARATOR);
214
224
    void *method;
215
216
224
    if (name_id == 0)
217
0
        return NULL;
218
219
224
    method = methdata->method_from_algorithm(name_id, algodef, prov);
220
221
    /*
222
     * Flag to indicate that there was actual construction errors.  This
223
     * helps inner_evp_generic_fetch() determine what error it should
224
     * record on inaccessible algorithms.
225
     */
226
224
    if (method == NULL)
227
0
        methdata->flag_construct_error_occurred = 1;
228
229
224
    return method;
230
224
}
231
232
static void destruct_evp_method(void *method, void *data)
233
224
{
234
224
    struct evp_method_data_st *methdata = data;
235
236
224
    methdata->destruct_method(method);
237
224
}
238
239
static void *
240
inner_evp_generic_fetch(struct evp_method_data_st *methdata,
241
                        OSSL_PROVIDER *prov, int operation_id,
242
                        const char *name, const char *properties,
243
                        void *(*new_method)(int name_id,
244
                                            const OSSL_ALGORITHM *algodef,
245
                                            OSSL_PROVIDER *prov),
246
                        int (*up_ref_method)(void *),
247
                        void (*free_method)(void *))
248
949k
{
249
949k
    OSSL_METHOD_STORE *store = get_evp_method_store(methdata->libctx);
250
949k
    OSSL_NAMEMAP *namemap = ossl_namemap_stored(methdata->libctx);
251
949k
    const char *const propq = properties != NULL ? properties : "";
252
949k
    uint32_t meth_id = 0;
253
949k
    void *method = NULL;
254
949k
    int unsupported, name_id;
255
256
949k
    if (store == NULL || namemap == NULL) {
257
0
        ERR_raise(ERR_LIB_EVP, ERR_R_PASSED_INVALID_ARGUMENT);
258
0
        return NULL;
259
0
    }
260
261
    /*
262
     * If there's ever an operation_id == 0 passed, we have an internal
263
     * programming error.
264
     */
265
949k
    if (!ossl_assert(operation_id > 0)) {
266
0
        ERR_raise(ERR_LIB_EVP, ERR_R_INTERNAL_ERROR);
267
0
        return NULL;
268
0
    }
269
270
    /* If we haven't received a name id yet, try to get one for the name */
271
949k
    name_id = name != NULL ? ossl_namemap_name2num(namemap, name) : 0;
272
273
    /*
274
     * If we have a name id, calculate a method id with evp_method_id().
275
     *
276
     * evp_method_id returns 0 if we have too many operations (more than
277
     * about 2^8) or too many names (more than about 2^24).  In that case,
278
     * we can't create any new method.
279
     * For all intents and purposes, this is an internal error.
280
     */
281
949k
    if (name_id != 0 && (meth_id = evp_method_id(name_id, operation_id)) == 0) {
282
0
        ERR_raise(ERR_LIB_EVP, ERR_R_INTERNAL_ERROR);
283
0
        return NULL;
284
0
    }
285
286
    /*
287
     * If we haven't found the name yet, chances are that the algorithm to
288
     * be fetched is unsupported.
289
     */
290
949k
    unsupported = name_id == 0;
291
292
949k
    if (meth_id == 0
293
949k
        || !ossl_method_store_cache_get(store, prov, meth_id, propq, &method)) {
294
122k
        OSSL_METHOD_CONSTRUCT_METHOD mcm = {
295
122k
            get_tmp_evp_method_store,
296
122k
            reserve_evp_method_store,
297
122k
            unreserve_evp_method_store,
298
122k
            get_evp_method_from_store,
299
122k
            put_evp_method_in_store,
300
122k
            construct_evp_method,
301
122k
            destruct_evp_method
302
122k
        };
303
304
122k
        methdata->operation_id = operation_id;
305
122k
        methdata->name_id = name_id;
306
122k
        methdata->names = name;
307
122k
        methdata->propquery = propq;
308
122k
        methdata->method_from_algorithm = new_method;
309
122k
        methdata->refcnt_up_method = up_ref_method;
310
122k
        methdata->destruct_method = free_method;
311
122k
        methdata->flag_construct_error_occurred = 0;
312
122k
        if ((method = ossl_method_construct(methdata->libctx, operation_id,
313
122k
                                            &prov, 0 /* !force_cache */,
314
122k
                                            &mcm, methdata)) != NULL) {
315
            /*
316
             * If construction did create a method for us, we know that
317
             * there is a correct name_id and meth_id, since those have
318
             * already been calculated in get_evp_method_from_store() and
319
             * put_evp_method_in_store() above.
320
             */
321
47
            if (name_id == 0)
322
1
                name_id = ossl_namemap_name2num(namemap, name);
323
47
            meth_id = evp_method_id(name_id, operation_id);
324
47
            if (name_id != 0)
325
47
                ossl_method_store_cache_set(store, prov, meth_id, propq,
326
47
                                            method, up_ref_method, free_method);
327
47
        }
328
329
        /*
330
         * If we never were in the constructor, the algorithm to be fetched
331
         * is unsupported.
332
         */
333
122k
        unsupported = !methdata->flag_construct_error_occurred;
334
122k
    }
335
336
949k
    if ((name_id != 0 || name != NULL) && method == NULL) {
337
117k
        int code = unsupported ? ERR_R_UNSUPPORTED : ERR_R_FETCH_FAILED;
338
339
117k
        if (name == NULL)
340
0
            name = ossl_namemap_num2name(namemap, name_id, 0);
341
117k
        ERR_raise_data(ERR_LIB_EVP, code,
342
117k
                       "%s, Algorithm (%s : %d), Properties (%s)",
343
117k
                       ossl_lib_ctx_get_descriptor(methdata->libctx),
344
117k
                       name == NULL ? "<null>" : name, name_id,
345
117k
                       properties == NULL ? "<null>" : properties);
346
117k
    }
347
348
949k
    return method;
349
949k
}
350
351
void *evp_generic_fetch(OSSL_LIB_CTX *libctx, int operation_id,
352
                        const char *name, const char *properties,
353
                        void *(*new_method)(int name_id,
354
                                            const OSSL_ALGORITHM *algodef,
355
                                            OSSL_PROVIDER *prov),
356
                        int (*up_ref_method)(void *),
357
                        void (*free_method)(void *))
358
939k
{
359
939k
    struct evp_method_data_st methdata;
360
939k
    void *method;
361
362
939k
    methdata.libctx = libctx;
363
939k
    methdata.tmp_store = NULL;
364
939k
    method = inner_evp_generic_fetch(&methdata, NULL, operation_id,
365
939k
                                     name, properties,
366
939k
                                     new_method, up_ref_method, free_method);
367
939k
    dealloc_tmp_evp_method_store(methdata.tmp_store);
368
939k
    return method;
369
939k
}
370
371
/*
372
 * evp_generic_fetch_from_prov() is special, and only returns methods from
373
 * the given provider.
374
 * This is meant to be used when one method needs to fetch an associated
375
 * method.
376
 */
377
void *evp_generic_fetch_from_prov(OSSL_PROVIDER *prov, int operation_id,
378
                                  const char *name, const char *properties,
379
                                  void *(*new_method)(int name_id,
380
                                                      const OSSL_ALGORITHM *algodef,
381
                                                      OSSL_PROVIDER *prov),
382
                                  int (*up_ref_method)(void *),
383
                                  void (*free_method)(void *))
384
5.14k
{
385
5.14k
    struct evp_method_data_st methdata;
386
5.14k
    void *method;
387
388
5.14k
    methdata.libctx = ossl_provider_libctx(prov);
389
5.14k
    methdata.tmp_store = NULL;
390
5.14k
    method = inner_evp_generic_fetch(&methdata, prov, operation_id,
391
5.14k
                                     name, properties,
392
5.14k
                                     new_method, up_ref_method, free_method);
393
5.14k
    dealloc_tmp_evp_method_store(methdata.tmp_store);
394
5.14k
    return method;
395
5.14k
}
396
397
int evp_method_store_cache_flush(OSSL_LIB_CTX *libctx)
398
2
{
399
2
    OSSL_METHOD_STORE *store = get_evp_method_store(libctx);
400
401
2
    if (store != NULL)
402
2
        return ossl_method_store_cache_flush_all(store);
403
0
    return 1;
404
2
}
405
406
int evp_method_store_remove_all_provided(const OSSL_PROVIDER *prov)
407
0
{
408
0
    OSSL_LIB_CTX *libctx = ossl_provider_libctx(prov);
409
0
    OSSL_METHOD_STORE *store = get_evp_method_store(libctx);
410
411
0
    if (store != NULL)
412
0
        return ossl_method_store_remove_all_provided(store, prov);
413
0
    return 1;
414
0
}
415
416
static int evp_set_parsed_default_properties(OSSL_LIB_CTX *libctx,
417
                                             OSSL_PROPERTY_LIST *def_prop,
418
                                             int loadconfig,
419
                                             int mirrored)
420
0
{
421
0
    OSSL_METHOD_STORE *store = get_evp_method_store(libctx);
422
0
    OSSL_PROPERTY_LIST **plp = ossl_ctx_global_properties(libctx, loadconfig);
423
424
0
    if (plp != NULL && store != NULL) {
425
0
#ifndef FIPS_MODULE
426
0
        char *propstr = NULL;
427
0
        size_t strsz;
428
429
0
        if (mirrored) {
430
0
            if (ossl_global_properties_no_mirrored(libctx))
431
0
                return 0;
432
0
        } else {
433
            /*
434
             * These properties have been explicitly set on this libctx, so
435
             * don't allow any mirroring from a parent libctx.
436
             */
437
0
            ossl_global_properties_stop_mirroring(libctx);
438
0
        }
439
440
0
        strsz = ossl_property_list_to_string(libctx, def_prop, NULL, 0);
441
0
        if (strsz > 0)
442
0
            propstr = OPENSSL_malloc(strsz);
443
0
        if (propstr == NULL) {
444
0
            ERR_raise(ERR_LIB_EVP, ERR_R_INTERNAL_ERROR);
445
0
            return 0;
446
0
        }
447
0
        if (ossl_property_list_to_string(libctx, def_prop, propstr,
448
0
                                         strsz) == 0) {
449
0
            OPENSSL_free(propstr);
450
0
            ERR_raise(ERR_LIB_EVP, ERR_R_INTERNAL_ERROR);
451
0
            return 0;
452
0
        }
453
0
        ossl_provider_default_props_update(libctx, propstr);
454
0
        OPENSSL_free(propstr);
455
0
#endif
456
0
        ossl_property_free(*plp);
457
0
        *plp = def_prop;
458
0
        if (store != NULL)
459
0
            return ossl_method_store_cache_flush_all(store);
460
0
    }
461
0
    ERR_raise(ERR_LIB_EVP, ERR_R_INTERNAL_ERROR);
462
0
    return 0;
463
0
}
464
465
int evp_set_default_properties_int(OSSL_LIB_CTX *libctx, const char *propq,
466
                                   int loadconfig, int mirrored)
467
0
{
468
0
    OSSL_PROPERTY_LIST *pl = NULL;
469
470
0
    if (propq != NULL && (pl = ossl_parse_query(libctx, propq, 1)) == NULL) {
471
0
        ERR_raise(ERR_LIB_EVP, EVP_R_DEFAULT_QUERY_PARSE_ERROR);
472
0
        return 0;
473
0
    }
474
0
    if (!evp_set_parsed_default_properties(libctx, pl, loadconfig, mirrored)) {
475
0
        ossl_property_free(pl);
476
0
        return 0;
477
0
    }
478
0
    return 1;
479
0
}
480
481
int EVP_set_default_properties(OSSL_LIB_CTX *libctx, const char *propq)
482
0
{
483
0
    return evp_set_default_properties_int(libctx, propq, 1, 0);
484
0
}
485
486
static int evp_default_properties_merge(OSSL_LIB_CTX *libctx, const char *propq,
487
                                        int loadconfig)
488
0
{
489
0
    OSSL_PROPERTY_LIST **plp = ossl_ctx_global_properties(libctx, loadconfig);
490
0
    OSSL_PROPERTY_LIST *pl1, *pl2;
491
492
0
    if (propq == NULL)
493
0
        return 1;
494
0
    if (plp == NULL || *plp == NULL)
495
0
        return evp_set_default_properties_int(libctx, propq, 0, 0);
496
0
    if ((pl1 = ossl_parse_query(libctx, propq, 1)) == NULL) {
497
0
        ERR_raise(ERR_LIB_EVP, EVP_R_DEFAULT_QUERY_PARSE_ERROR);
498
0
        return 0;
499
0
    }
500
0
    pl2 = ossl_property_merge(pl1, *plp);
501
0
    ossl_property_free(pl1);
502
0
    if (pl2 == NULL) {
503
0
        ERR_raise(ERR_LIB_EVP, ERR_R_CRYPTO_LIB);
504
0
        return 0;
505
0
    }
506
0
    if (!evp_set_parsed_default_properties(libctx, pl2, 0, 0)) {
507
0
        ossl_property_free(pl2);
508
0
        return 0;
509
0
    }
510
0
    return 1;
511
0
}
512
513
static int evp_default_property_is_enabled(OSSL_LIB_CTX *libctx,
514
                                           const char *prop_name)
515
0
{
516
0
    OSSL_PROPERTY_LIST **plp = ossl_ctx_global_properties(libctx, 1);
517
518
0
    return plp != NULL && ossl_property_is_enabled(libctx, prop_name, *plp);
519
0
}
520
521
int EVP_default_properties_is_fips_enabled(OSSL_LIB_CTX *libctx)
522
0
{
523
0
    return evp_default_property_is_enabled(libctx, "fips");
524
0
}
525
526
int evp_default_properties_enable_fips_int(OSSL_LIB_CTX *libctx, int enable,
527
                                           int loadconfig)
528
0
{
529
0
    const char *query = (enable != 0) ? "fips=yes" : "-fips";
530
531
0
    return evp_default_properties_merge(libctx, query, loadconfig);
532
0
}
533
534
int EVP_default_properties_enable_fips(OSSL_LIB_CTX *libctx, int enable)
535
0
{
536
0
    return evp_default_properties_enable_fips_int(libctx, enable, 1);
537
0
}
538
539
char *evp_get_global_properties_str(OSSL_LIB_CTX *libctx, int loadconfig)
540
0
{
541
0
    OSSL_PROPERTY_LIST **plp = ossl_ctx_global_properties(libctx, loadconfig);
542
0
    char *propstr = NULL;
543
0
    size_t sz;
544
545
0
    if (plp == NULL)
546
0
        return OPENSSL_strdup("");
547
548
0
    sz = ossl_property_list_to_string(libctx, *plp, NULL, 0);
549
0
    if (sz == 0) {
550
0
        ERR_raise(ERR_LIB_EVP, ERR_R_INTERNAL_ERROR);
551
0
        return NULL;
552
0
    }
553
554
0
    propstr = OPENSSL_malloc(sz);
555
0
    if (propstr == NULL)
556
0
        return NULL;
557
0
    if (ossl_property_list_to_string(libctx, *plp, propstr, sz) == 0) {
558
0
        ERR_raise(ERR_LIB_EVP, ERR_R_INTERNAL_ERROR);
559
0
        OPENSSL_free(propstr);
560
0
        return NULL;
561
0
    }
562
0
    return propstr;
563
0
}
564
565
struct filter_data_st {
566
    int operation_id;
567
    void (*user_fn)(void *method, void *arg);
568
    void *user_arg;
569
};
570
571
static void filter_on_operation_id(int id, void *method, void *arg)
572
1.07M
{
573
1.07M
    struct filter_data_st *data = arg;
574
575
1.07M
    if ((id & METHOD_ID_OPERATION_MASK) == data->operation_id)
576
86.2k
        data->user_fn(method, data->user_arg);
577
1.07M
}
578
579
void evp_generic_do_all(OSSL_LIB_CTX *libctx, int operation_id,
580
                        void (*user_fn)(void *method, void *arg),
581
                        void *user_arg,
582
                        void *(*new_method)(int name_id,
583
                                            const OSSL_ALGORITHM *algodef,
584
                                            OSSL_PROVIDER *prov),
585
                        int (*up_ref_method)(void *),
586
                        void (*free_method)(void *))
587
4.79k
{
588
4.79k
    struct evp_method_data_st methdata;
589
4.79k
    struct filter_data_st data;
590
591
4.79k
    methdata.libctx = libctx;
592
4.79k
    methdata.tmp_store = NULL;
593
4.79k
    (void)inner_evp_generic_fetch(&methdata, NULL, operation_id, NULL, NULL,
594
4.79k
                                  new_method, up_ref_method, free_method);
595
596
4.79k
    data.operation_id = operation_id;
597
4.79k
    data.user_fn = user_fn;
598
4.79k
    data.user_arg = user_arg;
599
4.79k
    if (methdata.tmp_store != NULL)
600
0
        ossl_method_store_do_all(methdata.tmp_store, &filter_on_operation_id,
601
0
                                 &data);
602
4.79k
    ossl_method_store_do_all(get_evp_method_store(libctx),
603
4.79k
                             &filter_on_operation_id, &data);
604
4.79k
    dealloc_tmp_evp_method_store(methdata.tmp_store);
605
4.79k
}
606
607
int evp_is_a(OSSL_PROVIDER *prov, int number,
608
             const char *legacy_name, const char *name)
609
18.8k
{
610
    /*
611
     * For a |prov| that is NULL, the library context will be NULL
612
     */
613
18.8k
    OSSL_LIB_CTX *libctx = ossl_provider_libctx(prov);
614
18.8k
    OSSL_NAMEMAP *namemap = ossl_namemap_stored(libctx);
615
616
18.8k
    if (prov == NULL)
617
2.47k
        number = ossl_namemap_name2num(namemap, legacy_name);
618
18.8k
    return ossl_namemap_name2num(namemap, name) == number;
619
18.8k
}
620
621
int evp_names_do_all(OSSL_PROVIDER *prov, int number,
622
                     void (*fn)(const char *name, void *data),
623
                     void *data)
624
226k
{
625
226k
    OSSL_LIB_CTX *libctx = ossl_provider_libctx(prov);
626
226k
    OSSL_NAMEMAP *namemap = ossl_namemap_stored(libctx);
627
628
226k
    return ossl_namemap_doall_names(namemap, number, fn, data);
629
226k
}