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