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