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