Home | History | Annotate | Line # | Download | only in openssl
      1  1.1  christos /*
      2  1.1  christos  * Copyright 2000-2022 The OpenSSL Project Authors. All Rights Reserved.
      3  1.1  christos  * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
      4  1.1  christos  *
      5  1.1  christos  * Licensed under the OpenSSL license (the "License").  You may not use
      6  1.1  christos  * this file except in compliance with the License.  You can obtain a copy
      7  1.1  christos  * in the file LICENSE in the source distribution or at
      8  1.1  christos  * https://www.openssl.org/source/license.html
      9  1.1  christos  */
     10  1.1  christos 
     11  1.1  christos #ifndef HEADER_ENGINE_H
     12  1.1  christos # define HEADER_ENGINE_H
     13  1.1  christos 
     14  1.1  christos # include <openssl/opensslconf.h>
     15  1.1  christos 
     16  1.1  christos # ifndef OPENSSL_NO_ENGINE
     17  1.1  christos # if OPENSSL_API_COMPAT < 0x10100000L
     18  1.1  christos #  include <openssl/bn.h>
     19  1.1  christos #  include <openssl/rsa.h>
     20  1.1  christos #  include <openssl/dsa.h>
     21  1.1  christos #  include <openssl/dh.h>
     22  1.1  christos #  include <openssl/ec.h>
     23  1.1  christos #  include <openssl/rand.h>
     24  1.1  christos #  include <openssl/ui.h>
     25  1.1  christos #  include <openssl/err.h>
     26  1.1  christos # endif
     27  1.1  christos # include <openssl/ossl_typ.h>
     28  1.1  christos # include <openssl/symhacks.h>
     29  1.1  christos # include <openssl/x509.h>
     30  1.1  christos # include <openssl/engineerr.h>
     31  1.1  christos # ifdef  __cplusplus
     32  1.1  christos extern "C" {
     33  1.1  christos # endif
     34  1.1  christos 
     35  1.1  christos /*
     36  1.1  christos  * These flags are used to control combinations of algorithm (methods) by
     37  1.1  christos  * bitwise "OR"ing.
     38  1.1  christos  */
     39  1.1  christos # define ENGINE_METHOD_RSA               (unsigned int)0x0001
     40  1.1  christos # define ENGINE_METHOD_DSA               (unsigned int)0x0002
     41  1.1  christos # define ENGINE_METHOD_DH                (unsigned int)0x0004
     42  1.1  christos # define ENGINE_METHOD_RAND              (unsigned int)0x0008
     43  1.1  christos # define ENGINE_METHOD_CIPHERS           (unsigned int)0x0040
     44  1.1  christos # define ENGINE_METHOD_DIGESTS           (unsigned int)0x0080
     45  1.1  christos # define ENGINE_METHOD_PKEY_METHS        (unsigned int)0x0200
     46  1.1  christos # define ENGINE_METHOD_PKEY_ASN1_METHS   (unsigned int)0x0400
     47  1.1  christos # define ENGINE_METHOD_EC                (unsigned int)0x0800
     48  1.1  christos /* Obvious all-or-nothing cases. */
     49  1.1  christos # define ENGINE_METHOD_ALL               (unsigned int)0xFFFF
     50  1.1  christos # define ENGINE_METHOD_NONE              (unsigned int)0x0000
     51  1.1  christos 
     52  1.1  christos /*
     53  1.1  christos  * This(ese) flag(s) controls behaviour of the ENGINE_TABLE mechanism used
     54  1.1  christos  * internally to control registration of ENGINE implementations, and can be
     55  1.1  christos  * set by ENGINE_set_table_flags(). The "NOINIT" flag prevents attempts to
     56  1.1  christos  * initialise registered ENGINEs if they are not already initialised.
     57  1.1  christos  */
     58  1.1  christos # define ENGINE_TABLE_FLAG_NOINIT        (unsigned int)0x0001
     59  1.1  christos 
     60  1.1  christos /* ENGINE flags that can be set by ENGINE_set_flags(). */
     61  1.1  christos /* Not used */
     62  1.1  christos /* #define ENGINE_FLAGS_MALLOCED        0x0001 */
     63  1.1  christos 
     64  1.1  christos /*
     65  1.1  christos  * This flag is for ENGINEs that wish to handle the various 'CMD'-related
     66  1.1  christos  * control commands on their own. Without this flag, ENGINE_ctrl() handles
     67  1.1  christos  * these control commands on behalf of the ENGINE using their "cmd_defns"
     68  1.1  christos  * data.
     69  1.1  christos  */
     70  1.1  christos # define ENGINE_FLAGS_MANUAL_CMD_CTRL    (int)0x0002
     71  1.1  christos 
     72  1.1  christos /*
     73  1.1  christos  * This flag is for ENGINEs who return new duplicate structures when found
     74  1.1  christos  * via "ENGINE_by_id()". When an ENGINE must store state (eg. if
     75  1.1  christos  * ENGINE_ctrl() commands are called in sequence as part of some stateful
     76  1.1  christos  * process like key-generation setup and execution), it can set this flag -
     77  1.1  christos  * then each attempt to obtain the ENGINE will result in it being copied into
     78  1.1  christos  * a new structure. Normally, ENGINEs don't declare this flag so
     79  1.1  christos  * ENGINE_by_id() just increments the existing ENGINE's structural reference
     80  1.1  christos  * count.
     81  1.1  christos  */
     82  1.1  christos # define ENGINE_FLAGS_BY_ID_COPY         (int)0x0004
     83  1.1  christos 
     84  1.1  christos /*
     85  1.1  christos  * This flag if for an ENGINE that does not want its methods registered as
     86  1.1  christos  * part of ENGINE_register_all_complete() for example if the methods are not
     87  1.1  christos  * usable as default methods.
     88  1.1  christos  */
     89  1.1  christos 
     90  1.1  christos # define ENGINE_FLAGS_NO_REGISTER_ALL    (int)0x0008
     91  1.1  christos 
     92  1.1  christos /*
     93  1.1  christos  * ENGINEs can support their own command types, and these flags are used in
     94  1.1  christos  * ENGINE_CTRL_GET_CMD_FLAGS to indicate to the caller what kind of input
     95  1.1  christos  * each command expects. Currently only numeric and string input is
     96  1.1  christos  * supported. If a control command supports none of the _NUMERIC, _STRING, or
     97  1.1  christos  * _NO_INPUT options, then it is regarded as an "internal" control command -
     98  1.1  christos  * and not for use in config setting situations. As such, they're not
     99  1.1  christos  * available to the ENGINE_ctrl_cmd_string() function, only raw ENGINE_ctrl()
    100  1.1  christos  * access. Changes to this list of 'command types' should be reflected
    101  1.1  christos  * carefully in ENGINE_cmd_is_executable() and ENGINE_ctrl_cmd_string().
    102  1.1  christos  */
    103  1.1  christos 
    104  1.1  christos /* accepts a 'long' input value (3rd parameter to ENGINE_ctrl) */
    105  1.1  christos # define ENGINE_CMD_FLAG_NUMERIC         (unsigned int)0x0001
    106  1.1  christos /*
    107  1.1  christos  * accepts string input (cast from 'void*' to 'const char *', 4th parameter
    108  1.1  christos  * to ENGINE_ctrl)
    109  1.1  christos  */
    110  1.1  christos # define ENGINE_CMD_FLAG_STRING          (unsigned int)0x0002
    111  1.1  christos /*
    112  1.1  christos  * Indicates that the control command takes *no* input. Ie. the control
    113  1.1  christos  * command is unparameterised.
    114  1.1  christos  */
    115  1.1  christos # define ENGINE_CMD_FLAG_NO_INPUT        (unsigned int)0x0004
    116  1.1  christos /*
    117  1.1  christos  * Indicates that the control command is internal. This control command won't
    118  1.1  christos  * be shown in any output, and is only usable through the ENGINE_ctrl_cmd()
    119  1.1  christos  * function.
    120  1.1  christos  */
    121  1.1  christos # define ENGINE_CMD_FLAG_INTERNAL        (unsigned int)0x0008
    122  1.1  christos 
    123  1.1  christos /*
    124  1.1  christos  * NB: These 3 control commands are deprecated and should not be used.
    125  1.1  christos  * ENGINEs relying on these commands should compile conditional support for
    126  1.1  christos  * compatibility (eg. if these symbols are defined) but should also migrate
    127  1.1  christos  * the same functionality to their own ENGINE-specific control functions that
    128  1.1  christos  * can be "discovered" by calling applications. The fact these control
    129  1.1  christos  * commands wouldn't be "executable" (ie. usable by text-based config)
    130  1.1  christos  * doesn't change the fact that application code can find and use them
    131  1.1  christos  * without requiring per-ENGINE hacking.
    132  1.1  christos  */
    133  1.1  christos 
    134  1.1  christos /*
    135  1.1  christos  * These flags are used to tell the ctrl function what should be done. All
    136  1.1  christos  * command numbers are shared between all engines, even if some don't make
    137  1.1  christos  * sense to some engines.  In such a case, they do nothing but return the
    138  1.1  christos  * error ENGINE_R_CTRL_COMMAND_NOT_IMPLEMENTED.
    139  1.1  christos  */
    140  1.1  christos # define ENGINE_CTRL_SET_LOGSTREAM               1
    141  1.1  christos # define ENGINE_CTRL_SET_PASSWORD_CALLBACK       2
    142  1.1  christos # define ENGINE_CTRL_HUP                         3/* Close and reinitialise
    143  1.1  christos                                                    * any handles/connections
    144  1.1  christos                                                    * etc. */
    145  1.1  christos # define ENGINE_CTRL_SET_USER_INTERFACE          4/* Alternative to callback */
    146  1.1  christos # define ENGINE_CTRL_SET_CALLBACK_DATA           5/* User-specific data, used
    147  1.1  christos                                                    * when calling the password
    148  1.1  christos                                                    * callback and the user
    149  1.1  christos                                                    * interface */
    150  1.1  christos # define ENGINE_CTRL_LOAD_CONFIGURATION          6/* Load a configuration,
    151  1.1  christos                                                    * given a string that
    152  1.1  christos                                                    * represents a file name
    153  1.1  christos                                                    * or so */
    154  1.1  christos # define ENGINE_CTRL_LOAD_SECTION                7/* Load data from a given
    155  1.1  christos                                                    * section in the already
    156  1.1  christos                                                    * loaded configuration */
    157  1.1  christos 
    158  1.1  christos /*
    159  1.1  christos  * These control commands allow an application to deal with an arbitrary
    160  1.1  christos  * engine in a dynamic way. Warn: Negative return values indicate errors FOR
    161  1.1  christos  * THESE COMMANDS because zero is used to indicate 'end-of-list'. Other
    162  1.1  christos  * commands, including ENGINE-specific command types, return zero for an
    163  1.1  christos  * error. An ENGINE can choose to implement these ctrl functions, and can
    164  1.1  christos  * internally manage things however it chooses - it does so by setting the
    165  1.1  christos  * ENGINE_FLAGS_MANUAL_CMD_CTRL flag (using ENGINE_set_flags()). Otherwise
    166  1.1  christos  * the ENGINE_ctrl() code handles this on the ENGINE's behalf using the
    167  1.1  christos  * cmd_defns data (set using ENGINE_set_cmd_defns()). This means an ENGINE's
    168  1.1  christos  * ctrl() handler need only implement its own commands - the above "meta"
    169  1.1  christos  * commands will be taken care of.
    170  1.1  christos  */
    171  1.1  christos 
    172  1.1  christos /*
    173  1.1  christos  * Returns non-zero if the supplied ENGINE has a ctrl() handler. If "not",
    174  1.1  christos  * then all the remaining control commands will return failure, so it is
    175  1.1  christos  * worth checking this first if the caller is trying to "discover" the
    176  1.1  christos  * engine's capabilities and doesn't want errors generated unnecessarily.
    177  1.1  christos  */
    178  1.1  christos # define ENGINE_CTRL_HAS_CTRL_FUNCTION           10
    179  1.1  christos /*
    180  1.1  christos  * Returns a positive command number for the first command supported by the
    181  1.1  christos  * engine. Returns zero if no ctrl commands are supported.
    182  1.1  christos  */
    183  1.1  christos # define ENGINE_CTRL_GET_FIRST_CMD_TYPE          11
    184  1.1  christos /*
    185  1.1  christos  * The 'long' argument specifies a command implemented by the engine, and the
    186  1.1  christos  * return value is the next command supported, or zero if there are no more.
    187  1.1  christos  */
    188  1.1  christos # define ENGINE_CTRL_GET_NEXT_CMD_TYPE           12
    189  1.1  christos /*
    190  1.1  christos  * The 'void*' argument is a command name (cast from 'const char *'), and the
    191  1.1  christos  * return value is the command that corresponds to it.
    192  1.1  christos  */
    193  1.1  christos # define ENGINE_CTRL_GET_CMD_FROM_NAME           13
    194  1.1  christos /*
    195  1.1  christos  * The next two allow a command to be converted into its corresponding string
    196  1.1  christos  * form. In each case, the 'long' argument supplies the command. In the
    197  1.1  christos  * NAME_LEN case, the return value is the length of the command name (not
    198  1.1  christos  * counting a trailing EOL). In the NAME case, the 'void*' argument must be a
    199  1.1  christos  * string buffer large enough, and it will be populated with the name of the
    200  1.1  christos  * command (WITH a trailing EOL).
    201  1.1  christos  */
    202  1.1  christos # define ENGINE_CTRL_GET_NAME_LEN_FROM_CMD       14
    203  1.1  christos # define ENGINE_CTRL_GET_NAME_FROM_CMD           15
    204  1.1  christos /* The next two are similar but give a "short description" of a command. */
    205  1.1  christos # define ENGINE_CTRL_GET_DESC_LEN_FROM_CMD       16
    206  1.1  christos # define ENGINE_CTRL_GET_DESC_FROM_CMD           17
    207  1.1  christos /*
    208  1.1  christos  * With this command, the return value is the OR'd combination of
    209  1.1  christos  * ENGINE_CMD_FLAG_*** values that indicate what kind of input a given
    210  1.1  christos  * engine-specific ctrl command expects.
    211  1.1  christos  */
    212  1.1  christos # define ENGINE_CTRL_GET_CMD_FLAGS               18
    213  1.1  christos 
    214  1.1  christos /*
    215  1.1  christos  * ENGINE implementations should start the numbering of their own control
    216  1.1  christos  * commands from this value. (ie. ENGINE_CMD_BASE, ENGINE_CMD_BASE + 1, etc).
    217  1.1  christos  */
    218  1.1  christos # define ENGINE_CMD_BASE                         200
    219  1.1  christos 
    220  1.1  christos /*
    221  1.1  christos  * NB: These 2 nCipher "chil" control commands are deprecated, and their
    222  1.1  christos  * functionality is now available through ENGINE-specific control commands
    223  1.1  christos  * (exposed through the above-mentioned 'CMD'-handling). Code using these 2
    224  1.1  christos  * commands should be migrated to the more general command handling before
    225  1.1  christos  * these are removed.
    226  1.1  christos  */
    227  1.1  christos 
    228  1.1  christos /* Flags specific to the nCipher "chil" engine */
    229  1.1  christos # define ENGINE_CTRL_CHIL_SET_FORKCHECK          100
    230  1.1  christos         /*
    231  1.1  christos          * Depending on the value of the (long)i argument, this sets or
    232  1.1  christos          * unsets the SimpleForkCheck flag in the CHIL API to enable or
    233  1.1  christos          * disable checking and workarounds for applications that fork().
    234  1.1  christos          */
    235  1.1  christos # define ENGINE_CTRL_CHIL_NO_LOCKING             101
    236  1.1  christos         /*
    237  1.1  christos          * This prevents the initialisation function from providing mutex
    238  1.1  christos          * callbacks to the nCipher library.
    239  1.1  christos          */
    240  1.1  christos 
    241  1.1  christos /*
    242  1.1  christos  * If an ENGINE supports its own specific control commands and wishes the
    243  1.1  christos  * framework to handle the above 'ENGINE_CMD_***'-manipulation commands on
    244  1.1  christos  * its behalf, it should supply a null-terminated array of ENGINE_CMD_DEFN
    245  1.1  christos  * entries to ENGINE_set_cmd_defns(). It should also implement a ctrl()
    246  1.1  christos  * handler that supports the stated commands (ie. the "cmd_num" entries as
    247  1.1  christos  * described by the array). NB: The array must be ordered in increasing order
    248  1.1  christos  * of cmd_num. "null-terminated" means that the last ENGINE_CMD_DEFN element
    249  1.1  christos  * has cmd_num set to zero and/or cmd_name set to NULL.
    250  1.1  christos  */
    251  1.1  christos typedef struct ENGINE_CMD_DEFN_st {
    252  1.1  christos     unsigned int cmd_num;       /* The command number */
    253  1.1  christos     const char *cmd_name;       /* The command name itself */
    254  1.1  christos     const char *cmd_desc;       /* A short description of the command */
    255  1.1  christos     unsigned int cmd_flags;     /* The input the command expects */
    256  1.1  christos } ENGINE_CMD_DEFN;
    257  1.1  christos 
    258  1.1  christos /* Generic function pointer */
    259  1.1  christos typedef int (*ENGINE_GEN_FUNC_PTR) (void);
    260  1.1  christos /* Generic function pointer taking no arguments */
    261  1.1  christos typedef int (*ENGINE_GEN_INT_FUNC_PTR) (ENGINE *);
    262  1.1  christos /* Specific control function pointer */
    263  1.1  christos typedef int (*ENGINE_CTRL_FUNC_PTR) (ENGINE *, int, long, void *,
    264  1.1  christos                                      void (*f) (void));
    265  1.1  christos /* Generic load_key function pointer */
    266  1.1  christos typedef EVP_PKEY *(*ENGINE_LOAD_KEY_PTR)(ENGINE *, const char *,
    267  1.1  christos                                          UI_METHOD *ui_method,
    268  1.1  christos                                          void *callback_data);
    269  1.1  christos typedef int (*ENGINE_SSL_CLIENT_CERT_PTR) (ENGINE *, SSL *ssl,
    270  1.1  christos                                            STACK_OF(X509_NAME) *ca_dn,
    271  1.1  christos                                            X509 **pcert, EVP_PKEY **pkey,
    272  1.1  christos                                            STACK_OF(X509) **pother,
    273  1.1  christos                                            UI_METHOD *ui_method,
    274  1.1  christos                                            void *callback_data);
    275  1.1  christos /*-
    276  1.1  christos  * These callback types are for an ENGINE's handler for cipher and digest logic.
    277  1.1  christos  * These handlers have these prototypes;
    278  1.1  christos  *   int foo(ENGINE *e, const EVP_CIPHER **cipher, const int **nids, int nid);
    279  1.1  christos  *   int foo(ENGINE *e, const EVP_MD **digest, const int **nids, int nid);
    280  1.1  christos  * Looking at how to implement these handlers in the case of cipher support, if
    281  1.1  christos  * the framework wants the EVP_CIPHER for 'nid', it will call;
    282  1.1  christos  *   foo(e, &p_evp_cipher, NULL, nid);    (return zero for failure)
    283  1.1  christos  * If the framework wants a list of supported 'nid's, it will call;
    284  1.1  christos  *   foo(e, NULL, &p_nids, 0); (returns number of 'nids' or -1 for error)
    285  1.1  christos  */
    286  1.1  christos /*
    287  1.1  christos  * Returns to a pointer to the array of supported cipher 'nid's. If the
    288  1.1  christos  * second parameter is non-NULL it is set to the size of the returned array.
    289  1.1  christos  */
    290  1.1  christos typedef int (*ENGINE_CIPHERS_PTR) (ENGINE *, const EVP_CIPHER **,
    291  1.1  christos                                    const int **, int);
    292  1.1  christos typedef int (*ENGINE_DIGESTS_PTR) (ENGINE *, const EVP_MD **, const int **,
    293  1.1  christos                                    int);
    294  1.1  christos typedef int (*ENGINE_PKEY_METHS_PTR) (ENGINE *, EVP_PKEY_METHOD **,
    295  1.1  christos                                       const int **, int);
    296  1.1  christos typedef int (*ENGINE_PKEY_ASN1_METHS_PTR) (ENGINE *, EVP_PKEY_ASN1_METHOD **,
    297  1.1  christos                                            const int **, int);
    298  1.1  christos /*
    299  1.1  christos  * STRUCTURE functions ... all of these functions deal with pointers to
    300  1.1  christos  * ENGINE structures where the pointers have a "structural reference". This
    301  1.1  christos  * means that their reference is to allowed access to the structure but it
    302  1.1  christos  * does not imply that the structure is functional. To simply increment or
    303  1.1  christos  * decrement the structural reference count, use ENGINE_by_id and
    304  1.1  christos  * ENGINE_free. NB: This is not required when iterating using ENGINE_get_next
    305  1.1  christos  * as it will automatically decrement the structural reference count of the
    306  1.1  christos  * "current" ENGINE and increment the structural reference count of the
    307  1.1  christos  * ENGINE it returns (unless it is NULL).
    308  1.1  christos  */
    309  1.1  christos 
    310  1.1  christos /* Get the first/last "ENGINE" type available. */
    311  1.1  christos ENGINE *ENGINE_get_first(void);
    312  1.1  christos ENGINE *ENGINE_get_last(void);
    313  1.1  christos /* Iterate to the next/previous "ENGINE" type (NULL = end of the list). */
    314  1.1  christos ENGINE *ENGINE_get_next(ENGINE *e);
    315  1.1  christos ENGINE *ENGINE_get_prev(ENGINE *e);
    316  1.1  christos /* Add another "ENGINE" type into the array. */
    317  1.1  christos int ENGINE_add(ENGINE *e);
    318  1.1  christos /* Remove an existing "ENGINE" type from the array. */
    319  1.1  christos int ENGINE_remove(ENGINE *e);
    320  1.1  christos /* Retrieve an engine from the list by its unique "id" value. */
    321  1.1  christos ENGINE *ENGINE_by_id(const char *id);
    322  1.1  christos 
    323  1.1  christos #if OPENSSL_API_COMPAT < 0x10100000L
    324  1.1  christos # define ENGINE_load_openssl() \
    325  1.1  christos     OPENSSL_init_crypto(OPENSSL_INIT_ENGINE_OPENSSL, NULL)
    326  1.1  christos # define ENGINE_load_dynamic() \
    327  1.1  christos     OPENSSL_init_crypto(OPENSSL_INIT_ENGINE_DYNAMIC, NULL)
    328  1.1  christos # ifndef OPENSSL_NO_STATIC_ENGINE
    329  1.1  christos #  define ENGINE_load_padlock() \
    330  1.1  christos     OPENSSL_init_crypto(OPENSSL_INIT_ENGINE_PADLOCK, NULL)
    331  1.1  christos #  define ENGINE_load_capi() \
    332  1.1  christos     OPENSSL_init_crypto(OPENSSL_INIT_ENGINE_CAPI, NULL)
    333  1.1  christos #  define ENGINE_load_afalg() \
    334  1.1  christos     OPENSSL_init_crypto(OPENSSL_INIT_ENGINE_AFALG, NULL)
    335  1.1  christos # endif
    336  1.1  christos # define ENGINE_load_cryptodev() \
    337  1.1  christos     OPENSSL_init_crypto(OPENSSL_INIT_ENGINE_CRYPTODEV, NULL)
    338  1.1  christos # define ENGINE_load_rdrand() \
    339  1.1  christos     OPENSSL_init_crypto(OPENSSL_INIT_ENGINE_RDRAND, NULL)
    340  1.1  christos #endif
    341  1.1  christos void ENGINE_load_builtin_engines(void);
    342  1.1  christos 
    343  1.1  christos /*
    344  1.1  christos  * Get and set global flags (ENGINE_TABLE_FLAG_***) for the implementation
    345  1.1  christos  * "registry" handling.
    346  1.1  christos  */
    347  1.1  christos unsigned int ENGINE_get_table_flags(void);
    348  1.1  christos void ENGINE_set_table_flags(unsigned int flags);
    349  1.1  christos 
    350  1.1  christos /*- Manage registration of ENGINEs per "table". For each type, there are 3
    351  1.1  christos  * functions;
    352  1.1  christos  *   ENGINE_register_***(e) - registers the implementation from 'e' (if it has one)
    353  1.1  christos  *   ENGINE_unregister_***(e) - unregister the implementation from 'e'
    354  1.1  christos  *   ENGINE_register_all_***() - call ENGINE_register_***() for each 'e' in the list
    355  1.1  christos  * Cleanup is automatically registered from each table when required.
    356  1.1  christos  */
    357  1.1  christos 
    358  1.1  christos int ENGINE_register_RSA(ENGINE *e);
    359  1.1  christos void ENGINE_unregister_RSA(ENGINE *e);
    360  1.1  christos void ENGINE_register_all_RSA(void);
    361  1.1  christos 
    362  1.1  christos int ENGINE_register_DSA(ENGINE *e);
    363  1.1  christos void ENGINE_unregister_DSA(ENGINE *e);
    364  1.1  christos void ENGINE_register_all_DSA(void);
    365  1.1  christos 
    366  1.1  christos int ENGINE_register_EC(ENGINE *e);
    367  1.1  christos void ENGINE_unregister_EC(ENGINE *e);
    368  1.1  christos void ENGINE_register_all_EC(void);
    369  1.1  christos 
    370  1.1  christos int ENGINE_register_DH(ENGINE *e);
    371  1.1  christos void ENGINE_unregister_DH(ENGINE *e);
    372  1.1  christos void ENGINE_register_all_DH(void);
    373  1.1  christos 
    374  1.1  christos int ENGINE_register_RAND(ENGINE *e);
    375  1.1  christos void ENGINE_unregister_RAND(ENGINE *e);
    376  1.1  christos void ENGINE_register_all_RAND(void);
    377  1.1  christos 
    378  1.1  christos int ENGINE_register_ciphers(ENGINE *e);
    379  1.1  christos void ENGINE_unregister_ciphers(ENGINE *e);
    380  1.1  christos void ENGINE_register_all_ciphers(void);
    381  1.1  christos 
    382  1.1  christos int ENGINE_register_digests(ENGINE *e);
    383  1.1  christos void ENGINE_unregister_digests(ENGINE *e);
    384  1.1  christos void ENGINE_register_all_digests(void);
    385  1.1  christos 
    386  1.1  christos int ENGINE_register_pkey_meths(ENGINE *e);
    387  1.1  christos void ENGINE_unregister_pkey_meths(ENGINE *e);
    388  1.1  christos void ENGINE_register_all_pkey_meths(void);
    389  1.1  christos 
    390  1.1  christos int ENGINE_register_pkey_asn1_meths(ENGINE *e);
    391  1.1  christos void ENGINE_unregister_pkey_asn1_meths(ENGINE *e);
    392  1.1  christos void ENGINE_register_all_pkey_asn1_meths(void);
    393  1.1  christos 
    394  1.1  christos /*
    395  1.1  christos  * These functions register all support from the above categories. Note, use
    396  1.1  christos  * of these functions can result in static linkage of code your application
    397  1.1  christos  * may not need. If you only need a subset of functionality, consider using
    398  1.1  christos  * more selective initialisation.
    399  1.1  christos  */
    400  1.1  christos int ENGINE_register_complete(ENGINE *e);
    401  1.1  christos int ENGINE_register_all_complete(void);
    402  1.1  christos 
    403  1.1  christos /*
    404  1.1  christos  * Send parameterised control commands to the engine. The possibilities to
    405  1.1  christos  * send down an integer, a pointer to data or a function pointer are
    406  1.1  christos  * provided. Any of the parameters may or may not be NULL, depending on the
    407  1.1  christos  * command number. In actuality, this function only requires a structural
    408  1.1  christos  * (rather than functional) reference to an engine, but many control commands
    409  1.1  christos  * may require the engine be functional. The caller should be aware of trying
    410  1.1  christos  * commands that require an operational ENGINE, and only use functional
    411  1.1  christos  * references in such situations.
    412  1.1  christos  */
    413  1.1  christos int ENGINE_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f) (void));
    414  1.1  christos 
    415  1.1  christos /*
    416  1.1  christos  * This function tests if an ENGINE-specific command is usable as a
    417  1.1  christos  * "setting". Eg. in an application's config file that gets processed through
    418  1.1  christos  * ENGINE_ctrl_cmd_string(). If this returns zero, it is not available to
    419  1.1  christos  * ENGINE_ctrl_cmd_string(), only ENGINE_ctrl().
    420  1.1  christos  */
    421  1.1  christos int ENGINE_cmd_is_executable(ENGINE *e, int cmd);
    422  1.1  christos 
    423  1.1  christos /*
    424  1.1  christos  * This function works like ENGINE_ctrl() with the exception of taking a
    425  1.1  christos  * command name instead of a command number, and can handle optional
    426  1.1  christos  * commands. See the comment on ENGINE_ctrl_cmd_string() for an explanation
    427  1.1  christos  * on how to use the cmd_name and cmd_optional.
    428  1.1  christos  */
    429  1.1  christos int ENGINE_ctrl_cmd(ENGINE *e, const char *cmd_name,
    430  1.1  christos                     long i, void *p, void (*f) (void), int cmd_optional);
    431  1.1  christos 
    432  1.1  christos /*
    433  1.1  christos  * This function passes a command-name and argument to an ENGINE. The
    434  1.1  christos  * cmd_name is converted to a command number and the control command is
    435  1.1  christos  * called using 'arg' as an argument (unless the ENGINE doesn't support such
    436  1.1  christos  * a command, in which case no control command is called). The command is
    437  1.1  christos  * checked for input flags, and if necessary the argument will be converted
    438  1.1  christos  * to a numeric value. If cmd_optional is non-zero, then if the ENGINE
    439  1.1  christos  * doesn't support the given cmd_name the return value will be success
    440  1.1  christos  * anyway. This function is intended for applications to use so that users
    441  1.1  christos  * (or config files) can supply engine-specific config data to the ENGINE at
    442  1.1  christos  * run-time to control behaviour of specific engines. As such, it shouldn't
    443  1.1  christos  * be used for calling ENGINE_ctrl() functions that return data, deal with
    444  1.1  christos  * binary data, or that are otherwise supposed to be used directly through
    445  1.1  christos  * ENGINE_ctrl() in application code. Any "return" data from an ENGINE_ctrl()
    446  1.1  christos  * operation in this function will be lost - the return value is interpreted
    447  1.1  christos  * as failure if the return value is zero, success otherwise, and this
    448  1.1  christos  * function returns a boolean value as a result. In other words, vendors of
    449  1.1  christos  * 'ENGINE'-enabled devices should write ENGINE implementations with
    450  1.1  christos  * parameterisations that work in this scheme, so that compliant ENGINE-based
    451  1.1  christos  * applications can work consistently with the same configuration for the
    452  1.1  christos  * same ENGINE-enabled devices, across applications.
    453  1.1  christos  */
    454  1.1  christos int ENGINE_ctrl_cmd_string(ENGINE *e, const char *cmd_name, const char *arg,
    455  1.1  christos                            int cmd_optional);
    456  1.1  christos 
    457  1.1  christos /*
    458  1.1  christos  * These functions are useful for manufacturing new ENGINE structures. They
    459  1.1  christos  * don't address reference counting at all - one uses them to populate an
    460  1.1  christos  * ENGINE structure with personalised implementations of things prior to
    461  1.1  christos  * using it directly or adding it to the builtin ENGINE list in OpenSSL.
    462  1.1  christos  * These are also here so that the ENGINE structure doesn't have to be
    463  1.1  christos  * exposed and break binary compatibility!
    464  1.1  christos  */
    465  1.1  christos ENGINE *ENGINE_new(void);
    466  1.1  christos int ENGINE_free(ENGINE *e);
    467  1.1  christos int ENGINE_up_ref(ENGINE *e);
    468  1.1  christos int ENGINE_set_id(ENGINE *e, const char *id);
    469  1.1  christos int ENGINE_set_name(ENGINE *e, const char *name);
    470  1.1  christos int ENGINE_set_RSA(ENGINE *e, const RSA_METHOD *rsa_meth);
    471  1.1  christos int ENGINE_set_DSA(ENGINE *e, const DSA_METHOD *dsa_meth);
    472  1.1  christos int ENGINE_set_EC(ENGINE *e, const EC_KEY_METHOD *ecdsa_meth);
    473  1.1  christos int ENGINE_set_DH(ENGINE *e, const DH_METHOD *dh_meth);
    474  1.1  christos int ENGINE_set_RAND(ENGINE *e, const RAND_METHOD *rand_meth);
    475  1.1  christos int ENGINE_set_destroy_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR destroy_f);
    476  1.1  christos int ENGINE_set_init_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR init_f);
    477  1.1  christos int ENGINE_set_finish_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR finish_f);
    478  1.1  christos int ENGINE_set_ctrl_function(ENGINE *e, ENGINE_CTRL_FUNC_PTR ctrl_f);
    479  1.1  christos int ENGINE_set_load_privkey_function(ENGINE *e,
    480  1.1  christos                                      ENGINE_LOAD_KEY_PTR loadpriv_f);
    481  1.1  christos int ENGINE_set_load_pubkey_function(ENGINE *e, ENGINE_LOAD_KEY_PTR loadpub_f);
    482  1.1  christos int ENGINE_set_load_ssl_client_cert_function(ENGINE *e,
    483  1.1  christos                                              ENGINE_SSL_CLIENT_CERT_PTR
    484  1.1  christos                                              loadssl_f);
    485  1.1  christos int ENGINE_set_ciphers(ENGINE *e, ENGINE_CIPHERS_PTR f);
    486  1.1  christos int ENGINE_set_digests(ENGINE *e, ENGINE_DIGESTS_PTR f);
    487  1.1  christos int ENGINE_set_pkey_meths(ENGINE *e, ENGINE_PKEY_METHS_PTR f);
    488  1.1  christos int ENGINE_set_pkey_asn1_meths(ENGINE *e, ENGINE_PKEY_ASN1_METHS_PTR f);
    489  1.1  christos int ENGINE_set_flags(ENGINE *e, int flags);
    490  1.1  christos int ENGINE_set_cmd_defns(ENGINE *e, const ENGINE_CMD_DEFN *defns);
    491  1.1  christos /* These functions allow control over any per-structure ENGINE data. */
    492  1.1  christos #define ENGINE_get_ex_new_index(l, p, newf, dupf, freef) \
    493  1.1  christos     CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_ENGINE, l, p, newf, dupf, freef)
    494  1.1  christos int ENGINE_set_ex_data(ENGINE *e, int idx, void *arg);
    495  1.1  christos void *ENGINE_get_ex_data(const ENGINE *e, int idx);
    496  1.1  christos 
    497  1.1  christos #if OPENSSL_API_COMPAT < 0x10100000L
    498  1.1  christos /*
    499  1.1  christos  * This function previously cleaned up anything that needs it. Auto-deinit will
    500  1.1  christos  * now take care of it so it is no longer required to call this function.
    501  1.1  christos  */
    502  1.1  christos # define ENGINE_cleanup() while(0) continue
    503  1.1  christos #endif
    504  1.1  christos 
    505  1.1  christos /*
    506  1.1  christos  * These return values from within the ENGINE structure. These can be useful
    507  1.1  christos  * with functional references as well as structural references - it depends
    508  1.1  christos  * which you obtained. Using the result for functional purposes if you only
    509  1.1  christos  * obtained a structural reference may be problematic!
    510  1.1  christos  */
    511  1.1  christos const char *ENGINE_get_id(const ENGINE *e);
    512  1.1  christos const char *ENGINE_get_name(const ENGINE *e);
    513  1.1  christos const RSA_METHOD *ENGINE_get_RSA(const ENGINE *e);
    514  1.1  christos const DSA_METHOD *ENGINE_get_DSA(const ENGINE *e);
    515  1.1  christos const EC_KEY_METHOD *ENGINE_get_EC(const ENGINE *e);
    516  1.1  christos const DH_METHOD *ENGINE_get_DH(const ENGINE *e);
    517  1.1  christos const RAND_METHOD *ENGINE_get_RAND(const ENGINE *e);
    518  1.1  christos ENGINE_GEN_INT_FUNC_PTR ENGINE_get_destroy_function(const ENGINE *e);
    519  1.1  christos ENGINE_GEN_INT_FUNC_PTR ENGINE_get_init_function(const ENGINE *e);
    520  1.1  christos ENGINE_GEN_INT_FUNC_PTR ENGINE_get_finish_function(const ENGINE *e);
    521  1.1  christos ENGINE_CTRL_FUNC_PTR ENGINE_get_ctrl_function(const ENGINE *e);
    522  1.1  christos ENGINE_LOAD_KEY_PTR ENGINE_get_load_privkey_function(const ENGINE *e);
    523  1.1  christos ENGINE_LOAD_KEY_PTR ENGINE_get_load_pubkey_function(const ENGINE *e);
    524  1.1  christos ENGINE_SSL_CLIENT_CERT_PTR ENGINE_get_ssl_client_cert_function(const ENGINE
    525  1.1  christos                                                                *e);
    526  1.1  christos ENGINE_CIPHERS_PTR ENGINE_get_ciphers(const ENGINE *e);
    527  1.1  christos ENGINE_DIGESTS_PTR ENGINE_get_digests(const ENGINE *e);
    528  1.1  christos ENGINE_PKEY_METHS_PTR ENGINE_get_pkey_meths(const ENGINE *e);
    529  1.1  christos ENGINE_PKEY_ASN1_METHS_PTR ENGINE_get_pkey_asn1_meths(const ENGINE *e);
    530  1.1  christos const EVP_CIPHER *ENGINE_get_cipher(ENGINE *e, int nid);
    531  1.1  christos const EVP_MD *ENGINE_get_digest(ENGINE *e, int nid);
    532  1.1  christos const EVP_PKEY_METHOD *ENGINE_get_pkey_meth(ENGINE *e, int nid);
    533  1.1  christos const EVP_PKEY_ASN1_METHOD *ENGINE_get_pkey_asn1_meth(ENGINE *e, int nid);
    534  1.1  christos const EVP_PKEY_ASN1_METHOD *ENGINE_get_pkey_asn1_meth_str(ENGINE *e,
    535  1.1  christos                                                           const char *str,
    536  1.1  christos                                                           int len);
    537  1.1  christos const EVP_PKEY_ASN1_METHOD *ENGINE_pkey_asn1_find_str(ENGINE **pe,
    538  1.1  christos                                                       const char *str,
    539  1.1  christos                                                       int len);
    540  1.1  christos const ENGINE_CMD_DEFN *ENGINE_get_cmd_defns(const ENGINE *e);
    541  1.1  christos int ENGINE_get_flags(const ENGINE *e);
    542  1.1  christos 
    543  1.1  christos /*
    544  1.1  christos  * FUNCTIONAL functions. These functions deal with ENGINE structures that
    545  1.1  christos  * have (or will) be initialised for use. Broadly speaking, the structural
    546  1.1  christos  * functions are useful for iterating the list of available engine types,
    547  1.1  christos  * creating new engine types, and other "list" operations. These functions
    548  1.1  christos  * actually deal with ENGINEs that are to be used. As such these functions
    549  1.1  christos  * can fail (if applicable) when particular engines are unavailable - eg. if
    550  1.1  christos  * a hardware accelerator is not attached or not functioning correctly. Each
    551  1.1  christos  * ENGINE has 2 reference counts; structural and functional. Every time a
    552  1.1  christos  * functional reference is obtained or released, a corresponding structural
    553  1.1  christos  * reference is automatically obtained or released too.
    554  1.1  christos  */
    555  1.1  christos 
    556  1.1  christos /*
    557  1.1  christos  * Initialise a engine type for use (or up its reference count if it's
    558  1.1  christos  * already in use). This will fail if the engine is not currently operational
    559  1.1  christos  * and cannot initialise.
    560  1.1  christos  */
    561  1.1  christos int ENGINE_init(ENGINE *e);
    562  1.1  christos /*
    563  1.1  christos  * Free a functional reference to a engine type. This does not require a
    564  1.1  christos  * corresponding call to ENGINE_free as it also releases a structural
    565  1.1  christos  * reference.
    566  1.1  christos  */
    567  1.1  christos int ENGINE_finish(ENGINE *e);
    568  1.1  christos 
    569  1.1  christos /*
    570  1.1  christos  * The following functions handle keys that are stored in some secondary
    571  1.1  christos  * location, handled by the engine.  The storage may be on a card or
    572  1.1  christos  * whatever.
    573  1.1  christos  */
    574  1.1  christos EVP_PKEY *ENGINE_load_private_key(ENGINE *e, const char *key_id,
    575  1.1  christos                                   UI_METHOD *ui_method, void *callback_data);
    576  1.1  christos EVP_PKEY *ENGINE_load_public_key(ENGINE *e, const char *key_id,
    577  1.1  christos                                  UI_METHOD *ui_method, void *callback_data);
    578  1.1  christos int ENGINE_load_ssl_client_cert(ENGINE *e, SSL *s,
    579  1.1  christos                                 STACK_OF(X509_NAME) *ca_dn, X509 **pcert,
    580  1.1  christos                                 EVP_PKEY **ppkey, STACK_OF(X509) **pother,
    581  1.1  christos                                 UI_METHOD *ui_method, void *callback_data);
    582  1.1  christos 
    583  1.1  christos /*
    584  1.1  christos  * This returns a pointer for the current ENGINE structure that is (by
    585  1.1  christos  * default) performing any RSA operations. The value returned is an
    586  1.1  christos  * incremented reference, so it should be free'd (ENGINE_finish) before it is
    587  1.1  christos  * discarded.
    588  1.1  christos  */
    589  1.1  christos ENGINE *ENGINE_get_default_RSA(void);
    590  1.1  christos /* Same for the other "methods" */
    591  1.1  christos ENGINE *ENGINE_get_default_DSA(void);
    592  1.1  christos ENGINE *ENGINE_get_default_EC(void);
    593  1.1  christos ENGINE *ENGINE_get_default_DH(void);
    594  1.1  christos ENGINE *ENGINE_get_default_RAND(void);
    595  1.1  christos /*
    596  1.1  christos  * These functions can be used to get a functional reference to perform
    597  1.1  christos  * ciphering or digesting corresponding to "nid".
    598  1.1  christos  */
    599  1.1  christos ENGINE *ENGINE_get_cipher_engine(int nid);
    600  1.1  christos ENGINE *ENGINE_get_digest_engine(int nid);
    601  1.1  christos ENGINE *ENGINE_get_pkey_meth_engine(int nid);
    602  1.1  christos ENGINE *ENGINE_get_pkey_asn1_meth_engine(int nid);
    603  1.1  christos 
    604  1.1  christos /*
    605  1.1  christos  * This sets a new default ENGINE structure for performing RSA operations. If
    606  1.1  christos  * the result is non-zero (success) then the ENGINE structure will have had
    607  1.1  christos  * its reference count up'd so the caller should still free their own
    608  1.1  christos  * reference 'e'.
    609  1.1  christos  */
    610  1.1  christos int ENGINE_set_default_RSA(ENGINE *e);
    611  1.1  christos int ENGINE_set_default_string(ENGINE *e, const char *def_list);
    612  1.1  christos /* Same for the other "methods" */
    613  1.1  christos int ENGINE_set_default_DSA(ENGINE *e);
    614  1.1  christos int ENGINE_set_default_EC(ENGINE *e);
    615  1.1  christos int ENGINE_set_default_DH(ENGINE *e);
    616  1.1  christos int ENGINE_set_default_RAND(ENGINE *e);
    617  1.1  christos int ENGINE_set_default_ciphers(ENGINE *e);
    618  1.1  christos int ENGINE_set_default_digests(ENGINE *e);
    619  1.1  christos int ENGINE_set_default_pkey_meths(ENGINE *e);
    620  1.1  christos int ENGINE_set_default_pkey_asn1_meths(ENGINE *e);
    621  1.1  christos 
    622  1.1  christos /*
    623  1.1  christos  * The combination "set" - the flags are bitwise "OR"d from the
    624  1.1  christos  * ENGINE_METHOD_*** defines above. As with the "ENGINE_register_complete()"
    625  1.1  christos  * function, this function can result in unnecessary static linkage. If your
    626  1.1  christos  * application requires only specific functionality, consider using more
    627  1.1  christos  * selective functions.
    628  1.1  christos  */
    629  1.1  christos int ENGINE_set_default(ENGINE *e, unsigned int flags);
    630  1.1  christos 
    631  1.1  christos void ENGINE_add_conf_module(void);
    632  1.1  christos 
    633  1.1  christos /* Deprecated functions ... */
    634  1.1  christos /* int ENGINE_clear_defaults(void); */
    635  1.1  christos 
    636  1.1  christos /**************************/
    637  1.1  christos /* DYNAMIC ENGINE SUPPORT */
    638  1.1  christos /**************************/
    639  1.1  christos 
    640  1.1  christos /* Binary/behaviour compatibility levels */
    641  1.1  christos # define OSSL_DYNAMIC_VERSION            (unsigned long)0x00030000
    642  1.1  christos /*
    643  1.1  christos  * Binary versions older than this are too old for us (whether we're a loader
    644  1.1  christos  * or a loadee)
    645  1.1  christos  */
    646  1.1  christos # define OSSL_DYNAMIC_OLDEST             (unsigned long)0x00030000
    647  1.1  christos 
    648  1.1  christos /*
    649  1.1  christos  * When compiling an ENGINE entirely as an external shared library, loadable
    650  1.1  christos  * by the "dynamic" ENGINE, these types are needed. The 'dynamic_fns'
    651  1.1  christos  * structure type provides the calling application's (or library's) error
    652  1.1  christos  * functionality and memory management function pointers to the loaded
    653  1.1  christos  * library. These should be used/set in the loaded library code so that the
    654  1.1  christos  * loading application's 'state' will be used/changed in all operations. The
    655  1.1  christos  * 'static_state' pointer allows the loaded library to know if it shares the
    656  1.1  christos  * same static data as the calling application (or library), and thus whether
    657  1.1  christos  * these callbacks need to be set or not.
    658  1.1  christos  */
    659  1.1  christos typedef void *(*dyn_MEM_malloc_fn) (size_t, const char *, int);
    660  1.1  christos typedef void *(*dyn_MEM_realloc_fn) (void *, size_t, const char *, int);
    661  1.1  christos typedef void (*dyn_MEM_free_fn) (void *, const char *, int);
    662  1.1  christos typedef struct st_dynamic_MEM_fns {
    663  1.1  christos     dyn_MEM_malloc_fn malloc_fn;
    664  1.1  christos     dyn_MEM_realloc_fn realloc_fn;
    665  1.1  christos     dyn_MEM_free_fn free_fn;
    666  1.1  christos } dynamic_MEM_fns;
    667  1.1  christos /*
    668  1.1  christos  * FIXME: Perhaps the memory and locking code (crypto.h) should declare and
    669  1.1  christos  * use these types so we (and any other dependent code) can simplify a bit??
    670  1.1  christos  */
    671  1.1  christos /* The top-level structure */
    672  1.1  christos typedef struct st_dynamic_fns {
    673  1.1  christos     void *static_state;
    674  1.1  christos     dynamic_MEM_fns mem_fns;
    675  1.1  christos } dynamic_fns;
    676  1.1  christos 
    677  1.1  christos /*
    678  1.1  christos  * The version checking function should be of this prototype. NB: The
    679  1.1  christos  * ossl_version value passed in is the OSSL_DYNAMIC_VERSION of the loading
    680  1.1  christos  * code. If this function returns zero, it indicates a (potential) version
    681  1.1  christos  * incompatibility and the loaded library doesn't believe it can proceed.
    682  1.1  christos  * Otherwise, the returned value is the (latest) version supported by the
    683  1.1  christos  * loading library. The loader may still decide that the loaded code's
    684  1.1  christos  * version is unsatisfactory and could veto the load. The function is
    685  1.1  christos  * expected to be implemented with the symbol name "v_check", and a default
    686  1.1  christos  * implementation can be fully instantiated with
    687  1.1  christos  * IMPLEMENT_DYNAMIC_CHECK_FN().
    688  1.1  christos  */
    689  1.1  christos typedef unsigned long (*dynamic_v_check_fn) (unsigned long ossl_version);
    690  1.1  christos # define IMPLEMENT_DYNAMIC_CHECK_FN() \
    691  1.1  christos         OPENSSL_EXPORT unsigned long v_check(unsigned long v); \
    692  1.1  christos         OPENSSL_EXPORT unsigned long v_check(unsigned long v) { \
    693  1.1  christos                 if (v >= OSSL_DYNAMIC_OLDEST) return OSSL_DYNAMIC_VERSION; \
    694  1.1  christos                 return 0; }
    695  1.1  christos 
    696  1.1  christos /*
    697  1.1  christos  * This function is passed the ENGINE structure to initialise with its own
    698  1.1  christos  * function and command settings. It should not adjust the structural or
    699  1.1  christos  * functional reference counts. If this function returns zero, (a) the load
    700  1.1  christos  * will be aborted, (b) the previous ENGINE state will be memcpy'd back onto
    701  1.1  christos  * the structure, and (c) the shared library will be unloaded. So
    702  1.1  christos  * implementations should do their own internal cleanup in failure
    703  1.1  christos  * circumstances otherwise they could leak. The 'id' parameter, if non-NULL,
    704  1.1  christos  * represents the ENGINE id that the loader is looking for. If this is NULL,
    705  1.1  christos  * the shared library can choose to return failure or to initialise a
    706  1.1  christos  * 'default' ENGINE. If non-NULL, the shared library must initialise only an
    707  1.1  christos  * ENGINE matching the passed 'id'. The function is expected to be
    708  1.1  christos  * implemented with the symbol name "bind_engine". A standard implementation
    709  1.1  christos  * can be instantiated with IMPLEMENT_DYNAMIC_BIND_FN(fn) where the parameter
    710  1.1  christos  * 'fn' is a callback function that populates the ENGINE structure and
    711  1.1  christos  * returns an int value (zero for failure). 'fn' should have prototype;
    712  1.1  christos  * [static] int fn(ENGINE *e, const char *id);
    713  1.1  christos  */
    714  1.1  christos typedef int (*dynamic_bind_engine) (ENGINE *e, const char *id,
    715  1.1  christos                                     const dynamic_fns *fns);
    716  1.1  christos # define IMPLEMENT_DYNAMIC_BIND_FN(fn) \
    717  1.1  christos         OPENSSL_EXPORT \
    718  1.1  christos         int bind_engine(ENGINE *e, const char *id, const dynamic_fns *fns); \
    719  1.1  christos         OPENSSL_EXPORT \
    720  1.1  christos         int bind_engine(ENGINE *e, const char *id, const dynamic_fns *fns) { \
    721  1.1  christos             if (ENGINE_get_static_state() == fns->static_state) goto skip_cbs; \
    722  1.1  christos             CRYPTO_set_mem_functions(fns->mem_fns.malloc_fn, \
    723  1.1  christos                                      fns->mem_fns.realloc_fn, \
    724  1.1  christos                                      fns->mem_fns.free_fn); \
    725  1.1  christos             OPENSSL_init_crypto(OPENSSL_INIT_NO_ATEXIT, NULL); \
    726  1.1  christos         skip_cbs: \
    727  1.1  christos             if (!fn(e, id)) return 0; \
    728  1.1  christos             return 1; }
    729  1.1  christos 
    730  1.1  christos /*
    731  1.1  christos  * If the loading application (or library) and the loaded ENGINE library
    732  1.1  christos  * share the same static data (eg. they're both dynamically linked to the
    733  1.1  christos  * same libcrypto.so) we need a way to avoid trying to set system callbacks -
    734  1.1  christos  * this would fail, and for the same reason that it's unnecessary to try. If
    735  1.1  christos  * the loaded ENGINE has (or gets from through the loader) its own copy of
    736  1.1  christos  * the libcrypto static data, we will need to set the callbacks. The easiest
    737  1.1  christos  * way to detect this is to have a function that returns a pointer to some
    738  1.1  christos  * static data and let the loading application and loaded ENGINE compare
    739  1.1  christos  * their respective values.
    740  1.1  christos  */
    741  1.1  christos void *ENGINE_get_static_state(void);
    742  1.1  christos 
    743  1.1  christos # if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__DragonFly__)
    744  1.1  christos DEPRECATEDIN_1_1_0(void ENGINE_setup_bsd_cryptodev(void))
    745  1.1  christos # endif
    746  1.1  christos 
    747  1.1  christos 
    748  1.1  christos #  ifdef  __cplusplus
    749  1.1  christos }
    750  1.1  christos #  endif
    751  1.1  christos # endif
    752  1.1  christos #endif
    753