update libressl to v2.7.4
[unleashed.git] / lib / libcrypto / man / DH_set_method.3
blob77d16164457e03793a06dea0cf40e058f4b61706
1 .\"     $OpenBSD: DH_set_method.3,v 1.6 2018/03/22 16:06:33 schwarze Exp $
2 .\"     OpenSSL b97fdb57 Nov 11 09:33:09 2016 +0100
3 .\"
4 .\" This file was written by Ulf Moeller <ulf@openssl.org>.
5 .\" Copyright (c) 2000, 2002, 2007 The OpenSSL Project.  All rights reserved.
6 .\"
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
9 .\" are met:
10 .\"
11 .\" 1. Redistributions of source code must retain the above copyright
12 .\"    notice, this list of conditions and the following disclaimer.
13 .\"
14 .\" 2. Redistributions in binary form must reproduce the above copyright
15 .\"    notice, this list of conditions and the following disclaimer in
16 .\"    the documentation and/or other materials provided with the
17 .\"    distribution.
18 .\"
19 .\" 3. All advertising materials mentioning features or use of this
20 .\"    software must display the following acknowledgment:
21 .\"    "This product includes software developed by the OpenSSL Project
22 .\"    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23 .\"
24 .\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25 .\"    endorse or promote products derived from this software without
26 .\"    prior written permission. For written permission, please contact
27 .\"    openssl-core@openssl.org.
28 .\"
29 .\" 5. Products derived from this software may not be called "OpenSSL"
30 .\"    nor may "OpenSSL" appear in their names without prior written
31 .\"    permission of the OpenSSL Project.
32 .\"
33 .\" 6. Redistributions of any form whatsoever must retain the following
34 .\"    acknowledgment:
35 .\"    "This product includes software developed by the OpenSSL Project
36 .\"    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37 .\"
38 .\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39 .\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41 .\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
42 .\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43 .\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44 .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45 .\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47 .\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49 .\" OF THE POSSIBILITY OF SUCH DAMAGE.
50 .\"
51 .Dd $Mdocdate: March 22 2018 $
52 .Dt DH_SET_METHOD 3
53 .Os
54 .Sh NAME
55 .Nm DH_set_default_method ,
56 .Nm DH_get_default_method ,
57 .Nm DH_set_method ,
58 .Nm DH_new_method ,
59 .Nm DH_OpenSSL
60 .Nd select DH method
61 .Sh SYNOPSIS
62 .In openssl/dh.h
63 .Ft void
64 .Fo DH_set_default_method
65 .Fa "const DH_METHOD *meth"
66 .Fc
67 .Ft const DH_METHOD *
68 .Fo DH_get_default_method
69 .Fa void
70 .Fc
71 .Ft int
72 .Fo DH_set_method
73 .Fa "DH *dh"
74 .Fa "const DH_METHOD *meth"
75 .Fc
76 .Ft DH *
77 .Fo DH_new_method
78 .Fa "ENGINE *engine"
79 .Fc
80 .Ft const DH_METHOD *
81 .Fo DH_OpenSSL
82 .Fa void
83 .Fc
84 .Sh DESCRIPTION
86 .Vt DH_METHOD
87 specifies the functions that OpenSSL uses for Diffie-Hellman operations.
88 By modifying the method, alternative implementations such as hardware
89 accelerators may be used.
90 See the
91 .Sx CAVEATS
92 section for how these DH API functions are affected by the use of
93 .Xr engine 3
94 API calls.
95 .Pp
96 Initially, the default
97 .Vt DH_METHOD
98 is the OpenSSL internal implementation as returned by
99 .Fn DH_OpenSSL .
101 .Fn DH_set_default_method
102 makes
103 .Fa meth
104 the default method for all
105 .Vt DH
106 structures created later.
107 .Sy NB :
108 This is true only whilst no
109 .Vt ENGINE
110 has been set as a default for DH, so this function is no longer
111 recommended.
113 .Fn DH_get_default_method
114 returns a pointer to the current default
115 .Vt DH_METHOD .
116 However, the meaningfulness of this result is dependent on whether the
117 .Xr engine 3
118 API is being used, so this function is no longer recommended.
120 .Fn DH_set_method
121 selects
122 .Fa meth
123 to perform all operations using the key
124 .Fa dh .
125 This will replace the
126 .Vt DH_METHOD
127 used by the
128 .Fa dh
129 key and if the previous method was supplied by an
130 .Vt ENGINE ,
131 the handle to that
132 .Vt ENGINE
133 will be released during the change.
134 It is possible to have
135 .Vt DH
136 keys that only work with certain
137 .Vt DH_METHOD
138 implementations (e.g. from an
139 .Vt ENGINE
140 module that supports embedded hardware-protected keys),
141 and in such cases attempting to change the
142 .Vt DH_METHOD
143 for the key can have unexpected results.
145 .Fn DH_new_method
146 allocates and initializes a
147 .Vt DH
148 structure so that
149 .Fa engine
150 will be used for the DH operations.
152 .Fa engine
154 .Dv NULL ,
155 the default
156 .Vt ENGINE
157 for DH operations is used and, if no default
158 .Vt ENGINE
159 is set, the
160 .Vt DH_METHOD
161 controlled by
162 .Fn DH_set_default_method
163 is used.
166 .Vt DH_METHOD
167 structure is defined as follows:
168 .Bd -literal
169 typedef struct dh_meth_st
171      /* name of the implementation */
172         const char *name;
174      /* generate private and public DH values for key agreement */
175         int (*generate_key)(DH *dh);
177      /* compute shared secret */
178         int (*compute_key)(unsigned char *key, BIGNUM *pub_key, DH *dh);
180      /* compute r = a ^ p mod m (May be NULL for some implementations) */
181         int (*bn_mod_exp)(DH *dh, BIGNUM *r, BIGNUM *a, const BIGNUM *p,
182                                 const BIGNUM *m, BN_CTX *ctx,
183                                 BN_MONT_CTX *m_ctx);
185      /* called at DH_new */
186         int (*init)(DH *dh);
188      /* called at DH_free */
189         int (*finish)(DH *dh);
191         int flags;
193         char *app_data; /* ?? */
195 } DH_METHOD;
197 .Sh RETURN VALUES
198 .Fn DH_OpenSSL
200 .Fn DH_get_default_method
201 return pointers to the respective
202 .Sy DH_METHOD Ns s.
204 .Fn DH_set_method
205 returns non-zero if the provided
206 .Fa meth
207 was successfully set as the method for
208 .Fa dh
209 (including unloading the
210 .Vt ENGINE
211 handle if the previous method was supplied by an
212 .Vt ENGINE ) .
214 .Fn DH_new_method
215 returns
216 .Dv NULL
217 and sets an error code that can be obtained by
218 .Xr ERR_get_error 3
219 if the allocation fails.
220 Otherwise it returns a pointer to the newly allocated structure.
221 .Sh SEE ALSO
222 .Xr DH_new 3
223 .Sh HISTORY
224 .Fn DH_set_default_method ,
225 .Fn DH_get_default_method ,
226 .Fn DH_set_method ,
227 .Fn DH_new_method
229 .Fn DH_OpenSSL
230 first appeared in OpenSSL 0.9.5 and have been available since
231 .Ox 2.7 .
232 .Sh CAVEATS
233 As of version 0.9.7,
234 .Vt DH_METHOD
235 implementations are grouped together with other algorithmic APIs
236 (e.g. RSA_METHOD, EVP_CIPHER) in
237 .Vt ENGINE
238 modules.
239 If a default
240 .Vt ENGINE
241 is specified for DH functionality using an
242 .Xr engine 3
243 API function, that will override any DH defaults set using the DH API
244 .Pq i.e. Fn DH_set_default_method .
245 For this reason, the
246 .Xr engine 3
247 API is the recommended way to control default implementations
248 for use in DH and other cryptographic algorithms.