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