Coverage Report

Created: 2026-10-28 06:28

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