1EVP_KEYEXCH-ECDH(7ossl)             OpenSSL            EVP_KEYEXCH-ECDH(7ossl)
2
3
4

NAME

6       EVP_KEYEXCH-ECDH - ECDH Key Exchange algorithm support
7

DESCRIPTION

9       Key exchange support for the ECDH key type.
10
11   ECDH Key Exchange parameters
12       "ecdh-cofactor-mode" (OSSL_EXCHANGE_PARAM_EC_ECDH_COFACTOR_MODE)
13       <integer>
14           Sets or gets the ECDH mode of operation for the associated key
15           exchange ctx.
16
17           In the context of an Elliptic Curve Diffie-Hellman key exchange,
18           this parameter can be used to select between the plain Diffie-
19           Hellman (DH) or Cofactor Diffie-Hellman (CDH) variants of the key
20           exchange algorithm.
21
22           When setting, the value should be 1, 0 or -1, respectively forcing
23           cofactor mode on, off, or resetting it to the default for the
24           private key associated with the given key exchange ctx.
25
26           When getting, the value should be either 1 or 0, respectively
27           signaling if the cofactor mode is on or off.
28
29           See also provider-keymgmt(7) for the related
30           OSSL_PKEY_PARAM_USE_COFACTOR_ECDH parameter that can be set on a
31           per-key basis.
32
33       "kdf-type" (OSSL_EXCHANGE_PARAM_KDF_TYPE) <UTF8 string>
34           See "Common Key Exchange parameters" in provider-keyexch(7).
35
36       "kdf-digest" (OSSL_EXCHANGE_PARAM_KDF_DIGEST) <UTF8 string>
37           See "Common Key Exchange parameters" in provider-keyexch(7).
38
39       "kdf-digest-props" (OSSL_EXCHANGE_PARAM_KDF_DIGEST_PROPS) <UTF8 string>
40           See "Common Key Exchange parameters" in provider-keyexch(7).
41
42       "kdf-outlen" (OSSL_EXCHANGE_PARAM_KDF_OUTLEN) <unsigned integer>
43           See "Common Key Exchange parameters" in provider-keyexch(7).
44
45       "kdf-ukm" (OSSL_EXCHANGE_PARAM_KDF_UKM) <octet string>
46           See "Common Key Exchange parameters" in provider-keyexch(7).
47

EXAMPLES

49       Keys for the host and peer must be generated as shown in "Examples" in
50       EVP_PKEY-EC(7) using the same curve name.
51
52       The code to generate a shared secret for the normal case is identical
53       to "Examples" in EVP_KEYEXCH-DH(7).
54
55       To derive a shared secret on the host using the host's key and the
56       peer's public key but also using X963KDF with a user key material:
57
58           /* It is assumed that the host_key, peer_pub_key and ukm are set up */
59           void derive_secret(EVP_PKEY *host_key, EVP_PKEY *peer_key,
60                              unsigned char *ukm, size_t ukm_len)
61           {
62               unsigned char secret[64];
63               size_t out_len = sizeof(secret);
64               size_t secret_len = out_len;
65               unsigned int pad = 1;
66               OSSL_PARAM params[6];
67               EVP_PKEY_CTX *dctx = EVP_PKEY_CTX_new_from_pkey(NULL, host_key, NULL);
68
69               EVP_PKEY_derive_init(dctx);
70
71               params[0] = OSSL_PARAM_construct_uint(OSSL_EXCHANGE_PARAM_PAD, &pad);
72               params[1] = OSSL_PARAM_construct_utf8_string(OSSL_EXCHANGE_PARAM_KDF_TYPE,
73                                                            "X963KDF", 0);
74               params[2] = OSSL_PARAM_construct_utf8_string(OSSL_EXCHANGE_PARAM_KDF_DIGEST,
75                                                            "SHA1", 0);
76               params[3] = OSSL_PARAM_construct_size_t(OSSL_EXCHANGE_PARAM_KDF_OUTLEN,
77                                                       &out_len);
78               params[4] = OSSL_PARAM_construct_octet_string(OSSL_EXCHANGE_PARAM_KDF_UKM,
79                                                             ukm, ukm_len);
80               params[5] = OSSL_PARAM_construct_end();
81               EVP_PKEY_CTX_set_params(dctx, params);
82
83               EVP_PKEY_derive_set_peer(dctx, peer_pub_key);
84               EVP_PKEY_derive(dctx, secret, &secret_len);
85               ...
86               OPENSSL_clear_free(secret, secret_len);
87               EVP_PKEY_CTX_free(dctx);
88           }
89

SEE ALSO

91       EVP_PKEY-EC(7) EVP_PKEY(3), provider-keyexch(7), provider-keymgmt(7),
92       OSSL_PROVIDER-default(7), OSSL_PROVIDER-FIPS(7),
93
95       Copyright 2020-2022 The OpenSSL Project Authors. All Rights Reserved.
96
97       Licensed under the Apache License 2.0 (the "License").  You may not use
98       this file except in compliance with the License.  You can obtain a copy
99       in the file LICENSE in the source distribution or at
100       <https://www.openssl.org/source/license.html>.
101
102
103
1043.0.5                             2022-07-05           EVP_KEYEXCH-ECDH(7ossl)
Impressum