~ubuntu-branches/ubuntu/maverick/openssl/maverick

« back to all changes in this revision

Viewing changes to doc/crypto/engine.pod

  • Committer: Bazaar Package Importer
  • Author(s): Kurt Roeckx
  • Date: 2005-12-13 21:37:42 UTC
  • mto: (11.1.1 lenny)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20051213213742-d0ydaylf80l16bj1
Tags: upstream-0.9.8a
ImportĀ upstreamĀ versionĀ 0.9.8a

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
 
24
24
 void ENGINE_load_openssl(void);
25
25
 void ENGINE_load_dynamic(void);
26
 
 void ENGINE_load_cswift(void);
27
 
 void ENGINE_load_chil(void);
 
26
 #ifndef OPENSSL_NO_STATIC_ENGINE
 
27
 void ENGINE_load_4758cca(void);
 
28
 void ENGINE_load_aep(void);
28
29
 void ENGINE_load_atalla(void);
 
30
 void ENGINE_load_chil(void);
 
31
 void ENGINE_load_cswift(void);
 
32
 void ENGINE_load_gmp(void);
29
33
 void ENGINE_load_nuron(void);
 
34
 void ENGINE_load_sureware(void);
30
35
 void ENGINE_load_ubsec(void);
31
 
 void ENGINE_load_aep(void);
32
 
 void ENGINE_load_sureware(void);
33
 
 void ENGINE_load_4758cca(void);
34
 
 void ENGINE_load_openbsd_dev_crypto(void);
 
36
 #endif
 
37
 void ENGINE_load_cryptodev(void);
35
38
 void ENGINE_load_builtin_engines(void);
36
39
 
37
40
 void ENGINE_cleanup(void);
38
41
 
39
42
 ENGINE *ENGINE_get_default_RSA(void);
40
43
 ENGINE *ENGINE_get_default_DSA(void);
 
44
 ENGINE *ENGINE_get_default_ECDH(void);
 
45
 ENGINE *ENGINE_get_default_ECDSA(void);
41
46
 ENGINE *ENGINE_get_default_DH(void);
42
47
 ENGINE *ENGINE_get_default_RAND(void);
43
48
 ENGINE *ENGINE_get_cipher_engine(int nid);
45
50
 
46
51
 int ENGINE_set_default_RSA(ENGINE *e);
47
52
 int ENGINE_set_default_DSA(ENGINE *e);
 
53
 int ENGINE_set_default_ECDH(ENGINE *e);
 
54
 int ENGINE_set_default_ECDSA(ENGINE *e);
48
55
 int ENGINE_set_default_DH(ENGINE *e);
49
56
 int ENGINE_set_default_RAND(ENGINE *e);
50
57
 int ENGINE_set_default_ciphers(ENGINE *e);
62
69
 int ENGINE_register_DSA(ENGINE *e);
63
70
 void ENGINE_unregister_DSA(ENGINE *e);
64
71
 void ENGINE_register_all_DSA(void);
 
72
 int ENGINE_register_ECDH(ENGINE *e);
 
73
 void ENGINE_unregister_ECDH(ENGINE *e);
 
74
 void ENGINE_register_all_ECDH(void);
 
75
 int ENGINE_register_ECDSA(ENGINE *e);
 
76
 void ENGINE_unregister_ECDSA(ENGINE *e);
 
77
 void ENGINE_register_all_ECDSA(void);
65
78
 int ENGINE_register_DH(ENGINE *e);
66
79
 void ENGINE_unregister_DH(ENGINE *e);
67
80
 void ENGINE_register_all_DH(void);
68
81
 int ENGINE_register_RAND(ENGINE *e);
69
82
 void ENGINE_unregister_RAND(ENGINE *e);
70
83
 void ENGINE_register_all_RAND(void);
 
84
 int ENGINE_register_STORE(ENGINE *e);
 
85
 void ENGINE_unregister_STORE(ENGINE *e);
 
86
 void ENGINE_register_all_STORE(void);
71
87
 int ENGINE_register_ciphers(ENGINE *e);
72
88
 void ENGINE_unregister_ciphers(ENGINE *e);
73
89
 void ENGINE_register_all_ciphers(void);
77
93
 int ENGINE_register_complete(ENGINE *e);
78
94
 int ENGINE_register_all_complete(void);
79
95
 
80
 
 int ENGINE_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)());
 
96
 int ENGINE_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void));
81
97
 int ENGINE_cmd_is_executable(ENGINE *e, int cmd);
82
98
 int ENGINE_ctrl_cmd(ENGINE *e, const char *cmd_name,
83
 
         long i, void *p, void (*f)(), int cmd_optional);
 
99
         long i, void *p, void (*f)(void), int cmd_optional);
84
100
 int ENGINE_ctrl_cmd_string(ENGINE *e, const char *cmd_name, const char *arg,
85
 
                 int cmd_optional);
 
101
         int cmd_optional);
86
102
 
87
103
 int ENGINE_set_ex_data(ENGINE *e, int idx, void *arg);
88
104
 void *ENGINE_get_ex_data(const ENGINE *e, int idx);
92
108
 
93
109
 ENGINE *ENGINE_new(void);
94
110
 int ENGINE_free(ENGINE *e);
 
111
 int ENGINE_up_ref(ENGINE *e);
95
112
 
96
113
 int ENGINE_set_id(ENGINE *e, const char *id);
97
114
 int ENGINE_set_name(ENGINE *e, const char *name);
98
115
 int ENGINE_set_RSA(ENGINE *e, const RSA_METHOD *rsa_meth);
99
116
 int ENGINE_set_DSA(ENGINE *e, const DSA_METHOD *dsa_meth);
 
117
 int ENGINE_set_ECDH(ENGINE *e, const ECDH_METHOD *dh_meth);
 
118
 int ENGINE_set_ECDSA(ENGINE *e, const ECDSA_METHOD *dh_meth);
100
119
 int ENGINE_set_DH(ENGINE *e, const DH_METHOD *dh_meth);
101
120
 int ENGINE_set_RAND(ENGINE *e, const RAND_METHOD *rand_meth);
 
121
 int ENGINE_set_STORE(ENGINE *e, const STORE_METHOD *rand_meth);
102
122
 int ENGINE_set_destroy_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR destroy_f);
103
123
 int ENGINE_set_init_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR init_f);
104
124
 int ENGINE_set_finish_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR finish_f);
114
134
 const char *ENGINE_get_name(const ENGINE *e);
115
135
 const RSA_METHOD *ENGINE_get_RSA(const ENGINE *e);
116
136
 const DSA_METHOD *ENGINE_get_DSA(const ENGINE *e);
 
137
 const ECDH_METHOD *ENGINE_get_ECDH(const ENGINE *e);
 
138
 const ECDSA_METHOD *ENGINE_get_ECDSA(const ENGINE *e);
117
139
 const DH_METHOD *ENGINE_get_DH(const ENGINE *e);
118
140
 const RAND_METHOD *ENGINE_get_RAND(const ENGINE *e);
 
141
 const STORE_METHOD *ENGINE_get_STORE(const ENGINE *e);
119
142
 ENGINE_GEN_INT_FUNC_PTR ENGINE_get_destroy_function(const ENGINE *e);
120
143
 ENGINE_GEN_INT_FUNC_PTR ENGINE_get_init_function(const ENGINE *e);
121
144
 ENGINE_GEN_INT_FUNC_PTR ENGINE_get_finish_function(const ENGINE *e);
148
171
implementation includes the following abstractions;
149
172
 
150
173
 RSA_METHOD - for providing alternative RSA implementations
151
 
 DSA_METHOD, DH_METHOD, RAND_METHOD - alternative DSA, DH, and RAND
 
174
 DSA_METHOD, DH_METHOD, RAND_METHOD, ECDH_METHOD, ECDSA_METHOD,
 
175
       STORE_METHOD - similarly for other OpenSSL APIs
152
176
 EVP_CIPHER - potentially multiple cipher algorithms (indexed by 'nid')
153
177
 EVP_DIGEST - potentially multiple hash algorithms (indexed by 'nid')
154
178
 key-loading - loading public and/or private EVP_PKEY keys
157
181
 
158
182
Due to the modular nature of the ENGINE API, pointers to ENGINEs need to be
159
183
treated as handles - ie. not only as pointers, but also as references to
160
 
the underlying ENGINE object. Ie. you should obtain a new reference when
 
184
the underlying ENGINE object. Ie. one should obtain a new reference when
161
185
making copies of an ENGINE pointer if the copies will be used (and
162
186
released) independantly.
163
187
 
164
188
ENGINE objects have two levels of reference-counting to match the way in
165
189
which the objects are used. At the most basic level, each ENGINE pointer is
166
 
inherently a B<structural> reference - you need a structural reference
167
 
simply to refer to the pointer value at all, as this kind of reference is
168
 
your guarantee that the structure can not be deallocated until you release
169
 
your reference.
 
190
inherently a B<structural> reference - a structural reference is required
 
191
to use the pointer value at all, as this kind of reference is a guarantee
 
192
that the structure can not be deallocated until the reference is released.
170
193
 
171
 
However, a structural reference provides no guarantee that the ENGINE has
172
 
been initiliased to be usable to perform any of its cryptographic
173
 
implementations - and indeed it's quite possible that most ENGINEs will not
174
 
initialised at all on standard setups, as ENGINEs are typically used to
 
194
However, a structural reference provides no guarantee that the ENGINE is
 
195
initiliased and able to use any of its cryptographic
 
196
implementations. Indeed it's quite possible that most ENGINEs will not
 
197
initialise at all in typical environments, as ENGINEs are typically used to
175
198
support specialised hardware. To use an ENGINE's functionality, you need a
176
199
B<functional> reference. This kind of reference can be considered a
177
200
specialised form of structural reference, because each functional reference
179
202
difficult-to-find programming bugs, it is recommended to treat the two
180
203
kinds of reference independantly. If you have a functional reference to an
181
204
ENGINE, you have a guarantee that the ENGINE has been initialised ready to
182
 
perform cryptographic operations and will not be uninitialised or cleaned
183
 
up until after you have released your reference.
184
 
 
185
 
We will discuss the two kinds of reference separately, including how to
186
 
tell which one you are dealing with at any given point in time (after all
187
 
they are both simply (ENGINE *) pointers, the difference is in the way they
188
 
are used).
 
205
perform cryptographic operations and will remain uninitialised
 
206
until after you have released your reference.
189
207
 
190
208
I<Structural references>
191
209
 
192
 
This basic type of reference is typically used for creating new ENGINEs
193
 
dynamically, iterating across OpenSSL's internal linked-list of loaded
 
210
This basic type of reference is used for instantiating new ENGINEs,
 
211
iterating across OpenSSL's internal linked-list of loaded
194
212
ENGINEs, reading information about an ENGINE, etc. Essentially a structural
195
213
reference is sufficient if you only need to query or manipulate the data of
196
214
an ENGINE implementation rather than use its functionality.
197
215
 
198
216
The ENGINE_new() function returns a structural reference to a new (empty)
199
 
ENGINE object. Other than that, structural references come from return
200
 
values to various ENGINE API functions such as; ENGINE_by_id(),
201
 
ENGINE_get_first(), ENGINE_get_last(), ENGINE_get_next(),
202
 
ENGINE_get_prev(). All structural references should be released by a
203
 
corresponding to call to the ENGINE_free() function - the ENGINE object
204
 
itself will only actually be cleaned up and deallocated when the last
205
 
structural reference is released.
 
217
ENGINE object. There are other ENGINE API functions that return structural
 
218
references such as; ENGINE_by_id(), ENGINE_get_first(), ENGINE_get_last(),
 
219
ENGINE_get_next(), ENGINE_get_prev(). All structural references should be
 
220
released by a corresponding to call to the ENGINE_free() function - the
 
221
ENGINE object itself will only actually be cleaned up and deallocated when
 
222
the last structural reference is released.
206
223
 
207
224
It should also be noted that many ENGINE API function calls that accept a
208
225
structural reference will internally obtain another reference - typically
237
254
already operational and couldn't be successfully initialised (eg. lack of
238
255
system drivers, no special hardware attached, etc), otherwise it will
239
256
return non-zero to indicate that the ENGINE is now operational and will
240
 
have allocated a new B<functional> reference to the ENGINE. In this case,
241
 
the supplied ENGINE pointer is, from the point of the view of the caller,
242
 
both a structural reference and a functional reference - so if the caller
243
 
intends to use it as a functional reference it should free the structural
244
 
reference with ENGINE_free() first. If the caller wishes to use it only as
245
 
a structural reference (eg. if the ENGINE_init() call was simply to test if
246
 
the ENGINE seems available/online), then it should free the functional
247
 
reference; all functional references are released by the ENGINE_finish()
248
 
function.
 
257
have allocated a new B<functional> reference to the ENGINE. All functional
 
258
references are released by calling ENGINE_finish() (which removes the
 
259
implicit structural reference as well).
249
260
 
250
261
The second way to get a functional reference is by asking OpenSSL for a
251
262
default implementation for a given task, eg. by ENGINE_get_default_RSA(),
259
270
For each supported abstraction, the ENGINE code maintains an internal table
260
271
of state to control which implementations are available for a given
261
272
abstraction and which should be used by default. These implementations are
262
 
registered in the tables separated-out by an 'nid' index, because
 
273
registered in the tables and indexed by an 'nid' value, because
263
274
abstractions like EVP_CIPHER and EVP_DIGEST support many distinct
264
 
algorithms and modes - ENGINEs will support different numbers and
265
 
combinations of these. In the case of other abstractions like RSA, DSA,
266
 
etc, there is only one "algorithm" so all implementations implicitly
267
 
register using the same 'nid' index. ENGINEs can be B<registered> into
268
 
these tables to make themselves available for use automatically by the
269
 
various abstractions, eg. RSA. For illustrative purposes, we continue with
270
 
the RSA example, though all comments apply similarly to the other
271
 
abstractions (they each get their own table and linkage to the
272
 
corresponding section of openssl code).
 
275
algorithms and modes, and ENGINEs can support arbitrarily many of them.
 
276
In the case of other abstractions like RSA, DSA, etc, there is only one
 
277
"algorithm" so all implementations implicitly register using the same 'nid'
 
278
index.
273
279
 
274
 
When a new RSA key is being created, ie. in RSA_new_method(), a
275
 
"get_default" call will be made to the ENGINE subsystem to process the RSA
276
 
state table and return a functional reference to an initialised ENGINE
277
 
whose RSA_METHOD should be used. If no ENGINE should (or can) be used, it
278
 
will return NULL and the RSA key will operate with a NULL ENGINE handle by
279
 
using the conventional RSA implementation in OpenSSL (and will from then on
280
 
behave the way it used to before the ENGINE API existed - for details see
281
 
L<RSA_new_method(3)|RSA_new_method(3)>).
 
280
When a default ENGINE is requested for a given abstraction/algorithm/mode, (eg.
 
281
when calling RSA_new_method(NULL)), a "get_default" call will be made to the
 
282
ENGINE subsystem to process the corresponding state table and return a
 
283
functional reference to an initialised ENGINE whose implementation should be
 
284
used. If no ENGINE should (or can) be used, it will return NULL and the caller
 
285
will operate with a NULL ENGINE handle - this usually equates to using the
 
286
conventional software implementation. In the latter case, OpenSSL will from
 
287
then on behave the way it used to before the ENGINE API existed.
282
288
 
283
289
Each state table has a flag to note whether it has processed this
284
290
"get_default" query since the table was last modified, because to process
295
301
"get_default" query will be if one is expressly set in the table. Eg.
296
302
ENGINE_set_default_RSA() does the same job as ENGINE_register_RSA() except
297
303
that it also sets the state table's cached response for the "get_default"
298
 
query.
299
 
 
300
 
In the case of abstractions like EVP_CIPHER, where implementations are
301
 
indexed by 'nid', these flags and cached-responses are distinct for each
302
 
'nid' value.
303
 
 
304
 
It is worth illustrating the difference between "registration" of ENGINEs
305
 
into these per-algorithm state tables and using the alternative
306
 
"set_default" functions. The latter handles both "registration" and also
307
 
setting the cached "default" ENGINE in each relevant state table - so
308
 
registered ENGINEs will only have a chance to be initialised for use as a
309
 
default if a default ENGINE wasn't already set for the same state table.
310
 
Eg. if ENGINE X supports cipher nids {A,B} and RSA, ENGINE Y supports
311
 
ciphers {A} and DSA, and the following code is executed;
312
 
 
313
 
 ENGINE_register_complete(X);
314
 
 ENGINE_set_default(Y, ENGINE_METHOD_ALL);
315
 
 e1 = ENGINE_get_default_RSA();
316
 
 e2 = ENGINE_get_cipher_engine(A);
317
 
 e3 = ENGINE_get_cipher_engine(B);
318
 
 e4 = ENGINE_get_default_DSA();
319
 
 e5 = ENGINE_get_cipher_engine(C);
320
 
 
321
 
The results would be as follows;
322
 
 
323
 
 assert(e1 == X);
324
 
 assert(e2 == Y);
325
 
 assert(e3 == X);
326
 
 assert(e4 == Y);
327
 
 assert(e5 == NULL);
 
304
query. In the case of abstractions like EVP_CIPHER, where implementations are
 
305
indexed by 'nid', these flags and cached-responses are distinct for each 'nid'
 
306
value.
328
307
 
329
308
=head2 Application requirements
330
309
 
360
339
 
361
340
If no ENGINE API functions are called at all in an application, then there
362
341
are no inherent memory leaks to worry about from the ENGINE functionality,
363
 
however if any ENGINEs are "load"ed, even if they are never registered or
 
342
however if any ENGINEs are loaded, even if they are never registered or
364
343
used, it is necessary to use the ENGINE_cleanup() function to
365
344
correspondingly cleanup before program exit, if the caller wishes to avoid
366
345
memory leaks. This mechanism uses an internal callback registration table
375
354
The fact that ENGINEs are made visible to OpenSSL (and thus are linked into
376
355
the program and loaded into memory at run-time) does not mean they are
377
356
"registered" or called into use by OpenSSL automatically - that behaviour
378
 
is something for the application to have control over. Some applications
 
357
is something for the application to control. Some applications
379
358
will want to allow the user to specify exactly which ENGINE they want used
380
359
if any is to be used at all. Others may prefer to load all support and have
381
360
OpenSSL automatically use at run-time any ENGINE that is able to
433
412
That's all that's required. Eg. the next time OpenSSL tries to set up an
434
413
RSA key, any bundled ENGINEs that implement RSA_METHOD will be passed to
435
414
ENGINE_init() and if any of those succeed, that ENGINE will be set as the
436
 
default for use with RSA from then on.
 
415
default for RSA use from then on.
437
416
 
438
417
=head2 Advanced configuration support
439
418
 
441
420
ENGINE implementation to define an arbitrary set of configuration
442
421
"commands" and expose them to OpenSSL and any applications based on
443
422
OpenSSL. This mechanism is entirely based on the use of name-value pairs
444
 
and and assumes ASCII input (no unicode or UTF for now!), so it is ideal if
 
423
and assumes ASCII input (no unicode or UTF for now!), so it is ideal if
445
424
applications want to provide a transparent way for users to provide
446
425
arbitrary configuration "directives" directly to such ENGINEs. It is also
447
426
possible for the application to dynamically interrogate the loaded ENGINE
450
429
scheme. However, if the user is expected to know which ENGINE device he/she
451
430
is using (in the case of specialised hardware, this goes without saying)
452
431
then applications may not need to concern themselves with discovering the
453
 
supported control commands and simply prefer to allow settings to passed
454
 
into ENGINEs exactly as they are provided by the user.
 
432
supported control commands and simply prefer to pass settings into ENGINEs
 
433
exactly as they are provided by the user.
455
434
 
456
435
Before illustrating how control commands work, it is worth mentioning what
457
436
they are typically used for. Broadly speaking there are two uses for
459
438
implementation (which may know nothing at all specific to the host system)
460
439
so that it can be initialised for use. This could include the path to any
461
440
driver or config files it needs to load, required network addresses,
462
 
smart-card identifiers, passwords to initialise password-protected devices,
 
441
smart-card identifiers, passwords to initialise protected devices,
463
442
logging information, etc etc. This class of commands typically needs to be
464
443
passed to an ENGINE B<before> attempting to initialise it, ie. before
465
444
calling ENGINE_init(). The other class of commands consist of settings or
466
445
operations that tweak certain behaviour or cause certain operations to take
467
446
place, and these commands may work either before or after ENGINE_init(), or
468
 
in same cases both. ENGINE implementations should provide indications of
 
447
in some cases both. ENGINE implementations should provide indications of
469
448
this in the descriptions attached to builtin control commands and/or in
470
449
external product documentation.
471
450
 
529
508
I<Discovering supported control commands>
530
509
 
531
510
It is possible to discover at run-time the names, numerical-ids, descriptions
532
 
and input parameters of the control commands supported from a structural
533
 
reference to any ENGINE. It is first important to note that some control
534
 
commands are defined by OpenSSL itself and it will intercept and handle these
535
 
control commands on behalf of the ENGINE, ie. the ENGINE's ctrl() handler is not
536
 
used for the control command. openssl/engine.h defines a symbol,
537
 
ENGINE_CMD_BASE, that all control commands implemented by ENGINEs from. Any
538
 
command value lower than this symbol is considered a "generic" command is
539
 
handled directly by the OpenSSL core routines.
 
511
and input parameters of the control commands supported by an ENGINE using a
 
512
structural reference. Note that some control commands are defined by OpenSSL
 
513
itself and it will intercept and handle these control commands on behalf of the
 
514
ENGINE, ie. the ENGINE's ctrl() handler is not used for the control command.
 
515
openssl/engine.h defines an index, ENGINE_CMD_BASE, that all control commands
 
516
implemented by ENGINEs should be numbered from. Any command value lower than
 
517
this symbol is considered a "generic" command is handled directly by the
 
518
OpenSSL core routines.
540
519
 
541
520
It is using these "core" control commands that one can discover the the control
542
521
commands implemented by a given ENGINE, specifically the commands;
552
531
 #define ENGINE_CTRL_GET_CMD_FLAGS              18
553
532
 
554
533
Whilst these commands are automatically processed by the OpenSSL framework code,
555
 
they use various properties exposed by each ENGINE by which to process these
556
 
queries. An ENGINE has 3 properties it exposes that can affect this behaviour;
 
534
they use various properties exposed by each ENGINE to process these
 
535
queries. An ENGINE has 3 properties it exposes that can affect how this behaves;
557
536
it can supply a ctrl() handler, it can specify ENGINE_FLAGS_MANUAL_CMD_CTRL in
558
537
the ENGINE's flags, and it can expose an array of control command descriptions.
559
538
If an ENGINE specifies the ENGINE_FLAGS_MANUAL_CMD_CTRL flag, then it will
615
594
 
616
595
=head1 SEE ALSO
617
596
 
618
 
L<rsa(3)|rsa(3)>, L<dsa(3)|dsa(3)>, L<dh(3)|dh(3)>, L<rand(3)|rand(3)>,
619
 
L<RSA_new_method(3)|RSA_new_method(3)>
 
597
L<rsa(3)|rsa(3)>, L<dsa(3)|dsa(3)>, L<dh(3)|dh(3)>, L<rand(3)|rand(3)>
620
598
 
621
599
=cut