xref: /freebsd/crypto/openssl/doc/man3/DH_generate_key.pod (revision 6fa42b91ca3f481912af98c4d49c44507eb1b8e1)
1=pod
2
3=head1 NAME
4
5DH_generate_key, DH_compute_key, DH_compute_key_padded - perform
6Diffie-Hellman key exchange
7
8=head1 SYNOPSIS
9
10 #include <openssl/dh.h>
11
12The following functions have been deprecated since OpenSSL 3.0, and can be
13hidden entirely by defining B<OPENSSL_API_COMPAT> with a suitable version value,
14see L<openssl_user_macros(7)>:
15
16 int DH_generate_key(DH *dh);
17
18 int DH_compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh);
19
20 int DH_compute_key_padded(unsigned char *key, const BIGNUM *pub_key, DH *dh);
21
22=head1 DESCRIPTION
23
24All of the functions described on this page are deprecated.
25Applications should instead use L<EVP_PKEY_derive_init(3)>
26and L<EVP_PKEY_derive(3)>.
27
28DH_generate_key() performs the first step of a Diffie-Hellman key
29exchange by generating private and public DH values. By calling
30DH_compute_key() or DH_compute_key_padded(), these are combined with
31the other party's public value to compute the shared key.
32
33DH_generate_key() expects B<dh> to contain the shared parameters
34B<dh-E<gt>p> and B<dh-E<gt>g>. It generates a random private DH value
35unless B<dh-E<gt>priv_key> is already set, and computes the
36corresponding public value B<dh-E<gt>pub_key>, which can then be
37published.
38
39DH_compute_key() computes the shared secret from the private DH value
40in B<dh> and the other party's public value in B<pub_key> and stores
41it in B<key>. B<key> must point to B<DH_size(dh)> bytes of memory.
42The padding style is RFC 5246 (8.1.2) that strips leading zero bytes.
43It is not constant time due to the leading zero bytes being stripped.
44The return value should be considered public.
45
46DH_compute_key_padded() is similar but stores a fixed number of bytes.
47The padding style is NIST SP 800-56A (C.1) that retains leading zero bytes.
48It is constant time due to the leading zero bytes being retained.
49The return value should be considered public.
50
51=head1 RETURN VALUES
52
53DH_generate_key() returns 1 on success, 0 otherwise.
54
55DH_compute_key() returns the size of the shared secret on success, -1
56on error.
57
58DH_compute_key_padded() returns B<DH_size(dh)> on success, -1 on error.
59
60The error codes can be obtained by L<ERR_get_error(3)>.
61
62=head1 SEE ALSO
63
64L<EVP_PKEY_derive(3)>,
65L<DH_new(3)>, L<ERR_get_error(3)>, L<RAND_bytes(3)>, L<DH_size(3)>
66
67=head1 HISTORY
68
69DH_compute_key_padded() was added in OpenSSL 1.0.2.
70
71All of these functions were deprecated in OpenSSL 3.0.
72
73=head1 COPYRIGHT
74
75Copyright 2000-2021 The OpenSSL Project Authors. All Rights Reserved.
76
77Licensed under the Apache License 2.0 (the "License").  You may not use
78this file except in compliance with the License.  You can obtain a copy
79in the file LICENSE in the source distribution or at
80L<https://www.openssl.org/source/license.html>.
81
82=cut
83