Coverage Report

Created: 2025-12-31 06:58

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openssl33/providers/implementations/exchange/ecdh_exch.c
Line
Count
Source
1
/*
2
 * Copyright 2020-2023 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
/*
11
 * ECDH low level APIs are deprecated for public use, but still ok for
12
 * internal use.
13
 */
14
#include "internal/deprecated.h"
15
16
#include <string.h>
17
#include <openssl/crypto.h>
18
#include <openssl/evp.h>
19
#include <openssl/core_dispatch.h>
20
#include <openssl/core_names.h>
21
#include <openssl/ec.h>
22
#include <openssl/params.h>
23
#include <openssl/err.h>
24
#include <openssl/proverr.h>
25
#include "prov/provider_ctx.h"
26
#include "prov/providercommon.h"
27
#include "prov/implementations.h"
28
#include "prov/securitycheck.h"
29
#include "crypto/ec.h" /* ossl_ecdh_kdf_X9_63() */
30
31
static OSSL_FUNC_keyexch_newctx_fn ecdh_newctx;
32
static OSSL_FUNC_keyexch_init_fn ecdh_init;
33
static OSSL_FUNC_keyexch_set_peer_fn ecdh_set_peer;
34
static OSSL_FUNC_keyexch_derive_fn ecdh_derive;
35
static OSSL_FUNC_keyexch_freectx_fn ecdh_freectx;
36
static OSSL_FUNC_keyexch_dupctx_fn ecdh_dupctx;
37
static OSSL_FUNC_keyexch_set_ctx_params_fn ecdh_set_ctx_params;
38
static OSSL_FUNC_keyexch_settable_ctx_params_fn ecdh_settable_ctx_params;
39
static OSSL_FUNC_keyexch_get_ctx_params_fn ecdh_get_ctx_params;
40
static OSSL_FUNC_keyexch_gettable_ctx_params_fn ecdh_gettable_ctx_params;
41
42
enum kdf_type {
43
    PROV_ECDH_KDF_NONE = 0,
44
    PROV_ECDH_KDF_X9_63
45
};
46
47
/*
48
 * What's passed as an actual key is defined by the KEYMGMT interface.
49
 * We happen to know that our KEYMGMT simply passes EC_KEY structures, so
50
 * we use that here too.
51
 */
52
53
typedef struct {
54
    OSSL_LIB_CTX *libctx;
55
56
    EC_KEY *k;
57
    EC_KEY *peerk;
58
59
    /*
60
     * ECDH cofactor mode:
61
     *
62
     *  . 0  disabled
63
     *  . 1  enabled
64
     *  . -1 use cofactor mode set for k
65
     */
66
    int cofactor_mode;
67
68
    /************
69
     * ECDH KDF *
70
     ************/
71
    /* KDF (if any) to use for ECDH */
72
    enum kdf_type kdf_type;
73
    /* Message digest to use for key derivation */
74
    EVP_MD *kdf_md;
75
    /* User key material */
76
    unsigned char *kdf_ukm;
77
    size_t kdf_ukmlen;
78
    /* KDF output length */
79
    size_t kdf_outlen;
80
} PROV_ECDH_CTX;
81
82
static void *ecdh_newctx(void *provctx)
83
4.31k
{
84
4.31k
    PROV_ECDH_CTX *pectx;
85
86
4.31k
    if (!ossl_prov_is_running())
87
0
        return NULL;
88
89
4.31k
    pectx = OPENSSL_zalloc(sizeof(*pectx));
90
4.31k
    if (pectx == NULL)
91
0
        return NULL;
92
93
4.31k
    pectx->libctx = PROV_LIBCTX_OF(provctx);
94
4.31k
    pectx->cofactor_mode = -1;
95
4.31k
    pectx->kdf_type = PROV_ECDH_KDF_NONE;
96
97
4.31k
    return (void *)pectx;
98
4.31k
}
99
100
static int ecdh_init(void *vpecdhctx, void *vecdh, const OSSL_PARAM params[])
101
1.27k
{
102
1.27k
    PROV_ECDH_CTX *pecdhctx = (PROV_ECDH_CTX *)vpecdhctx;
103
104
1.27k
    if (!ossl_prov_is_running()
105
1.27k
        || pecdhctx == NULL
106
1.27k
        || vecdh == NULL
107
1.27k
        || !EC_KEY_up_ref(vecdh))
108
0
        return 0;
109
1.27k
    EC_KEY_free(pecdhctx->k);
110
1.27k
    pecdhctx->k = vecdh;
111
1.27k
    pecdhctx->cofactor_mode = -1;
112
1.27k
    pecdhctx->kdf_type = PROV_ECDH_KDF_NONE;
113
1.27k
    return ecdh_set_ctx_params(pecdhctx, params)
114
1.27k
        && ossl_ec_check_key(pecdhctx->libctx, vecdh, 1);
115
1.27k
}
116
117
static int ecdh_match_params(const EC_KEY *priv, const EC_KEY *peer)
118
4.28k
{
119
4.28k
    int ret;
120
4.28k
    BN_CTX *ctx = NULL;
121
4.28k
    const EC_GROUP *group_priv = EC_KEY_get0_group(priv);
122
4.28k
    const EC_GROUP *group_peer = EC_KEY_get0_group(peer);
123
124
4.28k
    ctx = BN_CTX_new_ex(ossl_ec_key_get_libctx(priv));
125
4.28k
    if (ctx == NULL) {
126
0
        ERR_raise(ERR_LIB_PROV, ERR_R_BN_LIB);
127
0
        return 0;
128
0
    }
129
4.28k
    ret = group_priv != NULL
130
4.28k
        && group_peer != NULL
131
4.28k
        && EC_GROUP_cmp(group_priv, group_peer, ctx) == 0;
132
4.28k
    if (!ret)
133
4.28k
        ERR_raise(ERR_LIB_PROV, PROV_R_MISMATCHING_DOMAIN_PARAMETERS);
134
4.28k
    BN_CTX_free(ctx);
135
4.28k
    return ret;
136
4.28k
}
137
138
static int ecdh_set_peer(void *vpecdhctx, void *vecdh)
139
1.26k
{
140
1.26k
    PROV_ECDH_CTX *pecdhctx = (PROV_ECDH_CTX *)vpecdhctx;
141
142
1.26k
    if (!ossl_prov_is_running()
143
1.26k
        || pecdhctx == NULL
144
1.26k
        || vecdh == NULL
145
1.26k
        || !ecdh_match_params(pecdhctx->k, vecdh)
146
1.26k
        || !ossl_ec_check_key(pecdhctx->libctx, vecdh, 1)
147
1.26k
        || !EC_KEY_up_ref(vecdh))
148
0
        return 0;
149
150
1.26k
    EC_KEY_free(pecdhctx->peerk);
151
1.26k
    pecdhctx->peerk = vecdh;
152
1.26k
    return 1;
153
1.26k
}
154
155
static void ecdh_freectx(void *vpecdhctx)
156
4.31k
{
157
4.31k
    PROV_ECDH_CTX *pecdhctx = (PROV_ECDH_CTX *)vpecdhctx;
158
159
4.31k
    EC_KEY_free(pecdhctx->k);
160
4.31k
    EC_KEY_free(pecdhctx->peerk);
161
162
4.31k
    EVP_MD_free(pecdhctx->kdf_md);
163
4.31k
    OPENSSL_clear_free(pecdhctx->kdf_ukm, pecdhctx->kdf_ukmlen);
164
165
4.31k
    OPENSSL_free(pecdhctx);
166
4.31k
}
167
168
static void *ecdh_dupctx(void *vpecdhctx)
169
0
{
170
0
    PROV_ECDH_CTX *srcctx = (PROV_ECDH_CTX *)vpecdhctx;
171
0
    PROV_ECDH_CTX *dstctx;
172
173
0
    if (!ossl_prov_is_running())
174
0
        return NULL;
175
176
0
    dstctx = OPENSSL_zalloc(sizeof(*srcctx));
177
0
    if (dstctx == NULL)
178
0
        return NULL;
179
180
0
    *dstctx = *srcctx;
181
182
    /* clear all pointers */
183
184
0
    dstctx->k = NULL;
185
0
    dstctx->peerk = NULL;
186
0
    dstctx->kdf_md = NULL;
187
0
    dstctx->kdf_ukm = NULL;
188
189
    /* up-ref all ref-counted objects referenced in dstctx */
190
191
0
    if (srcctx->k != NULL && !EC_KEY_up_ref(srcctx->k))
192
0
        goto err;
193
0
    else
194
0
        dstctx->k = srcctx->k;
195
196
0
    if (srcctx->peerk != NULL && !EC_KEY_up_ref(srcctx->peerk))
197
0
        goto err;
198
0
    else
199
0
        dstctx->peerk = srcctx->peerk;
200
201
0
    if (srcctx->kdf_md != NULL && !EVP_MD_up_ref(srcctx->kdf_md))
202
0
        goto err;
203
0
    else
204
0
        dstctx->kdf_md = srcctx->kdf_md;
205
206
    /* Duplicate UKM data if present */
207
0
    if (srcctx->kdf_ukm != NULL && srcctx->kdf_ukmlen > 0) {
208
0
        dstctx->kdf_ukm = OPENSSL_memdup(srcctx->kdf_ukm,
209
0
            srcctx->kdf_ukmlen);
210
0
        if (dstctx->kdf_ukm == NULL)
211
0
            goto err;
212
0
    }
213
214
0
    return dstctx;
215
216
0
err:
217
0
    ecdh_freectx(dstctx);
218
0
    return NULL;
219
0
}
220
221
static int ecdh_set_ctx_params(void *vpecdhctx, const OSSL_PARAM params[])
222
658
{
223
658
    char name[80] = { '\0' }; /* should be big enough */
224
658
    char *str = NULL;
225
658
    PROV_ECDH_CTX *pectx = (PROV_ECDH_CTX *)vpecdhctx;
226
658
    const OSSL_PARAM *p;
227
228
658
    if (pectx == NULL)
229
0
        return 0;
230
658
    if (params == NULL)
231
658
        return 1;
232
233
0
    p = OSSL_PARAM_locate_const(params, OSSL_EXCHANGE_PARAM_EC_ECDH_COFACTOR_MODE);
234
0
    if (p != NULL) {
235
0
        int mode;
236
237
0
        if (!OSSL_PARAM_get_int(p, &mode))
238
0
            return 0;
239
240
0
        if (mode < -1 || mode > 1)
241
0
            return 0;
242
243
0
        pectx->cofactor_mode = mode;
244
0
    }
245
246
0
    p = OSSL_PARAM_locate_const(params, OSSL_EXCHANGE_PARAM_KDF_TYPE);
247
0
    if (p != NULL) {
248
0
        str = name;
249
0
        if (!OSSL_PARAM_get_utf8_string(p, &str, sizeof(name)))
250
0
            return 0;
251
252
0
        if (name[0] == '\0')
253
0
            pectx->kdf_type = PROV_ECDH_KDF_NONE;
254
0
        else if (strcmp(name, OSSL_KDF_NAME_X963KDF) == 0)
255
0
            pectx->kdf_type = PROV_ECDH_KDF_X9_63;
256
0
        else
257
0
            return 0;
258
0
    }
259
260
0
    p = OSSL_PARAM_locate_const(params, OSSL_EXCHANGE_PARAM_KDF_DIGEST);
261
0
    if (p != NULL) {
262
0
        char mdprops[80] = { '\0' }; /* should be big enough */
263
264
0
        str = name;
265
0
        if (!OSSL_PARAM_get_utf8_string(p, &str, sizeof(name)))
266
0
            return 0;
267
268
0
        str = mdprops;
269
0
        p = OSSL_PARAM_locate_const(params,
270
0
            OSSL_EXCHANGE_PARAM_KDF_DIGEST_PROPS);
271
272
0
        if (p != NULL) {
273
0
            if (!OSSL_PARAM_get_utf8_string(p, &str, sizeof(mdprops)))
274
0
                return 0;
275
0
        }
276
277
0
        EVP_MD_free(pectx->kdf_md);
278
0
        pectx->kdf_md = EVP_MD_fetch(pectx->libctx, name, mdprops);
279
0
        if (pectx->kdf_md == NULL)
280
0
            return 0;
281
0
        if (!ossl_digest_is_allowed(pectx->libctx, pectx->kdf_md)) {
282
0
            EVP_MD_free(pectx->kdf_md);
283
0
            pectx->kdf_md = NULL;
284
0
            return 0;
285
0
        }
286
0
    }
287
288
0
    p = OSSL_PARAM_locate_const(params, OSSL_EXCHANGE_PARAM_KDF_OUTLEN);
289
0
    if (p != NULL) {
290
0
        size_t outlen;
291
292
0
        if (!OSSL_PARAM_get_size_t(p, &outlen))
293
0
            return 0;
294
0
        pectx->kdf_outlen = outlen;
295
0
    }
296
297
0
    p = OSSL_PARAM_locate_const(params, OSSL_EXCHANGE_PARAM_KDF_UKM);
298
0
    if (p != NULL) {
299
0
        void *tmp_ukm = NULL;
300
0
        size_t tmp_ukmlen;
301
302
0
        if (!OSSL_PARAM_get_octet_string(p, &tmp_ukm, 0, &tmp_ukmlen))
303
0
            return 0;
304
0
        OPENSSL_free(pectx->kdf_ukm);
305
0
        pectx->kdf_ukm = tmp_ukm;
306
0
        pectx->kdf_ukmlen = tmp_ukmlen;
307
0
    }
308
309
0
    return 1;
310
0
}
311
312
static const OSSL_PARAM known_settable_ctx_params[] = {
313
    OSSL_PARAM_int(OSSL_EXCHANGE_PARAM_EC_ECDH_COFACTOR_MODE, NULL),
314
    OSSL_PARAM_utf8_string(OSSL_EXCHANGE_PARAM_KDF_TYPE, NULL, 0),
315
    OSSL_PARAM_utf8_string(OSSL_EXCHANGE_PARAM_KDF_DIGEST, NULL, 0),
316
    OSSL_PARAM_utf8_string(OSSL_EXCHANGE_PARAM_KDF_DIGEST_PROPS, NULL, 0),
317
    OSSL_PARAM_size_t(OSSL_EXCHANGE_PARAM_KDF_OUTLEN, NULL),
318
    OSSL_PARAM_octet_string(OSSL_EXCHANGE_PARAM_KDF_UKM, NULL, 0),
319
    OSSL_PARAM_END
320
};
321
322
static const OSSL_PARAM *ecdh_settable_ctx_params(ossl_unused void *vpecdhctx,
323
    ossl_unused void *provctx)
324
25
{
325
25
    return known_settable_ctx_params;
326
25
}
327
328
static int ecdh_get_ctx_params(void *vpecdhctx, OSSL_PARAM params[])
329
0
{
330
0
    PROV_ECDH_CTX *pectx = (PROV_ECDH_CTX *)vpecdhctx;
331
0
    OSSL_PARAM *p;
332
333
0
    if (pectx == NULL)
334
0
        return 0;
335
336
0
    p = OSSL_PARAM_locate(params, OSSL_EXCHANGE_PARAM_EC_ECDH_COFACTOR_MODE);
337
0
    if (p != NULL) {
338
0
        int mode = pectx->cofactor_mode;
339
340
0
        if (mode == -1) {
341
            /* check what is the default for pecdhctx->k */
342
0
            mode = EC_KEY_get_flags(pectx->k) & EC_FLAG_COFACTOR_ECDH ? 1 : 0;
343
0
        }
344
345
0
        if (!OSSL_PARAM_set_int(p, mode))
346
0
            return 0;
347
0
    }
348
349
0
    p = OSSL_PARAM_locate(params, OSSL_EXCHANGE_PARAM_KDF_TYPE);
350
0
    if (p != NULL) {
351
0
        const char *kdf_type = NULL;
352
353
0
        switch (pectx->kdf_type) {
354
0
        case PROV_ECDH_KDF_NONE:
355
0
            kdf_type = "";
356
0
            break;
357
0
        case PROV_ECDH_KDF_X9_63:
358
0
            kdf_type = OSSL_KDF_NAME_X963KDF;
359
0
            break;
360
0
        default:
361
0
            return 0;
362
0
        }
363
364
0
        if (!OSSL_PARAM_set_utf8_string(p, kdf_type))
365
0
            return 0;
366
0
    }
367
368
0
    p = OSSL_PARAM_locate(params, OSSL_EXCHANGE_PARAM_KDF_DIGEST);
369
0
    if (p != NULL
370
0
        && !OSSL_PARAM_set_utf8_string(p, pectx->kdf_md == NULL ? "" : EVP_MD_get0_name(pectx->kdf_md))) {
371
0
        return 0;
372
0
    }
373
374
0
    p = OSSL_PARAM_locate(params, OSSL_EXCHANGE_PARAM_KDF_OUTLEN);
375
0
    if (p != NULL && !OSSL_PARAM_set_size_t(p, pectx->kdf_outlen))
376
0
        return 0;
377
378
0
    p = OSSL_PARAM_locate(params, OSSL_EXCHANGE_PARAM_KDF_UKM);
379
0
    if (p != NULL && !OSSL_PARAM_set_octet_ptr(p, pectx->kdf_ukm, pectx->kdf_ukmlen))
380
0
        return 0;
381
382
0
    return 1;
383
0
}
384
385
static const OSSL_PARAM known_gettable_ctx_params[] = {
386
    OSSL_PARAM_int(OSSL_EXCHANGE_PARAM_EC_ECDH_COFACTOR_MODE, NULL),
387
    OSSL_PARAM_utf8_string(OSSL_EXCHANGE_PARAM_KDF_TYPE, NULL, 0),
388
    OSSL_PARAM_utf8_string(OSSL_EXCHANGE_PARAM_KDF_DIGEST, NULL, 0),
389
    OSSL_PARAM_size_t(OSSL_EXCHANGE_PARAM_KDF_OUTLEN, NULL),
390
    OSSL_PARAM_DEFN(OSSL_EXCHANGE_PARAM_KDF_UKM, OSSL_PARAM_OCTET_PTR,
391
        NULL, 0),
392
    OSSL_PARAM_END
393
};
394
395
static const OSSL_PARAM *ecdh_gettable_ctx_params(ossl_unused void *vpecdhctx,
396
    ossl_unused void *provctx)
397
0
{
398
0
    return known_gettable_ctx_params;
399
0
}
400
401
static ossl_inline
402
    size_t
403
    ecdh_size(const EC_KEY *k)
404
8.57k
{
405
8.57k
    size_t degree = 0;
406
8.57k
    const EC_GROUP *group;
407
408
8.57k
    if (k == NULL
409
8.57k
        || (group = EC_KEY_get0_group(k)) == NULL)
410
0
        return 0;
411
412
8.57k
    degree = EC_GROUP_get_degree(group);
413
414
8.57k
    return (degree + 7) / 8;
415
8.57k
}
416
417
static ossl_inline int ecdh_plain_derive(void *vpecdhctx, unsigned char *secret,
418
    size_t *psecretlen, size_t outlen)
419
2.53k
{
420
2.53k
    PROV_ECDH_CTX *pecdhctx = (PROV_ECDH_CTX *)vpecdhctx;
421
2.53k
    int retlen, ret = 0;
422
2.53k
    size_t ecdhsize, size;
423
2.53k
    const EC_POINT *ppubkey = NULL;
424
2.53k
    EC_KEY *privk = NULL;
425
2.53k
    const EC_GROUP *group;
426
2.53k
    const BIGNUM *cofactor;
427
2.53k
    int key_cofactor_mode;
428
429
2.53k
    if (pecdhctx->k == NULL || pecdhctx->peerk == NULL) {
430
0
        ERR_raise(ERR_LIB_PROV, PROV_R_MISSING_KEY);
431
0
        return 0;
432
0
    }
433
434
2.53k
    ecdhsize = ecdh_size(pecdhctx->k);
435
2.53k
    if (secret == NULL) {
436
1.26k
        *psecretlen = ecdhsize;
437
1.26k
        return 1;
438
1.26k
    }
439
440
1.26k
    if ((group = EC_KEY_get0_group(pecdhctx->k)) == NULL
441
1.26k
        || (cofactor = EC_GROUP_get0_cofactor(group)) == NULL)
442
0
        return 0;
443
444
    /*
445
     * NB: unlike PKCS#3 DH, if outlen is less than maximum size this is not
446
     * an error, the result is truncated.
447
     */
448
1.26k
    size = outlen < ecdhsize ? outlen : ecdhsize;
449
450
    /*
451
     * The ctx->cofactor_mode flag has precedence over the
452
     * cofactor_mode flag set on ctx->k.
453
     *
454
     * - if ctx->cofactor_mode == -1, use ctx->k directly
455
     * - if ctx->cofactor_mode == key_cofactor_mode, use ctx->k directly
456
     * - if ctx->cofactor_mode != key_cofactor_mode:
457
     *     - if ctx->k->cofactor == 1, the cofactor_mode flag is irrelevant, use
458
     *          ctx->k directly
459
     *     - if ctx->k->cofactor != 1, use a duplicate of ctx->k with the flag
460
     *          set to ctx->cofactor_mode
461
     */
462
1.26k
    key_cofactor_mode = (EC_KEY_get_flags(pecdhctx->k) & EC_FLAG_COFACTOR_ECDH) ? 1 : 0;
463
1.26k
    if (pecdhctx->cofactor_mode != -1
464
0
        && pecdhctx->cofactor_mode != key_cofactor_mode
465
0
        && !BN_is_one(cofactor)) {
466
0
        if ((privk = EC_KEY_dup(pecdhctx->k)) == NULL)
467
0
            return 0;
468
469
0
        if (pecdhctx->cofactor_mode == 1)
470
0
            EC_KEY_set_flags(privk, EC_FLAG_COFACTOR_ECDH);
471
0
        else
472
0
            EC_KEY_clear_flags(privk, EC_FLAG_COFACTOR_ECDH);
473
1.26k
    } else {
474
1.26k
        privk = pecdhctx->k;
475
1.26k
    }
476
477
1.26k
    ppubkey = EC_KEY_get0_public_key(pecdhctx->peerk);
478
479
1.26k
    retlen = ECDH_compute_key(secret, size, ppubkey, privk, NULL);
480
481
1.26k
    if (retlen <= 0)
482
0
        goto end;
483
484
1.26k
    *psecretlen = retlen;
485
1.26k
    ret = 1;
486
487
1.26k
end:
488
1.26k
    if (privk != pecdhctx->k)
489
0
        EC_KEY_free(privk);
490
1.26k
    return ret;
491
1.26k
}
492
493
static ossl_inline int ecdh_X9_63_kdf_derive(void *vpecdhctx, unsigned char *secret,
494
    size_t *psecretlen, size_t outlen)
495
0
{
496
0
    PROV_ECDH_CTX *pecdhctx = (PROV_ECDH_CTX *)vpecdhctx;
497
0
    unsigned char *stmp = NULL;
498
0
    size_t stmplen;
499
0
    int ret = 0;
500
501
0
    if (secret == NULL) {
502
0
        *psecretlen = pecdhctx->kdf_outlen;
503
0
        return 1;
504
0
    }
505
506
0
    if (pecdhctx->kdf_outlen > outlen) {
507
0
        ERR_raise(ERR_LIB_PROV, PROV_R_OUTPUT_BUFFER_TOO_SMALL);
508
0
        return 0;
509
0
    }
510
0
    if (!ecdh_plain_derive(vpecdhctx, NULL, &stmplen, 0))
511
0
        return 0;
512
0
    if ((stmp = OPENSSL_secure_malloc(stmplen)) == NULL)
513
0
        return 0;
514
0
    if (!ecdh_plain_derive(vpecdhctx, stmp, &stmplen, stmplen))
515
0
        goto err;
516
517
    /* Do KDF stuff */
518
0
    if (!ossl_ecdh_kdf_X9_63(secret, pecdhctx->kdf_outlen,
519
0
            stmp, stmplen,
520
0
            pecdhctx->kdf_ukm,
521
0
            pecdhctx->kdf_ukmlen,
522
0
            pecdhctx->kdf_md,
523
0
            pecdhctx->libctx, NULL))
524
0
        goto err;
525
0
    *psecretlen = pecdhctx->kdf_outlen;
526
0
    ret = 1;
527
528
0
err:
529
0
    OPENSSL_secure_clear_free(stmp, stmplen);
530
0
    return ret;
531
0
}
532
533
static int ecdh_derive(void *vpecdhctx, unsigned char *secret,
534
    size_t *psecretlen, size_t outlen)
535
8.57k
{
536
8.57k
    PROV_ECDH_CTX *pecdhctx = (PROV_ECDH_CTX *)vpecdhctx;
537
538
8.57k
    switch (pecdhctx->kdf_type) {
539
8.57k
    case PROV_ECDH_KDF_NONE:
540
8.57k
        return ecdh_plain_derive(vpecdhctx, secret, psecretlen, outlen);
541
0
    case PROV_ECDH_KDF_X9_63:
542
0
        return ecdh_X9_63_kdf_derive(vpecdhctx, secret, psecretlen, outlen);
543
0
    default:
544
0
        break;
545
8.57k
    }
546
0
    return 0;
547
8.57k
}
548
549
const OSSL_DISPATCH ossl_ecdh_keyexch_functions[] = {
550
    { OSSL_FUNC_KEYEXCH_NEWCTX, (void (*)(void))ecdh_newctx },
551
    { OSSL_FUNC_KEYEXCH_INIT, (void (*)(void))ecdh_init },
552
    { OSSL_FUNC_KEYEXCH_DERIVE, (void (*)(void))ecdh_derive },
553
    { OSSL_FUNC_KEYEXCH_SET_PEER, (void (*)(void))ecdh_set_peer },
554
    { OSSL_FUNC_KEYEXCH_FREECTX, (void (*)(void))ecdh_freectx },
555
    { OSSL_FUNC_KEYEXCH_DUPCTX, (void (*)(void))ecdh_dupctx },
556
    { OSSL_FUNC_KEYEXCH_SET_CTX_PARAMS, (void (*)(void))ecdh_set_ctx_params },
557
    { OSSL_FUNC_KEYEXCH_SETTABLE_CTX_PARAMS,
558
        (void (*)(void))ecdh_settable_ctx_params },
559
    { OSSL_FUNC_KEYEXCH_GET_CTX_PARAMS, (void (*)(void))ecdh_get_ctx_params },
560
    { OSSL_FUNC_KEYEXCH_GETTABLE_CTX_PARAMS,
561
        (void (*)(void))ecdh_gettable_ctx_params },
562
    OSSL_DISPATCH_END
563
};