Coverage Report

Created: 2026-07-24 06:26

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-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 <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
0
{
22
0
    EVP_ASYM_CIPHER *cipher = (EVP_ASYM_CIPHER *)data;
23
0
    int i;
24
25
0
    if (cipher == NULL)
26
0
        return;
27
0
    CRYPTO_DOWN_REF(&cipher->refcnt, &i);
28
0
    if (i > 0)
29
0
        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
0
{
38
0
    EVP_ASYM_CIPHER *cipher = (EVP_ASYM_CIPHER *)data;
39
0
    int ref = 0;
40
41
0
    return CRYPTO_UP_REF(&cipher->refcnt, &ref);
42
0
}
43
44
static int evp_pkey_asym_cipher_init(EVP_PKEY_CTX *ctx, int operation,
45
    const OSSL_PARAM params[])
46
0
{
47
0
    int ret = 0;
48
0
    void *provkey = NULL;
49
0
    EVP_ASYM_CIPHER *cipher = NULL;
50
0
    const char *desc;
51
0
    EVP_KEYMGMT *tmp_keymgmt = NULL;
52
0
    const OSSL_PROVIDER *tmp_prov = NULL;
53
0
    const char *supported_ciph = NULL;
54
0
    int iter;
55
56
0
    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
0
    evp_pkey_ctx_free_old_ops(ctx);
62
0
    ctx->operation = operation;
63
64
0
    ERR_set_mark();
65
66
0
    if (evp_pkey_ctx_is_legacy(ctx))
67
0
        goto err;
68
69
0
    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
0
    if (!ossl_assert(ctx->pkey->keymgmt == NULL
79
0
            || 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
0
    supported_ciph
85
0
        = evp_keymgmt_util_query_operation_name(ctx->keymgmt,
86
0
            OSSL_OP_ASYM_CIPHER);
87
0
    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
0
    for (iter = 1, provkey = NULL; iter < 3 && provkey == NULL; iter++) {
111
0
        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
0
        EVP_ASYM_CIPHER_free(cipher);
119
0
        cipher = NULL;
120
0
        EVP_KEYMGMT_free(tmp_keymgmt);
121
0
        tmp_keymgmt = NULL;
122
123
0
        switch (iter) {
124
0
        case 1:
125
0
            cipher = EVP_ASYM_CIPHER_fetch(ctx->libctx, supported_ciph,
126
0
                ctx->propquery);
127
0
            if (cipher != NULL)
128
0
                tmp_prov = EVP_ASYM_CIPHER_get0_provider(cipher);
129
0
            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
0
        }
138
0
        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
0
        tmp_keymgmt_tofree = tmp_keymgmt
151
0
            = evp_keymgmt_fetch_from_prov((OSSL_PROVIDER *)tmp_prov,
152
0
                EVP_KEYMGMT_get0_name(ctx->keymgmt),
153
0
                ctx->propquery);
154
0
        if (tmp_keymgmt != NULL)
155
0
            provkey = evp_pkey_export_to_provider(ctx->pkey, ctx->libctx,
156
0
                &tmp_keymgmt, ctx->propquery);
157
0
        if (tmp_keymgmt == NULL)
158
0
            EVP_KEYMGMT_free(tmp_keymgmt_tofree);
159
0
    }
160
161
0
    if (provkey == NULL) {
162
0
        EVP_ASYM_CIPHER_free(cipher);
163
0
        goto err;
164
0
    }
165
166
0
    ERR_pop_to_mark();
167
168
    /* No more legacy from here down to legacy: */
169
170
0
    ctx->op.ciph.cipher = cipher;
171
0
    ctx->op.ciph.algctx = cipher->newctx(ossl_provider_ctx(cipher->prov));
172
0
    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
0
    desc = cipher->description != NULL ? cipher->description : "";
179
0
    switch (operation) {
180
0
    case EVP_PKEY_OP_ENCRYPT:
181
0
        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
0
        ret = cipher->encrypt_init(ctx->op.ciph.algctx, provkey, params);
188
0
        break;
189
0
    case EVP_PKEY_OP_DECRYPT:
190
0
        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
0
        ret = cipher->decrypt_init(ctx->op.ciph.algctx, provkey, params);
197
0
        break;
198
0
    default:
199
0
        ERR_raise(ERR_LIB_EVP, EVP_R_INITIALIZATION_ERROR);
200
0
        goto err;
201
0
    }
202
203
0
    if (ret <= 0)
204
0
        goto err;
205
0
    EVP_KEYMGMT_free(tmp_keymgmt);
206
0
    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
0
}
216
217
int EVP_PKEY_encrypt_init(EVP_PKEY_CTX *ctx)
218
0
{
219
0
    return evp_pkey_asym_cipher_init(ctx, EVP_PKEY_OP_ENCRYPT, NULL);
220
0
}
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
0
{
231
0
    EVP_ASYM_CIPHER *cipher;
232
0
    const char *desc;
233
0
    int ret;
234
235
0
    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
0
    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
0
    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
0
    cipher = ctx->op.ciph.cipher;
250
0
    desc = cipher->description != NULL ? cipher->description : "";
251
0
    ERR_set_mark();
252
0
    ret = cipher->encrypt(ctx->op.ciph.algctx, out, outlen, (out == NULL ? 0 : *outlen), in, inlen);
253
0
    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
0
    ERR_clear_last_mark();
257
0
    return ret;
258
0
}
259
260
int EVP_PKEY_decrypt_init(EVP_PKEY_CTX *ctx)
261
0
{
262
0
    return evp_pkey_asym_cipher_init(ctx, EVP_PKEY_OP_DECRYPT, NULL);
263
0
}
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
0
{
274
0
    EVP_ASYM_CIPHER *cipher;
275
0
    const char *desc;
276
0
    int ret;
277
278
0
    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
0
    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
0
    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
0
    cipher = ctx->op.ciph.cipher;
294
0
    desc = cipher->description != NULL ? cipher->description : "";
295
0
    ERR_set_mark();
296
0
    ret = cipher->decrypt(ctx->op.ciph.algctx, out, outlen, (out == NULL ? 0 : *outlen), in, inlen);
297
0
    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
0
    ERR_clear_last_mark();
301
302
0
    return ret;
303
0
}
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
0
{
326
0
    EVP_ASYM_CIPHER *cipher = OPENSSL_zalloc(sizeof(EVP_ASYM_CIPHER));
327
328
0
    if (cipher == NULL)
329
0
        return NULL;
330
331
0
    if (!CRYPTO_NEW_REF(&cipher->refcnt, 1)
332
0
        || !ossl_provider_up_ref(prov)) {
333
0
        CRYPTO_FREE_REF(&cipher->refcnt);
334
0
        OPENSSL_free(cipher);
335
0
        return NULL;
336
0
    }
337
0
    cipher->prov = prov;
338
339
0
    return cipher;
340
0
}
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
0
{
346
0
    const OSSL_DISPATCH *fns = algodef->implementation;
347
0
    EVP_ASYM_CIPHER *cipher = NULL;
348
0
    int ctxfncnt = 0, encfncnt = 0, decfncnt = 0;
349
0
    int gparamfncnt = 0, sparamfncnt = 0;
350
351
0
    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
0
    cipher->name_id = name_id;
357
0
    cipher->no_store = no_store;
358
0
    if ((cipher->type_name = ossl_algorithm_get1_first_name(algodef)) == NULL)
359
0
        goto err;
360
0
    cipher->description = algodef->algorithm_description;
361
362
0
    for (; fns->function_id != 0; fns++) {
363
0
        switch (fns->function_id) {
364
0
        case OSSL_FUNC_ASYM_CIPHER_NEWCTX:
365
0
            if (cipher->newctx != NULL)
366
0
                break;
367
0
            cipher->newctx = OSSL_FUNC_asym_cipher_newctx(fns);
368
0
            ctxfncnt++;
369
0
            break;
370
0
        case OSSL_FUNC_ASYM_CIPHER_ENCRYPT_INIT:
371
0
            if (cipher->encrypt_init != NULL)
372
0
                break;
373
0
            cipher->encrypt_init = OSSL_FUNC_asym_cipher_encrypt_init(fns);
374
0
            encfncnt++;
375
0
            break;
376
0
        case OSSL_FUNC_ASYM_CIPHER_ENCRYPT:
377
0
            if (cipher->encrypt != NULL)
378
0
                break;
379
0
            cipher->encrypt = OSSL_FUNC_asym_cipher_encrypt(fns);
380
0
            encfncnt++;
381
0
            break;
382
0
        case OSSL_FUNC_ASYM_CIPHER_DECRYPT_INIT:
383
0
            if (cipher->decrypt_init != NULL)
384
0
                break;
385
0
            cipher->decrypt_init = OSSL_FUNC_asym_cipher_decrypt_init(fns);
386
0
            decfncnt++;
387
0
            break;
388
0
        case OSSL_FUNC_ASYM_CIPHER_DECRYPT:
389
0
            if (cipher->decrypt != NULL)
390
0
                break;
391
0
            cipher->decrypt = OSSL_FUNC_asym_cipher_decrypt(fns);
392
0
            decfncnt++;
393
0
            break;
394
0
        case OSSL_FUNC_ASYM_CIPHER_FREECTX:
395
0
            if (cipher->freectx != NULL)
396
0
                break;
397
0
            cipher->freectx = OSSL_FUNC_asym_cipher_freectx(fns);
398
0
            ctxfncnt++;
399
0
            break;
400
0
        case OSSL_FUNC_ASYM_CIPHER_DUPCTX:
401
0
            if (cipher->dupctx != NULL)
402
0
                break;
403
0
            cipher->dupctx = OSSL_FUNC_asym_cipher_dupctx(fns);
404
0
            break;
405
0
        case OSSL_FUNC_ASYM_CIPHER_GET_CTX_PARAMS:
406
0
            if (cipher->get_ctx_params != NULL)
407
0
                break;
408
0
            cipher->get_ctx_params
409
0
                = OSSL_FUNC_asym_cipher_get_ctx_params(fns);
410
0
            gparamfncnt++;
411
0
            break;
412
0
        case OSSL_FUNC_ASYM_CIPHER_GETTABLE_CTX_PARAMS:
413
0
            if (cipher->gettable_ctx_params != NULL)
414
0
                break;
415
0
            cipher->gettable_ctx_params
416
0
                = OSSL_FUNC_asym_cipher_gettable_ctx_params(fns);
417
0
            gparamfncnt++;
418
0
            break;
419
0
        case OSSL_FUNC_ASYM_CIPHER_SET_CTX_PARAMS:
420
0
            if (cipher->set_ctx_params != NULL)
421
0
                break;
422
0
            cipher->set_ctx_params
423
0
                = OSSL_FUNC_asym_cipher_set_ctx_params(fns);
424
0
            sparamfncnt++;
425
0
            break;
426
0
        case OSSL_FUNC_ASYM_CIPHER_SETTABLE_CTX_PARAMS:
427
0
            if (cipher->settable_ctx_params != NULL)
428
0
                break;
429
0
            cipher->settable_ctx_params
430
0
                = OSSL_FUNC_asym_cipher_settable_ctx_params(fns);
431
0
            sparamfncnt++;
432
0
            break;
433
0
        }
434
0
    }
435
0
    if (ctxfncnt != 2
436
0
        || (encfncnt != 0 && encfncnt != 2)
437
0
        || (decfncnt != 0 && decfncnt != 2)
438
0
        || (encfncnt != 2 && decfncnt != 2)
439
0
        || (gparamfncnt != 0 && gparamfncnt != 2)
440
0
        || (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
0
    return cipher;
455
0
err:
456
0
    evp_asym_cipher_free(cipher);
457
0
    return NULL;
458
0
}
459
460
void EVP_ASYM_CIPHER_free(EVP_ASYM_CIPHER *cipher)
461
0
{
462
#ifdef OPENSSL_NO_CACHED_FETCH
463
    evp_asym_cipher_free(cipher);
464
#else
465
0
    if (cipher != NULL && (cipher->no_store != 0))
466
0
        evp_asym_cipher_free(cipher);
467
0
#endif
468
0
}
469
470
int EVP_ASYM_CIPHER_up_ref(EVP_ASYM_CIPHER *cipher)
471
0
{
472
#ifdef OPENSSL_NO_CACHED_FETCH
473
    return evp_asym_cipher_up_ref(cipher);
474
#else
475
0
    if (cipher->no_store != 0)
476
0
        return evp_asym_cipher_up_ref(cipher);
477
0
    return 1;
478
0
#endif
479
0
}
480
481
OSSL_PROVIDER *EVP_ASYM_CIPHER_get0_provider(const EVP_ASYM_CIPHER *cipher)
482
0
{
483
0
    return cipher->prov;
484
0
}
485
486
EVP_ASYM_CIPHER *EVP_ASYM_CIPHER_fetch(OSSL_LIB_CTX *ctx, const char *algorithm,
487
    const char *properties)
488
0
{
489
0
    return evp_generic_fetch(ctx, OSSL_OP_ASYM_CIPHER, algorithm, properties,
490
0
        evp_asym_cipher_from_algorithm,
491
0
        evp_asym_cipher_up_ref,
492
0
        evp_asym_cipher_free);
493
0
}
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
0
{
531
0
    struct EVP_ASYM_CIPHER_do_all_provided_thunk t;
532
533
0
    t.fn = fn;
534
0
    t.arg = arg;
535
0
    evp_generic_do_all(libctx, OSSL_OP_ASYM_CIPHER,
536
0
        EVP_ASYM_CIPHER_do_all_provided_thunk, &t,
537
0
        evp_asym_cipher_from_algorithm,
538
0
        evp_asym_cipher_up_ref,
539
0
        evp_asym_cipher_free);
540
0
}
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
0
{
565
0
    void *provctx;
566
567
0
    if (cip == NULL || cip->settable_ctx_params == NULL)
568
0
        return NULL;
569
570
0
    provctx = ossl_provider_ctx(EVP_ASYM_CIPHER_get0_provider(cip));
571
    return cip->settable_ctx_params(NULL, provctx);
572
0
}