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