]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - secure/lib/libcrypto/man/man3/ENGINE_add.3
MFC: r359486
[FreeBSD/FreeBSD.git] / secure / lib / libcrypto / man / man3 / ENGINE_add.3
1 .\" Automatically generated by Pod::Man 4.11 (Pod::Simple 3.40)
2 .\"
3 .\" Standard preamble:
4 .\" ========================================================================
5 .de Sp \" Vertical space (when we can't use .PP)
6 .if t .sp .5v
7 .if n .sp
8 ..
9 .de Vb \" Begin verbatim text
10 .ft CW
11 .nf
12 .ne \\$1
13 ..
14 .de Ve \" End verbatim text
15 .ft R
16 .fi
17 ..
18 .\" Set up some character translations and predefined strings.  \*(-- will
19 .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
20 .\" double quote, and \*(R" will give a right double quote.  \*(C+ will
21 .\" give a nicer C++.  Capital omega is used to do unbreakable dashes and
22 .\" therefore won't be available.  \*(C` and \*(C' expand to `' in nroff,
23 .\" nothing in troff, for use with C<>.
24 .tr \(*W-
25 .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
26 .ie n \{\
27 .    ds -- \(*W-
28 .    ds PI pi
29 .    if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
30 .    if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\"  diablo 12 pitch
31 .    ds L" ""
32 .    ds R" ""
33 .    ds C` ""
34 .    ds C' ""
35 'br\}
36 .el\{\
37 .    ds -- \|\(em\|
38 .    ds PI \(*p
39 .    ds L" ``
40 .    ds R" ''
41 .    ds C`
42 .    ds C'
43 'br\}
44 .\"
45 .\" Escape single quotes in literal strings from groff's Unicode transform.
46 .ie \n(.g .ds Aq \(aq
47 .el       .ds Aq '
48 .\"
49 .\" If the F register is >0, we'll generate index entries on stderr for
50 .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
51 .\" entries marked with X<> in POD.  Of course, you'll have to process the
52 .\" output yourself in some meaningful fashion.
53 .\"
54 .\" Avoid warning from groff about undefined register 'F'.
55 .de IX
56 ..
57 .nr rF 0
58 .if \n(.g .if rF .nr rF 1
59 .if (\n(rF:(\n(.g==0)) \{\
60 .    if \nF \{\
61 .        de IX
62 .        tm Index:\\$1\t\\n%\t"\\$2"
63 ..
64 .        if !\nF==2 \{\
65 .            nr % 0
66 .            nr F 2
67 .        \}
68 .    \}
69 .\}
70 .rr rF
71 .\"
72 .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
73 .\" Fear.  Run.  Save yourself.  No user-serviceable parts.
74 .    \" fudge factors for nroff and troff
75 .if n \{\
76 .    ds #H 0
77 .    ds #V .8m
78 .    ds #F .3m
79 .    ds #[ \f1
80 .    ds #] \fP
81 .\}
82 .if t \{\
83 .    ds #H ((1u-(\\\\n(.fu%2u))*.13m)
84 .    ds #V .6m
85 .    ds #F 0
86 .    ds #[ \&
87 .    ds #] \&
88 .\}
89 .    \" simple accents for nroff and troff
90 .if n \{\
91 .    ds ' \&
92 .    ds ` \&
93 .    ds ^ \&
94 .    ds , \&
95 .    ds ~ ~
96 .    ds /
97 .\}
98 .if t \{\
99 .    ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
100 .    ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
101 .    ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
102 .    ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
103 .    ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
104 .    ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
105 .\}
106 .    \" troff and (daisy-wheel) nroff accents
107 .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
108 .ds 8 \h'\*(#H'\(*b\h'-\*(#H'
109 .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
110 .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
111 .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
112 .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
113 .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
114 .ds ae a\h'-(\w'a'u*4/10)'e
115 .ds Ae A\h'-(\w'A'u*4/10)'E
116 .    \" corrections for vroff
117 .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
118 .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
119 .    \" for low resolution devices (crt and lpr)
120 .if \n(.H>23 .if \n(.V>19 \
121 \{\
122 .    ds : e
123 .    ds 8 ss
124 .    ds o a
125 .    ds d- d\h'-1'\(ga
126 .    ds D- D\h'-1'\(hy
127 .    ds th \o'bp'
128 .    ds Th \o'LP'
129 .    ds ae ae
130 .    ds Ae AE
131 .\}
132 .rm #[ #] #H #V #F C
133 .\" ========================================================================
134 .\"
135 .IX Title "ENGINE_ADD 3"
136 .TH ENGINE_ADD 3 "2020-03-31" "1.1.1f" "OpenSSL"
137 .\" For nroff, turn off justification.  Always turn off hyphenation; it makes
138 .\" way too many mistakes in technical documents.
139 .if n .ad l
140 .nh
141 .SH "NAME"
142 ENGINE_get_DH, ENGINE_get_DSA, ENGINE_by_id, ENGINE_get_cipher_engine, ENGINE_get_default_DH, ENGINE_get_default_DSA, ENGINE_get_default_RAND, ENGINE_get_default_RSA, ENGINE_get_digest_engine, ENGINE_get_first, ENGINE_get_last, ENGINE_get_next, ENGINE_get_prev, ENGINE_new, ENGINE_get_ciphers, ENGINE_get_ctrl_function, ENGINE_get_digests, ENGINE_get_destroy_function, ENGINE_get_finish_function, ENGINE_get_init_function, ENGINE_get_load_privkey_function, ENGINE_get_load_pubkey_function, ENGINE_load_private_key, ENGINE_load_public_key, ENGINE_get_RAND, ENGINE_get_RSA, ENGINE_get_id, ENGINE_get_name, ENGINE_get_cmd_defns, ENGINE_get_cipher, ENGINE_get_digest, ENGINE_add, ENGINE_cmd_is_executable, ENGINE_ctrl, ENGINE_ctrl_cmd, ENGINE_ctrl_cmd_string, ENGINE_finish, ENGINE_free, ENGINE_get_flags, ENGINE_init, ENGINE_register_DH, ENGINE_register_DSA, ENGINE_register_RAND, ENGINE_register_RSA, ENGINE_register_all_complete, ENGINE_register_ciphers, ENGINE_register_complete, ENGINE_register_digests, ENGINE_remove, ENGINE_set_DH, ENGINE_set_DSA, ENGINE_set_RAND, ENGINE_set_RSA, ENGINE_set_ciphers, ENGINE_set_cmd_defns, ENGINE_set_ctrl_function, ENGINE_set_default, ENGINE_set_default_DH, ENGINE_set_default_DSA, ENGINE_set_default_RAND, ENGINE_set_default_RSA, ENGINE_set_default_ciphers, ENGINE_set_default_digests, ENGINE_set_default_string, ENGINE_set_destroy_function, ENGINE_set_digests, ENGINE_set_finish_function, ENGINE_set_flags, ENGINE_set_id, ENGINE_set_init_function, ENGINE_set_load_privkey_function, ENGINE_set_load_pubkey_function, ENGINE_set_name, ENGINE_up_ref, ENGINE_get_table_flags, ENGINE_cleanup, ENGINE_load_builtin_engines, ENGINE_register_all_DH, ENGINE_register_all_DSA, ENGINE_register_all_RAND, ENGINE_register_all_RSA, ENGINE_register_all_ciphers, ENGINE_register_all_digests, ENGINE_set_table_flags, ENGINE_unregister_DH, ENGINE_unregister_DSA, ENGINE_unregister_RAND, ENGINE_unregister_RSA, ENGINE_unregister_ciphers, ENGINE_unregister_digests \&\- ENGINE cryptographic module support
143 .SH "SYNOPSIS"
144 .IX Header "SYNOPSIS"
145 .Vb 1
146 \& #include <openssl/engine.h>
147 \&
148 \& ENGINE *ENGINE_get_first(void);
149 \& ENGINE *ENGINE_get_last(void);
150 \& ENGINE *ENGINE_get_next(ENGINE *e);
151 \& ENGINE *ENGINE_get_prev(ENGINE *e);
152 \&
153 \& int ENGINE_add(ENGINE *e);
154 \& int ENGINE_remove(ENGINE *e);
155 \&
156 \& ENGINE *ENGINE_by_id(const char *id);
157 \&
158 \& int ENGINE_init(ENGINE *e);
159 \& int ENGINE_finish(ENGINE *e);
160 \&
161 \& void ENGINE_load_builtin_engines(void);
162 \&
163 \& ENGINE *ENGINE_get_default_RSA(void);
164 \& ENGINE *ENGINE_get_default_DSA(void);
165 \& ENGINE *ENGINE_get_default_DH(void);
166 \& ENGINE *ENGINE_get_default_RAND(void);
167 \& ENGINE *ENGINE_get_cipher_engine(int nid);
168 \& ENGINE *ENGINE_get_digest_engine(int nid);
169 \&
170 \& int ENGINE_set_default_RSA(ENGINE *e);
171 \& int ENGINE_set_default_DSA(ENGINE *e);
172 \& int ENGINE_set_default_DH(ENGINE *e);
173 \& int ENGINE_set_default_RAND(ENGINE *e);
174 \& int ENGINE_set_default_ciphers(ENGINE *e);
175 \& int ENGINE_set_default_digests(ENGINE *e);
176 \& int ENGINE_set_default_string(ENGINE *e, const char *list);
177 \&
178 \& int ENGINE_set_default(ENGINE *e, unsigned int flags);
179 \&
180 \& unsigned int ENGINE_get_table_flags(void);
181 \& void ENGINE_set_table_flags(unsigned int flags);
182 \&
183 \& int ENGINE_register_RSA(ENGINE *e);
184 \& void ENGINE_unregister_RSA(ENGINE *e);
185 \& void ENGINE_register_all_RSA(void);
186 \& int ENGINE_register_DSA(ENGINE *e);
187 \& void ENGINE_unregister_DSA(ENGINE *e);
188 \& void ENGINE_register_all_DSA(void);
189 \& int ENGINE_register_DH(ENGINE *e);
190 \& void ENGINE_unregister_DH(ENGINE *e);
191 \& void ENGINE_register_all_DH(void);
192 \& int ENGINE_register_RAND(ENGINE *e);
193 \& void ENGINE_unregister_RAND(ENGINE *e);
194 \& void ENGINE_register_all_RAND(void);
195 \& int ENGINE_register_ciphers(ENGINE *e);
196 \& void ENGINE_unregister_ciphers(ENGINE *e);
197 \& void ENGINE_register_all_ciphers(void);
198 \& int ENGINE_register_digests(ENGINE *e);
199 \& void ENGINE_unregister_digests(ENGINE *e);
200 \& void ENGINE_register_all_digests(void);
201 \& int ENGINE_register_complete(ENGINE *e);
202 \& int ENGINE_register_all_complete(void);
203 \&
204 \& int ENGINE_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void));
205 \& int ENGINE_cmd_is_executable(ENGINE *e, int cmd);
206 \& int ENGINE_ctrl_cmd(ENGINE *e, const char *cmd_name,
207 \&                     long i, void *p, void (*f)(void), int cmd_optional);
208 \& int ENGINE_ctrl_cmd_string(ENGINE *e, const char *cmd_name, const char *arg,
209 \&                            int cmd_optional);
210 \&
211 \& ENGINE *ENGINE_new(void);
212 \& int ENGINE_free(ENGINE *e);
213 \& int ENGINE_up_ref(ENGINE *e);
214 \&
215 \& int ENGINE_set_id(ENGINE *e, const char *id);
216 \& int ENGINE_set_name(ENGINE *e, const char *name);
217 \& int ENGINE_set_RSA(ENGINE *e, const RSA_METHOD *rsa_meth);
218 \& int ENGINE_set_DSA(ENGINE *e, const DSA_METHOD *dsa_meth);
219 \& int ENGINE_set_DH(ENGINE *e, const DH_METHOD *dh_meth);
220 \& int ENGINE_set_RAND(ENGINE *e, const RAND_METHOD *rand_meth);
221 \& int ENGINE_set_destroy_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR destroy_f);
222 \& int ENGINE_set_init_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR init_f);
223 \& int ENGINE_set_finish_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR finish_f);
224 \& int ENGINE_set_ctrl_function(ENGINE *e, ENGINE_CTRL_FUNC_PTR ctrl_f);
225 \& int ENGINE_set_load_privkey_function(ENGINE *e, ENGINE_LOAD_KEY_PTR loadpriv_f);
226 \& int ENGINE_set_load_pubkey_function(ENGINE *e, ENGINE_LOAD_KEY_PTR loadpub_f);
227 \& int ENGINE_set_ciphers(ENGINE *e, ENGINE_CIPHERS_PTR f);
228 \& int ENGINE_set_digests(ENGINE *e, ENGINE_DIGESTS_PTR f);
229 \& int ENGINE_set_flags(ENGINE *e, int flags);
230 \& int ENGINE_set_cmd_defns(ENGINE *e, const ENGINE_CMD_DEFN *defns);
231 \&
232 \& const char *ENGINE_get_id(const ENGINE *e);
233 \& const char *ENGINE_get_name(const ENGINE *e);
234 \& const RSA_METHOD *ENGINE_get_RSA(const ENGINE *e);
235 \& const DSA_METHOD *ENGINE_get_DSA(const ENGINE *e);
236 \& const DH_METHOD *ENGINE_get_DH(const ENGINE *e);
237 \& const RAND_METHOD *ENGINE_get_RAND(const ENGINE *e);
238 \& ENGINE_GEN_INT_FUNC_PTR ENGINE_get_destroy_function(const ENGINE *e);
239 \& ENGINE_GEN_INT_FUNC_PTR ENGINE_get_init_function(const ENGINE *e);
240 \& ENGINE_GEN_INT_FUNC_PTR ENGINE_get_finish_function(const ENGINE *e);
241 \& ENGINE_CTRL_FUNC_PTR ENGINE_get_ctrl_function(const ENGINE *e);
242 \& ENGINE_LOAD_KEY_PTR ENGINE_get_load_privkey_function(const ENGINE *e);
243 \& ENGINE_LOAD_KEY_PTR ENGINE_get_load_pubkey_function(const ENGINE *e);
244 \& ENGINE_CIPHERS_PTR ENGINE_get_ciphers(const ENGINE *e);
245 \& ENGINE_DIGESTS_PTR ENGINE_get_digests(const ENGINE *e);
246 \& const EVP_CIPHER *ENGINE_get_cipher(ENGINE *e, int nid);
247 \& const EVP_MD *ENGINE_get_digest(ENGINE *e, int nid);
248 \& int ENGINE_get_flags(const ENGINE *e);
249 \& const ENGINE_CMD_DEFN *ENGINE_get_cmd_defns(const ENGINE *e);
250 \&
251 \& EVP_PKEY *ENGINE_load_private_key(ENGINE *e, const char *key_id,
252 \&                                   UI_METHOD *ui_method, void *callback_data);
253 \& EVP_PKEY *ENGINE_load_public_key(ENGINE *e, const char *key_id,
254 \&                                  UI_METHOD *ui_method, void *callback_data);
255 .Ve
256 .PP
257 Deprecated:
258 .PP
259 .Vb 3
260 \& #if OPENSSL_API_COMPAT < 0x10100000L
261 \& void ENGINE_cleanup(void)
262 \& #endif
263 .Ve
264 .SH "DESCRIPTION"
265 .IX Header "DESCRIPTION"
266 These functions create, manipulate, and use cryptographic modules in the
267 form of \fB\s-1ENGINE\s0\fR objects. These objects act as containers for
268 implementations of cryptographic algorithms, and support a
269 reference-counted mechanism to allow them to be dynamically loaded in and
270 out of the running application.
271 .PP
272 The cryptographic functionality that can be provided by an \fB\s-1ENGINE\s0\fR
273 implementation includes the following abstractions;
274 .PP
275 .Vb 6
276 \& RSA_METHOD \- for providing alternative RSA implementations
277 \& DSA_METHOD, DH_METHOD, RAND_METHOD, ECDH_METHOD, ECDSA_METHOD,
278 \&       \- similarly for other OpenSSL APIs
279 \& EVP_CIPHER \- potentially multiple cipher algorithms (indexed by \*(Aqnid\*(Aq)
280 \& EVP_DIGEST \- potentially multiple hash algorithms (indexed by \*(Aqnid\*(Aq)
281 \& key\-loading \- loading public and/or private EVP_PKEY keys
282 .Ve
283 .SS "Reference counting and handles"
284 .IX Subsection "Reference counting and handles"
285 Due to the modular nature of the \s-1ENGINE API,\s0 pointers to ENGINEs need to be
286 treated as handles \- ie. not only as pointers, but also as references to
287 the underlying \s-1ENGINE\s0 object. Ie. one should obtain a new reference when
288 making copies of an \s-1ENGINE\s0 pointer if the copies will be used (and
289 released) independently.
290 .PP
291 \&\s-1ENGINE\s0 objects have two levels of reference-counting to match the way in
292 which the objects are used. At the most basic level, each \s-1ENGINE\s0 pointer is
293 inherently a \fBstructural\fR reference \- a structural reference is required
294 to use the pointer value at all, as this kind of reference is a guarantee
295 that the structure can not be deallocated until the reference is released.
296 .PP
297 However, a structural reference provides no guarantee that the \s-1ENGINE\s0 is
298 initialised and able to use any of its cryptographic
299 implementations. Indeed it's quite possible that most ENGINEs will not
300 initialise at all in typical environments, as ENGINEs are typically used to
301 support specialised hardware. To use an \s-1ENGINE\s0's functionality, you need a
302 \&\fBfunctional\fR reference. This kind of reference can be considered a
303 specialised form of structural reference, because each functional reference
304 implicitly contains a structural reference as well \- however to avoid
305 difficult-to-find programming bugs, it is recommended to treat the two
306 kinds of reference independently. If you have a functional reference to an
307 \&\s-1ENGINE,\s0 you have a guarantee that the \s-1ENGINE\s0 has been initialised and
308 is ready to perform cryptographic operations, and will remain initialised
309 until after you have released your reference.
310 .PP
311 \&\fIStructural references\fR
312 .PP
313 This basic type of reference is used for instantiating new ENGINEs,
314 iterating across OpenSSL's internal linked-list of loaded
315 ENGINEs, reading information about an \s-1ENGINE,\s0 etc. Essentially a structural
316 reference is sufficient if you only need to query or manipulate the data of
317 an \s-1ENGINE\s0 implementation rather than use its functionality.
318 .PP
319 The \fBENGINE_new()\fR function returns a structural reference to a new (empty)
320 \&\s-1ENGINE\s0 object. There are other \s-1ENGINE API\s0 functions that return structural
321 references such as; \fBENGINE_by_id()\fR, \fBENGINE_get_first()\fR, \fBENGINE_get_last()\fR,
322 \&\fBENGINE_get_next()\fR, \fBENGINE_get_prev()\fR. All structural references should be
323 released by a corresponding to call to the \fBENGINE_free()\fR function \- the
324 \&\s-1ENGINE\s0 object itself will only actually be cleaned up and deallocated when
325 the last structural reference is released.
326 .PP
327 It should also be noted that many \s-1ENGINE API\s0 function calls that accept a
328 structural reference will internally obtain another reference \- typically
329 this happens whenever the supplied \s-1ENGINE\s0 will be needed by OpenSSL after
330 the function has returned. Eg. the function to add a new \s-1ENGINE\s0 to
331 OpenSSL's internal list is \fBENGINE_add()\fR \- if this function returns success,
332 then OpenSSL will have stored a new structural reference internally so the
333 caller is still responsible for freeing their own reference with
334 \&\fBENGINE_free()\fR when they are finished with it. In a similar way, some
335 functions will automatically release the structural reference passed to it
336 if part of the function's job is to do so. Eg. the \fBENGINE_get_next()\fR and
337 \&\fBENGINE_get_prev()\fR functions are used for iterating across the internal
338 \&\s-1ENGINE\s0 list \- they will return a new structural reference to the next (or
339 previous) \s-1ENGINE\s0 in the list or \s-1NULL\s0 if at the end (or beginning) of the
340 list, but in either case the structural reference passed to the function is
341 released on behalf of the caller.
342 .PP
343 To clarify a particular function's handling of references, one should
344 always consult that function's documentation \*(L"man\*(R" page, or failing that
345 the openssl/engine.h header file includes some hints.
346 .PP
347 \&\fIFunctional references\fR
348 .PP
349 As mentioned, functional references exist when the cryptographic
350 functionality of an \s-1ENGINE\s0 is required to be available. A functional
351 reference can be obtained in one of two ways; from an existing structural
352 reference to the required \s-1ENGINE,\s0 or by asking OpenSSL for the default
353 operational \s-1ENGINE\s0 for a given cryptographic purpose.
354 .PP
355 To obtain a functional reference from an existing structural reference,
356 call the \fBENGINE_init()\fR function. This returns zero if the \s-1ENGINE\s0 was not
357 already operational and couldn't be successfully initialised (eg. lack of
358 system drivers, no special hardware attached, etc), otherwise it will
359 return non-zero to indicate that the \s-1ENGINE\s0 is now operational and will
360 have allocated a new \fBfunctional\fR reference to the \s-1ENGINE.\s0 All functional
361 references are released by calling \fBENGINE_finish()\fR (which removes the
362 implicit structural reference as well).
363 .PP
364 The second way to get a functional reference is by asking OpenSSL for a
365 default implementation for a given task, eg. by \fBENGINE_get_default_RSA()\fR,
366 \&\fBENGINE_get_default_cipher_engine()\fR, etc. These are discussed in the next
367 section, though they are not usually required by application programmers as
368 they are used automatically when creating and using the relevant
369 algorithm-specific types in OpenSSL, such as \s-1RSA, DSA, EVP_CIPHER_CTX,\s0 etc.
370 .SS "Default implementations"
371 .IX Subsection "Default implementations"
372 For each supported abstraction, the \s-1ENGINE\s0 code maintains an internal table
373 of state to control which implementations are available for a given
374 abstraction and which should be used by default. These implementations are
375 registered in the tables and indexed by an 'nid' value, because
376 abstractions like \s-1EVP_CIPHER\s0 and \s-1EVP_DIGEST\s0 support many distinct
377 algorithms and modes, and ENGINEs can support arbitrarily many of them.
378 In the case of other abstractions like \s-1RSA, DSA,\s0 etc, there is only one
379 \&\*(L"algorithm\*(R" so all implementations implicitly register using the same 'nid'
380 index.
381 .PP
382 When a default \s-1ENGINE\s0 is requested for a given abstraction/algorithm/mode, (eg.
383 when calling RSA_new_method(\s-1NULL\s0)), a \*(L"get_default\*(R" call will be made to the
384 \&\s-1ENGINE\s0 subsystem to process the corresponding state table and return a
385 functional reference to an initialised \s-1ENGINE\s0 whose implementation should be
386 used. If no \s-1ENGINE\s0 should (or can) be used, it will return \s-1NULL\s0 and the caller
387 will operate with a \s-1NULL ENGINE\s0 handle \- this usually equates to using the
388 conventional software implementation. In the latter case, OpenSSL will from
389 then on behave the way it used to before the \s-1ENGINE API\s0 existed.
390 .PP
391 Each state table has a flag to note whether it has processed this
392 \&\*(L"get_default\*(R" query since the table was last modified, because to process
393 this question it must iterate across all the registered ENGINEs in the
394 table trying to initialise each of them in turn, in case one of them is
395 operational. If it returns a functional reference to an \s-1ENGINE,\s0 it will
396 also cache another reference to speed up processing future queries (without
397 needing to iterate across the table). Likewise, it will cache a \s-1NULL\s0
398 response if no \s-1ENGINE\s0 was available so that future queries won't repeat the
399 same iteration unless the state table changes. This behaviour can also be
400 changed; if the \s-1ENGINE_TABLE_FLAG_NOINIT\s0 flag is set (using
401 \&\fBENGINE_set_table_flags()\fR), no attempted initialisations will take place,
402 instead the only way for the state table to return a non-NULL \s-1ENGINE\s0 to the
403 \&\*(L"get_default\*(R" query will be if one is expressly set in the table. Eg.
404 \&\fBENGINE_set_default_RSA()\fR does the same job as \fBENGINE_register_RSA()\fR except
405 that it also sets the state table's cached response for the \*(L"get_default\*(R"
406 query. In the case of abstractions like \s-1EVP_CIPHER,\s0 where implementations are
407 indexed by 'nid', these flags and cached-responses are distinct for each 'nid'
408 value.
409 .SS "Application requirements"
410 .IX Subsection "Application requirements"
411 This section will explain the basic things an application programmer should
412 support to make the most useful elements of the \s-1ENGINE\s0 functionality
413 available to the user. The first thing to consider is whether the
414 programmer wishes to make alternative \s-1ENGINE\s0 modules available to the
415 application and user. OpenSSL maintains an internal linked list of
416 \&\*(L"visible\*(R" ENGINEs from which it has to operate \- at start-up, this list is
417 empty and in fact if an application does not call any \s-1ENGINE API\s0 calls and
418 it uses static linking against openssl, then the resulting application
419 binary will not contain any alternative \s-1ENGINE\s0 code at all. So the first
420 consideration is whether any/all available \s-1ENGINE\s0 implementations should be
421 made visible to OpenSSL \- this is controlled by calling the various \*(L"load\*(R"
422 functions.
423 .PP
424 The fact that ENGINEs are made visible to OpenSSL (and thus are linked into
425 the program and loaded into memory at run-time) does not mean they are
426 \&\*(L"registered\*(R" or called into use by OpenSSL automatically \- that behaviour
427 is something for the application to control. Some applications
428 will want to allow the user to specify exactly which \s-1ENGINE\s0 they want used
429 if any is to be used at all. Others may prefer to load all support and have
430 OpenSSL automatically use at run-time any \s-1ENGINE\s0 that is able to
431 successfully initialise \- ie. to assume that this corresponds to
432 acceleration hardware attached to the machine or some such thing. There are
433 probably numerous other ways in which applications may prefer to handle
434 things, so we will simply illustrate the consequences as they apply to a
435 couple of simple cases and leave developers to consider these and the
436 source code to openssl's builtin utilities as guides.
437 .PP
438 If no \s-1ENGINE API\s0 functions are called within an application, then OpenSSL
439 will not allocate any internal resources.  Prior to OpenSSL 1.1.0, however,
440 if any ENGINEs are loaded, even if not registered or used, it was necessary to
441 call \fBENGINE_cleanup()\fR before the program exits.
442 .PP
443 \&\fIUsing a specific \s-1ENGINE\s0 implementation\fR
444 .PP
445 Here we'll assume an application has been configured by its user or admin
446 to want to use the \*(L"\s-1ACME\*(R" ENGINE\s0 if it is available in the version of
447 OpenSSL the application was compiled with. If it is available, it should be
448 used by default for all \s-1RSA, DSA,\s0 and symmetric cipher operations, otherwise
449 OpenSSL should use its builtin software as per usual. The following code
450 illustrates how to approach this;
451 .PP
452 .Vb 10
453 \& ENGINE *e;
454 \& const char *engine_id = "ACME";
455 \& ENGINE_load_builtin_engines();
456 \& e = ENGINE_by_id(engine_id);
457 \& if (!e)
458 \&     /* the engine isn\*(Aqt available */
459 \&     return;
460 \& if (!ENGINE_init(e)) {
461 \&     /* the engine couldn\*(Aqt initialise, release \*(Aqe\*(Aq */
462 \&     ENGINE_free(e);
463 \&     return;
464 \& }
465 \& if (!ENGINE_set_default_RSA(e))
466 \&     /*
467 \&      * This should only happen when \*(Aqe\*(Aq can\*(Aqt initialise, but the previous
468 \&      * statement suggests it did.
469 \&      */
470 \&     abort();
471 \& ENGINE_set_default_DSA(e);
472 \& ENGINE_set_default_ciphers(e);
473 \& /* Release the functional reference from ENGINE_init() */
474 \& ENGINE_finish(e);
475 \& /* Release the structural reference from ENGINE_by_id() */
476 \& ENGINE_free(e);
477 .Ve
478 .PP
479 \&\fIAutomatically using builtin \s-1ENGINE\s0 implementations\fR
480 .PP
481 Here we'll assume we want to load and register all \s-1ENGINE\s0 implementations
482 bundled with OpenSSL, such that for any cryptographic algorithm required by
483 OpenSSL \- if there is an \s-1ENGINE\s0 that implements it and can be initialised,
484 it should be used. The following code illustrates how this can work;
485 .PP
486 .Vb 4
487 \& /* Load all bundled ENGINEs into memory and make them visible */
488 \& ENGINE_load_builtin_engines();
489 \& /* Register all of them for every algorithm they collectively implement */
490 \& ENGINE_register_all_complete();
491 .Ve
492 .PP
493 That's all that's required. Eg. the next time OpenSSL tries to set up an
494 \&\s-1RSA\s0 key, any bundled ENGINEs that implement \s-1RSA_METHOD\s0 will be passed to
495 \&\fBENGINE_init()\fR and if any of those succeed, that \s-1ENGINE\s0 will be set as the
496 default for \s-1RSA\s0 use from then on.
497 .SS "Advanced configuration support"
498 .IX Subsection "Advanced configuration support"
499 There is a mechanism supported by the \s-1ENGINE\s0 framework that allows each
500 \&\s-1ENGINE\s0 implementation to define an arbitrary set of configuration
501 \&\*(L"commands\*(R" and expose them to OpenSSL and any applications based on
502 OpenSSL. This mechanism is entirely based on the use of name-value pairs
503 and assumes \s-1ASCII\s0 input (no unicode or \s-1UTF\s0 for now!), so it is ideal if
504 applications want to provide a transparent way for users to provide
505 arbitrary configuration \*(L"directives\*(R" directly to such ENGINEs. It is also
506 possible for the application to dynamically interrogate the loaded \s-1ENGINE\s0
507 implementations for the names, descriptions, and input flags of their
508 available \*(L"control commands\*(R", providing a more flexible configuration
509 scheme. However, if the user is expected to know which \s-1ENGINE\s0 device he/she
510 is using (in the case of specialised hardware, this goes without saying)
511 then applications may not need to concern themselves with discovering the
512 supported control commands and simply prefer to pass settings into ENGINEs
513 exactly as they are provided by the user.
514 .PP
515 Before illustrating how control commands work, it is worth mentioning what
516 they are typically used for. Broadly speaking there are two uses for
517 control commands; the first is to provide the necessary details to the
518 implementation (which may know nothing at all specific to the host system)
519 so that it can be initialised for use. This could include the path to any
520 driver or config files it needs to load, required network addresses,
521 smart-card identifiers, passwords to initialise protected devices,
522 logging information, etc etc. This class of commands typically needs to be
523 passed to an \s-1ENGINE\s0 \fBbefore\fR attempting to initialise it, ie. before
524 calling \fBENGINE_init()\fR. The other class of commands consist of settings or
525 operations that tweak certain behaviour or cause certain operations to take
526 place, and these commands may work either before or after \fBENGINE_init()\fR, or
527 in some cases both. \s-1ENGINE\s0 implementations should provide indications of
528 this in the descriptions attached to builtin control commands and/or in
529 external product documentation.
530 .PP
531 \&\fIIssuing control commands to an \s-1ENGINE\s0\fR
532 .PP
533 Let's illustrate by example; a function for which the caller supplies the
534 name of the \s-1ENGINE\s0 it wishes to use, a table of string-pairs for use before
535 initialisation, and another table for use after initialisation. Note that
536 the string-pairs used for control commands consist of a command \*(L"name\*(R"
537 followed by the command \*(L"parameter\*(R" \- the parameter could be \s-1NULL\s0 in some
538 cases but the name can not. This function should initialise the \s-1ENGINE\s0
539 (issuing the \*(L"pre\*(R" commands beforehand and the \*(L"post\*(R" commands afterwards)
540 and set it as the default for everything except \s-1RAND\s0 and then return a
541 boolean success or failure.
542 .PP
543 .Vb 10
544 \& int generic_load_engine_fn(const char *engine_id,
545 \&                            const char **pre_cmds, int pre_num,
546 \&                            const char **post_cmds, int post_num)
547 \& {
548 \&     ENGINE *e = ENGINE_by_id(engine_id);
549 \&     if (!e) return 0;
550 \&     while (pre_num\-\-) {
551 \&         if (!ENGINE_ctrl_cmd_string(e, pre_cmds[0], pre_cmds[1], 0)) {
552 \&             fprintf(stderr, "Failed command (%s \- %s:%s)\en", engine_id,
553 \&                     pre_cmds[0], pre_cmds[1] ? pre_cmds[1] : "(NULL)");
554 \&             ENGINE_free(e);
555 \&             return 0;
556 \&         }
557 \&         pre_cmds += 2;
558 \&     }
559 \&     if (!ENGINE_init(e)) {
560 \&         fprintf(stderr, "Failed initialisation\en");
561 \&         ENGINE_free(e);
562 \&         return 0;
563 \&     }
564 \&     /*
565 \&      * ENGINE_init() returned a functional reference, so free the structural
566 \&      * reference from ENGINE_by_id().
567 \&      */
568 \&     ENGINE_free(e);
569 \&     while (post_num\-\-) {
570 \&         if (!ENGINE_ctrl_cmd_string(e, post_cmds[0], post_cmds[1], 0)) {
571 \&             fprintf(stderr, "Failed command (%s \- %s:%s)\en", engine_id,
572 \&                     post_cmds[0], post_cmds[1] ? post_cmds[1] : "(NULL)");
573 \&             ENGINE_finish(e);
574 \&             return 0;
575 \&         }
576 \&         post_cmds += 2;
577 \&     }
578 \&     ENGINE_set_default(e, ENGINE_METHOD_ALL & ~ENGINE_METHOD_RAND);
579 \&     /* Success */
580 \&     return 1;
581 \& }
582 .Ve
583 .PP
584 Note that \fBENGINE_ctrl_cmd_string()\fR accepts a boolean argument that can
585 relax the semantics of the function \- if set non-zero it will only return
586 failure if the \s-1ENGINE\s0 supported the given command name but failed while
587 executing it, if the \s-1ENGINE\s0 doesn't support the command name it will simply
588 return success without doing anything. In this case we assume the user is
589 only supplying commands specific to the given \s-1ENGINE\s0 so we set this to
590 \&\s-1FALSE.\s0
591 .PP
592 \&\fIDiscovering supported control commands\fR
593 .PP
594 It is possible to discover at run-time the names, numerical-ids, descriptions
595 and input parameters of the control commands supported by an \s-1ENGINE\s0 using a
596 structural reference. Note that some control commands are defined by OpenSSL
597 itself and it will intercept and handle these control commands on behalf of the
598 \&\s-1ENGINE,\s0 ie. the \s-1ENGINE\s0's \fBctrl()\fR handler is not used for the control command.
599 openssl/engine.h defines an index, \s-1ENGINE_CMD_BASE,\s0 that all control commands
600 implemented by ENGINEs should be numbered from. Any command value lower than
601 this symbol is considered a \*(L"generic\*(R" command is handled directly by the
602 OpenSSL core routines.
603 .PP
604 It is using these \*(L"core\*(R" control commands that one can discover the control
605 commands implemented by a given \s-1ENGINE,\s0 specifically the commands:
606 .PP
607 .Vb 9
608 \& ENGINE_HAS_CTRL_FUNCTION
609 \& ENGINE_CTRL_GET_FIRST_CMD_TYPE
610 \& ENGINE_CTRL_GET_NEXT_CMD_TYPE
611 \& ENGINE_CTRL_GET_CMD_FROM_NAME
612 \& ENGINE_CTRL_GET_NAME_LEN_FROM_CMD
613 \& ENGINE_CTRL_GET_NAME_FROM_CMD
614 \& ENGINE_CTRL_GET_DESC_LEN_FROM_CMD
615 \& ENGINE_CTRL_GET_DESC_FROM_CMD
616 \& ENGINE_CTRL_GET_CMD_FLAGS
617 .Ve
618 .PP
619 Whilst these commands are automatically processed by the OpenSSL framework code,
620 they use various properties exposed by each \s-1ENGINE\s0 to process these
621 queries. An \s-1ENGINE\s0 has 3 properties it exposes that can affect how this behaves;
622 it can supply a \fBctrl()\fR handler, it can specify \s-1ENGINE_FLAGS_MANUAL_CMD_CTRL\s0 in
623 the \s-1ENGINE\s0's flags, and it can expose an array of control command descriptions.
624 If an \s-1ENGINE\s0 specifies the \s-1ENGINE_FLAGS_MANUAL_CMD_CTRL\s0 flag, then it will
625 simply pass all these \*(L"core\*(R" control commands directly to the \s-1ENGINE\s0's \fBctrl()\fR
626 handler (and thus, it must have supplied one), so it is up to the \s-1ENGINE\s0 to
627 reply to these \*(L"discovery\*(R" commands itself. If that flag is not set, then the
628 OpenSSL framework code will work with the following rules:
629 .PP
630 .Vb 9
631 \& if no ctrl() handler supplied;
632 \&     ENGINE_HAS_CTRL_FUNCTION returns FALSE (zero),
633 \&     all other commands fail.
634 \& if a ctrl() handler was supplied but no array of control commands;
635 \&     ENGINE_HAS_CTRL_FUNCTION returns TRUE,
636 \&     all other commands fail.
637 \& if a ctrl() handler and array of control commands was supplied;
638 \&     ENGINE_HAS_CTRL_FUNCTION returns TRUE,
639 \&     all other commands proceed processing ...
640 .Ve
641 .PP
642 If the \s-1ENGINE\s0's array of control commands is empty then all other commands will
643 fail, otherwise; \s-1ENGINE_CTRL_GET_FIRST_CMD_TYPE\s0 returns the identifier of
644 the first command supported by the \s-1ENGINE, ENGINE_GET_NEXT_CMD_TYPE\s0 takes the
645 identifier of a command supported by the \s-1ENGINE\s0 and returns the next command
646 identifier or fails if there are no more, \s-1ENGINE_CMD_FROM_NAME\s0 takes a string
647 name for a command and returns the corresponding identifier or fails if no such
648 command name exists, and the remaining commands take a command identifier and
649 return properties of the corresponding commands. All except
650 \&\s-1ENGINE_CTRL_GET_FLAGS\s0 return the string length of a command name or description,
651 or populate a supplied character buffer with a copy of the command name or
652 description. \s-1ENGINE_CTRL_GET_FLAGS\s0 returns a bitwise-OR'd mask of the following
653 possible values:
654 .PP
655 .Vb 4
656 \& ENGINE_CMD_FLAG_NUMERIC
657 \& ENGINE_CMD_FLAG_STRING
658 \& ENGINE_CMD_FLAG_NO_INPUT
659 \& ENGINE_CMD_FLAG_INTERNAL
660 .Ve
661 .PP
662 If the \s-1ENGINE_CMD_FLAG_INTERNAL\s0 flag is set, then any other flags are purely
663 informational to the caller \- this flag will prevent the command being usable
664 for any higher-level \s-1ENGINE\s0 functions such as \fBENGINE_ctrl_cmd_string()\fR.
665 \&\*(L"\s-1INTERNAL\*(R"\s0 commands are not intended to be exposed to text-based configuration
666 by applications, administrations, users, etc. These can support arbitrary
667 operations via \fBENGINE_ctrl()\fR, including passing to and/or from the control
668 commands data of any arbitrary type. These commands are supported in the
669 discovery mechanisms simply to allow applications to determine if an \s-1ENGINE\s0
670 supports certain specific commands it might want to use (eg. application \*(L"foo\*(R"
671 might query various ENGINEs to see if they implement \*(L"\s-1FOO_GET_VENDOR_LOGO_GIF\*(R"\s0 \-
672 and \s-1ENGINE\s0 could therefore decide whether or not to support this \*(L"foo\*(R"\-specific
673 extension).
674 .SH "ENVIRONMENT"
675 .IX Header "ENVIRONMENT"
676 .IP "\fB\s-1OPENSSL_ENGINES\s0\fR" 4
677 .IX Item "OPENSSL_ENGINES"
678 The path to the engines directory.
679 Ignored in set-user-ID and set-group-ID programs.
680 .SH "RETURN VALUES"
681 .IX Header "RETURN VALUES"
682 \&\fBENGINE_get_first()\fR, \fBENGINE_get_last()\fR, \fBENGINE_get_next()\fR and \fBENGINE_get_prev()\fR
683 return a valid \fB\s-1ENGINE\s0\fR structure or \s-1NULL\s0 if an error occurred.
684 .PP
685 \&\fBENGINE_add()\fR and \fBENGINE_remove()\fR return 1 on success or 0 on error.
686 .PP
687 \&\fBENGINE_by_id()\fR returns a valid \fB\s-1ENGINE\s0\fR structure or \s-1NULL\s0 if an error occurred.
688 .PP
689 \&\fBENGINE_init()\fR and \fBENGINE_finish()\fR return 1 on success or 0 on error.
690 .PP
691 All \fBENGINE_get_default_TYPE()\fR functions, \fBENGINE_get_cipher_engine()\fR and
692 \&\fBENGINE_get_digest_engine()\fR return a valid \fB\s-1ENGINE\s0\fR structure on success or \s-1NULL\s0
693 if an error occurred.
694 .PP
695 All \fBENGINE_set_default_TYPE()\fR functions return 1 on success or 0 on error.
696 .PP
697 \&\fBENGINE_set_default()\fR returns 1 on success or 0 on error.
698 .PP
699 \&\fBENGINE_get_table_flags()\fR returns an unsigned integer value representing the
700 global table flags which are used to control the registration behaviour of
701 \&\fB\s-1ENGINE\s0\fR implementations.
702 .PP
703 All \fBENGINE_register_TYPE()\fR functions return 1 on success or 0 on error.
704 .PP
705 \&\fBENGINE_register_complete()\fR and \fBENGINE_register_all_complete()\fR return 1 on success
706 or 0 on error.
707 .PP
708 \&\fBENGINE_ctrl()\fR returns a positive value on success or others on error.
709 .PP
710 \&\fBENGINE_cmd_is_executable()\fR returns 1 if \fBcmd\fR is executable or 0 otherwise.
711 .PP
712 \&\fBENGINE_ctrl_cmd()\fR and \fBENGINE_ctrl_cmd_string()\fR return 1 on success or 0 on error.
713 .PP
714 \&\fBENGINE_new()\fR returns a valid \fB\s-1ENGINE\s0\fR structure on success or \s-1NULL\s0 if an error
715 occurred.
716 .PP
717 \&\fBENGINE_free()\fR returns 1 on success or 0 on error.
718 .PP
719 \&\fBENGINE_up_ref()\fR returns 1 on success or 0 on error.
720 .PP
721 \&\fBENGINE_set_id()\fR and \fBENGINE_set_name()\fR return 1 on success or 0 on error.
722 .PP
723 All other \fBENGINE_set_*\fR functions return 1 on success or 0 on error.
724 .PP
725 \&\fBENGINE_get_id()\fR and \fBENGINE_get_name()\fR return a string representing the identifier
726 and the name of the \s-1ENGINE\s0 \fBe\fR respectively.
727 .PP
728 \&\fBENGINE_get_RSA()\fR, \fBENGINE_get_DSA()\fR, \fBENGINE_get_DH()\fR and \fBENGINE_get_RAND()\fR
729 return corresponding method structures for each algorithms.
730 .PP
731 \&\fBENGINE_get_destroy_function()\fR, \fBENGINE_get_init_function()\fR,
732 \&\fBENGINE_get_finish_function()\fR, \fBENGINE_get_ctrl_function()\fR,
733 \&\fBENGINE_get_load_privkey_function()\fR, \fBENGINE_get_load_pubkey_function()\fR,
734 \&\fBENGINE_get_ciphers()\fR and \fBENGINE_get_digests()\fR return corresponding function
735 pointers of the callbacks.
736 .PP
737 \&\fBENGINE_get_cipher()\fR returns a valid \fB\s-1EVP_CIPHER\s0\fR structure on success or \s-1NULL\s0
738 if an error occurred.
739 .PP
740 \&\fBENGINE_get_digest()\fR returns a valid \fB\s-1EVP_MD\s0\fR structure on success or \s-1NULL\s0 if an
741 error occurred.
742 .PP
743 \&\fBENGINE_get_flags()\fR returns an integer representing the \s-1ENGINE\s0 flags which are
744 used to control various behaviours of an \s-1ENGINE.\s0
745 .PP
746 \&\fBENGINE_get_cmd_defns()\fR returns an \fB\s-1ENGINE_CMD_DEFN\s0\fR structure or \s-1NULL\s0 if it's
747 not set.
748 .PP
749 \&\fBENGINE_load_private_key()\fR and \fBENGINE_load_public_key()\fR return a valid \fB\s-1EVP_PKEY\s0\fR
750 structure on success or \s-1NULL\s0 if an error occurred.
751 .SH "SEE ALSO"
752 .IX Header "SEE ALSO"
753 \&\fBOPENSSL_init_crypto\fR\|(3), \fBRSA_new_method\fR\|(3), \fBDSA_new\fR\|(3), \fBDH_new\fR\|(3),
754 \&\fBRAND_bytes\fR\|(3), \fBconfig\fR\|(5)
755 .SH "HISTORY"
756 .IX Header "HISTORY"
757 \&\fBENGINE_cleanup()\fR was deprecated in OpenSSL 1.1.0 by the automatic cleanup
758 done by \fBOPENSSL_cleanup()\fR
759 and should not be used.
760 .SH "COPYRIGHT"
761 .IX Header "COPYRIGHT"
762 Copyright 2002\-2018 The OpenSSL Project Authors. All Rights Reserved.
763 .PP
764 Licensed under the OpenSSL license (the \*(L"License\*(R").  You may not use
765 this file except in compliance with the License.  You can obtain a copy
766 in the file \s-1LICENSE\s0 in the source distribution or at
767 <https://www.openssl.org/source/license.html>.