1ENGINE_ADD(3ossl)                   OpenSSL                  ENGINE_ADD(3ossl)
2
3
4

NAME

6       ENGINE_get_DH, ENGINE_get_DSA, ENGINE_by_id, ENGINE_get_cipher_engine,
7       ENGINE_get_default_DH, ENGINE_get_default_DSA, ENGINE_get_default_RAND,
8       ENGINE_get_default_RSA, ENGINE_get_digest_engine, ENGINE_get_first,
9       ENGINE_get_last, ENGINE_get_next, ENGINE_get_prev, ENGINE_new,
10       ENGINE_get_ciphers, ENGINE_get_ctrl_function, ENGINE_get_digests,
11       ENGINE_get_destroy_function, ENGINE_get_finish_function,
12       ENGINE_get_init_function, ENGINE_get_load_privkey_function,
13       ENGINE_get_load_pubkey_function, ENGINE_load_private_key,
14       ENGINE_load_public_key, ENGINE_get_RAND, ENGINE_get_RSA, ENGINE_get_id,
15       ENGINE_get_name, ENGINE_get_cmd_defns, ENGINE_get_cipher,
16       ENGINE_get_digest, ENGINE_add, ENGINE_cmd_is_executable, ENGINE_ctrl,
17       ENGINE_ctrl_cmd, ENGINE_ctrl_cmd_string, ENGINE_finish, ENGINE_free,
18       ENGINE_get_flags, ENGINE_init, ENGINE_register_DH, ENGINE_register_DSA,
19       ENGINE_register_RAND, ENGINE_register_RSA,
20       ENGINE_register_all_complete, ENGINE_register_ciphers,
21       ENGINE_register_complete, ENGINE_register_digests, ENGINE_remove,
22       ENGINE_set_DH, ENGINE_set_DSA, ENGINE_set_RAND, ENGINE_set_RSA,
23       ENGINE_set_ciphers, ENGINE_set_cmd_defns, ENGINE_set_ctrl_function,
24       ENGINE_set_default, ENGINE_set_default_DH, ENGINE_set_default_DSA,
25       ENGINE_set_default_RAND, ENGINE_set_default_RSA,
26       ENGINE_set_default_ciphers, ENGINE_set_default_digests,
27       ENGINE_set_default_string, ENGINE_set_destroy_function,
28       ENGINE_set_digests, ENGINE_set_finish_function, ENGINE_set_flags,
29       ENGINE_set_id, ENGINE_set_init_function,
30       ENGINE_set_load_privkey_function, ENGINE_set_load_pubkey_function,
31       ENGINE_set_name, ENGINE_up_ref, ENGINE_get_table_flags, ENGINE_cleanup,
32       ENGINE_load_builtin_engines, ENGINE_register_all_DH,
33       ENGINE_register_all_DSA, ENGINE_register_all_RAND,
34       ENGINE_register_all_RSA, ENGINE_register_all_ciphers,
35       ENGINE_register_all_digests, ENGINE_set_table_flags,
36       ENGINE_unregister_DH, ENGINE_unregister_DSA, ENGINE_unregister_RAND,
37       ENGINE_unregister_RSA, ENGINE_unregister_ciphers,
38       ENGINE_unregister_digests - ENGINE cryptographic module support
39

SYNOPSIS

41        #include <openssl/engine.h>
42
43       The following functions have been deprecated since OpenSSL 3.0, and can
44       be hidden entirely by defining OPENSSL_API_COMPAT with a suitable
45       version value, see openssl_user_macros(7):
46
47        ENGINE *ENGINE_get_first(void);
48        ENGINE *ENGINE_get_last(void);
49        ENGINE *ENGINE_get_next(ENGINE *e);
50        ENGINE *ENGINE_get_prev(ENGINE *e);
51
52        int ENGINE_add(ENGINE *e);
53        int ENGINE_remove(ENGINE *e);
54
55        ENGINE *ENGINE_by_id(const char *id);
56
57        int ENGINE_init(ENGINE *e);
58        int ENGINE_finish(ENGINE *e);
59
60        void ENGINE_load_builtin_engines(void);
61
62        ENGINE *ENGINE_get_default_RSA(void);
63        ENGINE *ENGINE_get_default_DSA(void);
64        ENGINE *ENGINE_get_default_DH(void);
65        ENGINE *ENGINE_get_default_RAND(void);
66        ENGINE *ENGINE_get_cipher_engine(int nid);
67        ENGINE *ENGINE_get_digest_engine(int nid);
68
69        int ENGINE_set_default_RSA(ENGINE *e);
70        int ENGINE_set_default_DSA(ENGINE *e);
71        int ENGINE_set_default_DH(ENGINE *e);
72        int ENGINE_set_default_RAND(ENGINE *e);
73        int ENGINE_set_default_ciphers(ENGINE *e);
74        int ENGINE_set_default_digests(ENGINE *e);
75        int ENGINE_set_default_string(ENGINE *e, const char *list);
76
77        int ENGINE_set_default(ENGINE *e, unsigned int flags);
78
79        unsigned int ENGINE_get_table_flags(void);
80        void ENGINE_set_table_flags(unsigned int flags);
81
82        int ENGINE_register_RSA(ENGINE *e);
83        void ENGINE_unregister_RSA(ENGINE *e);
84        void ENGINE_register_all_RSA(void);
85        int ENGINE_register_DSA(ENGINE *e);
86        void ENGINE_unregister_DSA(ENGINE *e);
87        void ENGINE_register_all_DSA(void);
88        int ENGINE_register_DH(ENGINE *e);
89        void ENGINE_unregister_DH(ENGINE *e);
90        void ENGINE_register_all_DH(void);
91        int ENGINE_register_RAND(ENGINE *e);
92        void ENGINE_unregister_RAND(ENGINE *e);
93        void ENGINE_register_all_RAND(void);
94        int ENGINE_register_ciphers(ENGINE *e);
95        void ENGINE_unregister_ciphers(ENGINE *e);
96        void ENGINE_register_all_ciphers(void);
97        int ENGINE_register_digests(ENGINE *e);
98        void ENGINE_unregister_digests(ENGINE *e);
99        void ENGINE_register_all_digests(void);
100        int ENGINE_register_complete(ENGINE *e);
101        int ENGINE_register_all_complete(void);
102
103        int ENGINE_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void));
104        int ENGINE_cmd_is_executable(ENGINE *e, int cmd);
105        int ENGINE_ctrl_cmd(ENGINE *e, const char *cmd_name,
106                            long i, void *p, void (*f)(void), int cmd_optional);
107        int ENGINE_ctrl_cmd_string(ENGINE *e, const char *cmd_name, const char *arg,
108                                   int cmd_optional);
109
110        ENGINE *ENGINE_new(void);
111        int ENGINE_free(ENGINE *e);
112        int ENGINE_up_ref(ENGINE *e);
113
114        int ENGINE_set_id(ENGINE *e, const char *id);
115        int ENGINE_set_name(ENGINE *e, const char *name);
116        int ENGINE_set_RSA(ENGINE *e, const RSA_METHOD *rsa_meth);
117        int ENGINE_set_DSA(ENGINE *e, const DSA_METHOD *dsa_meth);
118        int ENGINE_set_DH(ENGINE *e, const DH_METHOD *dh_meth);
119        int ENGINE_set_RAND(ENGINE *e, const RAND_METHOD *rand_meth);
120        int ENGINE_set_destroy_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR destroy_f);
121        int ENGINE_set_init_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR init_f);
122        int ENGINE_set_finish_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR finish_f);
123        int ENGINE_set_ctrl_function(ENGINE *e, ENGINE_CTRL_FUNC_PTR ctrl_f);
124        int ENGINE_set_load_privkey_function(ENGINE *e, ENGINE_LOAD_KEY_PTR loadpriv_f);
125        int ENGINE_set_load_pubkey_function(ENGINE *e, ENGINE_LOAD_KEY_PTR loadpub_f);
126        int ENGINE_set_ciphers(ENGINE *e, ENGINE_CIPHERS_PTR f);
127        int ENGINE_set_digests(ENGINE *e, ENGINE_DIGESTS_PTR f);
128        int ENGINE_set_flags(ENGINE *e, int flags);
129        int ENGINE_set_cmd_defns(ENGINE *e, const ENGINE_CMD_DEFN *defns);
130
131        const char *ENGINE_get_id(const ENGINE *e);
132        const char *ENGINE_get_name(const ENGINE *e);
133        const RSA_METHOD *ENGINE_get_RSA(const ENGINE *e);
134        const DSA_METHOD *ENGINE_get_DSA(const ENGINE *e);
135        const DH_METHOD *ENGINE_get_DH(const ENGINE *e);
136        const RAND_METHOD *ENGINE_get_RAND(const ENGINE *e);
137        ENGINE_GEN_INT_FUNC_PTR ENGINE_get_destroy_function(const ENGINE *e);
138        ENGINE_GEN_INT_FUNC_PTR ENGINE_get_init_function(const ENGINE *e);
139        ENGINE_GEN_INT_FUNC_PTR ENGINE_get_finish_function(const ENGINE *e);
140        ENGINE_CTRL_FUNC_PTR ENGINE_get_ctrl_function(const ENGINE *e);
141        ENGINE_LOAD_KEY_PTR ENGINE_get_load_privkey_function(const ENGINE *e);
142        ENGINE_LOAD_KEY_PTR ENGINE_get_load_pubkey_function(const ENGINE *e);
143        ENGINE_CIPHERS_PTR ENGINE_get_ciphers(const ENGINE *e);
144        ENGINE_DIGESTS_PTR ENGINE_get_digests(const ENGINE *e);
145        const EVP_CIPHER *ENGINE_get_cipher(ENGINE *e, int nid);
146        const EVP_MD *ENGINE_get_digest(ENGINE *e, int nid);
147        int ENGINE_get_flags(const ENGINE *e);
148        const ENGINE_CMD_DEFN *ENGINE_get_cmd_defns(const ENGINE *e);
149
150        EVP_PKEY *ENGINE_load_private_key(ENGINE *e, const char *key_id,
151                                          UI_METHOD *ui_method, void *callback_data);
152        EVP_PKEY *ENGINE_load_public_key(ENGINE *e, const char *key_id,
153                                         UI_METHOD *ui_method, void *callback_data);
154
155       The following function has been deprecated since OpenSSL 1.1.0, and can
156       be hidden entirely by defining OPENSSL_API_COMPAT with a suitable
157       version value, see openssl_user_macros(7):
158
159        void ENGINE_cleanup(void);
160

DESCRIPTION

162       All of the functions described on this page are deprecated.
163       Applications should instead use the provider APIs.
164
165       These functions create, manipulate, and use cryptographic modules in
166       the form of ENGINE objects. These objects act as containers for
167       implementations of cryptographic algorithms, and support a reference-
168       counted mechanism to allow them to be dynamically loaded in and out of
169       the running application.
170
171       The cryptographic functionality that can be provided by an ENGINE
172       implementation includes the following abstractions;
173
174        RSA_METHOD - for providing alternative RSA implementations
175        DSA_METHOD, DH_METHOD, RAND_METHOD, ECDH_METHOD, ECDSA_METHOD,
176              - similarly for other OpenSSL APIs
177        EVP_CIPHER - potentially multiple cipher algorithms (indexed by 'nid')
178        EVP_DIGEST - potentially multiple hash algorithms (indexed by 'nid')
179        key-loading - loading public and/or private EVP_PKEY keys
180
181   Reference counting and handles
182       Due to the modular nature of the ENGINE API, pointers to ENGINEs need
183       to be treated as handles - i.e. not only as pointers, but also as
184       references to the underlying ENGINE object. Ie. one should obtain a new
185       reference when making copies of an ENGINE pointer if the copies will be
186       used (and released) independently.
187
188       ENGINE objects have two levels of reference-counting to match the way
189       in which the objects are used. At the most basic level, each ENGINE
190       pointer is inherently a structural reference - a structural reference
191       is required to use the pointer value at all, as this kind of reference
192       is a guarantee that the structure can not be deallocated until the
193       reference is released.
194
195       However, a structural reference provides no guarantee that the ENGINE
196       is initialised and able to use any of its cryptographic
197       implementations. Indeed it's quite possible that most ENGINEs will not
198       initialise at all in typical environments, as ENGINEs are typically
199       used to support specialised hardware. To use an ENGINE's functionality,
200       you need a functional reference. This kind of reference can be
201       considered a specialised form of structural reference, because each
202       functional reference implicitly contains a structural reference as well
203       - however to avoid difficult-to-find programming bugs, it is
204       recommended to treat the two kinds of reference independently. If you
205       have a functional reference to an ENGINE, you have a guarantee that the
206       ENGINE has been initialised and is ready to perform cryptographic
207       operations, and will remain initialised until after you have released
208       your reference.
209
210       Structural references
211
212       This basic type of reference is used for instantiating new ENGINEs,
213       iterating across OpenSSL's internal linked-list of loaded ENGINEs,
214       reading information about an ENGINE, etc. Essentially a structural
215       reference is sufficient if you only need to query or manipulate the
216       data of an ENGINE implementation rather than use its functionality.
217
218       The ENGINE_new() function returns a structural reference to a new
219       (empty) ENGINE object. There are other ENGINE API functions that return
220       structural references such as; ENGINE_by_id(), ENGINE_get_first(),
221       ENGINE_get_last(), ENGINE_get_next(), ENGINE_get_prev(). All structural
222       references should be released by a corresponding to call to the
223       ENGINE_free() function - the ENGINE object itself will only actually be
224       cleaned up and deallocated when the last structural reference is
225       released.
226
227       It should also be noted that many ENGINE API function calls that accept
228       a structural reference will internally obtain another reference -
229       typically this happens whenever the supplied ENGINE will be needed by
230       OpenSSL after the function has returned. Eg. the function to add a new
231       ENGINE to OpenSSL's internal list is ENGINE_add() - if this function
232       returns success, then OpenSSL will have stored a new structural
233       reference internally so the caller is still responsible for freeing
234       their own reference with ENGINE_free() when they are finished with it.
235       In a similar way, some functions will automatically release the
236       structural reference passed to it if part of the function's job is to
237       do so. Eg. the ENGINE_get_next() and ENGINE_get_prev() functions are
238       used for iterating across the internal ENGINE list - they will return a
239       new structural reference to the next (or previous) ENGINE in the list
240       or NULL if at the end (or beginning) of the list, but in either case
241       the structural reference passed to the function is released on behalf
242       of the caller.
243
244       To clarify a particular function's handling of references, one should
245       always consult that function's documentation "man" page, or failing
246       that the <openssl/engine.h> header file includes some hints.
247
248       Functional references
249
250       As mentioned, functional references exist when the cryptographic
251       functionality of an ENGINE is required to be available. A functional
252       reference can be obtained in one of two ways; from an existing
253       structural reference to the required ENGINE, or by asking OpenSSL for
254       the default operational ENGINE for a given cryptographic purpose.
255
256       To obtain a functional reference from an existing structural reference,
257       call the ENGINE_init() function. This returns zero if the ENGINE was
258       not already operational and couldn't be successfully initialised (e.g.
259       lack of system drivers, no special hardware attached, etc), otherwise
260       it will return nonzero to indicate that the ENGINE is now operational
261       and will have allocated a new functional reference to the ENGINE. All
262       functional references are released by calling ENGINE_finish() (which
263       removes the implicit structural reference as well).
264
265       The second way to get a functional reference is by asking OpenSSL for a
266       default implementation for a given task, e.g. by
267       ENGINE_get_default_RSA(), ENGINE_get_default_cipher_engine(), etc.
268       These are discussed in the next section, though they are not usually
269       required by application programmers as they are used automatically when
270       creating and using the relevant algorithm-specific types in OpenSSL,
271       such as RSA, DSA, EVP_CIPHER_CTX, etc.
272
273   Default implementations
274       For each supported abstraction, the ENGINE code maintains an internal
275       table of state to control which implementations are available for a
276       given abstraction and which should be used by default. These
277       implementations are registered in the tables and indexed by an 'nid'
278       value, because abstractions like EVP_CIPHER and EVP_DIGEST support many
279       distinct algorithms and modes, and ENGINEs can support arbitrarily many
280       of them.  In the case of other abstractions like RSA, DSA, etc, there
281       is only one "algorithm" so all implementations implicitly register
282       using the same 'nid' index.
283
284       When a default ENGINE is requested for a given
285       abstraction/algorithm/mode, (e.g.  when calling RSA_new_method(NULL)),
286       a "get_default" call will be made to the ENGINE subsystem to process
287       the corresponding state table and return a functional reference to an
288       initialised ENGINE whose implementation should be used. If no ENGINE
289       should (or can) be used, it will return NULL and the caller will
290       operate with a NULL ENGINE handle - this usually equates to using the
291       conventional software implementation. In the latter case, OpenSSL will
292       from then on behave the way it used to before the ENGINE API existed.
293
294       Each state table has a flag to note whether it has processed this
295       "get_default" query since the table was last modified, because to
296       process this question it must iterate across all the registered ENGINEs
297       in the table trying to initialise each of them in turn, in case one of
298       them is operational. If it returns a functional reference to an ENGINE,
299       it will also cache another reference to speed up processing future
300       queries (without needing to iterate across the table). Likewise, it
301       will cache a NULL response if no ENGINE was available so that future
302       queries won't repeat the same iteration unless the state table changes.
303       This behaviour can also be changed; if the ENGINE_TABLE_FLAG_NOINIT
304       flag is set (using ENGINE_set_table_flags()), no attempted
305       initialisations will take place, instead the only way for the state
306       table to return a non-NULL ENGINE to the "get_default" query will be if
307       one is expressly set in the table. Eg.  ENGINE_set_default_RSA() does
308       the same job as ENGINE_register_RSA() except that it also sets the
309       state table's cached response for the "get_default" query. In the case
310       of abstractions like EVP_CIPHER, where implementations are indexed by
311       'nid', these flags and cached-responses are distinct for each 'nid'
312       value.
313
314   Application requirements
315       This section will explain the basic things an application programmer
316       should support to make the most useful elements of the ENGINE
317       functionality available to the user. The first thing to consider is
318       whether the programmer wishes to make alternative ENGINE modules
319       available to the application and user. OpenSSL maintains an internal
320       linked list of "visible" ENGINEs from which it has to operate - at
321       start-up, this list is empty and in fact if an application does not
322       call any ENGINE API calls and it uses static linking against openssl,
323       then the resulting application binary will not contain any alternative
324       ENGINE code at all. So the first consideration is whether any/all
325       available ENGINE implementations should be made visible to OpenSSL -
326       this is controlled by calling the various "load" functions.
327
328       The fact that ENGINEs are made visible to OpenSSL (and thus are linked
329       into the program and loaded into memory at run-time) does not mean they
330       are "registered" or called into use by OpenSSL automatically - that
331       behaviour is something for the application to control. Some
332       applications will want to allow the user to specify exactly which
333       ENGINE they want used if any is to be used at all. Others may prefer to
334       load all support and have OpenSSL automatically use at run-time any
335       ENGINE that is able to successfully initialise - i.e. to assume that
336       this corresponds to acceleration hardware attached to the machine or
337       some such thing. There are probably numerous other ways in which
338       applications may prefer to handle things, so we will simply illustrate
339       the consequences as they apply to a couple of simple cases and leave
340       developers to consider these and the source code to openssl's built-in
341       utilities as guides.
342
343       If no ENGINE API functions are called within an application, then
344       OpenSSL will not allocate any internal resources.  Prior to OpenSSL
345       1.1.0, however, if any ENGINEs are loaded, even if not registered or
346       used, it was necessary to call ENGINE_cleanup() before the program
347       exits.
348
349       Using a specific ENGINE implementation
350
351       Here we'll assume an application has been configured by its user or
352       admin to want to use the "ACME" ENGINE if it is available in the
353       version of OpenSSL the application was compiled with. If it is
354       available, it should be used by default for all RSA, DSA, and symmetric
355       cipher operations, otherwise OpenSSL should use its built-in software
356       as per usual. The following code illustrates how to approach this;
357
358        ENGINE *e;
359        const char *engine_id = "ACME";
360        ENGINE_load_builtin_engines();
361        e = ENGINE_by_id(engine_id);
362        if (!e)
363            /* the engine isn't available */
364            return;
365        if (!ENGINE_init(e)) {
366            /* the engine couldn't initialise, release 'e' */
367            ENGINE_free(e);
368            return;
369        }
370        if (!ENGINE_set_default_RSA(e))
371            /*
372             * This should only happen when 'e' can't initialise, but the previous
373             * statement suggests it did.
374             */
375            abort();
376        ENGINE_set_default_DSA(e);
377        ENGINE_set_default_ciphers(e);
378        /* Release the functional reference from ENGINE_init() */
379        ENGINE_finish(e);
380        /* Release the structural reference from ENGINE_by_id() */
381        ENGINE_free(e);
382
383       Automatically using built-in ENGINE implementations
384
385       Here we'll assume we want to load and register all ENGINE
386       implementations bundled with OpenSSL, such that for any cryptographic
387       algorithm required by OpenSSL - if there is an ENGINE that implements
388       it and can be initialised, it should be used. The following code
389       illustrates how this can work;
390
391        /* Load all bundled ENGINEs into memory and make them visible */
392        ENGINE_load_builtin_engines();
393        /* Register all of them for every algorithm they collectively implement */
394        ENGINE_register_all_complete();
395
396       That's all that's required. Eg. the next time OpenSSL tries to set up
397       an RSA key, any bundled ENGINEs that implement RSA_METHOD will be
398       passed to ENGINE_init() and if any of those succeed, that ENGINE will
399       be set as the default for RSA use from then on.
400
401   Advanced configuration support
402       There is a mechanism supported by the ENGINE framework that allows each
403       ENGINE implementation to define an arbitrary set of configuration
404       "commands" and expose them to OpenSSL and any applications based on
405       OpenSSL. This mechanism is entirely based on the use of name-value
406       pairs and assumes ASCII input (no unicode or UTF for now!), so it is
407       ideal if applications want to provide a transparent way for users to
408       provide arbitrary configuration "directives" directly to such ENGINEs.
409       It is also possible for the application to dynamically interrogate the
410       loaded ENGINE implementations for the names, descriptions, and input
411       flags of their available "control commands", providing a more flexible
412       configuration scheme. However, if the user is expected to know which
413       ENGINE device he/she is using (in the case of specialised hardware,
414       this goes without saying) then applications may not need to concern
415       themselves with discovering the supported control commands and simply
416       prefer to pass settings into ENGINEs exactly as they are provided by
417       the user.
418
419       Before illustrating how control commands work, it is worth mentioning
420       what they are typically used for. Broadly speaking there are two uses
421       for control commands; the first is to provide the necessary details to
422       the implementation (which may know nothing at all specific to the host
423       system) so that it can be initialised for use. This could include the
424       path to any driver or config files it needs to load, required network
425       addresses, smart-card identifiers, passwords to initialise protected
426       devices, logging information, etc etc. This class of commands typically
427       needs to be passed to an ENGINE before attempting to initialise it,
428       i.e. before calling ENGINE_init(). The other class of commands consist
429       of settings or operations that tweak certain behaviour or cause certain
430       operations to take place, and these commands may work either before or
431       after ENGINE_init(), or in some cases both. ENGINE implementations
432       should provide indications of this in the descriptions attached to
433       built-in control commands and/or in external product documentation.
434
435       Issuing control commands to an ENGINE
436
437       Let's illustrate by example; a function for which the caller supplies
438       the name of the ENGINE it wishes to use, a table of string-pairs for
439       use before initialisation, and another table for use after
440       initialisation. Note that the string-pairs used for control commands
441       consist of a command "name" followed by the command "parameter" - the
442       parameter could be NULL in some cases but the name can not. This
443       function should initialise the ENGINE (issuing the "pre" commands
444       beforehand and the "post" commands afterwards) and set it as the
445       default for everything except RAND and then return a boolean success or
446       failure.
447
448        int generic_load_engine_fn(const char *engine_id,
449                                   const char **pre_cmds, int pre_num,
450                                   const char **post_cmds, int post_num)
451        {
452            ENGINE *e = ENGINE_by_id(engine_id);
453            if (!e) return 0;
454            while (pre_num--) {
455                if (!ENGINE_ctrl_cmd_string(e, pre_cmds[0], pre_cmds[1], 0)) {
456                    fprintf(stderr, "Failed command (%s - %s:%s)\n", engine_id,
457                            pre_cmds[0], pre_cmds[1] ? pre_cmds[1] : "(NULL)");
458                    ENGINE_free(e);
459                    return 0;
460                }
461                pre_cmds += 2;
462            }
463            if (!ENGINE_init(e)) {
464                fprintf(stderr, "Failed initialisation\n");
465                ENGINE_free(e);
466                return 0;
467            }
468            /*
469             * ENGINE_init() returned a functional reference, so free the structural
470             * reference from ENGINE_by_id().
471             */
472            ENGINE_free(e);
473            while (post_num--) {
474                if (!ENGINE_ctrl_cmd_string(e, post_cmds[0], post_cmds[1], 0)) {
475                    fprintf(stderr, "Failed command (%s - %s:%s)\n", engine_id,
476                            post_cmds[0], post_cmds[1] ? post_cmds[1] : "(NULL)");
477                    ENGINE_finish(e);
478                    return 0;
479                }
480                post_cmds += 2;
481            }
482            ENGINE_set_default(e, ENGINE_METHOD_ALL & ~ENGINE_METHOD_RAND);
483            /* Success */
484            return 1;
485        }
486
487       Note that ENGINE_ctrl_cmd_string() accepts a boolean argument that can
488       relax the semantics of the function - if set nonzero it will only
489       return failure if the ENGINE supported the given command name but
490       failed while executing it, if the ENGINE doesn't support the command
491       name it will simply return success without doing anything. In this case
492       we assume the user is only supplying commands specific to the given
493       ENGINE so we set this to FALSE.
494
495       Discovering supported control commands
496
497       It is possible to discover at run-time the names, numerical-ids,
498       descriptions and input parameters of the control commands supported by
499       an ENGINE using a structural reference. Note that some control commands
500       are defined by OpenSSL itself and it will intercept and handle these
501       control commands on behalf of the ENGINE, i.e. the ENGINE's ctrl()
502       handler is not used for the control command.  <openssl/engine.h>
503       defines an index, ENGINE_CMD_BASE, that all control commands
504       implemented by ENGINEs should be numbered from. Any command value lower
505       than this symbol is considered a "generic" command is handled directly
506       by the OpenSSL core routines.
507
508       It is using these "core" control commands that one can discover the
509       control commands implemented by a given ENGINE, specifically the
510       commands:
511
512        ENGINE_HAS_CTRL_FUNCTION
513        ENGINE_CTRL_GET_FIRST_CMD_TYPE
514        ENGINE_CTRL_GET_NEXT_CMD_TYPE
515        ENGINE_CTRL_GET_CMD_FROM_NAME
516        ENGINE_CTRL_GET_NAME_LEN_FROM_CMD
517        ENGINE_CTRL_GET_NAME_FROM_CMD
518        ENGINE_CTRL_GET_DESC_LEN_FROM_CMD
519        ENGINE_CTRL_GET_DESC_FROM_CMD
520        ENGINE_CTRL_GET_CMD_FLAGS
521
522       Whilst these commands are automatically processed by the OpenSSL
523       framework code, they use various properties exposed by each ENGINE to
524       process these queries. An ENGINE has 3 properties it exposes that can
525       affect how this behaves; it can supply a ctrl() handler, it can specify
526       ENGINE_FLAGS_MANUAL_CMD_CTRL in the ENGINE's flags, and it can expose
527       an array of control command descriptions.  If an ENGINE specifies the
528       ENGINE_FLAGS_MANUAL_CMD_CTRL flag, then it will simply pass all these
529       "core" control commands directly to the ENGINE's ctrl() handler (and
530       thus, it must have supplied one), so it is up to the ENGINE to reply to
531       these "discovery" commands itself. If that flag is not set, then the
532       OpenSSL framework code will work with the following rules:
533
534        if no ctrl() handler supplied;
535            ENGINE_HAS_CTRL_FUNCTION returns FALSE (zero),
536            all other commands fail.
537        if a ctrl() handler was supplied but no array of control commands;
538            ENGINE_HAS_CTRL_FUNCTION returns TRUE,
539            all other commands fail.
540        if a ctrl() handler and array of control commands was supplied;
541            ENGINE_HAS_CTRL_FUNCTION returns TRUE,
542            all other commands proceed processing ...
543
544       If the ENGINE's array of control commands is empty then all other
545       commands will fail, otherwise; ENGINE_CTRL_GET_FIRST_CMD_TYPE returns
546       the identifier of the first command supported by the ENGINE,
547       ENGINE_GET_NEXT_CMD_TYPE takes the identifier of a command supported by
548       the ENGINE and returns the next command identifier or fails if there
549       are no more, ENGINE_CMD_FROM_NAME takes a string name for a command and
550       returns the corresponding identifier or fails if no such command name
551       exists, and the remaining commands take a command identifier and return
552       properties of the corresponding commands. All except
553       ENGINE_CTRL_GET_FLAGS return the string length of a command name or
554       description, or populate a supplied character buffer with a copy of the
555       command name or description. ENGINE_CTRL_GET_FLAGS returns a bitwise-
556       OR'd mask of the following possible values:
557
558        ENGINE_CMD_FLAG_NUMERIC
559        ENGINE_CMD_FLAG_STRING
560        ENGINE_CMD_FLAG_NO_INPUT
561        ENGINE_CMD_FLAG_INTERNAL
562
563       If the ENGINE_CMD_FLAG_INTERNAL flag is set, then any other flags are
564       purely informational to the caller - this flag will prevent the command
565       being usable for any higher-level ENGINE functions such as
566       ENGINE_ctrl_cmd_string().  "INTERNAL" commands are not intended to be
567       exposed to text-based configuration by applications, administrations,
568       users, etc. These can support arbitrary operations via ENGINE_ctrl(),
569       including passing to and/or from the control commands data of any
570       arbitrary type. These commands are supported in the discovery
571       mechanisms simply to allow applications to determine if an ENGINE
572       supports certain specific commands it might want to use (e.g.
573       application "foo" might query various ENGINEs to see if they implement
574       "FOO_GET_VENDOR_LOGO_GIF" - and ENGINE could therefore decide whether
575       or not to support this "foo"-specific extension).
576

ENVIRONMENT

578       OPENSSL_ENGINES
579           The path to the engines directory.  Ignored in set-user-ID and set-
580           group-ID programs.
581

RETURN VALUES

583       ENGINE_get_first(), ENGINE_get_last(), ENGINE_get_next() and
584       ENGINE_get_prev() return a valid ENGINE structure or NULL if an error
585       occurred.
586
587       ENGINE_add() and ENGINE_remove() return 1 on success or 0 on error.
588
589       ENGINE_by_id() returns a valid ENGINE structure or NULL if an error
590       occurred.
591
592       ENGINE_init() and ENGINE_finish() return 1 on success or 0 on error.
593
594       All ENGINE_get_default_TYPE() functions, ENGINE_get_cipher_engine() and
595       ENGINE_get_digest_engine() return a valid ENGINE structure on success
596       or NULL if an error occurred.
597
598       All ENGINE_set_default_TYPE() functions return 1 on success or 0 on
599       error.
600
601       ENGINE_set_default() returns 1 on success or 0 on error.
602
603       ENGINE_get_table_flags() returns an unsigned integer value representing
604       the global table flags which are used to control the registration
605       behaviour of ENGINE implementations.
606
607       All ENGINE_register_TYPE() functions return 1 on success or 0 on error.
608
609       ENGINE_register_complete() and ENGINE_register_all_complete() always
610       return 1.
611
612       ENGINE_ctrl() returns a positive value on success or others on error.
613
614       ENGINE_cmd_is_executable() returns 1 if cmd is executable or 0
615       otherwise.
616
617       ENGINE_ctrl_cmd() and ENGINE_ctrl_cmd_string() return 1 on success or 0
618       on error.
619
620       ENGINE_new() returns a valid ENGINE structure on success or NULL if an
621       error occurred.
622
623       ENGINE_free() always returns 1.
624
625       ENGINE_up_ref() returns 1 on success or 0 on error.
626
627       ENGINE_set_id() and ENGINE_set_name() return 1 on success or 0 on
628       error.
629
630       All other ENGINE_set_* functions return 1 on success or 0 on error.
631
632       ENGINE_get_id() and ENGINE_get_name() return a string representing the
633       identifier and the name of the ENGINE e respectively.
634
635       ENGINE_get_RSA(), ENGINE_get_DSA(), ENGINE_get_DH() and
636       ENGINE_get_RAND() return corresponding method structures for each
637       algorithms.
638
639       ENGINE_get_destroy_function(), ENGINE_get_init_function(),
640       ENGINE_get_finish_function(), ENGINE_get_ctrl_function(),
641       ENGINE_get_load_privkey_function(), ENGINE_get_load_pubkey_function(),
642       ENGINE_get_ciphers() and ENGINE_get_digests() return corresponding
643       function pointers of the callbacks.
644
645       ENGINE_get_cipher() returns a valid EVP_CIPHER structure on success or
646       NULL if an error occurred.
647
648       ENGINE_get_digest() returns a valid EVP_MD structure on success or NULL
649       if an error occurred.
650
651       ENGINE_get_flags() returns an integer representing the ENGINE flags
652       which are used to control various behaviours of an ENGINE.
653
654       ENGINE_get_cmd_defns() returns an ENGINE_CMD_DEFN structure or NULL if
655       it's not set.
656
657       ENGINE_load_private_key() and ENGINE_load_public_key() return a valid
658       EVP_PKEY structure on success or NULL if an error occurred.
659

SEE ALSO

661       OPENSSL_init_crypto(3), RSA_new_method(3), DSA_new(3), DH_new(3),
662       RAND_bytes(3), config(5)
663

HISTORY

665       All of these functions were deprecated in OpenSSL 3.0.
666
667       ENGINE_cleanup() was deprecated in OpenSSL 1.1.0 by the automatic
668       cleanup done by OPENSSL_cleanup() and should not be used.
669
671       Copyright 2002-2021 The OpenSSL Project Authors. All Rights Reserved.
672
673       Licensed under the Apache License 2.0 (the "License").  You may not use
674       this file except in compliance with the License.  You can obtain a copy
675       in the file LICENSE in the source distribution or at
676       <https://www.openssl.org/source/license.html>.
677
678
679
6803.0.5                             2022-11-01                 ENGINE_ADD(3ossl)
Impressum