blob: 2b14f2ad2762268339e33183570c497d3cd76277 [file] [log] [blame]
Ulf Möller4486d0c2000-01-22 20:05:23 +00001=pod
2
3=head1 NAME
4
Billy Brumley22aa4a32021-01-05 13:08:09 +02005DH_generate_key, DH_compute_key, DH_compute_key_padded - perform
6Diffie-Hellman key exchange
Ulf Möller4486d0c2000-01-22 20:05:23 +00007
8=head1 SYNOPSIS
9
10 #include <openssl/dh.h>
11
Matt Caswell3dbf8242021-12-02 11:33:49 +000012The 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)>:
Pauliada66e72020-02-03 19:05:31 +100015
Ulf Möller4486d0c2000-01-22 20:05:23 +000016 int DH_generate_key(DH *dh);
17
Billy Brumley22aa4a32021-01-05 13:08:09 +020018 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);
Ulf Möller4486d0c2000-01-22 20:05:23 +000021
22=head1 DESCRIPTION
23
Billy Brumley22aa4a32021-01-05 13:08:09 +020024All of the functions described on this page are deprecated.
Pauliada66e72020-02-03 19:05:31 +100025Applications should instead use L<EVP_PKEY_derive_init(3)>
26and L<EVP_PKEY_derive(3)>.
27
Ulf Möller4486d0c2000-01-22 20:05:23 +000028DH_generate_key() performs the first step of a Diffie-Hellman key
29exchange by generating private and public DH values. By calling
Billy Brumley22aa4a32021-01-05 13:08:09 +020030DH_compute_key() or DH_compute_key_padded(), these are combined with
31the other party's public value to compute the shared key.
Ulf Möller4486d0c2000-01-22 20:05:23 +000032
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
Bodo Möller924875e2001-07-27 22:34:25 +000035unless 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.
Ulf Möller4486d0c2000-01-22 20:05:23 +000038
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.
Billy Brumley22aa4a32021-01-05 13:08:09 +020042The 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.
Ulf Möller4486d0c2000-01-22 20:05:23 +000050
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
Billy Brumley22aa4a32021-01-05 13:08:09 +020058DH_compute_key_padded() returns B<DH_size(dh)> on success, -1 on error.
59
Rich Salz9b869742015-08-17 15:21:33 -040060The error codes can be obtained by L<ERR_get_error(3)>.
Ulf Möller4486d0c2000-01-22 20:05:23 +000061
62=head1 SEE ALSO
63
Pauliada66e72020-02-03 19:05:31 +100064L<EVP_PKEY_derive(3)>,
Richard Levitteb97fdb52016-11-11 09:33:09 +010065L<DH_new(3)>, L<ERR_get_error(3)>, L<RAND_bytes(3)>, L<DH_size(3)>
Ulf Möller4486d0c2000-01-22 20:05:23 +000066
Pauliada66e72020-02-03 19:05:31 +100067=head1 HISTORY
68
Billy Brumley22aa4a32021-01-05 13:08:09 +020069DH_compute_key_padded() was added in OpenSSL 1.0.2.
70
71All of these functions were deprecated in OpenSSL 3.0.
Pauliada66e72020-02-03 19:05:31 +100072
Rich Salze2f92612016-05-18 11:44:05 -040073=head1 COPYRIGHT
74
Richard Levitte4333b892021-01-28 13:54:57 +010075Copyright 2000-2021 The OpenSSL Project Authors. All Rights Reserved.
Rich Salze2f92612016-05-18 11:44:05 -040076
Richard Levitte4746f252018-12-06 14:04:44 +010077Licensed under the Apache License 2.0 (the "License"). You may not use
Rich Salze2f92612016-05-18 11:44:05 -040078this 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