DH_set_method.pod 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. =pod
  2. =head1 NAME
  3. DH_set_default_method, DH_get_default_method,
  4. DH_set_method, DH_new_method, DH_OpenSSL - select DH method
  5. =head1 SYNOPSIS
  6. #include <openssl/dh.h>
  7. #include <openssl/engine.h>
  8. void DH_set_default_method(const DH_METHOD *meth);
  9. const DH_METHOD *DH_get_default_method(void);
  10. int DH_set_method(DH *dh, const DH_METHOD *meth);
  11. DH *DH_new_method(ENGINE *engine);
  12. const DH_METHOD *DH_OpenSSL(void);
  13. =head1 DESCRIPTION
  14. A B<DH_METHOD> specifies the functions that OpenSSL uses for Diffie-Hellman
  15. operations. By modifying the method, alternative implementations
  16. such as hardware accelerators may be used. IMPORTANT: See the NOTES section for
  17. important information about how these DH API functions are affected by the use
  18. of B<ENGINE> API calls.
  19. Initially, the default DH_METHOD is the OpenSSL internal implementation, as
  20. returned by DH_OpenSSL().
  21. DH_set_default_method() makes B<meth> the default method for all DH
  22. structures created later. B<NB>: This is true only whilst no ENGINE has been set
  23. as a default for DH, so this function is no longer recommended.
  24. DH_get_default_method() returns a pointer to the current default DH_METHOD.
  25. However, the meaningfulness of this result is dependent on whether the ENGINE
  26. API is being used, so this function is no longer recommended.
  27. DH_set_method() selects B<meth> to perform all operations using the key B<dh>.
  28. This will replace the DH_METHOD used by the DH key and if the previous method
  29. was supplied by an ENGINE, the handle to that ENGINE will be released during the
  30. change. It is possible to have DH keys that only work with certain DH_METHOD
  31. implementations (eg. from an ENGINE module that supports embedded
  32. hardware-protected keys), and in such cases attempting to change the DH_METHOD
  33. for the key can have unexpected results.
  34. DH_new_method() allocates and initializes a DH structure so that B<engine> will
  35. be used for the DH operations. If B<engine> is NULL, the default ENGINE for DH
  36. operations is used, and if no default ENGINE is set, the DH_METHOD controlled by
  37. DH_set_default_method() is used.
  38. =head1 THE DH_METHOD STRUCTURE
  39. typedef struct dh_meth_st
  40. {
  41. /* name of the implementation */
  42. const char *name;
  43. /* generate private and public DH values for key agreement */
  44. int (*generate_key)(DH *dh);
  45. /* compute shared secret */
  46. int (*compute_key)(unsigned char *key, BIGNUM *pub_key, DH *dh);
  47. /* compute r = a ^ p mod m (May be NULL for some implementations) */
  48. int (*bn_mod_exp)(DH *dh, BIGNUM *r, BIGNUM *a, const BIGNUM *p,
  49. const BIGNUM *m, BN_CTX *ctx,
  50. BN_MONT_CTX *m_ctx);
  51. /* called at DH_new */
  52. int (*init)(DH *dh);
  53. /* called at DH_free */
  54. int (*finish)(DH *dh);
  55. int flags;
  56. char *app_data; /* ?? */
  57. } DH_METHOD;
  58. =head1 RETURN VALUES
  59. DH_OpenSSL() and DH_get_default_method() return pointers to the respective
  60. B<DH_METHOD>s.
  61. DH_set_default_method() returns no value.
  62. DH_set_method() returns non-zero if the provided B<meth> was successfully set as
  63. the method for B<dh> (including unloading the ENGINE handle if the previous
  64. method was supplied by an ENGINE).
  65. DH_new_method() returns NULL and sets an error code that can be obtained by
  66. L<ERR_get_error(3)|ERR_get_error(3)> if the allocation fails. Otherwise it
  67. returns a pointer to the newly allocated structure.
  68. =head1 NOTES
  69. As of version 0.9.7, DH_METHOD implementations are grouped together with other
  70. algorithmic APIs (eg. RSA_METHOD, EVP_CIPHER, etc) in B<ENGINE> modules. If a
  71. default ENGINE is specified for DH functionality using an ENGINE API function,
  72. that will override any DH defaults set using the DH API (ie.
  73. DH_set_default_method()). For this reason, the ENGINE API is the recommended way
  74. to control default implementations for use in DH and other cryptographic
  75. algorithms.
  76. =head1 SEE ALSO
  77. L<dh(3)|dh(3)>, L<DH_new(3)|DH_new(3)>
  78. =head1 HISTORY
  79. DH_set_default_method(), DH_get_default_method(), DH_set_method(),
  80. DH_new_method() and DH_OpenSSL() were added in OpenSSL 0.9.4.
  81. DH_set_default_openssl_method() and DH_get_default_openssl_method() replaced
  82. DH_set_default_method() and DH_get_default_method() respectively, and
  83. DH_set_method() and DH_new_method() were altered to use B<ENGINE>s rather than
  84. B<DH_METHOD>s during development of the engine version of OpenSSL 0.9.6. For
  85. 0.9.7, the handling of defaults in the ENGINE API was restructured so that this
  86. change was reversed, and behaviour of the other functions resembled more closely
  87. the previous behaviour. The behaviour of defaults in the ENGINE API now
  88. transparently overrides the behaviour of defaults in the DH API without
  89. requiring changing these function prototypes.
  90. =cut