Fix nits in pod files.
[openssl.git] / doc / crypto / engine.pod
1 =pod
2
3 =head1 NAME
4
5 engine - ENGINE cryptographic module support
6
7 =head1 SYNOPSIS
8
9  #include <openssl/engine.h>
10
11  ENGINE *ENGINE_get_first(void);
12  ENGINE *ENGINE_get_last(void);
13  ENGINE *ENGINE_get_next(ENGINE *e);
14  ENGINE *ENGINE_get_prev(ENGINE *e);
15
16  int ENGINE_add(ENGINE *e);
17  int ENGINE_remove(ENGINE *e);
18
19  ENGINE *ENGINE_by_id(const char *id);
20
21  int ENGINE_init(ENGINE *e);
22  int ENGINE_finish(ENGINE *e);
23
24  void ENGINE_load_builtin_engines(void);
25
26  ENGINE *ENGINE_get_default_RSA(void);
27  ENGINE *ENGINE_get_default_DSA(void);
28  ENGINE *ENGINE_get_default_ECDH(void);
29  ENGINE *ENGINE_get_default_ECDSA(void);
30  ENGINE *ENGINE_get_default_DH(void);
31  ENGINE *ENGINE_get_default_RAND(void);
32  ENGINE *ENGINE_get_cipher_engine(int nid);
33  ENGINE *ENGINE_get_digest_engine(int nid);
34
35  int ENGINE_set_default_RSA(ENGINE *e);
36  int ENGINE_set_default_DSA(ENGINE *e);
37  int ENGINE_set_default_ECDH(ENGINE *e);
38  int ENGINE_set_default_ECDSA(ENGINE *e);
39  int ENGINE_set_default_DH(ENGINE *e);
40  int ENGINE_set_default_RAND(ENGINE *e);
41  int ENGINE_set_default_ciphers(ENGINE *e);
42  int ENGINE_set_default_digests(ENGINE *e);
43  int ENGINE_set_default_string(ENGINE *e, const char *list);
44
45  int ENGINE_set_default(ENGINE *e, unsigned int flags);
46
47  unsigned int ENGINE_get_table_flags(void);
48  void ENGINE_set_table_flags(unsigned int flags);
49
50  int ENGINE_register_RSA(ENGINE *e);
51  void ENGINE_unregister_RSA(ENGINE *e);
52  void ENGINE_register_all_RSA(void);
53  int ENGINE_register_DSA(ENGINE *e);
54  void ENGINE_unregister_DSA(ENGINE *e);
55  void ENGINE_register_all_DSA(void);
56  int ENGINE_register_ECDH(ENGINE *e);
57  void ENGINE_unregister_ECDH(ENGINE *e);
58  void ENGINE_register_all_ECDH(void);
59  int ENGINE_register_ECDSA(ENGINE *e);
60  void ENGINE_unregister_ECDSA(ENGINE *e);
61  void ENGINE_register_all_ECDSA(void);
62  int ENGINE_register_DH(ENGINE *e);
63  void ENGINE_unregister_DH(ENGINE *e);
64  void ENGINE_register_all_DH(void);
65  int ENGINE_register_RAND(ENGINE *e);
66  void ENGINE_unregister_RAND(ENGINE *e);
67  void ENGINE_register_all_RAND(void);
68  int ENGINE_register_ciphers(ENGINE *e);
69  void ENGINE_unregister_ciphers(ENGINE *e);
70  void ENGINE_register_all_ciphers(void);
71  int ENGINE_register_digests(ENGINE *e);
72  void ENGINE_unregister_digests(ENGINE *e);
73  void ENGINE_register_all_digests(void);
74  int ENGINE_register_complete(ENGINE *e);
75  int ENGINE_register_all_complete(void);
76
77  int ENGINE_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void));
78  int ENGINE_cmd_is_executable(ENGINE *e, int cmd);
79  int ENGINE_ctrl_cmd(ENGINE *e, const char *cmd_name,
80          long i, void *p, void (*f)(void), int cmd_optional);
81  int ENGINE_ctrl_cmd_string(ENGINE *e, const char *cmd_name, const char *arg,
82          int cmd_optional);
83
84  ENGINE *ENGINE_new(void);
85  int ENGINE_free(ENGINE *e);
86  int ENGINE_up_ref(ENGINE *e);
87
88  int ENGINE_set_id(ENGINE *e, const char *id);
89  int ENGINE_set_name(ENGINE *e, const char *name);
90  int ENGINE_set_RSA(ENGINE *e, const RSA_METHOD *rsa_meth);
91  int ENGINE_set_DSA(ENGINE *e, const DSA_METHOD *dsa_meth);
92  int ENGINE_set_ECDH(ENGINE *e, const ECDH_METHOD *dh_meth);
93  int ENGINE_set_ECDSA(ENGINE *e, const ECDSA_METHOD *dh_meth);
94  int ENGINE_set_DH(ENGINE *e, const DH_METHOD *dh_meth);
95  int ENGINE_set_RAND(ENGINE *e, const RAND_METHOD *rand_meth);
96  int ENGINE_set_destroy_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR destroy_f);
97  int ENGINE_set_init_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR init_f);
98  int ENGINE_set_finish_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR finish_f);
99  int ENGINE_set_ctrl_function(ENGINE *e, ENGINE_CTRL_FUNC_PTR ctrl_f);
100  int ENGINE_set_load_privkey_function(ENGINE *e, ENGINE_LOAD_KEY_PTR loadpriv_f);
101  int ENGINE_set_load_pubkey_function(ENGINE *e, ENGINE_LOAD_KEY_PTR loadpub_f);
102  int ENGINE_set_ciphers(ENGINE *e, ENGINE_CIPHERS_PTR f);
103  int ENGINE_set_digests(ENGINE *e, ENGINE_DIGESTS_PTR f);
104  int ENGINE_set_flags(ENGINE *e, int flags);
105  int ENGINE_set_cmd_defns(ENGINE *e, const ENGINE_CMD_DEFN *defns);
106
107  const char *ENGINE_get_id(const ENGINE *e);
108  const char *ENGINE_get_name(const ENGINE *e);
109  const RSA_METHOD *ENGINE_get_RSA(const ENGINE *e);
110  const DSA_METHOD *ENGINE_get_DSA(const ENGINE *e);
111  const ECDH_METHOD *ENGINE_get_ECDH(const ENGINE *e);
112  const ECDSA_METHOD *ENGINE_get_ECDSA(const ENGINE *e);
113  const DH_METHOD *ENGINE_get_DH(const ENGINE *e);
114  const RAND_METHOD *ENGINE_get_RAND(const ENGINE *e);
115  ENGINE_GEN_INT_FUNC_PTR ENGINE_get_destroy_function(const ENGINE *e);
116  ENGINE_GEN_INT_FUNC_PTR ENGINE_get_init_function(const ENGINE *e);
117  ENGINE_GEN_INT_FUNC_PTR ENGINE_get_finish_function(const ENGINE *e);
118  ENGINE_CTRL_FUNC_PTR ENGINE_get_ctrl_function(const ENGINE *e);
119  ENGINE_LOAD_KEY_PTR ENGINE_get_load_privkey_function(const ENGINE *e);
120  ENGINE_LOAD_KEY_PTR ENGINE_get_load_pubkey_function(const ENGINE *e);
121  ENGINE_CIPHERS_PTR ENGINE_get_ciphers(const ENGINE *e);
122  ENGINE_DIGESTS_PTR ENGINE_get_digests(const ENGINE *e);
123  const EVP_CIPHER *ENGINE_get_cipher(ENGINE *e, int nid);
124  const EVP_MD *ENGINE_get_digest(ENGINE *e, int nid);
125  int ENGINE_get_flags(const ENGINE *e);
126  const ENGINE_CMD_DEFN *ENGINE_get_cmd_defns(const ENGINE *e);
127
128  EVP_PKEY *ENGINE_load_private_key(ENGINE *e, const char *key_id,
129      UI_METHOD *ui_method, void *callback_data);
130  EVP_PKEY *ENGINE_load_public_key(ENGINE *e, const char *key_id,
131      UI_METHOD *ui_method, void *callback_data);
132
133  void ENGINE_add_conf_module(void);
134
135 Deprecated:
136
137  #if OPENSSL_API_COMPAT < 0x10100000L
138  void ENGINE_cleanup(void)
139  #endif
140
141 =head1 DESCRIPTION
142
143 These functions create, manipulate, and use cryptographic modules in the
144 form of B<ENGINE> objects. These objects act as containers for
145 implementations of cryptographic algorithms, and support a
146 reference-counted mechanism to allow them to be dynamically loaded in and
147 out of the running application.
148
149 The cryptographic functionality that can be provided by an B<ENGINE>
150 implementation includes the following abstractions;
151
152  RSA_METHOD - for providing alternative RSA implementations
153  DSA_METHOD, DH_METHOD, RAND_METHOD, ECDH_METHOD, ECDSA_METHOD,
154        - similarly for other OpenSSL APIs
155  EVP_CIPHER - potentially multiple cipher algorithms (indexed by 'nid')
156  EVP_DIGEST - potentially multiple hash algorithms (indexed by 'nid')
157  key-loading - loading public and/or private EVP_PKEY keys
158
159 =head2 Reference counting and handles
160
161 Due to the modular nature of the ENGINE API, pointers to ENGINEs need to be
162 treated as handles - ie. not only as pointers, but also as references to
163 the underlying ENGINE object. Ie. one should obtain a new reference when
164 making copies of an ENGINE pointer if the copies will be used (and
165 released) independently.
166
167 ENGINE objects have two levels of reference-counting to match the way in
168 which the objects are used. At the most basic level, each ENGINE pointer is
169 inherently a B<structural> reference - a structural reference is required
170 to use the pointer value at all, as this kind of reference is a guarantee
171 that the structure can not be deallocated until the reference is released.
172
173 However, a structural reference provides no guarantee that the ENGINE is
174 initialised and able to use any of its cryptographic
175 implementations. Indeed it's quite possible that most ENGINEs will not
176 initialise at all in typical environments, as ENGINEs are typically used to
177 support specialised hardware. To use an ENGINE's functionality, you need a
178 B<functional> reference. This kind of reference can be considered a
179 specialised form of structural reference, because each functional reference
180 implicitly contains a structural reference as well - however to avoid
181 difficult-to-find programming bugs, it is recommended to treat the two
182 kinds of reference independently. If you have a functional reference to an
183 ENGINE, you have a guarantee that the ENGINE has been initialised and
184 is ready to perform cryptographic operations, and will remain initialised
185 until after you have released your reference.
186
187 I<Structural references>
188
189 This basic type of reference is used for instantiating new ENGINEs,
190 iterating across OpenSSL's internal linked-list of loaded
191 ENGINEs, reading information about an ENGINE, etc. Essentially a structural
192 reference is sufficient if you only need to query or manipulate the data of
193 an ENGINE implementation rather than use its functionality.
194
195 The ENGINE_new() function returns a structural reference to a new (empty)
196 ENGINE object. There are other ENGINE API functions that return structural
197 references such as; ENGINE_by_id(), ENGINE_get_first(), ENGINE_get_last(),
198 ENGINE_get_next(), ENGINE_get_prev(). All structural references should be
199 released by a corresponding to call to the ENGINE_free() function - the
200 ENGINE object itself will only actually be cleaned up and deallocated when
201 the last structural reference is released.
202
203 It should also be noted that many ENGINE API function calls that accept a
204 structural reference will internally obtain another reference - typically
205 this happens whenever the supplied ENGINE will be needed by OpenSSL after
206 the function has returned. Eg. the function to add a new ENGINE to
207 OpenSSL's internal list is ENGINE_add() - if this function returns success,
208 then OpenSSL will have stored a new structural reference internally so the
209 caller is still responsible for freeing their own reference with
210 ENGINE_free() when they are finished with it. In a similar way, some
211 functions will automatically release the structural reference passed to it
212 if part of the function's job is to do so. Eg. the ENGINE_get_next() and
213 ENGINE_get_prev() functions are used for iterating across the internal
214 ENGINE list - they will return a new structural reference to the next (or
215 previous) ENGINE in the list or NULL if at the end (or beginning) of the
216 list, but in either case the structural reference passed to the function is
217 released on behalf of the caller.
218
219 To clarify a particular function's handling of references, one should
220 always consult that function's documentation "man" page, or failing that
221 the openssl/engine.h header file includes some hints.
222
223 I<Functional references>
224
225 As mentioned, functional references exist when the cryptographic
226 functionality of an ENGINE is required to be available. A functional
227 reference can be obtained in one of two ways; from an existing structural
228 reference to the required ENGINE, or by asking OpenSSL for the default
229 operational ENGINE for a given cryptographic purpose.
230
231 To obtain a functional reference from an existing structural reference,
232 call the ENGINE_init() function. This returns zero if the ENGINE was not
233 already operational and couldn't be successfully initialised (eg. lack of
234 system drivers, no special hardware attached, etc), otherwise it will
235 return non-zero to indicate that the ENGINE is now operational and will
236 have allocated a new B<functional> reference to the ENGINE. All functional
237 references are released by calling ENGINE_finish() (which removes the
238 implicit structural reference as well).
239
240 The second way to get a functional reference is by asking OpenSSL for a
241 default implementation for a given task, eg. by ENGINE_get_default_RSA(),
242 ENGINE_get_default_cipher_engine(), etc. These are discussed in the next
243 section, though they are not usually required by application programmers as
244 they are used automatically when creating and using the relevant
245 algorithm-specific types in OpenSSL, such as RSA, DSA, EVP_CIPHER_CTX, etc.
246
247 =head2 Default implementations
248
249 For each supported abstraction, the ENGINE code maintains an internal table
250 of state to control which implementations are available for a given
251 abstraction and which should be used by default. These implementations are
252 registered in the tables and indexed by an 'nid' value, because
253 abstractions like EVP_CIPHER and EVP_DIGEST support many distinct
254 algorithms and modes, and ENGINEs can support arbitrarily many of them.
255 In the case of other abstractions like RSA, DSA, etc, there is only one
256 "algorithm" so all implementations implicitly register using the same 'nid'
257 index.
258
259 When a default ENGINE is requested for a given abstraction/algorithm/mode, (eg.
260 when calling RSA_new_method(NULL)), a "get_default" call will be made to the
261 ENGINE subsystem to process the corresponding state table and return a
262 functional reference to an initialised ENGINE whose implementation should be
263 used. If no ENGINE should (or can) be used, it will return NULL and the caller
264 will operate with a NULL ENGINE handle - this usually equates to using the
265 conventional software implementation. In the latter case, OpenSSL will from
266 then on behave the way it used to before the ENGINE API existed.
267
268 Each state table has a flag to note whether it has processed this
269 "get_default" query since the table was last modified, because to process
270 this question it must iterate across all the registered ENGINEs in the
271 table trying to initialise each of them in turn, in case one of them is
272 operational. If it returns a functional reference to an ENGINE, it will
273 also cache another reference to speed up processing future queries (without
274 needing to iterate across the table). Likewise, it will cache a NULL
275 response if no ENGINE was available so that future queries won't repeat the
276 same iteration unless the state table changes. This behaviour can also be
277 changed; if the ENGINE_TABLE_FLAG_NOINIT flag is set (using
278 ENGINE_set_table_flags()), no attempted initialisations will take place,
279 instead the only way for the state table to return a non-NULL ENGINE to the
280 "get_default" query will be if one is expressly set in the table. Eg.
281 ENGINE_set_default_RSA() does the same job as ENGINE_register_RSA() except
282 that it also sets the state table's cached response for the "get_default"
283 query. In the case of abstractions like EVP_CIPHER, where implementations are
284 indexed by 'nid', these flags and cached-responses are distinct for each 'nid'
285 value.
286
287 =head2 Application requirements
288
289 This section will explain the basic things an application programmer should
290 support to make the most useful elements of the ENGINE functionality
291 available to the user. The first thing to consider is whether the
292 programmer wishes to make alternative ENGINE modules available to the
293 application and user. OpenSSL maintains an internal linked list of
294 "visible" ENGINEs from which it has to operate - at start-up, this list is
295 empty and in fact if an application does not call any ENGINE API calls and
296 it uses static linking against openssl, then the resulting application
297 binary will not contain any alternative ENGINE code at all. So the first
298 consideration is whether any/all available ENGINE implementations should be
299 made visible to OpenSSL - this is controlled by calling the various "load"
300 functions.
301
302 Having called any of these functions, ENGINE objects would have been
303 dynamically allocated and populated with these implementations and linked
304 into OpenSSL's internal linked list. At this point it is important to
305 mention an important API function;
306
307  void ENGINE_cleanup(void)
308
309 If no ENGINE API functions are called at all in an application, then there
310 are no inherent memory leaks to worry about from the ENGINE functionality.
311 However, prior to OpenSSL 1.1.0 if any ENGINEs are loaded, even if they are
312 never registered or used, it was necessary to use the ENGINE_cleanup() function
313 to correspondingly cleanup before program exit, if the caller wishes to avoid
314 memory leaks. This mechanism used an internal callback registration table
315 so that any ENGINE API functionality that knows it requires cleanup can
316 register its cleanup details to be called during ENGINE_cleanup(). This
317 approach allowed ENGINE_cleanup() to clean up after any ENGINE functionality
318 at all that your program uses, yet doesn't automatically create linker
319 dependencies to all possible ENGINE functionality - only the cleanup
320 callbacks required by the functionality you do use will be required by the
321 linker. From OpenSSL 1.1.0 it is no longer necessary to explicitly call
322 ENGINE_cleanup and this function is deprecated. Cleanup automatically takes
323 place at program exit.
324
325 The fact that ENGINEs are made visible to OpenSSL (and thus are linked into
326 the program and loaded into memory at run-time) does not mean they are
327 "registered" or called into use by OpenSSL automatically - that behaviour
328 is something for the application to control. Some applications
329 will want to allow the user to specify exactly which ENGINE they want used
330 if any is to be used at all. Others may prefer to load all support and have
331 OpenSSL automatically use at run-time any ENGINE that is able to
332 successfully initialise - ie. to assume that this corresponds to
333 acceleration hardware attached to the machine or some such thing. There are
334 probably numerous other ways in which applications may prefer to handle
335 things, so we will simply illustrate the consequences as they apply to a
336 couple of simple cases and leave developers to consider these and the
337 source code to openssl's builtin utilities as guides.
338
339 I<Using a specific ENGINE implementation>
340
341 Here we'll assume an application has been configured by its user or admin
342 to want to use the "ACME" ENGINE if it is available in the version of
343 OpenSSL the application was compiled with. If it is available, it should be
344 used by default for all RSA, DSA, and symmetric cipher operations, otherwise
345 OpenSSL should use its builtin software as per usual. The following code
346 illustrates how to approach this;
347
348  ENGINE *e;
349  const char *engine_id = "ACME";
350  ENGINE_load_builtin_engines();
351  e = ENGINE_by_id(engine_id);
352  if(!e)
353      /* the engine isn't available */
354      return;
355  if(!ENGINE_init(e)) {
356      /* the engine couldn't initialise, release 'e' */
357      ENGINE_free(e);
358      return;
359  }
360  if(!ENGINE_set_default_RSA(e))
361      /* This should only happen when 'e' can't initialise, but the previous
362       * statement suggests it did. */
363      abort();
364  ENGINE_set_default_DSA(e);
365  ENGINE_set_default_ciphers(e);
366  /* Release the functional reference from ENGINE_init() */
367  ENGINE_finish(e);
368  /* Release the structural reference from ENGINE_by_id() */
369  ENGINE_free(e);
370
371 I<Automatically using builtin ENGINE implementations>
372
373 Here we'll assume we want to load and register all ENGINE implementations
374 bundled with OpenSSL, such that for any cryptographic algorithm required by
375 OpenSSL - if there is an ENGINE that implements it and can be initialised,
376 it should be used. The following code illustrates how this can work;
377
378  /* Load all bundled ENGINEs into memory and make them visible */
379  ENGINE_load_builtin_engines();
380  /* Register all of them for every algorithm they collectively implement */
381  ENGINE_register_all_complete();
382
383 That's all that's required. Eg. the next time OpenSSL tries to set up an
384 RSA key, any bundled ENGINEs that implement RSA_METHOD will be passed to
385 ENGINE_init() and if any of those succeed, that ENGINE will be set as the
386 default for RSA use from then on.
387
388 =head2 Advanced configuration support
389
390 There is a mechanism supported by the ENGINE framework that allows each
391 ENGINE implementation to define an arbitrary set of configuration
392 "commands" and expose them to OpenSSL and any applications based on
393 OpenSSL. This mechanism is entirely based on the use of name-value pairs
394 and assumes ASCII input (no unicode or UTF for now!), so it is ideal if
395 applications want to provide a transparent way for users to provide
396 arbitrary configuration "directives" directly to such ENGINEs. It is also
397 possible for the application to dynamically interrogate the loaded ENGINE
398 implementations for the names, descriptions, and input flags of their
399 available "control commands", providing a more flexible configuration
400 scheme. However, if the user is expected to know which ENGINE device he/she
401 is using (in the case of specialised hardware, this goes without saying)
402 then applications may not need to concern themselves with discovering the
403 supported control commands and simply prefer to pass settings into ENGINEs
404 exactly as they are provided by the user.
405
406 Before illustrating how control commands work, it is worth mentioning what
407 they are typically used for. Broadly speaking there are two uses for
408 control commands; the first is to provide the necessary details to the
409 implementation (which may know nothing at all specific to the host system)
410 so that it can be initialised for use. This could include the path to any
411 driver or config files it needs to load, required network addresses,
412 smart-card identifiers, passwords to initialise protected devices,
413 logging information, etc etc. This class of commands typically needs to be
414 passed to an ENGINE B<before> attempting to initialise it, ie. before
415 calling ENGINE_init(). The other class of commands consist of settings or
416 operations that tweak certain behaviour or cause certain operations to take
417 place, and these commands may work either before or after ENGINE_init(), or
418 in some cases both. ENGINE implementations should provide indications of
419 this in the descriptions attached to builtin control commands and/or in
420 external product documentation.
421
422 I<Issuing control commands to an ENGINE>
423
424 Let's illustrate by example; a function for which the caller supplies the
425 name of the ENGINE it wishes to use, a table of string-pairs for use before
426 initialisation, and another table for use after initialisation. Note that
427 the string-pairs used for control commands consist of a command "name"
428 followed by the command "parameter" - the parameter could be NULL in some
429 cases but the name can not. This function should initialise the ENGINE
430 (issuing the "pre" commands beforehand and the "post" commands afterwards)
431 and set it as the default for everything except RAND and then return a
432 boolean success or failure.
433
434  int generic_load_engine_fn(const char *engine_id,
435                             const char **pre_cmds, int pre_num,
436                             const char **post_cmds, int post_num)
437  {
438      ENGINE *e = ENGINE_by_id(engine_id);
439      if(!e) return 0;
440      while(pre_num--) {
441          if(!ENGINE_ctrl_cmd_string(e, pre_cmds[0], pre_cmds[1], 0)) {
442              fprintf(stderr, "Failed command (%s - %s:%s)\n", engine_id,
443                  pre_cmds[0], pre_cmds[1] ? pre_cmds[1] : "(NULL)");
444              ENGINE_free(e);
445              return 0;
446          }
447          pre_cmds += 2;
448      }
449      if(!ENGINE_init(e)) {
450          fprintf(stderr, "Failed initialisation\n");
451          ENGINE_free(e);
452          return 0;
453      }
454      /* ENGINE_init() returned a functional reference, so free the structural
455       * reference from ENGINE_by_id(). */
456      ENGINE_free(e);
457      while(post_num--) {
458          if(!ENGINE_ctrl_cmd_string(e, post_cmds[0], post_cmds[1], 0)) {
459              fprintf(stderr, "Failed command (%s - %s:%s)\n", engine_id,
460                  post_cmds[0], post_cmds[1] ? post_cmds[1] : "(NULL)");
461              ENGINE_finish(e);
462              return 0;
463          }
464          post_cmds += 2;
465      }
466      ENGINE_set_default(e, ENGINE_METHOD_ALL & ~ENGINE_METHOD_RAND);
467      /* Success */
468      return 1;
469  }
470
471 Note that ENGINE_ctrl_cmd_string() accepts a boolean argument that can
472 relax the semantics of the function - if set non-zero it will only return
473 failure if the ENGINE supported the given command name but failed while
474 executing it, if the ENGINE doesn't support the command name it will simply
475 return success without doing anything. In this case we assume the user is
476 only supplying commands specific to the given ENGINE so we set this to
477 FALSE.
478
479 I<Discovering supported control commands>
480
481 It is possible to discover at run-time the names, numerical-ids, descriptions
482 and input parameters of the control commands supported by an ENGINE using a
483 structural reference. Note that some control commands are defined by OpenSSL
484 itself and it will intercept and handle these control commands on behalf of the
485 ENGINE, ie. the ENGINE's ctrl() handler is not used for the control command.
486 openssl/engine.h defines an index, ENGINE_CMD_BASE, that all control commands
487 implemented by ENGINEs should be numbered from. Any command value lower than
488 this symbol is considered a "generic" command is handled directly by the
489 OpenSSL core routines.
490
491 It is using these "core" control commands that one can discover the control
492 commands implemented by a given ENGINE, specifically the commands;
493
494  #define ENGINE_HAS_CTRL_FUNCTION               10
495  #define ENGINE_CTRL_GET_FIRST_CMD_TYPE         11
496  #define ENGINE_CTRL_GET_NEXT_CMD_TYPE          12
497  #define ENGINE_CTRL_GET_CMD_FROM_NAME          13
498  #define ENGINE_CTRL_GET_NAME_LEN_FROM_CMD      14
499  #define ENGINE_CTRL_GET_NAME_FROM_CMD          15
500  #define ENGINE_CTRL_GET_DESC_LEN_FROM_CMD      16
501  #define ENGINE_CTRL_GET_DESC_FROM_CMD          17
502  #define ENGINE_CTRL_GET_CMD_FLAGS              18
503
504 Whilst these commands are automatically processed by the OpenSSL framework code,
505 they use various properties exposed by each ENGINE to process these
506 queries. An ENGINE has 3 properties it exposes that can affect how this behaves;
507 it can supply a ctrl() handler, it can specify ENGINE_FLAGS_MANUAL_CMD_CTRL in
508 the ENGINE's flags, and it can expose an array of control command descriptions.
509 If an ENGINE specifies the ENGINE_FLAGS_MANUAL_CMD_CTRL flag, then it will
510 simply pass all these "core" control commands directly to the ENGINE's ctrl()
511 handler (and thus, it must have supplied one), so it is up to the ENGINE to
512 reply to these "discovery" commands itself. If that flag is not set, then the
513 OpenSSL framework code will work with the following rules;
514
515  if no ctrl() handler supplied;
516      ENGINE_HAS_CTRL_FUNCTION returns FALSE (zero),
517      all other commands fail.
518  if a ctrl() handler was supplied but no array of control commands;
519      ENGINE_HAS_CTRL_FUNCTION returns TRUE,
520      all other commands fail.
521  if a ctrl() handler and array of control commands was supplied;
522      ENGINE_HAS_CTRL_FUNCTION returns TRUE,
523      all other commands proceed processing ...
524
525 If the ENGINE's array of control commands is empty then all other commands will
526 fail, otherwise; ENGINE_CTRL_GET_FIRST_CMD_TYPE returns the identifier of
527 the first command supported by the ENGINE, ENGINE_GET_NEXT_CMD_TYPE takes the
528 identifier of a command supported by the ENGINE and returns the next command
529 identifier or fails if there are no more, ENGINE_CMD_FROM_NAME takes a string
530 name for a command and returns the corresponding identifier or fails if no such
531 command name exists, and the remaining commands take a command identifier and
532 return properties of the corresponding commands. All except
533 ENGINE_CTRL_GET_FLAGS return the string length of a command name or description,
534 or populate a supplied character buffer with a copy of the command name or
535 description. ENGINE_CTRL_GET_FLAGS returns a bitwise-OR'd mask of the following
536 possible values;
537
538  #define ENGINE_CMD_FLAG_NUMERIC                (unsigned int)0x0001
539  #define ENGINE_CMD_FLAG_STRING                 (unsigned int)0x0002
540  #define ENGINE_CMD_FLAG_NO_INPUT               (unsigned int)0x0004
541  #define ENGINE_CMD_FLAG_INTERNAL               (unsigned int)0x0008
542
543 If the ENGINE_CMD_FLAG_INTERNAL flag is set, then any other flags are purely
544 informational to the caller - this flag will prevent the command being usable
545 for any higher-level ENGINE functions such as ENGINE_ctrl_cmd_string().
546 "INTERNAL" commands are not intended to be exposed to text-based configuration
547 by applications, administrations, users, etc. These can support arbitrary
548 operations via ENGINE_ctrl(), including passing to and/or from the control
549 commands data of any arbitrary type. These commands are supported in the
550 discovery mechanisms simply to allow applications to determine if an ENGINE
551 supports certain specific commands it might want to use (eg. application "foo"
552 might query various ENGINEs to see if they implement "FOO_GET_VENDOR_LOGO_GIF" -
553 and ENGINE could therefore decide whether or not to support this "foo"-specific
554 extension).
555
556 =head1 SEE ALSO
557
558 L<OPENSSL_init_crypto(3)>, L<rsa(3)>, L<dsa(3)>, L<dh(3)>, L<rand(3)>
559
560 =head1 HISTORY
561
562 ENGINE_cleanup(), ENGINE_load_openssl(), ENGINE_load_dynamic(), and
563 ENGINE_load_cryptodev() were deprecated in OpenSSL 1.1.0 by
564 OPENSSL_init_crypto().
565
566 =cut
567
568 =head1 COPYRIGHT
569
570 Copyright 2002-2016 The OpenSSL Project Authors. All Rights Reserved.
571
572 Licensed under the OpenSSL license (the "License").  You may not use
573 this file except in compliance with the License.  You can obtain a copy
574 in the file LICENSE in the source distribution or at
575 L<https://www.openssl.org/source/license.html>.
576
577 =cut