1DH_GENERATE_KEY(3) OpenSSL DH_GENERATE_KEY(3)
2
3
4
6 DH_generate_key, DH_compute_key, DH_compute_key_padded - perform
7 Diffie-Hellman key exchange
8
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
19 DH_generate_key() performs the first step of a Diffie-Hellman key
20 exchange by generating private and public DH values. By calling
21 DH_compute_key() or DH_compute_key_padded(), these are combined with
22 the other party's public value to compute the shared key.
23
24 DH_generate_key() expects dh to contain the shared parameters dh->p and
25 dh->g. It generates a random private DH value unless dh->priv_key is
26 already set, and computes the corresponding public value dh->pub_key,
27 which can then be published.
28
29 DH_compute_key() computes the shared secret from the private DH value
30 in dh and the other party's public value in pub_key and stores it in
31 key. key must point to DH_size(dh) bytes of memory. The padding style
32 is RFC 5246 (8.1.2) that strips leading zero bytes. It is not constant
33 time due to the leading zero bytes being stripped. The return value
34 should be considered public.
35
36 DH_compute_key_padded() is similar but stores a fixed number of bytes.
37 The padding style is NIST SP 800-56A (C.1) that retains leading zero
38 bytes. It is constant time due to the leading zero bytes being
39 retained. The return value should be considered public.
40
42 DH_generate_key() returns 1 on success, 0 otherwise.
43
44 DH_compute_key() returns the size of the shared secret on success, -1
45 on error.
46
47 DH_compute_key_padded() returns DH_size(dh) on success, -1 on error.
48
49 The error codes can be obtained by ERR_get_error(3).
50
52 DH_new(3), ERR_get_error(3), RAND_bytes(3), DH_size(3)
53
55 DH_compute_key_padded() was added in OpenSSL 1.0.2.
56
58 Copyright 2000-2021 The OpenSSL Project Authors. All Rights Reserved.
59
60 Licensed under the OpenSSL license (the "License"). You may not use
61 this file except in compliance with the License. You can obtain a copy
62 in the file LICENSE in the source distribution or at
63 <https://www.openssl.org/source/license.html>.
64
65
66
671.1.1q 2023-02-06 DH_GENERATE_KEY(3)