1 .\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.14
4 .\" ========================================================================
5 .de Sh \" Subsection heading
13 .de Sp \" Vertical space (when we can't use .PP)
17 .de Vb \" Begin verbatim text
22 .de Ve \" End verbatim text
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<>.
33 .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
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
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.
57 . tm Index:\\$1\t\\n%\t"\\$2"
63 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
64 .\" way too many mistakes in technical documents.
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
79 . ds #H ((1u-(\\\\n(.fu%2u))*.13m)
85 . \" simple accents for nroff and troff
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'
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 \
129 .\" ========================================================================
132 .TH engine 3 "2005-02-24" "0.9.7d" "OpenSSL"
134 engine \- ENGINE cryptographic module support
136 .IX Header "SYNOPSIS"
138 \& #include <openssl/engine.h>
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);
149 \& int ENGINE_add(ENGINE *e);
150 \& int ENGINE_remove(ENGINE *e);
154 \& ENGINE *ENGINE_by_id(const char *id);
158 \& int ENGINE_init(ENGINE *e);
159 \& int ENGINE_finish(ENGINE *e);
163 \& void ENGINE_load_openssl(void);
164 \& void ENGINE_load_dynamic(void);
165 \& void ENGINE_load_cswift(void);
166 \& void ENGINE_load_chil(void);
167 \& void ENGINE_load_atalla(void);
168 \& void ENGINE_load_nuron(void);
169 \& void ENGINE_load_ubsec(void);
170 \& void ENGINE_load_aep(void);
171 \& void ENGINE_load_sureware(void);
172 \& void ENGINE_load_4758cca(void);
173 \& void ENGINE_load_openbsd_dev_crypto(void);
174 \& void ENGINE_load_builtin_engines(void);
178 \& void ENGINE_cleanup(void);
182 \& ENGINE *ENGINE_get_default_RSA(void);
183 \& ENGINE *ENGINE_get_default_DSA(void);
184 \& ENGINE *ENGINE_get_default_DH(void);
185 \& ENGINE *ENGINE_get_default_RAND(void);
186 \& ENGINE *ENGINE_get_cipher_engine(int nid);
187 \& 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_DH(ENGINE *e);
194 \& int ENGINE_set_default_RAND(ENGINE *e);
195 \& int ENGINE_set_default_ciphers(ENGINE *e);
196 \& int ENGINE_set_default_digests(ENGINE *e);
197 \& int ENGINE_set_default_string(ENGINE *e, const char *list);
201 \& int ENGINE_set_default(ENGINE *e, unsigned int flags);
205 \& unsigned int ENGINE_get_table_flags(void);
206 \& void ENGINE_set_table_flags(unsigned int flags);
210 \& int ENGINE_register_RSA(ENGINE *e);
211 \& void ENGINE_unregister_RSA(ENGINE *e);
212 \& void ENGINE_register_all_RSA(void);
213 \& int ENGINE_register_DSA(ENGINE *e);
214 \& void ENGINE_unregister_DSA(ENGINE *e);
215 \& void ENGINE_register_all_DSA(void);
216 \& int ENGINE_register_DH(ENGINE *e);
217 \& void ENGINE_unregister_DH(ENGINE *e);
218 \& void ENGINE_register_all_DH(void);
219 \& int ENGINE_register_RAND(ENGINE *e);
220 \& void ENGINE_unregister_RAND(ENGINE *e);
221 \& void ENGINE_register_all_RAND(void);
222 \& int ENGINE_register_ciphers(ENGINE *e);
223 \& void ENGINE_unregister_ciphers(ENGINE *e);
224 \& void ENGINE_register_all_ciphers(void);
225 \& int ENGINE_register_digests(ENGINE *e);
226 \& void ENGINE_unregister_digests(ENGINE *e);
227 \& void ENGINE_register_all_digests(void);
228 \& int ENGINE_register_complete(ENGINE *e);
229 \& int ENGINE_register_all_complete(void);
233 \& int ENGINE_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)());
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)(), int cmd_optional);
237 \& int ENGINE_ctrl_cmd_string(ENGINE *e, const char *cmd_name, const char *arg,
238 \& int cmd_optional);
242 \& int ENGINE_set_ex_data(ENGINE *e, int idx, void *arg);
243 \& void *ENGINE_get_ex_data(const ENGINE *e, int idx);
247 \& int ENGINE_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
248 \& CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
252 \& ENGINE *ENGINE_new(void);
253 \& int ENGINE_free(ENGINE *e);
257 \& int ENGINE_set_id(ENGINE *e, const char *id);
258 \& int ENGINE_set_name(ENGINE *e, const char *name);
259 \& int ENGINE_set_RSA(ENGINE *e, const RSA_METHOD *rsa_meth);
260 \& int ENGINE_set_DSA(ENGINE *e, const DSA_METHOD *dsa_meth);
261 \& int ENGINE_set_DH(ENGINE *e, const DH_METHOD *dh_meth);
262 \& int ENGINE_set_RAND(ENGINE *e, const RAND_METHOD *rand_meth);
263 \& int ENGINE_set_destroy_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR destroy_f);
264 \& int ENGINE_set_init_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR init_f);
265 \& int ENGINE_set_finish_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR finish_f);
266 \& int ENGINE_set_ctrl_function(ENGINE *e, ENGINE_CTRL_FUNC_PTR ctrl_f);
267 \& int ENGINE_set_load_privkey_function(ENGINE *e, ENGINE_LOAD_KEY_PTR loadpriv_f);
268 \& int ENGINE_set_load_pubkey_function(ENGINE *e, ENGINE_LOAD_KEY_PTR loadpub_f);
269 \& int ENGINE_set_ciphers(ENGINE *e, ENGINE_CIPHERS_PTR f);
270 \& int ENGINE_set_digests(ENGINE *e, ENGINE_DIGESTS_PTR f);
271 \& int ENGINE_set_flags(ENGINE *e, int flags);
272 \& int ENGINE_set_cmd_defns(ENGINE *e, const ENGINE_CMD_DEFN *defns);
276 \& const char *ENGINE_get_id(const ENGINE *e);
277 \& const char *ENGINE_get_name(const ENGINE *e);
278 \& const RSA_METHOD *ENGINE_get_RSA(const ENGINE *e);
279 \& const DSA_METHOD *ENGINE_get_DSA(const ENGINE *e);
280 \& const DH_METHOD *ENGINE_get_DH(const ENGINE *e);
281 \& const RAND_METHOD *ENGINE_get_RAND(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);
297 \& EVP_PKEY *ENGINE_load_private_key(ENGINE *e, const char *key_id,
298 \& UI_METHOD *ui_method, void *callback_data);
299 \& EVP_PKEY *ENGINE_load_public_key(ENGINE *e, const char *key_id,
300 \& UI_METHOD *ui_method, void *callback_data);
304 \& void ENGINE_add_conf_module(void);
307 .IX Header "DESCRIPTION"
308 These functions create, manipulate, and use cryptographic modules in the
309 form of \fB\s-1ENGINE\s0\fR objects. These objects act as containers for
310 implementations of cryptographic algorithms, and support a
311 reference-counted mechanism to allow them to be dynamically loaded in and
312 out of the running application.
314 The cryptographic functionality that can be provided by an \fB\s-1ENGINE\s0\fR
315 implementation includes the following abstractions;
318 \& RSA_METHOD - for providing alternative RSA implementations
319 \& DSA_METHOD, DH_METHOD, RAND_METHOD - alternative DSA, DH, and RAND
320 \& EVP_CIPHER - potentially multiple cipher algorithms (indexed by 'nid')
321 \& EVP_DIGEST - potentially multiple hash algorithms (indexed by 'nid')
322 \& key-loading - loading public and/or private EVP_PKEY keys
324 .Sh "Reference counting and handles"
325 .IX Subsection "Reference counting and handles"
326 Due to the modular nature of the \s-1ENGINE\s0 \s-1API\s0, pointers to ENGINEs need to be
327 treated as handles \- ie. not only as pointers, but also as references to
328 the underlying \s-1ENGINE\s0 object. Ie. you should obtain a new reference when
329 making copies of an \s-1ENGINE\s0 pointer if the copies will be used (and
330 released) independantly.
332 \&\s-1ENGINE\s0 objects have two levels of reference-counting to match the way in
333 which the objects are used. At the most basic level, each \s-1ENGINE\s0 pointer is
334 inherently a \fBstructural\fR reference \- you need a structural reference
335 simply to refer to the pointer value at all, as this kind of reference is
336 your guarantee that the structure can not be deallocated until you release
339 However, a structural reference provides no guarantee that the \s-1ENGINE\s0 has
340 been initiliased to be usable to perform any of its cryptographic
341 implementations \- and indeed it's quite possible that most ENGINEs will not
342 initialised at all on standard setups, as ENGINEs are typically used to
343 support specialised hardware. To use an \s-1ENGINE\s0's functionality, you need a
344 \&\fBfunctional\fR reference. This kind of reference can be considered a
345 specialised form of structural reference, because each functional reference
346 implicitly contains a structural reference as well \- however to avoid
347 difficult-to-find programming bugs, it is recommended to treat the two
348 kinds of reference independantly. If you have a functional reference to an
349 \&\s-1ENGINE\s0, you have a guarantee that the \s-1ENGINE\s0 has been initialised ready to
350 perform cryptographic operations and will not be uninitialised or cleaned
351 up until after you have released your reference.
353 We will discuss the two kinds of reference separately, including how to
354 tell which one you are dealing with at any given point in time (after all
355 they are both simply (\s-1ENGINE\s0 *) pointers, the difference is in the way they
358 \&\fIStructural references\fR
360 This basic type of reference is typically used for creating new ENGINEs
361 dynamically, iterating across OpenSSL's internal linked-list of loaded
362 ENGINEs, reading information about an \s-1ENGINE\s0, etc. Essentially a structural
363 reference is sufficient if you only need to query or manipulate the data of
364 an \s-1ENGINE\s0 implementation rather than use its functionality.
366 The \fIENGINE_new()\fR function returns a structural reference to a new (empty)
367 \&\s-1ENGINE\s0 object. Other than that, structural references come from return
368 values to various \s-1ENGINE\s0 \s-1API\s0 functions such as; \fIENGINE_by_id()\fR,
369 \&\fIENGINE_get_first()\fR, \fIENGINE_get_last()\fR, \fIENGINE_get_next()\fR,
370 \&\fIENGINE_get_prev()\fR. All structural references should be released by a
371 corresponding to call to the \fIENGINE_free()\fR function \- the \s-1ENGINE\s0 object
372 itself will only actually be cleaned up and deallocated when the last
373 structural reference is released.
375 It should also be noted that many \s-1ENGINE\s0 \s-1API\s0 function calls that accept a
376 structural reference will internally obtain another reference \- typically
377 this happens whenever the supplied \s-1ENGINE\s0 will be needed by OpenSSL after
378 the function has returned. Eg. the function to add a new \s-1ENGINE\s0 to
379 OpenSSL's internal list is \fIENGINE_add()\fR \- if this function returns success,
380 then OpenSSL will have stored a new structural reference internally so the
381 caller is still responsible for freeing their own reference with
382 \&\fIENGINE_free()\fR when they are finished with it. In a similar way, some
383 functions will automatically release the structural reference passed to it
384 if part of the function's job is to do so. Eg. the \fIENGINE_get_next()\fR and
385 \&\fIENGINE_get_prev()\fR functions are used for iterating across the internal
386 \&\s-1ENGINE\s0 list \- they will return a new structural reference to the next (or
387 previous) \s-1ENGINE\s0 in the list or \s-1NULL\s0 if at the end (or beginning) of the
388 list, but in either case the structural reference passed to the function is
389 released on behalf of the caller.
391 To clarify a particular function's handling of references, one should
392 always consult that function's documentation \*(L"man\*(R" page, or failing that
393 the openssl/engine.h header file includes some hints.
395 \&\fIFunctional references\fR
397 As mentioned, functional references exist when the cryptographic
398 functionality of an \s-1ENGINE\s0 is required to be available. A functional
399 reference can be obtained in one of two ways; from an existing structural
400 reference to the required \s-1ENGINE\s0, or by asking OpenSSL for the default
401 operational \s-1ENGINE\s0 for a given cryptographic purpose.
403 To obtain a functional reference from an existing structural reference,
404 call the \fIENGINE_init()\fR function. This returns zero if the \s-1ENGINE\s0 was not
405 already operational and couldn't be successfully initialised (eg. lack of
406 system drivers, no special hardware attached, etc), otherwise it will
407 return non-zero to indicate that the \s-1ENGINE\s0 is now operational and will
408 have allocated a new \fBfunctional\fR reference to the \s-1ENGINE\s0. In this case,
409 the supplied \s-1ENGINE\s0 pointer is, from the point of the view of the caller,
410 both a structural reference and a functional reference \- so if the caller
411 intends to use it as a functional reference it should free the structural
412 reference with \fIENGINE_free()\fR first. If the caller wishes to use it only as
413 a structural reference (eg. if the \fIENGINE_init()\fR call was simply to test if
414 the \s-1ENGINE\s0 seems available/online), then it should free the functional
415 reference; all functional references are released by the \fIENGINE_finish()\fR
418 The second way to get a functional reference is by asking OpenSSL for a
419 default implementation for a given task, eg. by \fIENGINE_get_default_RSA()\fR,
420 \&\fIENGINE_get_default_cipher_engine()\fR, etc. These are discussed in the next
421 section, though they are not usually required by application programmers as
422 they are used automatically when creating and using the relevant
423 algorithm-specific types in OpenSSL, such as \s-1RSA\s0, \s-1DSA\s0, \s-1EVP_CIPHER_CTX\s0, etc.
424 .Sh "Default implementations"
425 .IX Subsection "Default implementations"
426 For each supported abstraction, the \s-1ENGINE\s0 code maintains an internal table
427 of state to control which implementations are available for a given
428 abstraction and which should be used by default. These implementations are
429 registered in the tables separated-out by an 'nid' index, because
430 abstractions like \s-1EVP_CIPHER\s0 and \s-1EVP_DIGEST\s0 support many distinct
431 algorithms and modes \- ENGINEs will support different numbers and
432 combinations of these. In the case of other abstractions like \s-1RSA\s0, \s-1DSA\s0,
433 etc, there is only one \*(L"algorithm\*(R" so all implementations implicitly
434 register using the same 'nid' index. ENGINEs can be \fBregistered\fR into
435 these tables to make themselves available for use automatically by the
436 various abstractions, eg. \s-1RSA\s0. For illustrative purposes, we continue with
437 the \s-1RSA\s0 example, though all comments apply similarly to the other
438 abstractions (they each get their own table and linkage to the
439 corresponding section of openssl code).
441 When a new \s-1RSA\s0 key is being created, ie. in \fIRSA_new_method()\fR, a
442 \&\*(L"get_default\*(R" call will be made to the \s-1ENGINE\s0 subsystem to process the \s-1RSA\s0
443 state table and return a functional reference to an initialised \s-1ENGINE\s0
444 whose \s-1RSA_METHOD\s0 should be used. If no \s-1ENGINE\s0 should (or can) be used, it
445 will return \s-1NULL\s0 and the \s-1RSA\s0 key will operate with a \s-1NULL\s0 \s-1ENGINE\s0 handle by
446 using the conventional \s-1RSA\s0 implementation in OpenSSL (and will from then on
447 behave the way it used to before the \s-1ENGINE\s0 \s-1API\s0 existed \- for details see
448 \&\fIRSA_new_method\fR\|(3)).
450 Each state table has a flag to note whether it has processed this
451 \&\*(L"get_default\*(R" query since the table was last modified, because to process
452 this question it must iterate across all the registered ENGINEs in the
453 table trying to initialise each of them in turn, in case one of them is
454 operational. If it returns a functional reference to an \s-1ENGINE\s0, it will
455 also cache another reference to speed up processing future queries (without
456 needing to iterate across the table). Likewise, it will cache a \s-1NULL\s0
457 response if no \s-1ENGINE\s0 was available so that future queries won't repeat the
458 same iteration unless the state table changes. This behaviour can also be
459 changed; if the \s-1ENGINE_TABLE_FLAG_NOINIT\s0 flag is set (using
460 \&\fIENGINE_set_table_flags()\fR), no attempted initialisations will take place,
461 instead the only way for the state table to return a non-NULL \s-1ENGINE\s0 to the
462 \&\*(L"get_default\*(R" query will be if one is expressly set in the table. Eg.
463 \&\fIENGINE_set_default_RSA()\fR does the same job as \fIENGINE_register_RSA()\fR except
464 that it also sets the state table's cached response for the \*(L"get_default\*(R"
467 In the case of abstractions like \s-1EVP_CIPHER\s0, where implementations are
468 indexed by 'nid', these flags and cached-responses are distinct for each
471 It is worth illustrating the difference between \*(L"registration\*(R" of ENGINEs
472 into these per-algorithm state tables and using the alternative
473 \&\*(L"set_default\*(R" functions. The latter handles both \*(L"registration\*(R" and also
474 setting the cached \*(L"default\*(R" \s-1ENGINE\s0 in each relevant state table \- so
475 registered ENGINEs will only have a chance to be initialised for use as a
476 default if a default \s-1ENGINE\s0 wasn't already set for the same state table.
477 Eg. if \s-1ENGINE\s0 X supports cipher nids {A,B} and \s-1RSA\s0, \s-1ENGINE\s0 Y supports
478 ciphers {A} and \s-1DSA\s0, and the following code is executed;
481 \& ENGINE_register_complete(X);
482 \& ENGINE_set_default(Y, ENGINE_METHOD_ALL);
483 \& e1 = ENGINE_get_default_RSA();
484 \& e2 = ENGINE_get_cipher_engine(A);
485 \& e3 = ENGINE_get_cipher_engine(B);
486 \& e4 = ENGINE_get_default_DSA();
487 \& e5 = ENGINE_get_cipher_engine(C);
490 The results would be as follows;
497 \& assert(e5 == NULL);
499 .Sh "Application requirements"
500 .IX Subsection "Application requirements"
501 This section will explain the basic things an application programmer should
502 support to make the most useful elements of the \s-1ENGINE\s0 functionality
503 available to the user. The first thing to consider is whether the
504 programmer wishes to make alternative \s-1ENGINE\s0 modules available to the
505 application and user. OpenSSL maintains an internal linked list of
506 \&\*(L"visible\*(R" ENGINEs from which it has to operate \- at start\-up, this list is
507 empty and in fact if an application does not call any \s-1ENGINE\s0 \s-1API\s0 calls and
508 it uses static linking against openssl, then the resulting application
509 binary will not contain any alternative \s-1ENGINE\s0 code at all. So the first
510 consideration is whether any/all available \s-1ENGINE\s0 implementations should be
511 made visible to OpenSSL \- this is controlled by calling the various \*(L"load\*(R"
515 \& /* Make the "dynamic" ENGINE available */
516 \& void ENGINE_load_dynamic(void);
517 \& /* Make the CryptoSwift hardware acceleration support available */
518 \& void ENGINE_load_cswift(void);
519 \& /* Make support for nCipher's "CHIL" hardware available */
520 \& void ENGINE_load_chil(void);
522 \& /* Make ALL ENGINE implementations bundled with OpenSSL available */
523 \& void ENGINE_load_builtin_engines(void);
526 Having called any of these functions, \s-1ENGINE\s0 objects would have been
527 dynamically allocated and populated with these implementations and linked
528 into OpenSSL's internal linked list. At this point it is important to
529 mention an important \s-1API\s0 function;
532 \& void ENGINE_cleanup(void);
535 If no \s-1ENGINE\s0 \s-1API\s0 functions are called at all in an application, then there
536 are no inherent memory leaks to worry about from the \s-1ENGINE\s0 functionality,
537 however if any ENGINEs are \*(L"load\*(R"ed, even if they are never registered or
538 used, it is necessary to use the \fIENGINE_cleanup()\fR function to
539 correspondingly cleanup before program exit, if the caller wishes to avoid
540 memory leaks. This mechanism uses an internal callback registration table
541 so that any \s-1ENGINE\s0 \s-1API\s0 functionality that knows it requires cleanup can
542 register its cleanup details to be called during \fIENGINE_cleanup()\fR. This
543 approach allows \fIENGINE_cleanup()\fR to clean up after any \s-1ENGINE\s0 functionality
544 at all that your program uses, yet doesn't automatically create linker
545 dependencies to all possible \s-1ENGINE\s0 functionality \- only the cleanup
546 callbacks required by the functionality you do use will be required by the
549 The fact that ENGINEs are made visible to OpenSSL (and thus are linked into
550 the program and loaded into memory at run\-time) does not mean they are
551 \&\*(L"registered\*(R" or called into use by OpenSSL automatically \- that behaviour
552 is something for the application to have control over. Some applications
553 will want to allow the user to specify exactly which \s-1ENGINE\s0 they want used
554 if any is to be used at all. Others may prefer to load all support and have
555 OpenSSL automatically use at run-time any \s-1ENGINE\s0 that is able to
556 successfully initialise \- ie. to assume that this corresponds to
557 acceleration hardware attached to the machine or some such thing. There are
558 probably numerous other ways in which applications may prefer to handle
559 things, so we will simply illustrate the consequences as they apply to a
560 couple of simple cases and leave developers to consider these and the
561 source code to openssl's builtin utilities as guides.
563 \&\fIUsing a specific \s-1ENGINE\s0 implementation\fR
565 Here we'll assume an application has been configured by its user or admin
566 to want to use the \*(L"\s-1ACME\s0\*(R" \s-1ENGINE\s0 if it is available in the version of
567 OpenSSL the application was compiled with. If it is available, it should be
568 used by default for all \s-1RSA\s0, \s-1DSA\s0, and symmetric cipher operation, otherwise
569 OpenSSL should use its builtin software as per usual. The following code
570 illustrates how to approach this;
574 \& const char *engine_id = "ACME";
575 \& ENGINE_load_builtin_engines();
576 \& e = ENGINE_by_id(engine_id);
578 \& /* the engine isn't available */
580 \& if(!ENGINE_init(e)) {
581 \& /* the engine couldn't initialise, release 'e' */
585 \& if(!ENGINE_set_default_RSA(e))
586 \& /* This should only happen when 'e' can't initialise, but the previous
587 \& * statement suggests it did. */
589 \& ENGINE_set_default_DSA(e);
590 \& ENGINE_set_default_ciphers(e);
591 \& /* Release the functional reference from ENGINE_init() */
593 \& /* Release the structural reference from ENGINE_by_id() */
597 \&\fIAutomatically using builtin \s-1ENGINE\s0 implementations\fR
599 Here we'll assume we want to load and register all \s-1ENGINE\s0 implementations
600 bundled with OpenSSL, such that for any cryptographic algorithm required by
601 OpenSSL \- if there is an \s-1ENGINE\s0 that implements it and can be initialise,
602 it should be used. The following code illustrates how this can work;
605 \& /* Load all bundled ENGINEs into memory and make them visible */
606 \& ENGINE_load_builtin_engines();
607 \& /* Register all of them for every algorithm they collectively implement */
608 \& ENGINE_register_all_complete();
611 That's all that's required. Eg. the next time OpenSSL tries to set up an
612 \&\s-1RSA\s0 key, any bundled ENGINEs that implement \s-1RSA_METHOD\s0 will be passed to
613 \&\fIENGINE_init()\fR and if any of those succeed, that \s-1ENGINE\s0 will be set as the
614 default for use with \s-1RSA\s0 from then on.
615 .Sh "Advanced configuration support"
616 .IX Subsection "Advanced configuration support"
617 There is a mechanism supported by the \s-1ENGINE\s0 framework that allows each
618 \&\s-1ENGINE\s0 implementation to define an arbitrary set of configuration
619 \&\*(L"commands\*(R" and expose them to OpenSSL and any applications based on
620 OpenSSL. This mechanism is entirely based on the use of name-value pairs
621 and and assumes \s-1ASCII\s0 input (no unicode or \s-1UTF\s0 for now!), so it is ideal if
622 applications want to provide a transparent way for users to provide
623 arbitrary configuration \*(L"directives\*(R" directly to such ENGINEs. It is also
624 possible for the application to dynamically interrogate the loaded \s-1ENGINE\s0
625 implementations for the names, descriptions, and input flags of their
626 available \*(L"control commands\*(R", providing a more flexible configuration
627 scheme. However, if the user is expected to know which \s-1ENGINE\s0 device he/she
628 is using (in the case of specialised hardware, this goes without saying)
629 then applications may not need to concern themselves with discovering the
630 supported control commands and simply prefer to allow settings to passed
631 into ENGINEs exactly as they are provided by the user.
633 Before illustrating how control commands work, it is worth mentioning what
634 they are typically used for. Broadly speaking there are two uses for
635 control commands; the first is to provide the necessary details to the
636 implementation (which may know nothing at all specific to the host system)
637 so that it can be initialised for use. This could include the path to any
638 driver or config files it needs to load, required network addresses,
639 smart-card identifiers, passwords to initialise password-protected devices,
640 logging information, etc etc. This class of commands typically needs to be
641 passed to an \s-1ENGINE\s0 \fBbefore\fR attempting to initialise it, ie. before
642 calling \fIENGINE_init()\fR. The other class of commands consist of settings or
643 operations that tweak certain behaviour or cause certain operations to take
644 place, and these commands may work either before or after \fIENGINE_init()\fR, or
645 in same cases both. \s-1ENGINE\s0 implementations should provide indications of
646 this in the descriptions attached to builtin control commands and/or in
647 external product documentation.
649 \&\fIIssuing control commands to an \s-1ENGINE\s0\fR
651 Let's illustrate by example; a function for which the caller supplies the
652 name of the \s-1ENGINE\s0 it wishes to use, a table of string-pairs for use before
653 initialisation, and another table for use after initialisation. Note that
654 the string-pairs used for control commands consist of a command \*(L"name\*(R"
655 followed by the command \*(L"parameter\*(R" \- the parameter could be \s-1NULL\s0 in some
656 cases but the name can not. This function should initialise the \s-1ENGINE\s0
657 (issuing the \*(L"pre\*(R" commands beforehand and the \*(L"post\*(R" commands afterwards)
658 and set it as the default for everything except \s-1RAND\s0 and then return a
659 boolean success or failure.
662 \& int generic_load_engine_fn(const char *engine_id,
663 \& const char **pre_cmds, int pre_num,
664 \& const char **post_cmds, int post_num)
666 \& ENGINE *e = ENGINE_by_id(engine_id);
668 \& while(pre_num--) {
669 \& if(!ENGINE_ctrl_cmd_string(e, pre_cmds[0], pre_cmds[1], 0)) {
670 \& fprintf(stderr, "Failed command (%s - %s:%s)\en", engine_id,
671 \& pre_cmds[0], pre_cmds[1] ? pre_cmds[1] : "(NULL)");
677 \& if(!ENGINE_init(e)) {
678 \& fprintf(stderr, "Failed initialisation\en");
682 \& /* ENGINE_init() returned a functional reference, so free the structural
683 \& * reference from ENGINE_by_id(). */
685 \& while(post_num--) {
686 \& if(!ENGINE_ctrl_cmd_string(e, post_cmds[0], post_cmds[1], 0)) {
687 \& fprintf(stderr, "Failed command (%s - %s:%s)\en", engine_id,
688 \& post_cmds[0], post_cmds[1] ? post_cmds[1] : "(NULL)");
694 \& ENGINE_set_default(e, ENGINE_METHOD_ALL & ~ENGINE_METHOD_RAND);
700 Note that \fIENGINE_ctrl_cmd_string()\fR accepts a boolean argument that can
701 relax the semantics of the function \- if set non-zero it will only return
702 failure if the \s-1ENGINE\s0 supported the given command name but failed while
703 executing it, if the \s-1ENGINE\s0 doesn't support the command name it will simply
704 return success without doing anything. In this case we assume the user is
705 only supplying commands specific to the given \s-1ENGINE\s0 so we set this to
708 \&\fIDiscovering supported control commands\fR
710 It is possible to discover at run-time the names, numerical\-ids, descriptions
711 and input parameters of the control commands supported from a structural
712 reference to any \s-1ENGINE\s0. It is first important to note that some control
713 commands are defined by OpenSSL itself and it will intercept and handle these
714 control commands on behalf of the \s-1ENGINE\s0, ie. the \s-1ENGINE\s0's \fIctrl()\fR handler is not
715 used for the control command. openssl/engine.h defines a symbol,
716 \&\s-1ENGINE_CMD_BASE\s0, that all control commands implemented by ENGINEs from. Any
717 command value lower than this symbol is considered a \*(L"generic\*(R" command is
718 handled directly by the OpenSSL core routines.
720 It is using these \*(L"core\*(R" control commands that one can discover the the control
721 commands implemented by a given \s-1ENGINE\s0, specifically the commands;
724 \& #define ENGINE_HAS_CTRL_FUNCTION 10
725 \& #define ENGINE_CTRL_GET_FIRST_CMD_TYPE 11
726 \& #define ENGINE_CTRL_GET_NEXT_CMD_TYPE 12
727 \& #define ENGINE_CTRL_GET_CMD_FROM_NAME 13
728 \& #define ENGINE_CTRL_GET_NAME_LEN_FROM_CMD 14
729 \& #define ENGINE_CTRL_GET_NAME_FROM_CMD 15
730 \& #define ENGINE_CTRL_GET_DESC_LEN_FROM_CMD 16
731 \& #define ENGINE_CTRL_GET_DESC_FROM_CMD 17
732 \& #define ENGINE_CTRL_GET_CMD_FLAGS 18
735 Whilst these commands are automatically processed by the OpenSSL framework code,
736 they use various properties exposed by each \s-1ENGINE\s0 by which to process these
737 queries. An \s-1ENGINE\s0 has 3 properties it exposes that can affect this behaviour;
738 it can supply a \fIctrl()\fR handler, it can specify \s-1ENGINE_FLAGS_MANUAL_CMD_CTRL\s0 in
739 the \s-1ENGINE\s0's flags, and it can expose an array of control command descriptions.
740 If an \s-1ENGINE\s0 specifies the \s-1ENGINE_FLAGS_MANUAL_CMD_CTRL\s0 flag, then it will
741 simply pass all these \*(L"core\*(R" control commands directly to the \s-1ENGINE\s0's \fIctrl()\fR
742 handler (and thus, it must have supplied one), so it is up to the \s-1ENGINE\s0 to
743 reply to these \*(L"discovery\*(R" commands itself. If that flag is not set, then the
744 OpenSSL framework code will work with the following rules;
747 \& if no ctrl() handler supplied;
748 \& ENGINE_HAS_CTRL_FUNCTION returns FALSE (zero),
749 \& all other commands fail.
750 \& if a ctrl() handler was supplied but no array of control commands;
751 \& ENGINE_HAS_CTRL_FUNCTION returns TRUE,
752 \& all other commands fail.
753 \& if a ctrl() handler and array of control commands was supplied;
754 \& ENGINE_HAS_CTRL_FUNCTION returns TRUE,
755 \& all other commands proceed processing ...
758 If the \s-1ENGINE\s0's array of control commands is empty then all other commands will
759 fail, otherwise; \s-1ENGINE_CTRL_GET_FIRST_CMD_TYPE\s0 returns the identifier of
760 the first command supported by the \s-1ENGINE\s0, \s-1ENGINE_GET_NEXT_CMD_TYPE\s0 takes the
761 identifier of a command supported by the \s-1ENGINE\s0 and returns the next command
762 identifier or fails if there are no more, \s-1ENGINE_CMD_FROM_NAME\s0 takes a string
763 name for a command and returns the corresponding identifier or fails if no such
764 command name exists, and the remaining commands take a command identifier and
765 return properties of the corresponding commands. All except
766 \&\s-1ENGINE_CTRL_GET_FLAGS\s0 return the string length of a command name or description,
767 or populate a supplied character buffer with a copy of the command name or
768 description. \s-1ENGINE_CTRL_GET_FLAGS\s0 returns a bitwise\-OR'd mask of the following
772 \& #define ENGINE_CMD_FLAG_NUMERIC (unsigned int)0x0001
773 \& #define ENGINE_CMD_FLAG_STRING (unsigned int)0x0002
774 \& #define ENGINE_CMD_FLAG_NO_INPUT (unsigned int)0x0004
775 \& #define ENGINE_CMD_FLAG_INTERNAL (unsigned int)0x0008
778 If the \s-1ENGINE_CMD_FLAG_INTERNAL\s0 flag is set, then any other flags are purely
779 informational to the caller \- this flag will prevent the command being usable
780 for any higher-level \s-1ENGINE\s0 functions such as \fIENGINE_ctrl_cmd_string()\fR.
781 \&\*(L"\s-1INTERNAL\s0\*(R" commands are not intended to be exposed to text-based configuration
782 by applications, administrations, users, etc. These can support arbitrary
783 operations via \fIENGINE_ctrl()\fR, including passing to and/or from the control
784 commands data of any arbitrary type. These commands are supported in the
785 discovery mechanisms simply to allow applications determinie if an \s-1ENGINE\s0
786 supports certain specific commands it might want to use (eg. application \*(L"foo\*(R"
787 might query various ENGINEs to see if they implement \*(L"\s-1FOO_GET_VENDOR_LOGO_GIF\s0\*(R" \-
788 and \s-1ENGINE\s0 could therefore decide whether or not to support this \*(L"foo\*(R"\-specific
790 .Sh "Future developments"
791 .IX Subsection "Future developments"
792 The \s-1ENGINE\s0 \s-1API\s0 and internal architecture is currently being reviewed. Slated for
793 possible release in 0.9.8 is support for transparent loading of \*(L"dynamic\*(R"
794 ENGINEs (built as self-contained shared\-libraries). This would allow \s-1ENGINE\s0
795 implementations to be provided independantly of OpenSSL libraries and/or
796 OpenSSL-based applications, and would also remove any requirement for
797 applications to explicitly use the \*(L"dynamic\*(R" \s-1ENGINE\s0 to bind to shared-library
800 .IX Header "SEE ALSO"
801 \&\fIrsa\fR\|(3), \fIdsa\fR\|(3), \fIdh\fR\|(3), \fIrand\fR\|(3),
802 \&\fIRSA_new_method\fR\|(3)