Coverage Report

Created: 2026-07-23 06:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openssl34/crypto/evp/asymcipher.c
Line
Count
Source
1
/*
2
 * Copyright 2006-2026 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 <stdio.h>
11
#include <stdlib.h>
12
#include <openssl/objects.h>
13
#include <openssl/evp.h>
14
#include "internal/cryptlib.h"
15
#include "internal/provider.h"
16
#include "internal/core.h"
17
#include "crypto/evp.h"
18
#include "evp_local.h"
19
20
static int evp_pkey_asym_cipher_init(EVP_PKEY_CTX *ctx, int operation,
21
    const OSSL_PARAM params[])
22
10.3k
{
23
10.3k
    int ret = 0;
24
10.3k
    void *provkey = NULL;
25
10.3k
    EVP_ASYM_CIPHER *cipher = NULL;
26
10.3k
    EVP_KEYMGMT *tmp_keymgmt = NULL;
27
10.3k
    const OSSL_PROVIDER *tmp_prov = NULL;
28
10.3k
    const char *supported_ciph = NULL;
29
10.3k
    int iter;
30
31
10.3k
    if (ctx == NULL) {
32
0
        ERR_raise(ERR_LIB_EVP, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
33
0
        return -2;
34
0
    }
35
36
10.3k
    evp_pkey_ctx_free_old_ops(ctx);
37
10.3k
    ctx->operation = operation;
38
39
10.3k
    ERR_set_mark();
40
41
10.3k
    if (evp_pkey_ctx_is_legacy(ctx))
42
0
        goto legacy;
43
44
10.3k
    if (ctx->pkey == NULL) {
45
0
        ERR_clear_last_mark();
46
0
        ERR_raise(ERR_LIB_EVP, EVP_R_NO_KEY_SET);
47
0
        goto err;
48
0
    }
49
50
    /*
51
     * Try to derive the supported asym cipher from |ctx->keymgmt|.
52
     */
53
10.3k
    if (!ossl_assert(ctx->pkey->keymgmt == NULL
54
10.3k
            || ctx->pkey->keymgmt == ctx->keymgmt)) {
55
0
        ERR_clear_last_mark();
56
0
        ERR_raise(ERR_LIB_EVP, ERR_R_INTERNAL_ERROR);
57
0
        goto err;
58
0
    }
59
10.3k
    supported_ciph
60
10.3k
        = evp_keymgmt_util_query_operation_name(ctx->keymgmt,
61
10.3k
            OSSL_OP_ASYM_CIPHER);
62
10.3k
    if (supported_ciph == NULL) {
63
0
        ERR_clear_last_mark();
64
0
        ERR_raise(ERR_LIB_EVP, EVP_R_INITIALIZATION_ERROR);
65
0
        goto err;
66
0
    }
67
68
    /*
69
     * We perform two iterations:
70
     *
71
     * 1.  Do the normal asym cipher fetch, using the fetching data given by
72
     *     the EVP_PKEY_CTX.
73
     * 2.  Do the provider specific asym cipher fetch, from the same provider
74
     *     as |ctx->keymgmt|
75
     *
76
     * We then try to fetch the keymgmt from the same provider as the
77
     * asym cipher, and try to export |ctx->pkey| to that keymgmt (when
78
     * this keymgmt happens to be the same as |ctx->keymgmt|, the export
79
     * is a no-op, but we call it anyway to not complicate the code even
80
     * more).
81
     * If the export call succeeds (returns a non-NULL provider key pointer),
82
     * we're done and can perform the operation itself.  If not, we perform
83
     * the second iteration, or jump to legacy.
84
     */
85
20.6k
    for (iter = 1, provkey = NULL; iter < 3 && provkey == NULL; iter++) {
86
10.3k
        EVP_KEYMGMT *tmp_keymgmt_tofree;
87
88
        /*
89
         * If we're on the second iteration, free the results from the first.
90
         * They are NULL on the first iteration, so no need to check what
91
         * iteration we're on.
92
         */
93
10.3k
        EVP_ASYM_CIPHER_free(cipher);
94
10.3k
        cipher = NULL;
95
10.3k
        EVP_KEYMGMT_free(tmp_keymgmt);
96
10.3k
        tmp_keymgmt = NULL;
97
98
10.3k
        switch (iter) {
99
10.3k
        case 1:
100
10.3k
            cipher = EVP_ASYM_CIPHER_fetch(ctx->libctx, supported_ciph,
101
10.3k
                ctx->propquery);
102
10.3k
            if (cipher != NULL)
103
10.3k
                tmp_prov = EVP_ASYM_CIPHER_get0_provider(cipher);
104
10.3k
            break;
105
0
        case 2:
106
0
            tmp_prov = EVP_KEYMGMT_get0_provider(ctx->keymgmt);
107
0
            cipher = evp_asym_cipher_fetch_from_prov((OSSL_PROVIDER *)tmp_prov,
108
0
                supported_ciph, ctx->propquery);
109
0
            if (cipher == NULL)
110
0
                goto legacy;
111
0
            break;
112
10.3k
        }
113
10.3k
        if (cipher == NULL)
114
0
            continue;
115
116
        /*
117
         * Ensure that the key is provided, either natively, or as a cached
118
         * export.  We start by fetching the keymgmt with the same name as
119
         * |ctx->pkey|, but from the provider of the asym cipher method, using
120
         * the same property query as when fetching the asym cipher method.
121
         * With the keymgmt we found (if we did), we try to export |ctx->pkey|
122
         * to it (evp_pkey_export_to_provider() is smart enough to only actually
123
         * export it if |tmp_keymgmt| is different from |ctx->pkey|'s keymgmt)
124
         */
125
10.3k
        tmp_keymgmt_tofree = tmp_keymgmt
126
10.3k
            = evp_keymgmt_fetch_from_prov((OSSL_PROVIDER *)tmp_prov,
127
10.3k
                EVP_KEYMGMT_get0_name(ctx->keymgmt),
128
10.3k
                ctx->propquery);
129
10.3k
        if (tmp_keymgmt != NULL)
130
10.3k
            provkey = evp_pkey_export_to_provider(ctx->pkey, ctx->libctx,
131
10.3k
                &tmp_keymgmt, ctx->propquery);
132
10.3k
        if (tmp_keymgmt == NULL)
133
0
            EVP_KEYMGMT_free(tmp_keymgmt_tofree);
134
10.3k
    }
135
136
10.3k
    if (provkey == NULL) {
137
0
        EVP_ASYM_CIPHER_free(cipher);
138
0
        goto legacy;
139
0
    }
140
141
10.3k
    ERR_pop_to_mark();
142
143
    /* No more legacy from here down to legacy: */
144
145
10.3k
    ctx->op.ciph.cipher = cipher;
146
10.3k
    ctx->op.ciph.algctx = cipher->newctx(ossl_provider_ctx(cipher->prov));
147
10.3k
    if (ctx->op.ciph.algctx == NULL) {
148
        /* The provider key can stay in the cache */
149
0
        ERR_raise(ERR_LIB_EVP, EVP_R_INITIALIZATION_ERROR);
150
0
        goto err;
151
0
    }
152
153
10.3k
    switch (operation) {
154
5.43k
    case EVP_PKEY_OP_ENCRYPT:
155
5.43k
        if (cipher->encrypt_init == NULL) {
156
0
            ERR_raise(ERR_LIB_EVP, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
157
0
            ret = -2;
158
0
            goto err;
159
0
        }
160
5.43k
        ret = cipher->encrypt_init(ctx->op.ciph.algctx, provkey, params);
161
5.43k
        break;
162
4.89k
    case EVP_PKEY_OP_DECRYPT:
163
4.89k
        if (cipher->decrypt_init == NULL) {
164
0
            ERR_raise(ERR_LIB_EVP, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
165
0
            ret = -2;
166
0
            goto err;
167
0
        }
168
4.89k
        ret = cipher->decrypt_init(ctx->op.ciph.algctx, provkey, params);
169
4.89k
        break;
170
0
    default:
171
0
        ERR_raise(ERR_LIB_EVP, EVP_R_INITIALIZATION_ERROR);
172
0
        goto err;
173
10.3k
    }
174
175
10.3k
    if (ret <= 0)
176
0
        goto err;
177
10.3k
    EVP_KEYMGMT_free(tmp_keymgmt);
178
10.3k
    return 1;
179
180
0
legacy:
181
    /*
182
     * If we don't have the full support we need with provided methods,
183
     * let's go see if legacy does.
184
     */
185
0
    ERR_pop_to_mark();
186
0
    EVP_KEYMGMT_free(tmp_keymgmt);
187
0
    tmp_keymgmt = NULL;
188
189
0
    if (ctx->pmeth == NULL || ctx->pmeth->encrypt == NULL) {
190
0
        ERR_raise(ERR_LIB_EVP, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
191
0
        return -2;
192
0
    }
193
0
    switch (ctx->operation) {
194
0
    case EVP_PKEY_OP_ENCRYPT:
195
0
        if (ctx->pmeth->encrypt_init == NULL)
196
0
            return 1;
197
0
        ret = ctx->pmeth->encrypt_init(ctx);
198
0
        break;
199
0
    case EVP_PKEY_OP_DECRYPT:
200
0
        if (ctx->pmeth->decrypt_init == NULL)
201
0
            return 1;
202
0
        ret = ctx->pmeth->decrypt_init(ctx);
203
0
        break;
204
0
    default:
205
0
        ERR_raise(ERR_LIB_EVP, EVP_R_INITIALIZATION_ERROR);
206
0
        ret = -1;
207
0
    }
208
209
0
err:
210
0
    if (ret <= 0) {
211
0
        evp_pkey_ctx_free_old_ops(ctx);
212
0
        ctx->operation = EVP_PKEY_OP_UNDEFINED;
213
0
    }
214
0
    EVP_KEYMGMT_free(tmp_keymgmt);
215
0
    return ret;
216
0
}
217
218
int EVP_PKEY_encrypt_init(EVP_PKEY_CTX *ctx)
219
10.6k
{
220
10.6k
    return evp_pkey_asym_cipher_init(ctx, EVP_PKEY_OP_ENCRYPT, NULL);
221
10.6k
}
222
223
int EVP_PKEY_encrypt_init_ex(EVP_PKEY_CTX *ctx, const OSSL_PARAM params[])
224
0
{
225
0
    return evp_pkey_asym_cipher_init(ctx, EVP_PKEY_OP_ENCRYPT, params);
226
0
}
227
228
int EVP_PKEY_encrypt(EVP_PKEY_CTX *ctx,
229
    unsigned char *out, size_t *outlen,
230
    const unsigned char *in, size_t inlen)
231
10.8k
{
232
10.8k
    int ret;
233
234
10.8k
    if (ctx == NULL) {
235
0
        ERR_raise(ERR_LIB_EVP, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
236
0
        return -2;
237
0
    }
238
239
10.8k
    if (ctx->operation != EVP_PKEY_OP_ENCRYPT) {
240
0
        ERR_raise(ERR_LIB_EVP, EVP_R_OPERATION_NOT_INITIALIZED);
241
0
        return -1;
242
0
    }
243
244
10.8k
    if (ctx->op.ciph.algctx == NULL)
245
0
        goto legacy;
246
247
10.8k
    ret = ctx->op.ciph.cipher->encrypt(ctx->op.ciph.algctx, out, outlen,
248
10.8k
        (out == NULL ? 0 : *outlen), in, inlen);
249
10.8k
    return ret;
250
251
0
legacy:
252
0
    if (ctx->pmeth == NULL || ctx->pmeth->encrypt == NULL) {
253
0
        ERR_raise(ERR_LIB_EVP, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
254
0
        return -2;
255
0
    }
256
0
    M_check_autoarg(ctx, out, outlen, EVP_F_EVP_PKEY_ENCRYPT) return ctx->pmeth->encrypt(ctx, out, outlen, in, inlen);
257
0
}
258
259
int EVP_PKEY_decrypt_init(EVP_PKEY_CTX *ctx)
260
10.6k
{
261
10.6k
    return evp_pkey_asym_cipher_init(ctx, EVP_PKEY_OP_DECRYPT, NULL);
262
10.6k
}
263
264
int EVP_PKEY_decrypt_init_ex(EVP_PKEY_CTX *ctx, const OSSL_PARAM params[])
265
0
{
266
0
    return evp_pkey_asym_cipher_init(ctx, EVP_PKEY_OP_DECRYPT, params);
267
0
}
268
269
int EVP_PKEY_decrypt(EVP_PKEY_CTX *ctx,
270
    unsigned char *out, size_t *outlen,
271
    const unsigned char *in, size_t inlen)
272
4.89k
{
273
4.89k
    int ret;
274
275
4.89k
    if (ctx == NULL) {
276
0
        ERR_raise(ERR_LIB_EVP, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
277
0
        return -2;
278
0
    }
279
280
4.89k
    if (ctx->operation != EVP_PKEY_OP_DECRYPT) {
281
0
        ERR_raise(ERR_LIB_EVP, EVP_R_OPERATION_NOT_INITIALIZED);
282
0
        return -1;
283
0
    }
284
285
4.89k
    if (ctx->op.ciph.algctx == NULL)
286
0
        goto legacy;
287
288
4.89k
    ret = ctx->op.ciph.cipher->decrypt(ctx->op.ciph.algctx, out, outlen,
289
4.89k
        (out == NULL ? 0 : *outlen), in, inlen);
290
4.89k
    return ret;
291
292
0
legacy:
293
0
    if (ctx->pmeth == NULL || ctx->pmeth->decrypt == NULL) {
294
0
        ERR_raise(ERR_LIB_EVP, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
295
0
        return -2;
296
0
    }
297
0
    M_check_autoarg(ctx, out, outlen, EVP_F_EVP_PKEY_DECRYPT) return ctx->pmeth->decrypt(ctx, out, outlen, in, inlen);
298
0
}
299
300
/* decrypt to new buffer of dynamic size, checking any pre-determined size */
301
int evp_pkey_decrypt_alloc(EVP_PKEY_CTX *ctx, unsigned char **outp,
302
    size_t *outlenp, size_t expected_outlen,
303
    const unsigned char *in, size_t inlen)
304
0
{
305
0
    if (EVP_PKEY_decrypt(ctx, NULL, outlenp, in, inlen) <= 0
306
0
        || (*outp = OPENSSL_malloc(*outlenp)) == NULL)
307
0
        return -1;
308
0
    if (EVP_PKEY_decrypt(ctx, *outp, outlenp, in, inlen) <= 0
309
0
        || *outlenp == 0
310
0
        || (expected_outlen != 0 && *outlenp != expected_outlen)) {
311
0
        ERR_raise(ERR_LIB_EVP, ERR_R_EVP_LIB);
312
0
        OPENSSL_clear_free(*outp, *outlenp);
313
0
        *outp = NULL;
314
0
        return 0;
315
0
    }
316
0
    return 1;
317
0
}
318
319
static EVP_ASYM_CIPHER *evp_asym_cipher_new(OSSL_PROVIDER *prov)
320
20
{
321
20
    EVP_ASYM_CIPHER *cipher = OPENSSL_zalloc(sizeof(EVP_ASYM_CIPHER));
322
323
20
    if (cipher == NULL)
324
0
        return NULL;
325
326
20
    if (!CRYPTO_NEW_REF(&cipher->refcnt, 1)) {
327
0
        OPENSSL_free(cipher);
328
0
        return NULL;
329
0
    }
330
20
    cipher->prov = prov;
331
20
    ossl_provider_up_ref(prov);
332
333
20
    return cipher;
334
20
}
335
336
static void *evp_asym_cipher_from_algorithm(int name_id,
337
    const OSSL_ALGORITHM *algodef,
338
    OSSL_PROVIDER *prov)
339
58
{
340
58
    const OSSL_DISPATCH *fns = algodef->implementation;
341
58
    EVP_ASYM_CIPHER *cipher = NULL;
342
58
    int ctxfncnt = 0, encfncnt = 0, decfncnt = 0;
343
58
    int gparamfncnt = 0, sparamfncnt = 0;
344
345
58
    if ((cipher = evp_asym_cipher_new(prov)) == NULL) {
346
0
        ERR_raise(ERR_LIB_EVP, ERR_R_EVP_LIB);
347
0
        goto err;
348
0
    }
349
350
58
    cipher->name_id = name_id;
351
58
    if ((cipher->type_name = ossl_algorithm_get1_first_name(algodef)) == NULL)
352
0
        goto err;
353
58
    cipher->description = algodef->algorithm_description;
354
355
696
    for (; fns->function_id != 0; fns++) {
356
638
        switch (fns->function_id) {
357
58
        case OSSL_FUNC_ASYM_CIPHER_NEWCTX:
358
58
            if (cipher->newctx != NULL)
359
0
                break;
360
58
            cipher->newctx = OSSL_FUNC_asym_cipher_newctx(fns);
361
58
            ctxfncnt++;
362
58
            break;
363
58
        case OSSL_FUNC_ASYM_CIPHER_ENCRYPT_INIT:
364
58
            if (cipher->encrypt_init != NULL)
365
0
                break;
366
58
            cipher->encrypt_init = OSSL_FUNC_asym_cipher_encrypt_init(fns);
367
58
            encfncnt++;
368
58
            break;
369
58
        case OSSL_FUNC_ASYM_CIPHER_ENCRYPT:
370
58
            if (cipher->encrypt != NULL)
371
0
                break;
372
58
            cipher->encrypt = OSSL_FUNC_asym_cipher_encrypt(fns);
373
58
            encfncnt++;
374
58
            break;
375
58
        case OSSL_FUNC_ASYM_CIPHER_DECRYPT_INIT:
376
58
            if (cipher->decrypt_init != NULL)
377
0
                break;
378
58
            cipher->decrypt_init = OSSL_FUNC_asym_cipher_decrypt_init(fns);
379
58
            decfncnt++;
380
58
            break;
381
58
        case OSSL_FUNC_ASYM_CIPHER_DECRYPT:
382
58
            if (cipher->decrypt != NULL)
383
0
                break;
384
58
            cipher->decrypt = OSSL_FUNC_asym_cipher_decrypt(fns);
385
58
            decfncnt++;
386
58
            break;
387
58
        case OSSL_FUNC_ASYM_CIPHER_FREECTX:
388
58
            if (cipher->freectx != NULL)
389
0
                break;
390
58
            cipher->freectx = OSSL_FUNC_asym_cipher_freectx(fns);
391
58
            ctxfncnt++;
392
58
            break;
393
58
        case OSSL_FUNC_ASYM_CIPHER_DUPCTX:
394
58
            if (cipher->dupctx != NULL)
395
0
                break;
396
58
            cipher->dupctx = OSSL_FUNC_asym_cipher_dupctx(fns);
397
58
            break;
398
58
        case OSSL_FUNC_ASYM_CIPHER_GET_CTX_PARAMS:
399
58
            if (cipher->get_ctx_params != NULL)
400
0
                break;
401
58
            cipher->get_ctx_params
402
58
                = OSSL_FUNC_asym_cipher_get_ctx_params(fns);
403
58
            gparamfncnt++;
404
58
            break;
405
58
        case OSSL_FUNC_ASYM_CIPHER_GETTABLE_CTX_PARAMS:
406
58
            if (cipher->gettable_ctx_params != NULL)
407
0
                break;
408
58
            cipher->gettable_ctx_params
409
58
                = OSSL_FUNC_asym_cipher_gettable_ctx_params(fns);
410
58
            gparamfncnt++;
411
58
            break;
412
58
        case OSSL_FUNC_ASYM_CIPHER_SET_CTX_PARAMS:
413
58
            if (cipher->set_ctx_params != NULL)
414
0
                break;
415
58
            cipher->set_ctx_params
416
58
                = OSSL_FUNC_asym_cipher_set_ctx_params(fns);
417
58
            sparamfncnt++;
418
58
            break;
419
58
        case OSSL_FUNC_ASYM_CIPHER_SETTABLE_CTX_PARAMS:
420
58
            if (cipher->settable_ctx_params != NULL)
421
0
                break;
422
58
            cipher->settable_ctx_params
423
58
                = OSSL_FUNC_asym_cipher_settable_ctx_params(fns);
424
58
            sparamfncnt++;
425
58
            break;
426
638
        }
427
638
    }
428
58
    if (ctxfncnt != 2
429
58
        || (encfncnt != 0 && encfncnt != 2)
430
58
        || (decfncnt != 0 && decfncnt != 2)
431
58
        || (encfncnt != 2 && decfncnt != 2)
432
58
        || (gparamfncnt != 0 && gparamfncnt != 2)
433
58
        || (sparamfncnt != 0 && sparamfncnt != 2)) {
434
        /*
435
         * In order to be a consistent set of functions we must have at least
436
         * a set of context functions (newctx and freectx) as well as a pair of
437
         * "cipher" functions: (encrypt_init, encrypt) or
438
         * (decrypt_init decrypt). set_ctx_params and settable_ctx_params are
439
         * optional, but if one of them is present then the other one must also
440
         * be present. The same applies to get_ctx_params and
441
         * gettable_ctx_params. The dupctx function is optional.
442
         */
443
0
        ERR_raise(ERR_LIB_EVP, EVP_R_INVALID_PROVIDER_FUNCTIONS);
444
0
        goto err;
445
0
    }
446
447
58
    return cipher;
448
0
err:
449
0
    EVP_ASYM_CIPHER_free(cipher);
450
0
    return NULL;
451
58
}
452
453
void EVP_ASYM_CIPHER_free(EVP_ASYM_CIPHER *cipher)
454
35.2k
{
455
35.2k
    int i;
456
457
35.2k
    if (cipher == NULL)
458
17.5k
        return;
459
17.6k
    CRYPTO_DOWN_REF(&cipher->refcnt, &i);
460
17.6k
    if (i > 0)
461
17.6k
        return;
462
34
    OPENSSL_free(cipher->type_name);
463
34
    ossl_provider_free(cipher->prov);
464
34
    CRYPTO_FREE_REF(&cipher->refcnt);
465
34
    OPENSSL_free(cipher);
466
34
}
467
468
int EVP_ASYM_CIPHER_up_ref(EVP_ASYM_CIPHER *cipher)
469
17.6k
{
470
17.6k
    int ref = 0;
471
472
17.6k
    CRYPTO_UP_REF(&cipher->refcnt, &ref);
473
17.6k
    return 1;
474
17.6k
}
475
476
OSSL_PROVIDER *EVP_ASYM_CIPHER_get0_provider(const EVP_ASYM_CIPHER *cipher)
477
31.9k
{
478
31.9k
    return cipher->prov;
479
31.9k
}
480
481
EVP_ASYM_CIPHER *EVP_ASYM_CIPHER_fetch(OSSL_LIB_CTX *ctx, const char *algorithm,
482
    const char *properties)
483
21.2k
{
484
21.2k
    return evp_generic_fetch(ctx, OSSL_OP_ASYM_CIPHER, algorithm, properties,
485
21.2k
        evp_asym_cipher_from_algorithm,
486
21.2k
        (int (*)(void *))EVP_ASYM_CIPHER_up_ref,
487
21.2k
        (void (*)(void *))EVP_ASYM_CIPHER_free);
488
21.2k
}
489
490
EVP_ASYM_CIPHER *evp_asym_cipher_fetch_from_prov(OSSL_PROVIDER *prov,
491
    const char *algorithm,
492
    const char *properties)
493
0
{
494
0
    return evp_generic_fetch_from_prov(prov, OSSL_OP_ASYM_CIPHER,
495
0
        algorithm, properties,
496
0
        evp_asym_cipher_from_algorithm,
497
0
        (int (*)(void *))EVP_ASYM_CIPHER_up_ref,
498
0
        (void (*)(void *))EVP_ASYM_CIPHER_free);
499
0
}
500
501
int EVP_ASYM_CIPHER_is_a(const EVP_ASYM_CIPHER *cipher, const char *name)
502
0
{
503
0
    return evp_is_a(cipher->prov, cipher->name_id, NULL, name);
504
0
}
505
506
int evp_asym_cipher_get_number(const EVP_ASYM_CIPHER *cipher)
507
0
{
508
0
    return cipher->name_id;
509
0
}
510
511
const char *EVP_ASYM_CIPHER_get0_name(const EVP_ASYM_CIPHER *cipher)
512
0
{
513
0
    return cipher->type_name;
514
0
}
515
516
const char *EVP_ASYM_CIPHER_get0_description(const EVP_ASYM_CIPHER *cipher)
517
0
{
518
0
    return cipher->description;
519
0
}
520
521
void EVP_ASYM_CIPHER_do_all_provided(OSSL_LIB_CTX *libctx,
522
    void (*fn)(EVP_ASYM_CIPHER *cipher,
523
        void *arg),
524
    void *arg)
525
8
{
526
8
    evp_generic_do_all(libctx, OSSL_OP_ASYM_CIPHER,
527
8
        (void (*)(void *, void *))fn, arg,
528
8
        evp_asym_cipher_from_algorithm,
529
8
        (int (*)(void *))EVP_ASYM_CIPHER_up_ref,
530
8
        (void (*)(void *))EVP_ASYM_CIPHER_free);
531
8
}
532
533
int EVP_ASYM_CIPHER_names_do_all(const EVP_ASYM_CIPHER *cipher,
534
    void (*fn)(const char *name, void *data),
535
    void *data)
536
0
{
537
0
    if (cipher->prov != NULL)
538
0
        return evp_names_do_all(cipher->prov, cipher->name_id, fn, data);
539
540
0
    return 1;
541
0
}
542
543
const OSSL_PARAM *EVP_ASYM_CIPHER_gettable_ctx_params(const EVP_ASYM_CIPHER *cip)
544
0
{
545
0
    void *provctx;
546
547
0
    if (cip == NULL || cip->gettable_ctx_params == NULL)
548
0
        return NULL;
549
550
0
    provctx = ossl_provider_ctx(EVP_ASYM_CIPHER_get0_provider(cip));
551
0
    return cip->gettable_ctx_params(NULL, provctx);
552
0
}
553
554
const OSSL_PARAM *EVP_ASYM_CIPHER_settable_ctx_params(const EVP_ASYM_CIPHER *cip)
555
22
{
556
22
    void *provctx;
557
558
22
    if (cip == NULL || cip->settable_ctx_params == NULL)
559
0
        return NULL;
560
561
22
    provctx = ossl_provider_ctx(EVP_ASYM_CIPHER_get0_provider(cip));
562
    return cip->settable_ctx_params(NULL, provctx);
563
22
}