xref: /freebsd/crypto/openssl/doc/man3/DH_generate_key.pod (revision b077aed33b7b6aefca7b17ddb250cf521f938613)
1e71b7053SJung-uk Kim=pod
2e71b7053SJung-uk Kim
3e71b7053SJung-uk Kim=head1 NAME
4e71b7053SJung-uk Kim
588e852c0SJung-uk KimDH_generate_key, DH_compute_key, DH_compute_key_padded - perform
688e852c0SJung-uk KimDiffie-Hellman key exchange
7e71b7053SJung-uk Kim
8e71b7053SJung-uk Kim=head1 SYNOPSIS
9e71b7053SJung-uk Kim
10e71b7053SJung-uk Kim #include <openssl/dh.h>
11e71b7053SJung-uk Kim
12*b077aed3SPierre ProncheryThe following functions have been deprecated since OpenSSL 3.0, and can be
13*b077aed3SPierre Proncheryhidden entirely by defining B<OPENSSL_API_COMPAT> with a suitable version value,
14*b077aed3SPierre Proncherysee L<openssl_user_macros(7)>:
15*b077aed3SPierre Pronchery
16e71b7053SJung-uk Kim int DH_generate_key(DH *dh);
17e71b7053SJung-uk Kim
1888e852c0SJung-uk Kim int DH_compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh);
1988e852c0SJung-uk Kim
2088e852c0SJung-uk Kim int DH_compute_key_padded(unsigned char *key, const BIGNUM *pub_key, DH *dh);
21e71b7053SJung-uk Kim
22e71b7053SJung-uk Kim=head1 DESCRIPTION
23e71b7053SJung-uk Kim
24*b077aed3SPierre ProncheryAll of the functions described on this page are deprecated.
25*b077aed3SPierre ProncheryApplications should instead use L<EVP_PKEY_derive_init(3)>
26*b077aed3SPierre Proncheryand L<EVP_PKEY_derive(3)>.
27*b077aed3SPierre Pronchery
28e71b7053SJung-uk KimDH_generate_key() performs the first step of a Diffie-Hellman key
29e71b7053SJung-uk Kimexchange by generating private and public DH values. By calling
3088e852c0SJung-uk KimDH_compute_key() or DH_compute_key_padded(), these are combined with
3188e852c0SJung-uk Kimthe other party's public value to compute the shared key.
32e71b7053SJung-uk Kim
33e71b7053SJung-uk KimDH_generate_key() expects B<dh> to contain the shared parameters
34e71b7053SJung-uk KimB<dh-E<gt>p> and B<dh-E<gt>g>. It generates a random private DH value
35e71b7053SJung-uk Kimunless B<dh-E<gt>priv_key> is already set, and computes the
36e71b7053SJung-uk Kimcorresponding public value B<dh-E<gt>pub_key>, which can then be
37e71b7053SJung-uk Kimpublished.
38e71b7053SJung-uk Kim
39e71b7053SJung-uk KimDH_compute_key() computes the shared secret from the private DH value
40e71b7053SJung-uk Kimin B<dh> and the other party's public value in B<pub_key> and stores
41e71b7053SJung-uk Kimit in B<key>. B<key> must point to B<DH_size(dh)> bytes of memory.
4288e852c0SJung-uk KimThe padding style is RFC 5246 (8.1.2) that strips leading zero bytes.
4388e852c0SJung-uk KimIt is not constant time due to the leading zero bytes being stripped.
4488e852c0SJung-uk KimThe return value should be considered public.
4588e852c0SJung-uk Kim
4688e852c0SJung-uk KimDH_compute_key_padded() is similar but stores a fixed number of bytes.
4788e852c0SJung-uk KimThe padding style is NIST SP 800-56A (C.1) that retains leading zero bytes.
4888e852c0SJung-uk KimIt is constant time due to the leading zero bytes being retained.
4988e852c0SJung-uk KimThe return value should be considered public.
50e71b7053SJung-uk Kim
51e71b7053SJung-uk Kim=head1 RETURN VALUES
52e71b7053SJung-uk Kim
53e71b7053SJung-uk KimDH_generate_key() returns 1 on success, 0 otherwise.
54e71b7053SJung-uk Kim
55e71b7053SJung-uk KimDH_compute_key() returns the size of the shared secret on success, -1
56e71b7053SJung-uk Kimon error.
57e71b7053SJung-uk Kim
5888e852c0SJung-uk KimDH_compute_key_padded() returns B<DH_size(dh)> on success, -1 on error.
5988e852c0SJung-uk Kim
60e71b7053SJung-uk KimThe error codes can be obtained by L<ERR_get_error(3)>.
61e71b7053SJung-uk Kim
62e71b7053SJung-uk Kim=head1 SEE ALSO
63e71b7053SJung-uk Kim
64*b077aed3SPierre ProncheryL<EVP_PKEY_derive(3)>,
65e71b7053SJung-uk KimL<DH_new(3)>, L<ERR_get_error(3)>, L<RAND_bytes(3)>, L<DH_size(3)>
66e71b7053SJung-uk Kim
6788e852c0SJung-uk Kim=head1 HISTORY
6888e852c0SJung-uk Kim
6988e852c0SJung-uk KimDH_compute_key_padded() was added in OpenSSL 1.0.2.
7088e852c0SJung-uk Kim
71*b077aed3SPierre ProncheryAll of these functions were deprecated in OpenSSL 3.0.
72*b077aed3SPierre Pronchery
73e71b7053SJung-uk Kim=head1 COPYRIGHT
74e71b7053SJung-uk Kim
7588e852c0SJung-uk KimCopyright 2000-2021 The OpenSSL Project Authors. All Rights Reserved.
76e71b7053SJung-uk Kim
77*b077aed3SPierre ProncheryLicensed under the Apache License 2.0 (the "License").  You may not use
78e71b7053SJung-uk Kimthis file except in compliance with the License.  You can obtain a copy
79e71b7053SJung-uk Kimin the file LICENSE in the source distribution or at
80e71b7053SJung-uk KimL<https://www.openssl.org/source/license.html>.
81e71b7053SJung-uk Kim
82e71b7053SJung-uk Kim=cut
83