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