Coverage Report

Created: 2025-06-13 06:56

/src/openssl/crypto/evp/exchange.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 2019-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 <openssl/crypto.h>
11
#include <openssl/evp.h>
12
#include <openssl/err.h>
13
#include "internal/cryptlib.h"
14
#include "internal/refcount.h"
15
#include "internal/provider.h"
16
#include "internal/core.h"
17
#include "internal/numbers.h"   /* includes SIZE_MAX */
18
#include "crypto/evp.h"
19
#include "evp_local.h"
20
21
static void evp_keyexch_free(void *data)
22
0
{
23
0
    EVP_KEYEXCH_free(data);
24
0
}
25
26
static int evp_keyexch_up_ref(void *data)
27
0
{
28
0
    return EVP_KEYEXCH_up_ref(data);
29
0
}
30
31
static EVP_KEYEXCH *evp_keyexch_new(OSSL_PROVIDER *prov)
32
0
{
33
0
    EVP_KEYEXCH *exchange = OPENSSL_zalloc(sizeof(EVP_KEYEXCH));
34
35
0
    if (exchange == NULL)
36
0
        return NULL;
37
38
0
    if (!CRYPTO_NEW_REF(&exchange->refcnt, 1)
39
0
        || !ossl_provider_up_ref(prov)) {
40
0
        CRYPTO_FREE_REF(&exchange->refcnt);
41
0
        OPENSSL_free(exchange);
42
0
        return NULL;
43
0
    }
44
0
    exchange->prov = prov;
45
46
0
    return exchange;
47
0
}
48
49
static void *evp_keyexch_from_algorithm(int name_id,
50
                                        const OSSL_ALGORITHM *algodef,
51
                                        OSSL_PROVIDER *prov)
52
0
{
53
0
    const OSSL_DISPATCH *fns = algodef->implementation;
54
0
    EVP_KEYEXCH *exchange = NULL;
55
0
    int fncnt = 0, sparamfncnt = 0, gparamfncnt = 0;
56
57
0
    if ((exchange = evp_keyexch_new(prov)) == NULL) {
58
0
        ERR_raise(ERR_LIB_EVP, ERR_R_EVP_LIB);
59
0
        goto err;
60
0
    }
61
62
0
    exchange->name_id = name_id;
63
0
    if ((exchange->type_name = ossl_algorithm_get1_first_name(algodef)) == NULL)
64
0
        goto err;
65
0
    exchange->description = algodef->algorithm_description;
66
67
0
    for (; fns->function_id != 0; fns++) {
68
0
        switch (fns->function_id) {
69
0
        case OSSL_FUNC_KEYEXCH_NEWCTX:
70
0
            if (exchange->newctx != NULL)
71
0
                break;
72
0
            exchange->newctx = OSSL_FUNC_keyexch_newctx(fns);
73
0
            fncnt++;
74
0
            break;
75
0
        case OSSL_FUNC_KEYEXCH_INIT:
76
0
            if (exchange->init != NULL)
77
0
                break;
78
0
            exchange->init = OSSL_FUNC_keyexch_init(fns);
79
0
            fncnt++;
80
0
            break;
81
0
        case OSSL_FUNC_KEYEXCH_SET_PEER:
82
0
            if (exchange->set_peer != NULL)
83
0
                break;
84
0
            exchange->set_peer = OSSL_FUNC_keyexch_set_peer(fns);
85
0
            break;
86
0
        case OSSL_FUNC_KEYEXCH_DERIVE:
87
0
            if (exchange->derive != NULL)
88
0
                break;
89
0
            exchange->derive = OSSL_FUNC_keyexch_derive(fns);
90
0
            fncnt++;
91
0
            break;
92
0
        case OSSL_FUNC_KEYEXCH_FREECTX:
93
0
            if (exchange->freectx != NULL)
94
0
                break;
95
0
            exchange->freectx = OSSL_FUNC_keyexch_freectx(fns);
96
0
            fncnt++;
97
0
            break;
98
0
        case OSSL_FUNC_KEYEXCH_DUPCTX:
99
0
            if (exchange->dupctx != NULL)
100
0
                break;
101
0
            exchange->dupctx = OSSL_FUNC_keyexch_dupctx(fns);
102
0
            break;
103
0
        case OSSL_FUNC_KEYEXCH_GET_CTX_PARAMS:
104
0
            if (exchange->get_ctx_params != NULL)
105
0
                break;
106
0
            exchange->get_ctx_params = OSSL_FUNC_keyexch_get_ctx_params(fns);
107
0
            gparamfncnt++;
108
0
            break;
109
0
        case OSSL_FUNC_KEYEXCH_GETTABLE_CTX_PARAMS:
110
0
            if (exchange->gettable_ctx_params != NULL)
111
0
                break;
112
0
            exchange->gettable_ctx_params
113
0
                = OSSL_FUNC_keyexch_gettable_ctx_params(fns);
114
0
            gparamfncnt++;
115
0
            break;
116
0
        case OSSL_FUNC_KEYEXCH_SET_CTX_PARAMS:
117
0
            if (exchange->set_ctx_params != NULL)
118
0
                break;
119
0
            exchange->set_ctx_params = OSSL_FUNC_keyexch_set_ctx_params(fns);
120
0
            sparamfncnt++;
121
0
            break;
122
0
        case OSSL_FUNC_KEYEXCH_SETTABLE_CTX_PARAMS:
123
0
            if (exchange->settable_ctx_params != NULL)
124
0
                break;
125
0
            exchange->settable_ctx_params
126
0
                = OSSL_FUNC_keyexch_settable_ctx_params(fns);
127
0
            sparamfncnt++;
128
0
            break;
129
0
        }
130
0
    }
131
0
    if (fncnt != 4
132
0
            || (gparamfncnt != 0 && gparamfncnt != 2)
133
0
            || (sparamfncnt != 0 && sparamfncnt != 2)) {
134
        /*
135
         * In order to be a consistent set of functions we must have at least
136
         * a complete set of "exchange" functions: init, derive, newctx,
137
         * and freectx. The set_ctx_params and settable_ctx_params functions are
138
         * optional, but if one of them is present then the other one must also
139
         * be present. Same goes for get_ctx_params and gettable_ctx_params.
140
         * The dupctx and set_peer functions are optional.
141
         */
142
0
        ERR_raise(ERR_LIB_EVP, EVP_R_INVALID_PROVIDER_FUNCTIONS);
143
0
        goto err;
144
0
    }
145
146
0
    return exchange;
147
148
0
 err:
149
0
    EVP_KEYEXCH_free(exchange);
150
0
    return NULL;
151
0
}
152
153
void EVP_KEYEXCH_free(EVP_KEYEXCH *exchange)
154
0
{
155
0
    int i;
156
157
0
    if (exchange == NULL)
158
0
        return;
159
0
    CRYPTO_DOWN_REF(&exchange->refcnt, &i);
160
0
    if (i > 0)
161
0
        return;
162
0
    OPENSSL_free(exchange->type_name);
163
0
    ossl_provider_free(exchange->prov);
164
0
    CRYPTO_FREE_REF(&exchange->refcnt);
165
0
    OPENSSL_free(exchange);
166
0
}
167
168
int EVP_KEYEXCH_up_ref(EVP_KEYEXCH *exchange)
169
0
{
170
0
    int ref = 0;
171
172
0
    CRYPTO_UP_REF(&exchange->refcnt, &ref);
173
0
    return 1;
174
0
}
175
176
OSSL_PROVIDER *EVP_KEYEXCH_get0_provider(const EVP_KEYEXCH *exchange)
177
0
{
178
0
    return exchange->prov;
179
0
}
180
181
EVP_KEYEXCH *EVP_KEYEXCH_fetch(OSSL_LIB_CTX *ctx, const char *algorithm,
182
                               const char *properties)
183
0
{
184
0
    return evp_generic_fetch(ctx, OSSL_OP_KEYEXCH, algorithm, properties,
185
0
                             evp_keyexch_from_algorithm,
186
0
                             evp_keyexch_up_ref,
187
0
                             evp_keyexch_free);
188
0
}
189
190
EVP_KEYEXCH *evp_keyexch_fetch_from_prov(OSSL_PROVIDER *prov,
191
                                         const char *algorithm,
192
                                         const char *properties)
193
0
{
194
0
    return evp_generic_fetch_from_prov(prov, OSSL_OP_KEYEXCH,
195
0
                                       algorithm, properties,
196
0
                                       evp_keyexch_from_algorithm,
197
0
                                       evp_keyexch_up_ref,
198
0
                                       evp_keyexch_free);
199
0
}
200
201
int EVP_PKEY_derive_init(EVP_PKEY_CTX *ctx)
202
0
{
203
0
    return EVP_PKEY_derive_init_ex(ctx, NULL);
204
0
}
205
206
int EVP_PKEY_derive_init_ex(EVP_PKEY_CTX *ctx, const OSSL_PARAM params[])
207
0
{
208
0
    int ret;
209
0
    void *provkey = NULL;
210
0
    EVP_KEYEXCH *exchange = NULL;
211
0
    EVP_KEYMGMT *tmp_keymgmt = NULL;
212
0
    const OSSL_PROVIDER *tmp_prov = NULL;
213
0
    const char *supported_exch = NULL;
214
0
    int iter;
215
216
0
    if (ctx == NULL) {
217
0
        ERR_raise(ERR_LIB_EVP, ERR_R_PASSED_NULL_PARAMETER);
218
0
        return -2;
219
0
    }
220
221
0
    evp_pkey_ctx_free_old_ops(ctx);
222
0
    ctx->operation = EVP_PKEY_OP_DERIVE;
223
224
0
    ERR_set_mark();
225
226
0
    if (evp_pkey_ctx_is_legacy(ctx))
227
0
        goto legacy;
228
229
    /*
230
     * Some algorithms (e.g. legacy KDFs) don't have a pkey - so we create
231
     * a blank one.
232
     */
233
0
    if (ctx->pkey == NULL) {
234
0
        EVP_PKEY *pkey = EVP_PKEY_new();
235
236
0
        if (pkey == NULL
237
0
            || !EVP_PKEY_set_type_by_keymgmt(pkey, ctx->keymgmt)
238
0
            || (pkey->keydata = evp_keymgmt_newdata(ctx->keymgmt)) == NULL) {
239
0
            ERR_clear_last_mark();
240
0
            EVP_PKEY_free(pkey);
241
0
            ERR_raise(ERR_LIB_EVP, EVP_R_INITIALIZATION_ERROR);
242
0
            goto err;
243
0
        }
244
0
        ctx->pkey = pkey;
245
0
    }
246
247
    /*
248
     * Try to derive the supported exch from |ctx->keymgmt|.
249
     */
250
0
    if (!ossl_assert(ctx->pkey->keymgmt == NULL
251
0
                     || ctx->pkey->keymgmt == ctx->keymgmt)) {
252
0
        ERR_clear_last_mark();
253
0
        ERR_raise(ERR_LIB_EVP, ERR_R_INTERNAL_ERROR);
254
0
        goto err;
255
0
    }
256
0
    supported_exch = evp_keymgmt_util_query_operation_name(ctx->keymgmt,
257
0
                                                           OSSL_OP_KEYEXCH);
258
0
    if (supported_exch == NULL) {
259
0
        ERR_clear_last_mark();
260
0
        ERR_raise(ERR_LIB_EVP, EVP_R_INITIALIZATION_ERROR);
261
0
        goto err;
262
0
    }
263
264
265
    /*
266
     * We perform two iterations:
267
     *
268
     * 1.  Do the normal exchange fetch, using the fetching data given by
269
     *     the EVP_PKEY_CTX.
270
     * 2.  Do the provider specific exchange fetch, from the same provider
271
     *     as |ctx->keymgmt|
272
     *
273
     * We then try to fetch the keymgmt from the same provider as the
274
     * exchange, and try to export |ctx->pkey| to that keymgmt (when
275
     * this keymgmt happens to be the same as |ctx->keymgmt|, the export
276
     * is a no-op, but we call it anyway to not complicate the code even
277
     * more).
278
     * If the export call succeeds (returns a non-NULL provider key pointer),
279
     * we're done and can perform the operation itself.  If not, we perform
280
     * the second iteration, or jump to legacy.
281
     */
282
0
    for (iter = 1, provkey = NULL; iter < 3 && provkey == NULL; iter++) {
283
0
        EVP_KEYMGMT *tmp_keymgmt_tofree = NULL;
284
285
        /*
286
         * If we're on the second iteration, free the results from the first.
287
         * They are NULL on the first iteration, so no need to check what
288
         * iteration we're on.
289
         */
290
0
        EVP_KEYEXCH_free(exchange);
291
0
        EVP_KEYMGMT_free(tmp_keymgmt);
292
293
0
        switch (iter) {
294
0
        case 1:
295
0
            exchange =
296
0
                EVP_KEYEXCH_fetch(ctx->libctx, supported_exch, ctx->propquery);
297
0
            if (exchange != NULL)
298
0
                tmp_prov = EVP_KEYEXCH_get0_provider(exchange);
299
0
            break;
300
0
        case 2:
301
0
            tmp_prov = EVP_KEYMGMT_get0_provider(ctx->keymgmt);
302
0
            exchange =
303
0
                evp_keyexch_fetch_from_prov((OSSL_PROVIDER *)tmp_prov,
304
0
                                              supported_exch, ctx->propquery);
305
0
            if (exchange == NULL)
306
0
                goto legacy;
307
0
            break;
308
0
        }
309
0
        if (exchange == NULL)
310
0
            continue;
311
312
        /*
313
         * Ensure that the key is provided, either natively, or as a cached
314
         * export.  We start by fetching the keymgmt with the same name as
315
         * |ctx->keymgmt|, but from the provider of the exchange method, using
316
         * the same property query as when fetching the exchange method.
317
         * With the keymgmt we found (if we did), we try to export |ctx->pkey|
318
         * to it (evp_pkey_export_to_provider() is smart enough to only actually
319
         * export it if |tmp_keymgmt| is different from |ctx->pkey|'s keymgmt)
320
         */
321
0
        tmp_keymgmt_tofree = tmp_keymgmt =
322
0
            evp_keymgmt_fetch_from_prov((OSSL_PROVIDER *)tmp_prov,
323
0
                                        EVP_KEYMGMT_get0_name(ctx->keymgmt),
324
0
                                        ctx->propquery);
325
0
        if (tmp_keymgmt != NULL)
326
0
            provkey = evp_pkey_export_to_provider(ctx->pkey, ctx->libctx,
327
0
                                                  &tmp_keymgmt, ctx->propquery);
328
0
        if (tmp_keymgmt == NULL)
329
0
            EVP_KEYMGMT_free(tmp_keymgmt_tofree);
330
0
    }
331
332
0
    if (provkey == NULL) {
333
0
        EVP_KEYEXCH_free(exchange);
334
0
        goto legacy;
335
0
    }
336
337
0
    ERR_pop_to_mark();
338
339
    /* No more legacy from here down to legacy: */
340
341
    /* A Coverity false positive with up_ref/down_ref and free */
342
    /* coverity[use_after_free] */
343
0
    ctx->op.kex.exchange = exchange;
344
    /* A Coverity false positive with up_ref/down_ref and free */
345
    /* coverity[deref_arg] */
346
0
    ctx->op.kex.algctx = exchange->newctx(ossl_provider_ctx(exchange->prov));
347
0
    if (ctx->op.kex.algctx == NULL) {
348
        /* The provider key can stay in the cache */
349
0
        ERR_raise(ERR_LIB_EVP, EVP_R_INITIALIZATION_ERROR);
350
0
        goto err;
351
0
    }
352
0
    ret = exchange->init(ctx->op.kex.algctx, provkey, params);
353
354
0
    EVP_KEYMGMT_free(tmp_keymgmt);
355
0
    return ret ? 1 : 0;
356
0
 err:
357
0
    evp_pkey_ctx_free_old_ops(ctx);
358
0
    ctx->operation = EVP_PKEY_OP_UNDEFINED;
359
0
    EVP_KEYMGMT_free(tmp_keymgmt);
360
0
    return 0;
361
362
0
 legacy:
363
    /*
364
     * If we don't have the full support we need with provided methods,
365
     * let's go see if legacy does.
366
     */
367
0
    ERR_pop_to_mark();
368
369
#ifdef FIPS_MODULE
370
    return 0;
371
#else
372
0
    if (ctx->pmeth == NULL || ctx->pmeth->derive == NULL) {
373
0
        ERR_raise(ERR_LIB_EVP, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
374
0
        return -2;
375
0
    }
376
377
0
    if (ctx->pmeth->derive_init == NULL)
378
0
        return 1;
379
0
    ret = ctx->pmeth->derive_init(ctx);
380
0
    if (ret <= 0)
381
0
        ctx->operation = EVP_PKEY_OP_UNDEFINED;
382
0
    EVP_KEYMGMT_free(tmp_keymgmt);
383
0
    return ret;
384
0
#endif
385
0
}
386
387
int EVP_PKEY_derive_set_peer_ex(EVP_PKEY_CTX *ctx, EVP_PKEY *peer,
388
                                int validate_peer)
389
0
{
390
0
    int ret = 0, check;
391
0
    void *provkey = NULL;
392
0
    EVP_PKEY_CTX *check_ctx = NULL;
393
0
    EVP_KEYMGMT *tmp_keymgmt = NULL, *tmp_keymgmt_tofree = NULL;
394
395
0
    if (ctx == NULL) {
396
0
        ERR_raise(ERR_LIB_EVP, ERR_R_PASSED_NULL_PARAMETER);
397
0
        return -1;
398
0
    }
399
400
0
    if (!EVP_PKEY_CTX_IS_DERIVE_OP(ctx) || ctx->op.kex.algctx == NULL)
401
0
        goto legacy;
402
403
0
    if (ctx->op.kex.exchange->set_peer == NULL) {
404
0
        ERR_raise(ERR_LIB_EVP, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
405
0
        return -2;
406
0
    }
407
408
0
    if (validate_peer) {
409
0
        check_ctx = EVP_PKEY_CTX_new_from_pkey(ctx->libctx, peer, ctx->propquery);
410
0
        if (check_ctx == NULL)
411
0
            return -1;
412
0
        check = EVP_PKEY_public_check(check_ctx);
413
0
        EVP_PKEY_CTX_free(check_ctx);
414
0
        if (check <= 0)
415
0
            return -1;
416
0
    }
417
418
    /*
419
     * Ensure that the |peer| is provided, either natively, or as a cached
420
     * export.  We start by fetching the keymgmt with the same name as
421
     * |ctx->keymgmt|, but from the provider of the exchange method, using
422
     * the same property query as when fetching the exchange method.
423
     * With the keymgmt we found (if we did), we try to export |peer|
424
     * to it (evp_pkey_export_to_provider() is smart enough to only actually
425
     * export it if |tmp_keymgmt| is different from |peer|'s keymgmt)
426
     */
427
0
    tmp_keymgmt_tofree = tmp_keymgmt =
428
0
        evp_keymgmt_fetch_from_prov((OSSL_PROVIDER *)
429
0
                                    EVP_KEYEXCH_get0_provider(ctx->op.kex.exchange),
430
0
                                    EVP_KEYMGMT_get0_name(ctx->keymgmt),
431
0
                                    ctx->propquery);
432
0
    if (tmp_keymgmt != NULL)
433
        /* A Coverity issue with up_ref/down_ref and free */
434
        /* coverity[pass_freed_arg] */
435
0
        provkey = evp_pkey_export_to_provider(peer, ctx->libctx,
436
0
                                              &tmp_keymgmt, ctx->propquery);
437
0
    EVP_KEYMGMT_free(tmp_keymgmt_tofree);
438
439
    /*
440
     * If making the key provided wasn't possible, legacy may be able to pick
441
     * it up
442
     */
443
0
    if (provkey == NULL)
444
0
        goto legacy;
445
0
    ret = ctx->op.kex.exchange->set_peer(ctx->op.kex.algctx, provkey);
446
0
    if (ret <= 0)
447
0
        return ret;
448
0
    goto common;
449
450
0
 legacy:
451
#ifdef FIPS_MODULE
452
    return ret;
453
#else
454
0
    if (ctx->pmeth == NULL
455
0
        || !(ctx->pmeth->derive != NULL
456
0
             || ctx->pmeth->encrypt != NULL
457
0
             || ctx->pmeth->decrypt != NULL)
458
0
        || ctx->pmeth->ctrl == NULL) {
459
0
        ERR_raise(ERR_LIB_EVP, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
460
0
        return -2;
461
0
    }
462
0
    if (ctx->operation != EVP_PKEY_OP_DERIVE
463
0
        && ctx->operation != EVP_PKEY_OP_ENCRYPT
464
0
        && ctx->operation != EVP_PKEY_OP_DECRYPT) {
465
0
        ERR_raise(ERR_LIB_EVP, EVP_R_OPERATION_NOT_INITIALIZED);
466
0
        return -1;
467
0
    }
468
469
0
    ret = ctx->pmeth->ctrl(ctx, EVP_PKEY_CTRL_PEER_KEY, 0, peer);
470
471
0
    if (ret <= 0)
472
0
        return ret;
473
474
0
    if (ret == 2)
475
0
        return 1;
476
477
0
    if (ctx->pkey == NULL) {
478
0
        ERR_raise(ERR_LIB_EVP, EVP_R_NO_KEY_SET);
479
0
        return -1;
480
0
    }
481
482
0
    if (ctx->pkey->type != peer->type) {
483
0
        ERR_raise(ERR_LIB_EVP, EVP_R_DIFFERENT_KEY_TYPES);
484
0
        return -1;
485
0
    }
486
487
    /*
488
     * For clarity.  The error is if parameters in peer are
489
     * present (!missing) but don't match.  EVP_PKEY_parameters_eq may return
490
     * 1 (match), 0 (don't match) and -2 (comparison is not defined).  -1
491
     * (different key types) is impossible here because it is checked earlier.
492
     * -2 is OK for us here, as well as 1, so we can check for 0 only.
493
     */
494
0
    if (!EVP_PKEY_missing_parameters(peer) &&
495
0
        !EVP_PKEY_parameters_eq(ctx->pkey, peer)) {
496
0
        ERR_raise(ERR_LIB_EVP, EVP_R_DIFFERENT_PARAMETERS);
497
0
        return -1;
498
0
    }
499
500
0
    ret = ctx->pmeth->ctrl(ctx, EVP_PKEY_CTRL_PEER_KEY, 1, peer);
501
0
    if (ret <= 0)
502
0
        return ret;
503
0
#endif
504
505
0
 common:
506
0
    if (!EVP_PKEY_up_ref(peer))
507
0
        return -1;
508
509
0
    EVP_PKEY_free(ctx->peerkey);
510
0
    ctx->peerkey = peer;
511
512
0
    return 1;
513
0
}
514
515
int EVP_PKEY_derive_set_peer(EVP_PKEY_CTX *ctx, EVP_PKEY *peer)
516
0
{
517
0
    return EVP_PKEY_derive_set_peer_ex(ctx, peer, 1);
518
0
}
519
520
int EVP_PKEY_derive(EVP_PKEY_CTX *ctx, unsigned char *key, size_t *pkeylen)
521
0
{
522
0
    int ret;
523
524
0
    if (ctx == NULL || pkeylen == NULL) {
525
0
        ERR_raise(ERR_LIB_EVP, ERR_R_PASSED_NULL_PARAMETER);
526
0
        return -1;
527
0
    }
528
529
0
    if (!EVP_PKEY_CTX_IS_DERIVE_OP(ctx)) {
530
0
        ERR_raise(ERR_LIB_EVP, EVP_R_OPERATION_NOT_INITIALIZED);
531
0
        return -1;
532
0
    }
533
534
0
    if (ctx->op.kex.algctx == NULL)
535
0
        goto legacy;
536
537
0
    ret = ctx->op.kex.exchange->derive(ctx->op.kex.algctx, key, pkeylen,
538
0
                                       key != NULL ? *pkeylen : 0);
539
540
0
    return ret;
541
0
 legacy:
542
0
    if (ctx->pmeth == NULL || ctx->pmeth->derive == NULL) {
543
0
        ERR_raise(ERR_LIB_EVP, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
544
0
        return -2;
545
0
    }
546
547
0
    M_check_autoarg(ctx, key, pkeylen, EVP_F_EVP_PKEY_DERIVE)
548
0
        return ctx->pmeth->derive(ctx, key, pkeylen);
549
0
}
550
551
int evp_keyexch_get_number(const EVP_KEYEXCH *keyexch)
552
0
{
553
0
    return keyexch->name_id;
554
0
}
555
556
const char *EVP_KEYEXCH_get0_name(const EVP_KEYEXCH *keyexch)
557
0
{
558
0
    return keyexch->type_name;
559
0
}
560
561
const char *EVP_KEYEXCH_get0_description(const EVP_KEYEXCH *keyexch)
562
0
{
563
0
    return keyexch->description;
564
0
}
565
566
int EVP_KEYEXCH_is_a(const EVP_KEYEXCH *keyexch, const char *name)
567
0
{
568
0
    return keyexch != NULL
569
0
           && evp_is_a(keyexch->prov, keyexch->name_id, NULL, name);
570
0
}
571
572
void EVP_KEYEXCH_do_all_provided(OSSL_LIB_CTX *libctx,
573
                                 void (*fn)(EVP_KEYEXCH *keyexch, void *arg),
574
                                 void *arg)
575
0
{
576
0
    evp_generic_do_all(libctx, OSSL_OP_KEYEXCH,
577
0
                       (void (*)(void *, void *))fn, arg,
578
0
                       evp_keyexch_from_algorithm,
579
0
                       evp_keyexch_up_ref,
580
0
                       evp_keyexch_free);
581
0
}
582
583
int EVP_KEYEXCH_names_do_all(const EVP_KEYEXCH *keyexch,
584
                             void (*fn)(const char *name, void *data),
585
                             void *data)
586
0
{
587
0
    if (keyexch->prov != NULL)
588
0
        return evp_names_do_all(keyexch->prov, keyexch->name_id, fn, data);
589
590
0
    return 1;
591
0
}
592
593
const OSSL_PARAM *EVP_KEYEXCH_gettable_ctx_params(const EVP_KEYEXCH *keyexch)
594
0
{
595
0
    void *provctx;
596
597
0
    if (keyexch == NULL || keyexch->gettable_ctx_params == NULL)
598
0
        return NULL;
599
600
0
    provctx = ossl_provider_ctx(EVP_KEYEXCH_get0_provider(keyexch));
601
0
    return keyexch->gettable_ctx_params(NULL, provctx);
602
0
}
603
604
const OSSL_PARAM *EVP_KEYEXCH_settable_ctx_params(const EVP_KEYEXCH *keyexch)
605
0
{
606
0
    void *provctx;
607
608
0
    if (keyexch == NULL || keyexch->settable_ctx_params == NULL)
609
0
        return NULL;
610
0
    provctx = ossl_provider_ctx(EVP_KEYEXCH_get0_provider(keyexch));
611
0
    return keyexch->settable_ctx_params(NULL, provctx);
612
0
}