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