Coverage Report

Created: 2025-12-10 06:24

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