DH_generate_key.pod 2.3 KB

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