1 | =pod
|
---|
2 |
|
---|
3 | =head1 NAME
|
---|
4 |
|
---|
5 | DH_generate_key, DH_compute_key, DH_compute_key_padded - perform
|
---|
6 | Diffie-Hellman key exchange
|
---|
7 |
|
---|
8 | =head1 SYNOPSIS
|
---|
9 |
|
---|
10 | #include <openssl/dh.h>
|
---|
11 |
|
---|
12 | int DH_generate_key(DH *dh);
|
---|
13 |
|
---|
14 | int DH_compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh);
|
---|
15 |
|
---|
16 | int DH_compute_key_padded(unsigned char *key, const BIGNUM *pub_key, DH *dh);
|
---|
17 |
|
---|
18 | =head1 DESCRIPTION
|
---|
19 |
|
---|
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.
|
---|
24 |
|
---|
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
|
---|
29 | published.
|
---|
30 |
|
---|
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.
|
---|
37 |
|
---|
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.
|
---|
42 |
|
---|
43 | =head1 RETURN VALUES
|
---|
44 |
|
---|
45 | DH_generate_key() returns 1 on success, 0 otherwise.
|
---|
46 |
|
---|
47 | DH_compute_key() returns the size of the shared secret on success, -1
|
---|
48 | on error.
|
---|
49 |
|
---|
50 | DH_compute_key_padded() returns B<DH_size(dh)> on success, -1 on error.
|
---|
51 |
|
---|
52 | The error codes can be obtained by L<ERR_get_error(3)>.
|
---|
53 |
|
---|
54 | =head1 SEE ALSO
|
---|
55 |
|
---|
56 | L<DH_new(3)>, L<ERR_get_error(3)>, L<RAND_bytes(3)>, L<DH_size(3)>
|
---|
57 |
|
---|
58 | =head1 HISTORY
|
---|
59 |
|
---|
60 | DH_compute_key_padded() was added in OpenSSL 1.0.2.
|
---|
61 |
|
---|
62 | =head1 COPYRIGHT
|
---|
63 |
|
---|
64 | Copyright 2000-2021 The OpenSSL Project Authors. All Rights Reserved.
|
---|
65 |
|
---|
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>.
|
---|
70 |
|
---|
71 | =cut
|
---|