xref: /openbsd-src/lib/libcrypto/man/DH_set_method.3 (revision aa997e528a848ca5596493c2a801bdd6fb26ae61)
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
85A
86.Vt DH_METHOD
87specifies the functions that OpenSSL uses for Diffie-Hellman operations.
88By modifying the method, alternative implementations such as hardware
89accelerators may be used.
90See the
91.Sx CAVEATS
92section for how these DH API functions are affected by the use of
93.Xr engine 3
94API calls.
95.Pp
96Initially, the default
97.Vt DH_METHOD
98is the OpenSSL internal implementation as returned by
99.Fn DH_OpenSSL .
100.Pp
101.Fn DH_set_default_method
102makes
103.Fa meth
104the default method for all
105.Vt DH
106structures created later.
107.Sy NB :
108This is true only whilst no
109.Vt ENGINE
110has been set as a default for DH, so this function is no longer
111recommended.
112.Pp
113.Fn DH_get_default_method
114returns a pointer to the current default
115.Vt DH_METHOD .
116However, the meaningfulness of this result is dependent on whether the
117.Xr engine 3
118API is being used, so this function is no longer recommended.
119.Pp
120.Fn DH_set_method
121selects
122.Fa meth
123to perform all operations using the key
124.Fa dh .
125This will replace the
126.Vt DH_METHOD
127used by the
128.Fa dh
129key and if the previous method was supplied by an
130.Vt ENGINE ,
131the handle to that
132.Vt ENGINE
133will be released during the change.
134It is possible to have
135.Vt DH
136keys that only work with certain
137.Vt DH_METHOD
138implementations (e.g. from an
139.Vt ENGINE
140module that supports embedded hardware-protected keys),
141and in such cases attempting to change the
142.Vt DH_METHOD
143for the key can have unexpected results.
144.Pp
145.Fn DH_new_method
146allocates and initializes a
147.Vt DH
148structure so that
149.Fa engine
150will be used for the DH operations.
151If
152.Fa engine
153is
154.Dv NULL ,
155the default
156.Vt ENGINE
157for DH operations is used and, if no default
158.Vt ENGINE
159is set, the
160.Vt DH_METHOD
161controlled by
162.Fn DH_set_default_method
163is used.
164.Pp
165The
166.Vt DH_METHOD
167structure is defined as follows:
168.Bd -literal
169typedef struct dh_meth_st
170{
171     /* name of the implementation */
172	const char *name;
173
174     /* generate private and public DH values for key agreement */
175        int (*generate_key)(DH *dh);
176
177     /* compute shared secret */
178        int (*compute_key)(unsigned char *key, BIGNUM *pub_key, DH *dh);
179
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);
184
185     /* called at DH_new */
186        int (*init)(DH *dh);
187
188     /* called at DH_free */
189        int (*finish)(DH *dh);
190
191        int flags;
192
193        char *app_data; /* ?? */
194
195} DH_METHOD;
196.Ed
197.Sh RETURN VALUES
198.Fn DH_OpenSSL
199and
200.Fn DH_get_default_method
201return pointers to the respective
202.Sy DH_METHOD Ns s.
203.Pp
204.Fn DH_set_method
205returns non-zero if the provided
206.Fa meth
207was successfully set as the method for
208.Fa dh
209(including unloading the
210.Vt ENGINE
211handle if the previous method was supplied by an
212.Vt ENGINE ) .
213.Pp
214.Fn DH_new_method
215returns
216.Dv NULL
217and sets an error code that can be obtained by
218.Xr ERR_get_error 3
219if the allocation fails.
220Otherwise 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
228and
229.Fn DH_OpenSSL
230first appeared in OpenSSL 0.9.5 and have been available since
231.Ox 2.7 .
232.Sh CAVEATS
233As of version 0.9.7,
234.Vt DH_METHOD
235implementations are grouped together with other algorithmic APIs
236(e.g. RSA_METHOD, EVP_CIPHER) in
237.Vt ENGINE
238modules.
239If a default
240.Vt ENGINE
241is specified for DH functionality using an
242.Xr engine 3
243API function, that will override any DH defaults set using the DH API
244.Pq i.e. Fn DH_set_default_method .
245For this reason, the
246.Xr engine 3
247API is the recommended way to control default implementations
248for use in DH and other cryptographic algorithms.
249