5 DH_generate_key, DH_compute_key - perform Diffie-Hellman key exchange
9 #include <openssl/dh.h>
11 Deprecated since OpenSSL 3.0, can be hidden entirely by defining
12 B<OPENSSL_API_COMPAT> with a suitable version value, see
13 L<openssl_user_macros(7)>:
15 int DH_generate_key(DH *dh);
17 int DH_compute_key(unsigned char *key, BIGNUM *pub_key, DH *dh);
21 Both of the functions described on this page are deprecated.
22 Applications should instead use L<EVP_PKEY_derive_init(3)>
23 and L<EVP_PKEY_derive(3)>.
25 DH_generate_key() performs the first step of a Diffie-Hellman key
26 exchange by generating private and public DH values. By calling
27 DH_compute_key(), these are combined with the other party's public
28 value to compute the shared key.
30 DH_generate_key() expects B<dh> to contain the shared parameters
31 B<dh-E<gt>p> and B<dh-E<gt>g>. It generates a random private DH value
32 unless B<dh-E<gt>priv_key> is already set, and computes the
33 corresponding public value B<dh-E<gt>pub_key>, which can then be
36 DH_compute_key() computes the shared secret from the private DH value
37 in B<dh> and the other party's public value in B<pub_key> and stores
38 it in B<key>. B<key> must point to B<DH_size(dh)> bytes of memory.
42 DH_generate_key() returns 1 on success, 0 otherwise.
44 DH_compute_key() returns the size of the shared secret on success, -1
47 The error codes can be obtained by L<ERR_get_error(3)>.
51 L<EVP_PKEY_derive(3)>,
52 L<DH_new(3)>, L<ERR_get_error(3)>, L<RAND_bytes(3)>, L<DH_size(3)>
56 Both of these functions were deprecated in OpenSSL 3.0.
60 Copyright 2000-2020 The OpenSSL Project Authors. All Rights Reserved.
62 Licensed under the Apache License 2.0 (the "License"). You may not use
63 this file except in compliance with the License. You can obtain a copy
64 in the file LICENSE in the source distribution or at
65 L<https://www.openssl.org/source/license.html>.