1DH_GENERATE_KEY(3ossl)              OpenSSL             DH_GENERATE_KEY(3ossl)
2
3
4

NAME

6       DH_generate_key, DH_compute_key, DH_compute_key_padded - perform
7       Diffie-Hellman key exchange
8

SYNOPSIS

10        #include <openssl/dh.h>
11
12       The following functions have been deprecated since OpenSSL 3.0, and can
13       be hidden entirely by defining OPENSSL_API_COMPAT with a suitable
14       version value, see 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

DESCRIPTION

23       All of the functions described on this page are deprecated.
24       Applications should instead use EVP_PKEY_derive_init(3) and
25       EVP_PKEY_derive(3).
26
27       DH_generate_key() performs the first step of a Diffie-Hellman key
28       exchange by generating private and public DH values. By calling
29       DH_compute_key() or DH_compute_key_padded(), these are combined with
30       the other party's public value to compute the shared key.
31
32       DH_generate_key() expects dh to contain the shared parameters dh->p and
33       dh->g. It generates a random private DH value unless dh->priv_key is
34       already set, and computes the corresponding public value dh->pub_key,
35       which can then be published.
36
37       DH_compute_key() computes the shared secret from the private DH value
38       in dh and the other party's public value in pub_key and stores it in
39       key. key must point to DH_size(dh) bytes of memory.  The padding style
40       is RFC 5246 (8.1.2) that strips leading zero bytes.  It is not constant
41       time due to the leading zero bytes being stripped.  The return value
42       should be considered public.
43
44       DH_compute_key_padded() is similar but stores a fixed number of bytes.
45       The padding style is NIST SP 800-56A (C.1) that retains leading zero
46       bytes.  It is constant time due to the leading zero bytes being
47       retained.  The return value should be considered public.
48

RETURN VALUES

50       DH_generate_key() returns 1 on success, 0 otherwise.
51
52       DH_compute_key() returns the size of the shared secret on success, -1
53       on error.
54
55       DH_compute_key_padded() returns DH_size(dh) on success, -1 on error.
56
57       The error codes can be obtained by ERR_get_error(3).
58

SEE ALSO

60       EVP_PKEY_derive(3), DH_new(3), ERR_get_error(3), RAND_bytes(3),
61       DH_size(3)
62

HISTORY

64       DH_compute_key_padded() was added in OpenSSL 1.0.2.
65
66       All of these functions were deprecated in OpenSSL 3.0.
67
69       Copyright 2000-2021 The OpenSSL Project Authors. All Rights Reserved.
70
71       Licensed under the Apache License 2.0 (the "License").  You may not use
72       this file except in compliance with the License.  You can obtain a copy
73       in the file LICENSE in the source distribution or at
74       <https://www.openssl.org/source/license.html>.
75
76
77
783.1.1                             2023-08-31            DH_GENERATE_KEY(3ossl)
Impressum