Merge from vendor branch OPENSSL:
[dragonfly.git] / secure / lib / libcrypto / man / engine.3
CommitLineData
8b0cefbb
JR
1.\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.14
2.\"
3.\" Standard preamble:
4.\" ========================================================================
5.de Sh \" Subsection heading
984263bc
MD
6.br
7.if t .Sp
8.ne 5
9.PP
10\fB\\$1\fR
11.PP
12..
8b0cefbb 13.de Sp \" Vertical space (when we can't use .PP)
984263bc
MD
14.if t .sp .5v
15.if n .sp
16..
8b0cefbb 17.de Vb \" Begin verbatim text
984263bc
MD
18.ft CW
19.nf
20.ne \\$1
21..
8b0cefbb 22.de Ve \" End verbatim text
984263bc 23.ft R
984263bc
MD
24.fi
25..
8b0cefbb
JR
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<>.
984263bc 32.tr \(*W-|\(bv\*(Tr
8b0cefbb 33.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
984263bc 34.ie n \{\
8b0cefbb
JR
35. ds -- \(*W-
36. ds PI pi
37. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
38. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
39. ds L" ""
40. ds R" ""
41. ds C` ""
42. ds C' ""
984263bc
MD
43'br\}
44.el\{\
8b0cefbb
JR
45. ds -- \|\(em\|
46. ds PI \(*p
47. ds L" ``
48. ds R" ''
984263bc 49'br\}
8b0cefbb
JR
50.\"
51.\" If the F register is turned on, we'll generate index entries on stderr for
52.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index
53.\" entries marked with X<> in POD. Of course, you'll have to process the
54.\" output yourself in some meaningful fashion.
55.if \nF \{\
56. de IX
57. tm Index:\\$1\t\\n%\t"\\$2"
984263bc 58..
8b0cefbb
JR
59. nr % 0
60. rr F
984263bc 61.\}
8b0cefbb
JR
62.\"
63.\" For nroff, turn off justification. Always turn off hyphenation; it makes
64.\" way too many mistakes in technical documents.
65.hy 0
984263bc 66.if n .na
8b0cefbb
JR
67.\"
68.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
69.\" Fear. Run. Save yourself. No user-serviceable parts.
70. \" fudge factors for nroff and troff
984263bc 71.if n \{\
8b0cefbb
JR
72. ds #H 0
73. ds #V .8m
74. ds #F .3m
75. ds #[ \f1
76. ds #] \fP
984263bc
MD
77.\}
78.if t \{\
8b0cefbb
JR
79. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
80. ds #V .6m
81. ds #F 0
82. ds #[ \&
83. ds #] \&
984263bc 84.\}
8b0cefbb 85. \" simple accents for nroff and troff
984263bc 86.if n \{\
8b0cefbb
JR
87. ds ' \&
88. ds ` \&
89. ds ^ \&
90. ds , \&
91. ds ~ ~
92. ds /
984263bc
MD
93.\}
94.if t \{\
8b0cefbb
JR
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'
984263bc 101.\}
8b0cefbb 102. \" troff and (daisy-wheel) nroff accents
984263bc
MD
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
8b0cefbb 112. \" corrections for vroff
984263bc
MD
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'
8b0cefbb 115. \" for low resolution devices (crt and lpr)
984263bc
MD
116.if \n(.H>23 .if \n(.V>19 \
117\{\
8b0cefbb
JR
118. ds : e
119. ds 8 ss
120. ds o a
121. ds d- d\h'-1'\(ga
122. ds D- D\h'-1'\(hy
123. ds th \o'bp'
124. ds Th \o'LP'
125. ds ae ae
126. ds Ae AE
984263bc
MD
127.\}
128.rm #[ #] #H #V #F C
8b0cefbb
JR
129.\" ========================================================================
130.\"
131.IX Title "engine 3"
132.TH engine 3 "2004-12-18" "0.9.7e" "OpenSSL"
984263bc 133.SH "NAME"
74dab6c2 134engine \- ENGINE cryptographic module support
984263bc 135.SH "SYNOPSIS"
8b0cefbb 136.IX Header "SYNOPSIS"
984263bc
MD
137.Vb 1
138\& #include <openssl/engine.h>
139.Ve
8b0cefbb 140.PP
984263bc
MD
141.Vb 4
142\& ENGINE *ENGINE_get_first(void);
143\& ENGINE *ENGINE_get_last(void);
144\& ENGINE *ENGINE_get_next(ENGINE *e);
145\& ENGINE *ENGINE_get_prev(ENGINE *e);
146.Ve
8b0cefbb 147.PP
984263bc
MD
148.Vb 2
149\& int ENGINE_add(ENGINE *e);
150\& int ENGINE_remove(ENGINE *e);
151.Ve
8b0cefbb 152.PP
984263bc
MD
153.Vb 1
154\& ENGINE *ENGINE_by_id(const char *id);
155.Ve
8b0cefbb 156.PP
984263bc
MD
157.Vb 2
158\& int ENGINE_init(ENGINE *e);
159\& int ENGINE_finish(ENGINE *e);
160.Ve
8b0cefbb 161.PP
984263bc
MD
162.Vb 12
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);
175.Ve
8b0cefbb 176.PP
984263bc
MD
177.Vb 1
178\& void ENGINE_cleanup(void);
179.Ve
8b0cefbb 180.PP
984263bc
MD
181.Vb 6
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);
188.Ve
8b0cefbb 189.PP
984263bc
MD
190.Vb 7
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);
198.Ve
8b0cefbb 199.PP
984263bc
MD
200.Vb 1
201\& int ENGINE_set_default(ENGINE *e, unsigned int flags);
202.Ve
8b0cefbb 203.PP
984263bc
MD
204.Vb 2
205\& unsigned int ENGINE_get_table_flags(void);
206\& void ENGINE_set_table_flags(unsigned int flags);
207.Ve
8b0cefbb 208.PP
984263bc
MD
209.Vb 20
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);
230.Ve
8b0cefbb 231.PP
984263bc
MD
232.Vb 6
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);
239.Ve
8b0cefbb 240.PP
984263bc
MD
241.Vb 2
242\& int ENGINE_set_ex_data(ENGINE *e, int idx, void *arg);
243\& void *ENGINE_get_ex_data(const ENGINE *e, int idx);
244.Ve
8b0cefbb 245.PP
984263bc
MD
246.Vb 2
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);
249.Ve
8b0cefbb 250.PP
984263bc
MD
251.Vb 2
252\& ENGINE *ENGINE_new(void);
253\& int ENGINE_free(ENGINE *e);
254.Ve
8b0cefbb 255.PP
984263bc
MD
256.Vb 16
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);
273.Ve
8b0cefbb 274.PP
984263bc
MD
275.Vb 18
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);
294.Ve
8b0cefbb 295.PP
984263bc
MD
296.Vb 4
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);
301.Ve
8b0cefbb 302.PP
984263bc
MD
303.Vb 1
304\& void ENGINE_add_conf_module(void);
305.Ve
306.SH "DESCRIPTION"
8b0cefbb 307.IX Header "DESCRIPTION"
984263bc 308These functions create, manipulate, and use cryptographic modules in the
8b0cefbb 309form of \fB\s-1ENGINE\s0\fR objects. These objects act as containers for
984263bc
MD
310implementations of cryptographic algorithms, and support a
311reference-counted mechanism to allow them to be dynamically loaded in and
312out of the running application.
313.PP
8b0cefbb 314The cryptographic functionality that can be provided by an \fB\s-1ENGINE\s0\fR
984263bc
MD
315implementation includes the following abstractions;
316.PP
317.Vb 5
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
323.Ve
324.Sh "Reference counting and handles"
8b0cefbb 325.IX Subsection "Reference counting and handles"
984263bc
MD
326Due to the modular nature of the \s-1ENGINE\s0 \s-1API\s0, pointers to ENGINEs need to be
327treated as handles \- ie. not only as pointers, but also as references to
328the underlying \s-1ENGINE\s0 object. Ie. you should obtain a new reference when
329making copies of an \s-1ENGINE\s0 pointer if the copies will be used (and
330released) independantly.
331.PP
8b0cefbb 332\&\s-1ENGINE\s0 objects have two levels of reference-counting to match the way in
984263bc
MD
333which the objects are used. At the most basic level, each \s-1ENGINE\s0 pointer is
334inherently a \fBstructural\fR reference \- you need a structural reference
335simply to refer to the pointer value at all, as this kind of reference is
336your guarantee that the structure can not be deallocated until you release
337your reference.
338.PP
339However, a structural reference provides no guarantee that the \s-1ENGINE\s0 has
340been initiliased to be usable to perform any of its cryptographic
341implementations \- and indeed it's quite possible that most ENGINEs will not
342initialised at all on standard setups, as ENGINEs are typically used to
343support specialised hardware. To use an \s-1ENGINE\s0's functionality, you need a
8b0cefbb 344\&\fBfunctional\fR reference. This kind of reference can be considered a
984263bc
MD
345specialised form of structural reference, because each functional reference
346implicitly contains a structural reference as well \- however to avoid
347difficult-to-find programming bugs, it is recommended to treat the two
348kinds of reference independantly. If you have a functional reference to an
8b0cefbb 349\&\s-1ENGINE\s0, you have a guarantee that the \s-1ENGINE\s0 has been initialised ready to
984263bc
MD
350perform cryptographic operations and will not be uninitialised or cleaned
351up until after you have released your reference.
352.PP
353We will discuss the two kinds of reference separately, including how to
354tell which one you are dealing with at any given point in time (after all
355they are both simply (\s-1ENGINE\s0 *) pointers, the difference is in the way they
356are used).
357.PP
8b0cefbb 358\&\fIStructural references\fR
984263bc
MD
359.PP
360This basic type of reference is typically used for creating new ENGINEs
361dynamically, iterating across OpenSSL's internal linked-list of loaded
362ENGINEs, reading information about an \s-1ENGINE\s0, etc. Essentially a structural
363reference is sufficient if you only need to query or manipulate the data of
364an \s-1ENGINE\s0 implementation rather than use its functionality.
365.PP
366The \fIENGINE_new()\fR function returns a structural reference to a new (empty)
8b0cefbb 367\&\s-1ENGINE\s0 object. Other than that, structural references come from return
984263bc 368values to various \s-1ENGINE\s0 \s-1API\s0 functions such as; \fIENGINE_by_id()\fR,
8b0cefbb
JR
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
984263bc
MD
371corresponding to call to the \fIENGINE_free()\fR function \- the \s-1ENGINE\s0 object
372itself will only actually be cleaned up and deallocated when the last
373structural reference is released.
374.PP
375It should also be noted that many \s-1ENGINE\s0 \s-1API\s0 function calls that accept a
376structural reference will internally obtain another reference \- typically
377this happens whenever the supplied \s-1ENGINE\s0 will be needed by OpenSSL after
378the function has returned. Eg. the function to add a new \s-1ENGINE\s0 to
379OpenSSL's internal list is \fIENGINE_add()\fR \- if this function returns success,
380then OpenSSL will have stored a new structural reference internally so the
381caller is still responsible for freeing their own reference with
8b0cefbb 382\&\fIENGINE_free()\fR when they are finished with it. In a similar way, some
984263bc
MD
383functions will automatically release the structural reference passed to it
384if part of the function's job is to do so. Eg. the \fIENGINE_get_next()\fR and
8b0cefbb
JR
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
984263bc
MD
387previous) \s-1ENGINE\s0 in the list or \s-1NULL\s0 if at the end (or beginning) of the
388list, but in either case the structural reference passed to the function is
389released on behalf of the caller.
390.PP
391To clarify a particular function's handling of references, one should
392always consult that function's documentation \*(L"man\*(R" page, or failing that
393the openssl/engine.h header file includes some hints.
394.PP
8b0cefbb 395\&\fIFunctional references\fR
984263bc
MD
396.PP
397As mentioned, functional references exist when the cryptographic
398functionality of an \s-1ENGINE\s0 is required to be available. A functional
399reference can be obtained in one of two ways; from an existing structural
400reference to the required \s-1ENGINE\s0, or by asking OpenSSL for the default
401operational \s-1ENGINE\s0 for a given cryptographic purpose.
402.PP
403To obtain a functional reference from an existing structural reference,
404call the \fIENGINE_init()\fR function. This returns zero if the \s-1ENGINE\s0 was not
405already operational and couldn't be successfully initialised (eg. lack of
406system drivers, no special hardware attached, etc), otherwise it will
407return non-zero to indicate that the \s-1ENGINE\s0 is now operational and will
408have allocated a new \fBfunctional\fR reference to the \s-1ENGINE\s0. In this case,
409the supplied \s-1ENGINE\s0 pointer is, from the point of the view of the caller,
410both a structural reference and a functional reference \- so if the caller
411intends to use it as a functional reference it should free the structural
412reference with \fIENGINE_free()\fR first. If the caller wishes to use it only as
413a structural reference (eg. if the \fIENGINE_init()\fR call was simply to test if
414the \s-1ENGINE\s0 seems available/online), then it should free the functional
415reference; all functional references are released by the \fIENGINE_finish()\fR
416function.
417.PP
418The second way to get a functional reference is by asking OpenSSL for a
419default implementation for a given task, eg. by \fIENGINE_get_default_RSA()\fR,
8b0cefbb 420\&\fIENGINE_get_default_cipher_engine()\fR, etc. These are discussed in the next
984263bc
MD
421section, though they are not usually required by application programmers as
422they are used automatically when creating and using the relevant
423algorithm-specific types in OpenSSL, such as \s-1RSA\s0, \s-1DSA\s0, \s-1EVP_CIPHER_CTX\s0, etc.
424.Sh "Default implementations"
8b0cefbb 425.IX Subsection "Default implementations"
984263bc
MD
426For each supported abstraction, the \s-1ENGINE\s0 code maintains an internal table
427of state to control which implementations are available for a given
428abstraction and which should be used by default. These implementations are
8b0cefbb 429registered in the tables separated-out by an 'nid' index, because
984263bc
MD
430abstractions like \s-1EVP_CIPHER\s0 and \s-1EVP_DIGEST\s0 support many distinct
431algorithms and modes \- ENGINEs will support different numbers and
432combinations of these. In the case of other abstractions like \s-1RSA\s0, \s-1DSA\s0,
433etc, there is only one \*(L"algorithm\*(R" so all implementations implicitly
8b0cefbb 434register using the same 'nid' index. ENGINEs can be \fBregistered\fR into
984263bc
MD
435these tables to make themselves available for use automatically by the
436various abstractions, eg. \s-1RSA\s0. For illustrative purposes, we continue with
437the \s-1RSA\s0 example, though all comments apply similarly to the other
438abstractions (they each get their own table and linkage to the
439corresponding section of openssl code).
440.PP
441When a new \s-1RSA\s0 key is being created, ie. in \fIRSA_new_method()\fR, a
8b0cefbb 442\&\*(L"get_default\*(R" call will be made to the \s-1ENGINE\s0 subsystem to process the \s-1RSA\s0
984263bc
MD
443state table and return a functional reference to an initialised \s-1ENGINE\s0
444whose \s-1RSA_METHOD\s0 should be used. If no \s-1ENGINE\s0 should (or can) be used, it
445will return \s-1NULL\s0 and the \s-1RSA\s0 key will operate with a \s-1NULL\s0 \s-1ENGINE\s0 handle by
446using the conventional \s-1RSA\s0 implementation in OpenSSL (and will from then on
447behave the way it used to before the \s-1ENGINE\s0 \s-1API\s0 existed \- for details see
8b0cefbb 448\&\fIRSA_new_method\fR\|(3)).
984263bc
MD
449.PP
450Each state table has a flag to note whether it has processed this
8b0cefbb 451\&\*(L"get_default\*(R" query since the table was last modified, because to process
984263bc
MD
452this question it must iterate across all the registered ENGINEs in the
453table trying to initialise each of them in turn, in case one of them is
454operational. If it returns a functional reference to an \s-1ENGINE\s0, it will
455also cache another reference to speed up processing future queries (without
456needing to iterate across the table). Likewise, it will cache a \s-1NULL\s0
457response if no \s-1ENGINE\s0 was available so that future queries won't repeat the
458same iteration unless the state table changes. This behaviour can also be
459changed; if the \s-1ENGINE_TABLE_FLAG_NOINIT\s0 flag is set (using
8b0cefbb
JR
460\&\fIENGINE_set_table_flags()\fR), no attempted initialisations will take place,
461instead 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
984263bc
MD
464that it also sets the state table's cached response for the \*(L"get_default\*(R"
465query.
466.PP
467In the case of abstractions like \s-1EVP_CIPHER\s0, where implementations are
8b0cefbb
JR
468indexed by 'nid', these flags and cached-responses are distinct for each
469\&'nid' value.
984263bc
MD
470.PP
471It is worth illustrating the difference between \*(L"registration\*(R" of ENGINEs
472into these per-algorithm state tables and using the alternative
8b0cefbb 473\&\*(L"set_default\*(R" functions. The latter handles both \*(L"registration\*(R" and also
984263bc
MD
474setting the cached \*(L"default\*(R" \s-1ENGINE\s0 in each relevant state table \- so
475registered ENGINEs will only have a chance to be initialised for use as a
476default if a default \s-1ENGINE\s0 wasn't already set for the same state table.
477Eg. if \s-1ENGINE\s0 X supports cipher nids {A,B} and \s-1RSA\s0, \s-1ENGINE\s0 Y supports
478ciphers {A} and \s-1DSA\s0, and the following code is executed;
479.PP
480.Vb 7
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);
488.Ve
8b0cefbb 489.PP
984263bc
MD
490The results would be as follows;
491.PP
492.Vb 5
493\& assert(e1 == X);
494\& assert(e2 == Y);
495\& assert(e3 == X);
496\& assert(e4 == Y);
497\& assert(e5 == NULL);
498.Ve
499.Sh "Application requirements"
8b0cefbb 500.IX Subsection "Application requirements"
984263bc
MD
501This section will explain the basic things an application programmer should
502support to make the most useful elements of the \s-1ENGINE\s0 functionality
503available to the user. The first thing to consider is whether the
504programmer wishes to make alternative \s-1ENGINE\s0 modules available to the
505application and user. OpenSSL maintains an internal linked list of
8b0cefbb 506\&\*(L"visible\*(R" ENGINEs from which it has to operate \- at start\-up, this list is
984263bc
MD
507empty and in fact if an application does not call any \s-1ENGINE\s0 \s-1API\s0 calls and
508it uses static linking against openssl, then the resulting application
509binary will not contain any alternative \s-1ENGINE\s0 code at all. So the first
510consideration is whether any/all available \s-1ENGINE\s0 implementations should be
511made visible to OpenSSL \- this is controlled by calling the various \*(L"load\*(R"
512functions, eg.
513.PP
514.Vb 9
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);
521\& ...
522\& /* Make ALL ENGINE implementations bundled with OpenSSL available */
523\& void ENGINE_load_builtin_engines(void);
524.Ve
8b0cefbb 525.PP
984263bc
MD
526Having called any of these functions, \s-1ENGINE\s0 objects would have been
527dynamically allocated and populated with these implementations and linked
528into OpenSSL's internal linked list. At this point it is important to
529mention an important \s-1API\s0 function;
530.PP
531.Vb 1
532\& void ENGINE_cleanup(void);
533.Ve
8b0cefbb 534.PP
984263bc
MD
535If no \s-1ENGINE\s0 \s-1API\s0 functions are called at all in an application, then there
536are no inherent memory leaks to worry about from the \s-1ENGINE\s0 functionality,
8b0cefbb 537however if any ENGINEs are \*(L"load\*(R"ed, even if they are never registered or
984263bc
MD
538used, it is necessary to use the \fIENGINE_cleanup()\fR function to
539correspondingly cleanup before program exit, if the caller wishes to avoid
540memory leaks. This mechanism uses an internal callback registration table
541so that any \s-1ENGINE\s0 \s-1API\s0 functionality that knows it requires cleanup can
542register its cleanup details to be called during \fIENGINE_cleanup()\fR. This
543approach allows \fIENGINE_cleanup()\fR to clean up after any \s-1ENGINE\s0 functionality
544at all that your program uses, yet doesn't automatically create linker
545dependencies to all possible \s-1ENGINE\s0 functionality \- only the cleanup
546callbacks required by the functionality you do use will be required by the
547linker.
548.PP
549The fact that ENGINEs are made visible to OpenSSL (and thus are linked into
8b0cefbb
JR
550the 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
984263bc
MD
552is something for the application to have control over. Some applications
553will want to allow the user to specify exactly which \s-1ENGINE\s0 they want used
554if any is to be used at all. Others may prefer to load all support and have
555OpenSSL automatically use at run-time any \s-1ENGINE\s0 that is able to
556successfully initialise \- ie. to assume that this corresponds to
557acceleration hardware attached to the machine or some such thing. There are
558probably numerous other ways in which applications may prefer to handle
559things, so we will simply illustrate the consequences as they apply to a
560couple of simple cases and leave developers to consider these and the
561source code to openssl's builtin utilities as guides.
562.PP
8b0cefbb 563\&\fIUsing a specific \s-1ENGINE\s0 implementation\fR
984263bc
MD
564.PP
565Here we'll assume an application has been configured by its user or admin
566to want to use the \*(L"\s-1ACME\s0\*(R" \s-1ENGINE\s0 if it is available in the version of
567OpenSSL the application was compiled with. If it is available, it should be
568used by default for all \s-1RSA\s0, \s-1DSA\s0, and symmetric cipher operation, otherwise
569OpenSSL should use its builtin software as per usual. The following code
570illustrates how to approach this;
571.PP
572.Vb 22
573\& ENGINE *e;
574\& const char *engine_id = "ACME";
575\& ENGINE_load_builtin_engines();
576\& e = ENGINE_by_id(engine_id);
577\& if(!e)
578\& /* the engine isn't available */
579\& return;
580\& if(!ENGINE_init(e)) {
581\& /* the engine couldn't initialise, release 'e' */
582\& ENGINE_free(e);
583\& return;
584\& }
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. */
588\& abort();
589\& ENGINE_set_default_DSA(e);
590\& ENGINE_set_default_ciphers(e);
591\& /* Release the functional reference from ENGINE_init() */
592\& ENGINE_finish(e);
593\& /* Release the structural reference from ENGINE_by_id() */
594\& ENGINE_free(e);
595.Ve
8b0cefbb
JR
596.PP
597\&\fIAutomatically using builtin \s-1ENGINE\s0 implementations\fR
984263bc
MD
598.PP
599Here we'll assume we want to load and register all \s-1ENGINE\s0 implementations
600bundled with OpenSSL, such that for any cryptographic algorithm required by
601OpenSSL \- if there is an \s-1ENGINE\s0 that implements it and can be initialise,
602it should be used. The following code illustrates how this can work;
603.PP
604.Vb 4
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();
609.Ve
8b0cefbb 610.PP
984263bc 611That's all that's required. Eg. the next time OpenSSL tries to set up an
8b0cefbb
JR
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
984263bc
MD
614default for use with \s-1RSA\s0 from then on.
615.Sh "Advanced configuration support"
8b0cefbb 616.IX Subsection "Advanced configuration support"
984263bc 617There is a mechanism supported by the \s-1ENGINE\s0 framework that allows each
8b0cefbb
JR
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
984263bc
MD
620OpenSSL. This mechanism is entirely based on the use of name-value pairs
621and and assumes \s-1ASCII\s0 input (no unicode or \s-1UTF\s0 for now!), so it is ideal if
622applications want to provide a transparent way for users to provide
623arbitrary configuration \*(L"directives\*(R" directly to such ENGINEs. It is also
624possible for the application to dynamically interrogate the loaded \s-1ENGINE\s0
625implementations for the names, descriptions, and input flags of their
626available \*(L"control commands\*(R", providing a more flexible configuration
627scheme. However, if the user is expected to know which \s-1ENGINE\s0 device he/she
628is using (in the case of specialised hardware, this goes without saying)
629then applications may not need to concern themselves with discovering the
630supported control commands and simply prefer to allow settings to passed
631into ENGINEs exactly as they are provided by the user.
632.PP
633Before illustrating how control commands work, it is worth mentioning what
634they are typically used for. Broadly speaking there are two uses for
635control commands; the first is to provide the necessary details to the
636implementation (which may know nothing at all specific to the host system)
637so that it can be initialised for use. This could include the path to any
638driver or config files it needs to load, required network addresses,
639smart-card identifiers, passwords to initialise password-protected devices,
640logging information, etc etc. This class of commands typically needs to be
641passed to an \s-1ENGINE\s0 \fBbefore\fR attempting to initialise it, ie. before
642calling \fIENGINE_init()\fR. The other class of commands consist of settings or
643operations that tweak certain behaviour or cause certain operations to take
644place, and these commands may work either before or after \fIENGINE_init()\fR, or
645in same cases both. \s-1ENGINE\s0 implementations should provide indications of
646this in the descriptions attached to builtin control commands and/or in
647external product documentation.
648.PP
8b0cefbb 649\&\fIIssuing control commands to an \s-1ENGINE\s0\fR
984263bc
MD
650.PP
651Let's illustrate by example; a function for which the caller supplies the
652name of the \s-1ENGINE\s0 it wishes to use, a table of string-pairs for use before
653initialisation, and another table for use after initialisation. Note that
654the string-pairs used for control commands consist of a command \*(L"name\*(R"
655followed by the command \*(L"parameter\*(R" \- the parameter could be \s-1NULL\s0 in some
656cases 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)
658and set it as the default for everything except \s-1RAND\s0 and then return a
659boolean success or failure.
660.PP
661.Vb 36
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)
665\& {
666\& ENGINE *e = ENGINE_by_id(engine_id);
667\& if(!e) return 0;
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)");
672\& ENGINE_free(e);
673\& return 0;
674\& }
675\& pre_cmds += 2;
676\& }
677\& if(!ENGINE_init(e)) {
678\& fprintf(stderr, "Failed initialisation\en");
679\& ENGINE_free(e);
680\& return 0;
681\& }
682\& /* ENGINE_init() returned a functional reference, so free the structural
683\& * reference from ENGINE_by_id(). */
684\& ENGINE_free(e);
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)");
689\& ENGINE_finish(e);
690\& return 0;
691\& }
692\& post_cmds += 2;
693\& }
694\& ENGINE_set_default(e, ENGINE_METHOD_ALL & ~ENGINE_METHOD_RAND);
695\& /* Success */
696\& return 1;
697\& }
698.Ve
8b0cefbb 699.PP
984263bc
MD
700Note that \fIENGINE_ctrl_cmd_string()\fR accepts a boolean argument that can
701relax the semantics of the function \- if set non-zero it will only return
702failure if the \s-1ENGINE\s0 supported the given command name but failed while
703executing it, if the \s-1ENGINE\s0 doesn't support the command name it will simply
704return success without doing anything. In this case we assume the user is
705only supplying commands specific to the given \s-1ENGINE\s0 so we set this to
8b0cefbb 706\&\s-1FALSE\s0.
984263bc 707.PP
8b0cefbb 708\&\fIDiscovering supported control commands\fR
984263bc 709.PP
8b0cefbb 710It is possible to discover at run-time the names, numerical\-ids, descriptions
984263bc
MD
711and input parameters of the control commands supported from a structural
712reference to any \s-1ENGINE\s0. It is first important to note that some control
713commands are defined by OpenSSL itself and it will intercept and handle these
714control commands on behalf of the \s-1ENGINE\s0, ie. the \s-1ENGINE\s0's \fIctrl()\fR handler is not
715used for the control command. openssl/engine.h defines a symbol,
8b0cefbb 716\&\s-1ENGINE_CMD_BASE\s0, that all control commands implemented by ENGINEs from. Any
984263bc
MD
717command value lower than this symbol is considered a \*(L"generic\*(R" command is
718handled directly by the OpenSSL core routines.
719.PP
720It is using these \*(L"core\*(R" control commands that one can discover the the control
721commands implemented by a given \s-1ENGINE\s0, specifically the commands;
722.PP
723.Vb 9
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
733.Ve
8b0cefbb 734.PP
984263bc
MD
735Whilst these commands are automatically processed by the OpenSSL framework code,
736they use various properties exposed by each \s-1ENGINE\s0 by which to process these
737queries. An \s-1ENGINE\s0 has 3 properties it exposes that can affect this behaviour;
738it can supply a \fIctrl()\fR handler, it can specify \s-1ENGINE_FLAGS_MANUAL_CMD_CTRL\s0 in
739the \s-1ENGINE\s0's flags, and it can expose an array of control command descriptions.
740If an \s-1ENGINE\s0 specifies the \s-1ENGINE_FLAGS_MANUAL_CMD_CTRL\s0 flag, then it will
741simply pass all these \*(L"core\*(R" control commands directly to the \s-1ENGINE\s0's \fIctrl()\fR
742handler (and thus, it must have supplied one), so it is up to the \s-1ENGINE\s0 to
743reply to these \*(L"discovery\*(R" commands itself. If that flag is not set, then the
744OpenSSL framework code will work with the following rules;
745.PP
746.Vb 9
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 ...
756.Ve
8b0cefbb 757.PP
984263bc
MD
758If the \s-1ENGINE\s0's array of control commands is empty then all other commands will
759fail, otherwise; \s-1ENGINE_CTRL_GET_FIRST_CMD_TYPE\s0 returns the identifier of
760the first command supported by the \s-1ENGINE\s0, \s-1ENGINE_GET_NEXT_CMD_TYPE\s0 takes the
761identifier of a command supported by the \s-1ENGINE\s0 and returns the next command
762identifier or fails if there are no more, \s-1ENGINE_CMD_FROM_NAME\s0 takes a string
763name for a command and returns the corresponding identifier or fails if no such
764command name exists, and the remaining commands take a command identifier and
765return properties of the corresponding commands. All except
8b0cefbb 766\&\s-1ENGINE_CTRL_GET_FLAGS\s0 return the string length of a command name or description,
984263bc 767or populate a supplied character buffer with a copy of the command name or
8b0cefbb 768description. \s-1ENGINE_CTRL_GET_FLAGS\s0 returns a bitwise\-OR'd mask of the following
984263bc
MD
769possible values;
770.PP
771.Vb 4
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
776.Ve
8b0cefbb 777.PP
984263bc
MD
778If the \s-1ENGINE_CMD_FLAG_INTERNAL\s0 flag is set, then any other flags are purely
779informational to the caller \- this flag will prevent the command being usable
780for any higher-level \s-1ENGINE\s0 functions such as \fIENGINE_ctrl_cmd_string()\fR.
8b0cefbb 781\&\*(L"\s-1INTERNAL\s0\*(R" commands are not intended to be exposed to text-based configuration
984263bc
MD
782by applications, administrations, users, etc. These can support arbitrary
783operations via \fIENGINE_ctrl()\fR, including passing to and/or from the control
784commands data of any arbitrary type. These commands are supported in the
785discovery mechanisms simply to allow applications determinie if an \s-1ENGINE\s0
786supports certain specific commands it might want to use (eg. application \*(L"foo\*(R"
787might query various ENGINEs to see if they implement \*(L"\s-1FOO_GET_VENDOR_LOGO_GIF\s0\*(R" \-
788and \s-1ENGINE\s0 could therefore decide whether or not to support this \*(L"foo\*(R"\-specific
789extension).
790.Sh "Future developments"
8b0cefbb 791.IX Subsection "Future developments"
984263bc
MD
792The \s-1ENGINE\s0 \s-1API\s0 and internal architecture is currently being reviewed. Slated for
793possible release in 0.9.8 is support for transparent loading of \*(L"dynamic\*(R"
8b0cefbb 794ENGINEs (built as self-contained shared\-libraries). This would allow \s-1ENGINE\s0
984263bc 795implementations to be provided independantly of OpenSSL libraries and/or
8b0cefbb 796OpenSSL-based applications, and would also remove any requirement for
984263bc
MD
797applications to explicitly use the \*(L"dynamic\*(R" \s-1ENGINE\s0 to bind to shared-library
798implementations.
799.SH "SEE ALSO"
74dab6c2 800.IX Header "SEE ALSO"
8b0cefbb
JR
801\&\fIrsa\fR\|(3), \fIdsa\fR\|(3), \fIdh\fR\|(3), \fIrand\fR\|(3),
802\&\fIRSA_new_method\fR\|(3)