5 EVP_KEYEXCH-ECDH - ECDH Key Exchange algorithm support
9 Key exchange support for the B<ECDH> key type.
11 =head2 ECDH Key Exchange parameters
15 =item "ecdh-cofactor-mode" (B<OSSL_EXCHANGE_PARAM_EC_ECDH_COFACTOR_MODE>) <integer>
17 Sets or gets the ECDH mode of operation for the associated key exchange ctx.
19 In the context of an Elliptic Curve Diffie-Hellman key exchange, this parameter
20 can be used to select between the plain Diffie-Hellman (DH) or Cofactor
21 Diffie-Hellman (CDH) variants of the key exchange algorithm.
23 When setting, the value should be 1, 0 or -1, respectively forcing cofactor mode
24 on, off, or resetting it to the default for the private key associated with the
25 given key exchange ctx.
27 When getting, the value should be either 1 or 0, respectively signaling if the
28 cofactor mode is on or off.
30 See also L<provider-keymgmt(7)> for the related
31 B<OSSL_PKEY_PARAM_USE_COFACTOR_ECDH> parameter that can be set on a
34 =item "kdf-type" (B<OSSL_EXCHANGE_PARAM_KDF_TYPE>) <utf8_string>
36 Sets or gets the Key Derivation Function type to apply within the associated key
39 =item "kdf-digest" (B<OSSL_EXCHANGE_PARAM_KDF_DIGEST>) <utf8_string>
41 Sets or gets the Digest algorithm to be used as part of the Key Derivation Function
42 associated with the given key exchange ctx.
44 =item "kdf-digest-props" (B<OSSL_EXCHANGE_PARAM_KDF_DIGEST_PROPS>) <utf8_string>
46 Sets properties to be used upon look up of the implementation for the selected
47 Digest algorithm for the Key Derivation Function associated with the given key
50 =item "kdf-outlen" (B<OSSL_EXCHANGE_PARAM_KDF_OUTLEN>) <size_t>
52 Sets or gets the desired size for the output of the chosen Key Derivation Function
53 associated with the given key exchange ctx.
55 =item "kdf-ukm" (B<OSSL_EXCHANGE_PARAM_KDF_UKM>) <octet_string>
57 Sets the User Key Material to be used as part of the selected Key Derivation
58 Function associated with the given key exchange ctx.
60 =item "kdf-ukm" (B<OSSL_EXCHANGE_PARAM_KDF_UKM>) <octet_string_ptr>
62 Gets a pointer to the User Key Material to be used as part of the selected
63 Key Derivation Function associated with the given key exchange ctx.
65 =item "kdf-ukm-len" (B<OSSL_EXCHANGE_PARAM_KDF_UKM_LEN>) <size_t>
67 Gets the size of the User Key Material to be used as part of the selected
68 Key Derivation Function associated with the given key exchange ctx.
74 Keys for the host and peer must be generated as shown in
75 L<EVP_PKEY-EC(7)/Examples> using the same curve name.
77 The code to generate a shared secret for the normal case is identical to
78 L<EVP_KEYEXCH-DH(7)/Examples>.
80 To derive a shared secret on the host using the host's key and the peer's public
81 key but also using X963KDF with a user key material:
83 /* It is assumed that the host_key, peer_pub_key and ukm are set up */
84 void derive_secret(EVP_PKEY *host_key, EVP_PKEY *peer_key,
85 unsigned char *ukm, size_t ukm_len)
87 unsigned char secret[64];
88 size_t out_len = sizeof(secret);
89 size_t secret_len = out_len;
92 EVP_PKET_CTX *dctx = EVP_PKEY_CTX_new_from_pkey(NULL, host_key, NULL);
94 EVP_PKEY_derive_init(dctx);
96 params[0] = OSSL_PARAM_construct_uint(OSSL_EXCHANGE_PARAM_PAD, &pad);
97 params[1] = OSSL_PARAM_construct_utf8_string(OSSL_EXCHANGE_PARAM_KDF_TYPE,
99 params[2] = OSSL_PARAM_construct_utf8_string(OSSL_EXCHANGE_PARAM_KDF_DIGEST,
101 params[3] = OSSL_PARAM_construct_size_t(OSSL_EXCHANGE_PARAM_KDF_OUTLEN,
103 params[4] = OSSL_PARAM_construct_octet_string(OSSL_EXCHANGE_PARAM_KDF_UKM,
105 params[5] = OSSL_PARAM_construct_end();
106 EVP_PKEY_CTX_set_params(dctx, params);
108 EVP_PKEY_derive_set_peer(dctx, peer_pub_key);
109 EVP_PKEY_derive(dctx, secret, &secret_len);
111 OPENSSL_clear_free(secret, secret_len);
112 EVP_PKEY_CTX_free(dctx);
119 L<provider-keyexch(7)>,
120 L<provider-keymgmt(7)>,
121 L<OSSL_PROVIDER-default(7)>,
122 L<OSSL_PROVIDER-FIPS(7)>,
126 Copyright 2020 The OpenSSL Project Authors. All Rights Reserved.
128 Licensed under the Apache License 2.0 (the "License"). You may not use
129 this file except in compliance with the License. You can obtain a copy
130 in the file LICENSE in the source distribution or at
131 L<https://www.openssl.org/source/license.html>.