2
0

DH_generate_key.pod 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. =pod
  2. =head1 NAME
  3. DH_generate_key, DH_compute_key, DH_compute_key_padded - perform
  4. Diffie-Hellman key exchange
  5. =head1 SYNOPSIS
  6. #include <openssl/dh.h>
  7. The following functions have been deprecated since OpenSSL 3.0, and can be
  8. hidden entirely by defining B<OPENSSL_API_COMPAT> with a suitable version value,
  9. see L<openssl_user_macros(7)>:
  10. int DH_generate_key(DH *dh);
  11. int DH_compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh);
  12. int DH_compute_key_padded(unsigned char *key, const BIGNUM *pub_key, DH *dh);
  13. =head1 DESCRIPTION
  14. All of the functions described on this page are deprecated.
  15. Applications should instead use L<EVP_PKEY_derive_init(3)>
  16. and L<EVP_PKEY_derive(3)>.
  17. DH_generate_key() performs the first step of a Diffie-Hellman key
  18. exchange by generating private and public DH values. By calling
  19. DH_compute_key() or DH_compute_key_padded(), these are combined with
  20. the other party's public value to compute the shared key.
  21. DH_generate_key() expects B<dh> to contain the shared parameters
  22. B<dh-E<gt>p> and B<dh-E<gt>g>. It generates a random private DH value
  23. unless B<dh-E<gt>priv_key> is already set, and computes the
  24. corresponding public value B<dh-E<gt>pub_key>, which can then be
  25. published.
  26. DH_compute_key() computes the shared secret from the private DH value
  27. in B<dh> and the other party's public value in B<pub_key> and stores
  28. it in B<key>. B<key> must point to B<DH_size(dh)> bytes of memory.
  29. The padding style is RFC 5246 (8.1.2) that strips leading zero bytes.
  30. It is not constant time due to the leading zero bytes being stripped.
  31. The return value should be considered public.
  32. DH_compute_key_padded() is similar but stores a fixed number of bytes.
  33. The padding style is NIST SP 800-56A (C.1) that retains leading zero bytes.
  34. It is constant time due to the leading zero bytes being retained.
  35. The return value should be considered public.
  36. =head1 RETURN VALUES
  37. DH_generate_key() returns 1 on success, 0 otherwise.
  38. DH_compute_key() returns the size of the shared secret on success, -1
  39. on error.
  40. DH_compute_key_padded() returns B<DH_size(dh)> on success, -1 on error.
  41. The error codes can be obtained by L<ERR_get_error(3)>.
  42. =head1 SEE ALSO
  43. L<EVP_PKEY_derive(3)>,
  44. L<DH_new(3)>, L<ERR_get_error(3)>, L<RAND_bytes(3)>, L<DH_size(3)>
  45. =head1 HISTORY
  46. DH_compute_key_padded() was added in OpenSSL 1.0.2.
  47. All of these functions were deprecated in OpenSSL 3.0.
  48. =head1 COPYRIGHT
  49. Copyright 2000-2021 The OpenSSL Project Authors. All Rights Reserved.
  50. Licensed under the Apache License 2.0 (the "License"). You may not use
  51. this file except in compliance with the License. You can obtain a copy
  52. in the file LICENSE in the source distribution or at
  53. L<https://www.openssl.org/source/license.html>.
  54. =cut