5 DH_generate_key, DH_compute_key, DH_compute_key_padded - perform
6 Diffie-Hellman key exchange
10 #include <openssl/dh.h>
12 int DH_generate_key(DH *dh);
14 int DH_compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh);
16 int DH_compute_key_padded(unsigned char *key, const BIGNUM *pub_key, DH *dh);
20 DH_generate_key() performs the first step of a Diffie-Hellman key
21 exchange by generating private and public DH values. By calling
22 DH_compute_key() or DH_compute_key_padded(), these are combined with
23 the other party's public value to compute the shared key.
25 DH_generate_key() expects B<dh> to contain the shared parameters
26 B<dh-E<gt>p> and B<dh-E<gt>g>. It generates a random private DH value
27 unless B<dh-E<gt>priv_key> is already set, and computes the
28 corresponding public value B<dh-E<gt>pub_key>, which can then be
31 DH_compute_key() computes the shared secret from the private DH value
32 in B<dh> and the other party's public value in B<pub_key> and stores
33 it in B<key>. B<key> must point to B<DH_size(dh)> bytes of memory.
34 The padding style is RFC 5246 (8.1.2) that strips leading zero bytes.
35 It is not constant time due to the leading zero bytes being stripped.
36 The return value should be considered public.
38 DH_compute_key_padded() is similar but stores a fixed number of bytes.
39 The padding style is NIST SP 800-56A (C.1) that retains leading zero bytes.
40 It is constant time due to the leading zero bytes being retained.
41 The return value should be considered public.
45 DH_generate_key() returns 1 on success, 0 otherwise.
47 DH_compute_key() returns the size of the shared secret on success, -1
50 DH_compute_key_padded() returns B<DH_size(dh)> on success, -1 on error.
52 The error codes can be obtained by L<ERR_get_error(3)>.
56 L<DH_new(3)>, L<ERR_get_error(3)>, L<RAND_bytes(3)>, L<DH_size(3)>
60 DH_compute_key_padded() was added in OpenSSL 1.0.2.
64 Copyright 2000-2021 The OpenSSL Project Authors. All Rights Reserved.
66 Licensed under the OpenSSL license (the "License"). You may not use
67 this file except in compliance with the License. You can obtain a copy
68 in the file LICENSE in the source distribution or at
69 L<https://www.openssl.org/source/license.html>.