10Sstevel@tonic-gate /* openssl/engine.h */ 20Sstevel@tonic-gate /* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL 30Sstevel@tonic-gate * project 2000. 40Sstevel@tonic-gate */ 50Sstevel@tonic-gate /* ==================================================================== 6*2139Sjp161948 * Copyright (c) 1999-2004 The OpenSSL Project. All rights reserved. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * Redistribution and use in source and binary forms, with or without 90Sstevel@tonic-gate * modification, are permitted provided that the following conditions 100Sstevel@tonic-gate * are met: 110Sstevel@tonic-gate * 120Sstevel@tonic-gate * 1. Redistributions of source code must retain the above copyright 130Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer. 140Sstevel@tonic-gate * 150Sstevel@tonic-gate * 2. Redistributions in binary form must reproduce the above copyright 160Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer in 170Sstevel@tonic-gate * the documentation and/or other materials provided with the 180Sstevel@tonic-gate * distribution. 190Sstevel@tonic-gate * 200Sstevel@tonic-gate * 3. All advertising materials mentioning features or use of this 210Sstevel@tonic-gate * software must display the following acknowledgment: 220Sstevel@tonic-gate * "This product includes software developed by the OpenSSL Project 230Sstevel@tonic-gate * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" 240Sstevel@tonic-gate * 250Sstevel@tonic-gate * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 260Sstevel@tonic-gate * endorse or promote products derived from this software without 270Sstevel@tonic-gate * prior written permission. For written permission, please contact 280Sstevel@tonic-gate * licensing@OpenSSL.org. 290Sstevel@tonic-gate * 300Sstevel@tonic-gate * 5. Products derived from this software may not be called "OpenSSL" 310Sstevel@tonic-gate * nor may "OpenSSL" appear in their names without prior written 320Sstevel@tonic-gate * permission of the OpenSSL Project. 330Sstevel@tonic-gate * 340Sstevel@tonic-gate * 6. Redistributions of any form whatsoever must retain the following 350Sstevel@tonic-gate * acknowledgment: 360Sstevel@tonic-gate * "This product includes software developed by the OpenSSL Project 370Sstevel@tonic-gate * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" 380Sstevel@tonic-gate * 390Sstevel@tonic-gate * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 400Sstevel@tonic-gate * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 410Sstevel@tonic-gate * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 420Sstevel@tonic-gate * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 430Sstevel@tonic-gate * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 440Sstevel@tonic-gate * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 450Sstevel@tonic-gate * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 460Sstevel@tonic-gate * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 470Sstevel@tonic-gate * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 480Sstevel@tonic-gate * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 490Sstevel@tonic-gate * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 500Sstevel@tonic-gate * OF THE POSSIBILITY OF SUCH DAMAGE. 510Sstevel@tonic-gate * ==================================================================== 520Sstevel@tonic-gate * 530Sstevel@tonic-gate * This product includes cryptographic software written by Eric Young 540Sstevel@tonic-gate * (eay@cryptsoft.com). This product includes software written by Tim 550Sstevel@tonic-gate * Hudson (tjh@cryptsoft.com). 560Sstevel@tonic-gate * 570Sstevel@tonic-gate */ 58*2139Sjp161948 /* ==================================================================== 59*2139Sjp161948 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. 60*2139Sjp161948 * ECDH support in OpenSSL originally developed by 61*2139Sjp161948 * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project. 62*2139Sjp161948 */ 63*2139Sjp161948 64*2139Sjp161948 /* 65*2139Sjp161948 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 66*2139Sjp161948 * Use is subject to license terms. 67*2139Sjp161948 */ 68*2139Sjp161948 69*2139Sjp161948 #pragma ident "%Z%%M% %I% %E% SMI" 700Sstevel@tonic-gate 710Sstevel@tonic-gate #ifndef HEADER_ENGINE_H 720Sstevel@tonic-gate #define HEADER_ENGINE_H 730Sstevel@tonic-gate 740Sstevel@tonic-gate #include <openssl/opensslconf.h> 750Sstevel@tonic-gate 760Sstevel@tonic-gate #ifdef OPENSSL_NO_ENGINE 770Sstevel@tonic-gate #error ENGINE is disabled. 780Sstevel@tonic-gate #endif 790Sstevel@tonic-gate 80*2139Sjp161948 #ifndef OPENSSL_NO_DEPRECATED 810Sstevel@tonic-gate #include <openssl/bn.h> 820Sstevel@tonic-gate #ifndef OPENSSL_NO_RSA 830Sstevel@tonic-gate #include <openssl/rsa.h> 840Sstevel@tonic-gate #endif 850Sstevel@tonic-gate #ifndef OPENSSL_NO_DSA 860Sstevel@tonic-gate #include <openssl/dsa.h> 870Sstevel@tonic-gate #endif 880Sstevel@tonic-gate #ifndef OPENSSL_NO_DH 890Sstevel@tonic-gate #include <openssl/dh.h> 900Sstevel@tonic-gate #endif 91*2139Sjp161948 #ifndef OPENSSL_NO_ECDH 92*2139Sjp161948 #include <openssl/ecdh.h> 93*2139Sjp161948 #endif 94*2139Sjp161948 #ifndef OPENSSL_NO_ECDSA 95*2139Sjp161948 #include <openssl/ecdsa.h> 96*2139Sjp161948 #endif 970Sstevel@tonic-gate #include <openssl/rand.h> 98*2139Sjp161948 #include <openssl/store.h> 990Sstevel@tonic-gate #include <openssl/ui.h> 100*2139Sjp161948 #include <openssl/err.h> 101*2139Sjp161948 #endif 102*2139Sjp161948 103*2139Sjp161948 #include <openssl/ossl_typ.h> 1040Sstevel@tonic-gate #include <openssl/symhacks.h> 1050Sstevel@tonic-gate 1060Sstevel@tonic-gate #ifdef __cplusplus 1070Sstevel@tonic-gate extern "C" { 1080Sstevel@tonic-gate #endif 1090Sstevel@tonic-gate 1100Sstevel@tonic-gate /* These flags are used to control combinations of algorithm (methods) 1110Sstevel@tonic-gate * by bitwise "OR"ing. */ 1120Sstevel@tonic-gate #define ENGINE_METHOD_RSA (unsigned int)0x0001 1130Sstevel@tonic-gate #define ENGINE_METHOD_DSA (unsigned int)0x0002 1140Sstevel@tonic-gate #define ENGINE_METHOD_DH (unsigned int)0x0004 1150Sstevel@tonic-gate #define ENGINE_METHOD_RAND (unsigned int)0x0008 116*2139Sjp161948 #define ENGINE_METHOD_ECDH (unsigned int)0x0010 117*2139Sjp161948 #define ENGINE_METHOD_ECDSA (unsigned int)0x0020 1180Sstevel@tonic-gate #define ENGINE_METHOD_CIPHERS (unsigned int)0x0040 1190Sstevel@tonic-gate #define ENGINE_METHOD_DIGESTS (unsigned int)0x0080 120*2139Sjp161948 #define ENGINE_METHOD_STORE (unsigned int)0x0100 1210Sstevel@tonic-gate /* Obvious all-or-nothing cases. */ 1220Sstevel@tonic-gate #define ENGINE_METHOD_ALL (unsigned int)0xFFFF 1230Sstevel@tonic-gate #define ENGINE_METHOD_NONE (unsigned int)0x0000 1240Sstevel@tonic-gate 1250Sstevel@tonic-gate /* This(ese) flag(s) controls behaviour of the ENGINE_TABLE mechanism used 1260Sstevel@tonic-gate * internally to control registration of ENGINE implementations, and can be set 1270Sstevel@tonic-gate * by ENGINE_set_table_flags(). The "NOINIT" flag prevents attempts to 1280Sstevel@tonic-gate * initialise registered ENGINEs if they are not already initialised. */ 1290Sstevel@tonic-gate #define ENGINE_TABLE_FLAG_NOINIT (unsigned int)0x0001 1300Sstevel@tonic-gate 1310Sstevel@tonic-gate /* ENGINE flags that can be set by ENGINE_set_flags(). */ 1320Sstevel@tonic-gate /* #define ENGINE_FLAGS_MALLOCED 0x0001 */ /* Not used */ 1330Sstevel@tonic-gate 1340Sstevel@tonic-gate /* This flag is for ENGINEs that wish to handle the various 'CMD'-related 1350Sstevel@tonic-gate * control commands on their own. Without this flag, ENGINE_ctrl() handles these 1360Sstevel@tonic-gate * control commands on behalf of the ENGINE using their "cmd_defns" data. */ 1370Sstevel@tonic-gate #define ENGINE_FLAGS_MANUAL_CMD_CTRL (int)0x0002 1380Sstevel@tonic-gate 1390Sstevel@tonic-gate /* This flag is for ENGINEs who return new duplicate structures when found via 1400Sstevel@tonic-gate * "ENGINE_by_id()". When an ENGINE must store state (eg. if ENGINE_ctrl() 1410Sstevel@tonic-gate * commands are called in sequence as part of some stateful process like 1420Sstevel@tonic-gate * key-generation setup and execution), it can set this flag - then each attempt 1430Sstevel@tonic-gate * to obtain the ENGINE will result in it being copied into a new structure. 1440Sstevel@tonic-gate * Normally, ENGINEs don't declare this flag so ENGINE_by_id() just increments 1450Sstevel@tonic-gate * the existing ENGINE's structural reference count. */ 1460Sstevel@tonic-gate #define ENGINE_FLAGS_BY_ID_COPY (int)0x0004 1470Sstevel@tonic-gate 1480Sstevel@tonic-gate /* ENGINEs can support their own command types, and these flags are used in 1490Sstevel@tonic-gate * ENGINE_CTRL_GET_CMD_FLAGS to indicate to the caller what kind of input each 1500Sstevel@tonic-gate * command expects. Currently only numeric and string input is supported. If a 1510Sstevel@tonic-gate * control command supports none of the _NUMERIC, _STRING, or _NO_INPUT options, 1520Sstevel@tonic-gate * then it is regarded as an "internal" control command - and not for use in 1530Sstevel@tonic-gate * config setting situations. As such, they're not available to the 1540Sstevel@tonic-gate * ENGINE_ctrl_cmd_string() function, only raw ENGINE_ctrl() access. Changes to 1550Sstevel@tonic-gate * this list of 'command types' should be reflected carefully in 1560Sstevel@tonic-gate * ENGINE_cmd_is_executable() and ENGINE_ctrl_cmd_string(). */ 1570Sstevel@tonic-gate 1580Sstevel@tonic-gate /* accepts a 'long' input value (3rd parameter to ENGINE_ctrl) */ 1590Sstevel@tonic-gate #define ENGINE_CMD_FLAG_NUMERIC (unsigned int)0x0001 1600Sstevel@tonic-gate /* accepts string input (cast from 'void*' to 'const char *', 4th parameter to 1610Sstevel@tonic-gate * ENGINE_ctrl) */ 1620Sstevel@tonic-gate #define ENGINE_CMD_FLAG_STRING (unsigned int)0x0002 1630Sstevel@tonic-gate /* Indicates that the control command takes *no* input. Ie. the control command 1640Sstevel@tonic-gate * is unparameterised. */ 1650Sstevel@tonic-gate #define ENGINE_CMD_FLAG_NO_INPUT (unsigned int)0x0004 1660Sstevel@tonic-gate /* Indicates that the control command is internal. This control command won't 1670Sstevel@tonic-gate * be shown in any output, and is only usable through the ENGINE_ctrl_cmd() 1680Sstevel@tonic-gate * function. */ 1690Sstevel@tonic-gate #define ENGINE_CMD_FLAG_INTERNAL (unsigned int)0x0008 1700Sstevel@tonic-gate 1710Sstevel@tonic-gate /* NB: These 3 control commands are deprecated and should not be used. ENGINEs 1720Sstevel@tonic-gate * relying on these commands should compile conditional support for 1730Sstevel@tonic-gate * compatibility (eg. if these symbols are defined) but should also migrate the 1740Sstevel@tonic-gate * same functionality to their own ENGINE-specific control functions that can be 1750Sstevel@tonic-gate * "discovered" by calling applications. The fact these control commands 1760Sstevel@tonic-gate * wouldn't be "executable" (ie. usable by text-based config) doesn't change the 1770Sstevel@tonic-gate * fact that application code can find and use them without requiring per-ENGINE 1780Sstevel@tonic-gate * hacking. */ 1790Sstevel@tonic-gate 1800Sstevel@tonic-gate /* These flags are used to tell the ctrl function what should be done. 1810Sstevel@tonic-gate * All command numbers are shared between all engines, even if some don't 1820Sstevel@tonic-gate * make sense to some engines. In such a case, they do nothing but return 1830Sstevel@tonic-gate * the error ENGINE_R_CTRL_COMMAND_NOT_IMPLEMENTED. */ 1840Sstevel@tonic-gate #define ENGINE_CTRL_SET_LOGSTREAM 1 1850Sstevel@tonic-gate #define ENGINE_CTRL_SET_PASSWORD_CALLBACK 2 1860Sstevel@tonic-gate #define ENGINE_CTRL_HUP 3 /* Close and reinitialise any 1870Sstevel@tonic-gate handles/connections etc. */ 1880Sstevel@tonic-gate #define ENGINE_CTRL_SET_USER_INTERFACE 4 /* Alternative to callback */ 1890Sstevel@tonic-gate #define ENGINE_CTRL_SET_CALLBACK_DATA 5 /* User-specific data, used 190*2139Sjp161948 when calling the password 191*2139Sjp161948 callback and the user 192*2139Sjp161948 interface */ 193*2139Sjp161948 #define ENGINE_CTRL_LOAD_CONFIGURATION 6 /* Load a configuration, given 194*2139Sjp161948 a string that represents a 195*2139Sjp161948 file name or so */ 196*2139Sjp161948 #define ENGINE_CTRL_LOAD_SECTION 7 /* Load data from a given 197*2139Sjp161948 section in the already loaded 198*2139Sjp161948 configuration */ 1990Sstevel@tonic-gate 2000Sstevel@tonic-gate /* These control commands allow an application to deal with an arbitrary engine 2010Sstevel@tonic-gate * in a dynamic way. Warn: Negative return values indicate errors FOR THESE 2020Sstevel@tonic-gate * COMMANDS because zero is used to indicate 'end-of-list'. Other commands, 2030Sstevel@tonic-gate * including ENGINE-specific command types, return zero for an error. 2040Sstevel@tonic-gate * 2050Sstevel@tonic-gate * An ENGINE can choose to implement these ctrl functions, and can internally 2060Sstevel@tonic-gate * manage things however it chooses - it does so by setting the 2070Sstevel@tonic-gate * ENGINE_FLAGS_MANUAL_CMD_CTRL flag (using ENGINE_set_flags()). Otherwise the 2080Sstevel@tonic-gate * ENGINE_ctrl() code handles this on the ENGINE's behalf using the cmd_defns 2090Sstevel@tonic-gate * data (set using ENGINE_set_cmd_defns()). This means an ENGINE's ctrl() 2100Sstevel@tonic-gate * handler need only implement its own commands - the above "meta" commands will 2110Sstevel@tonic-gate * be taken care of. */ 2120Sstevel@tonic-gate 2130Sstevel@tonic-gate /* Returns non-zero if the supplied ENGINE has a ctrl() handler. If "not", then 2140Sstevel@tonic-gate * all the remaining control commands will return failure, so it is worth 2150Sstevel@tonic-gate * checking this first if the caller is trying to "discover" the engine's 2160Sstevel@tonic-gate * capabilities and doesn't want errors generated unnecessarily. */ 2170Sstevel@tonic-gate #define ENGINE_CTRL_HAS_CTRL_FUNCTION 10 2180Sstevel@tonic-gate /* Returns a positive command number for the first command supported by the 2190Sstevel@tonic-gate * engine. Returns zero if no ctrl commands are supported. */ 2200Sstevel@tonic-gate #define ENGINE_CTRL_GET_FIRST_CMD_TYPE 11 2210Sstevel@tonic-gate /* The 'long' argument specifies a command implemented by the engine, and the 2220Sstevel@tonic-gate * return value is the next command supported, or zero if there are no more. */ 2230Sstevel@tonic-gate #define ENGINE_CTRL_GET_NEXT_CMD_TYPE 12 2240Sstevel@tonic-gate /* The 'void*' argument is a command name (cast from 'const char *'), and the 2250Sstevel@tonic-gate * return value is the command that corresponds to it. */ 2260Sstevel@tonic-gate #define ENGINE_CTRL_GET_CMD_FROM_NAME 13 2270Sstevel@tonic-gate /* The next two allow a command to be converted into its corresponding string 2280Sstevel@tonic-gate * form. In each case, the 'long' argument supplies the command. In the NAME_LEN 2290Sstevel@tonic-gate * case, the return value is the length of the command name (not counting a 2300Sstevel@tonic-gate * trailing EOL). In the NAME case, the 'void*' argument must be a string buffer 2310Sstevel@tonic-gate * large enough, and it will be populated with the name of the command (WITH a 2320Sstevel@tonic-gate * trailing EOL). */ 2330Sstevel@tonic-gate #define ENGINE_CTRL_GET_NAME_LEN_FROM_CMD 14 2340Sstevel@tonic-gate #define ENGINE_CTRL_GET_NAME_FROM_CMD 15 2350Sstevel@tonic-gate /* The next two are similar but give a "short description" of a command. */ 2360Sstevel@tonic-gate #define ENGINE_CTRL_GET_DESC_LEN_FROM_CMD 16 2370Sstevel@tonic-gate #define ENGINE_CTRL_GET_DESC_FROM_CMD 17 2380Sstevel@tonic-gate /* With this command, the return value is the OR'd combination of 2390Sstevel@tonic-gate * ENGINE_CMD_FLAG_*** values that indicate what kind of input a given 2400Sstevel@tonic-gate * engine-specific ctrl command expects. */ 2410Sstevel@tonic-gate #define ENGINE_CTRL_GET_CMD_FLAGS 18 2420Sstevel@tonic-gate 2430Sstevel@tonic-gate /* ENGINE implementations should start the numbering of their own control 2440Sstevel@tonic-gate * commands from this value. (ie. ENGINE_CMD_BASE, ENGINE_CMD_BASE + 1, etc). */ 245*2139Sjp161948 #define ENGINE_CMD_BASE 200 2460Sstevel@tonic-gate 2470Sstevel@tonic-gate /* NB: These 2 nCipher "chil" control commands are deprecated, and their 2480Sstevel@tonic-gate * functionality is now available through ENGINE-specific control commands 2490Sstevel@tonic-gate * (exposed through the above-mentioned 'CMD'-handling). Code using these 2 2500Sstevel@tonic-gate * commands should be migrated to the more general command handling before these 2510Sstevel@tonic-gate * are removed. */ 2520Sstevel@tonic-gate 2530Sstevel@tonic-gate /* Flags specific to the nCipher "chil" engine */ 2540Sstevel@tonic-gate #define ENGINE_CTRL_CHIL_SET_FORKCHECK 100 2550Sstevel@tonic-gate /* Depending on the value of the (long)i argument, this sets or 2560Sstevel@tonic-gate * unsets the SimpleForkCheck flag in the CHIL API to enable or 2570Sstevel@tonic-gate * disable checking and workarounds for applications that fork(). 2580Sstevel@tonic-gate */ 2590Sstevel@tonic-gate #define ENGINE_CTRL_CHIL_NO_LOCKING 101 2600Sstevel@tonic-gate /* This prevents the initialisation function from providing mutex 2610Sstevel@tonic-gate * callbacks to the nCipher library. */ 2620Sstevel@tonic-gate 2630Sstevel@tonic-gate /* If an ENGINE supports its own specific control commands and wishes the 2640Sstevel@tonic-gate * framework to handle the above 'ENGINE_CMD_***'-manipulation commands on its 2650Sstevel@tonic-gate * behalf, it should supply a null-terminated array of ENGINE_CMD_DEFN entries 2660Sstevel@tonic-gate * to ENGINE_set_cmd_defns(). It should also implement a ctrl() handler that 2670Sstevel@tonic-gate * supports the stated commands (ie. the "cmd_num" entries as described by the 2680Sstevel@tonic-gate * array). NB: The array must be ordered in increasing order of cmd_num. 2690Sstevel@tonic-gate * "null-terminated" means that the last ENGINE_CMD_DEFN element has cmd_num set 2700Sstevel@tonic-gate * to zero and/or cmd_name set to NULL. */ 2710Sstevel@tonic-gate typedef struct ENGINE_CMD_DEFN_st 2720Sstevel@tonic-gate { 2730Sstevel@tonic-gate unsigned int cmd_num; /* The command number */ 2740Sstevel@tonic-gate const char *cmd_name; /* The command name itself */ 2750Sstevel@tonic-gate const char *cmd_desc; /* A short description of the command */ 2760Sstevel@tonic-gate unsigned int cmd_flags; /* The input the command expects */ 2770Sstevel@tonic-gate } ENGINE_CMD_DEFN; 2780Sstevel@tonic-gate 2790Sstevel@tonic-gate /* Generic function pointer */ 280*2139Sjp161948 typedef int (*ENGINE_GEN_FUNC_PTR)(void); 2810Sstevel@tonic-gate /* Generic function pointer taking no arguments */ 2820Sstevel@tonic-gate typedef int (*ENGINE_GEN_INT_FUNC_PTR)(ENGINE *); 2830Sstevel@tonic-gate /* Specific control function pointer */ 284*2139Sjp161948 typedef int (*ENGINE_CTRL_FUNC_PTR)(ENGINE *, int, long, void *, void (*f)(void)); 2850Sstevel@tonic-gate /* Generic load_key function pointer */ 2860Sstevel@tonic-gate typedef EVP_PKEY * (*ENGINE_LOAD_KEY_PTR)(ENGINE *, const char *, 2870Sstevel@tonic-gate UI_METHOD *ui_method, void *callback_data); 2880Sstevel@tonic-gate /* These callback types are for an ENGINE's handler for cipher and digest logic. 2890Sstevel@tonic-gate * These handlers have these prototypes; 2900Sstevel@tonic-gate * int foo(ENGINE *e, const EVP_CIPHER **cipher, const int **nids, int nid); 2910Sstevel@tonic-gate * int foo(ENGINE *e, const EVP_MD **digest, const int **nids, int nid); 2920Sstevel@tonic-gate * Looking at how to implement these handlers in the case of cipher support, if 2930Sstevel@tonic-gate * the framework wants the EVP_CIPHER for 'nid', it will call; 2940Sstevel@tonic-gate * foo(e, &p_evp_cipher, NULL, nid); (return zero for failure) 2950Sstevel@tonic-gate * If the framework wants a list of supported 'nid's, it will call; 2960Sstevel@tonic-gate * foo(e, NULL, &p_nids, 0); (returns number of 'nids' or -1 for error) 2970Sstevel@tonic-gate */ 2980Sstevel@tonic-gate /* Returns to a pointer to the array of supported cipher 'nid's. If the second 2990Sstevel@tonic-gate * parameter is non-NULL it is set to the size of the returned array. */ 3000Sstevel@tonic-gate typedef int (*ENGINE_CIPHERS_PTR)(ENGINE *, const EVP_CIPHER **, const int **, int); 3010Sstevel@tonic-gate typedef int (*ENGINE_DIGESTS_PTR)(ENGINE *, const EVP_MD **, const int **, int); 3020Sstevel@tonic-gate 3030Sstevel@tonic-gate /* STRUCTURE functions ... all of these functions deal with pointers to ENGINE 3040Sstevel@tonic-gate * structures where the pointers have a "structural reference". This means that 3050Sstevel@tonic-gate * their reference is to allowed access to the structure but it does not imply 3060Sstevel@tonic-gate * that the structure is functional. To simply increment or decrement the 3070Sstevel@tonic-gate * structural reference count, use ENGINE_by_id and ENGINE_free. NB: This is not 3080Sstevel@tonic-gate * required when iterating using ENGINE_get_next as it will automatically 3090Sstevel@tonic-gate * decrement the structural reference count of the "current" ENGINE and 3100Sstevel@tonic-gate * increment the structural reference count of the ENGINE it returns (unless it 3110Sstevel@tonic-gate * is NULL). */ 3120Sstevel@tonic-gate 3130Sstevel@tonic-gate /* Get the first/last "ENGINE" type available. */ 3140Sstevel@tonic-gate ENGINE *ENGINE_get_first(void); 3150Sstevel@tonic-gate ENGINE *ENGINE_get_last(void); 3160Sstevel@tonic-gate /* Iterate to the next/previous "ENGINE" type (NULL = end of the list). */ 3170Sstevel@tonic-gate ENGINE *ENGINE_get_next(ENGINE *e); 3180Sstevel@tonic-gate ENGINE *ENGINE_get_prev(ENGINE *e); 3190Sstevel@tonic-gate /* Add another "ENGINE" type into the array. */ 3200Sstevel@tonic-gate int ENGINE_add(ENGINE *e); 3210Sstevel@tonic-gate /* Remove an existing "ENGINE" type from the array. */ 3220Sstevel@tonic-gate int ENGINE_remove(ENGINE *e); 3230Sstevel@tonic-gate /* Retrieve an engine from the list by its unique "id" value. */ 3240Sstevel@tonic-gate ENGINE *ENGINE_by_id(const char *id); 3250Sstevel@tonic-gate /* Add all the built-in engines. */ 3260Sstevel@tonic-gate void ENGINE_load_openssl(void); 3270Sstevel@tonic-gate void ENGINE_load_dynamic(void); 328*2139Sjp161948 #ifndef OPENSSL_NO_STATIC_ENGINE 329*2139Sjp161948 void ENGINE_load_4758cca(void); 330*2139Sjp161948 void ENGINE_load_aep(void); 331*2139Sjp161948 void ENGINE_load_atalla(void); 3320Sstevel@tonic-gate void ENGINE_load_chil(void); 333*2139Sjp161948 void ENGINE_load_cswift(void); 334*2139Sjp161948 #ifndef OPENSSL_NO_GMP 335*2139Sjp161948 void ENGINE_load_gmp(void); 336*2139Sjp161948 #endif 3370Sstevel@tonic-gate void ENGINE_load_nuron(void); 338*2139Sjp161948 void ENGINE_load_sureware(void); 3390Sstevel@tonic-gate void ENGINE_load_ubsec(void); 340*2139Sjp161948 #endif 3410Sstevel@tonic-gate void ENGINE_load_cryptodev(void); 3420Sstevel@tonic-gate void ENGINE_load_pk11(void); 343*2139Sjp161948 void ENGINE_load_padlock(void); 3440Sstevel@tonic-gate void ENGINE_load_builtin_engines(void); 3450Sstevel@tonic-gate 3460Sstevel@tonic-gate /* Get and set global flags (ENGINE_TABLE_FLAG_***) for the implementation 3470Sstevel@tonic-gate * "registry" handling. */ 3480Sstevel@tonic-gate unsigned int ENGINE_get_table_flags(void); 3490Sstevel@tonic-gate void ENGINE_set_table_flags(unsigned int flags); 3500Sstevel@tonic-gate 3510Sstevel@tonic-gate /* Manage registration of ENGINEs per "table". For each type, there are 3 3520Sstevel@tonic-gate * functions; 3530Sstevel@tonic-gate * ENGINE_register_***(e) - registers the implementation from 'e' (if it has one) 3540Sstevel@tonic-gate * ENGINE_unregister_***(e) - unregister the implementation from 'e' 3550Sstevel@tonic-gate * ENGINE_register_all_***() - call ENGINE_register_***() for each 'e' in the list 3560Sstevel@tonic-gate * Cleanup is automatically registered from each table when required, so 3570Sstevel@tonic-gate * ENGINE_cleanup() will reverse any "register" operations. */ 3580Sstevel@tonic-gate 3590Sstevel@tonic-gate int ENGINE_register_RSA(ENGINE *e); 3600Sstevel@tonic-gate void ENGINE_unregister_RSA(ENGINE *e); 3610Sstevel@tonic-gate void ENGINE_register_all_RSA(void); 3620Sstevel@tonic-gate 3630Sstevel@tonic-gate int ENGINE_register_DSA(ENGINE *e); 3640Sstevel@tonic-gate void ENGINE_unregister_DSA(ENGINE *e); 3650Sstevel@tonic-gate void ENGINE_register_all_DSA(void); 3660Sstevel@tonic-gate 367*2139Sjp161948 int ENGINE_register_ECDH(ENGINE *e); 368*2139Sjp161948 void ENGINE_unregister_ECDH(ENGINE *e); 369*2139Sjp161948 void ENGINE_register_all_ECDH(void); 370*2139Sjp161948 371*2139Sjp161948 int ENGINE_register_ECDSA(ENGINE *e); 372*2139Sjp161948 void ENGINE_unregister_ECDSA(ENGINE *e); 373*2139Sjp161948 void ENGINE_register_all_ECDSA(void); 374*2139Sjp161948 3750Sstevel@tonic-gate int ENGINE_register_DH(ENGINE *e); 3760Sstevel@tonic-gate void ENGINE_unregister_DH(ENGINE *e); 3770Sstevel@tonic-gate void ENGINE_register_all_DH(void); 3780Sstevel@tonic-gate 3790Sstevel@tonic-gate int ENGINE_register_RAND(ENGINE *e); 3800Sstevel@tonic-gate void ENGINE_unregister_RAND(ENGINE *e); 3810Sstevel@tonic-gate void ENGINE_register_all_RAND(void); 3820Sstevel@tonic-gate 383*2139Sjp161948 int ENGINE_register_STORE(ENGINE *e); 384*2139Sjp161948 void ENGINE_unregister_STORE(ENGINE *e); 385*2139Sjp161948 void ENGINE_register_all_STORE(void); 386*2139Sjp161948 3870Sstevel@tonic-gate int ENGINE_register_ciphers(ENGINE *e); 3880Sstevel@tonic-gate void ENGINE_unregister_ciphers(ENGINE *e); 3890Sstevel@tonic-gate void ENGINE_register_all_ciphers(void); 3900Sstevel@tonic-gate 3910Sstevel@tonic-gate int ENGINE_register_digests(ENGINE *e); 3920Sstevel@tonic-gate void ENGINE_unregister_digests(ENGINE *e); 3930Sstevel@tonic-gate void ENGINE_register_all_digests(void); 3940Sstevel@tonic-gate 3950Sstevel@tonic-gate /* These functions register all support from the above categories. Note, use of 3960Sstevel@tonic-gate * these functions can result in static linkage of code your application may not 3970Sstevel@tonic-gate * need. If you only need a subset of functionality, consider using more 3980Sstevel@tonic-gate * selective initialisation. */ 3990Sstevel@tonic-gate int ENGINE_register_complete(ENGINE *e); 4000Sstevel@tonic-gate int ENGINE_register_all_complete(void); 4010Sstevel@tonic-gate 4020Sstevel@tonic-gate /* Send parametrised control commands to the engine. The possibilities to send 4030Sstevel@tonic-gate * down an integer, a pointer to data or a function pointer are provided. Any of 4040Sstevel@tonic-gate * the parameters may or may not be NULL, depending on the command number. In 4050Sstevel@tonic-gate * actuality, this function only requires a structural (rather than functional) 4060Sstevel@tonic-gate * reference to an engine, but many control commands may require the engine be 4070Sstevel@tonic-gate * functional. The caller should be aware of trying commands that require an 4080Sstevel@tonic-gate * operational ENGINE, and only use functional references in such situations. */ 409*2139Sjp161948 int ENGINE_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void)); 4100Sstevel@tonic-gate 4110Sstevel@tonic-gate /* This function tests if an ENGINE-specific command is usable as a "setting". 4120Sstevel@tonic-gate * Eg. in an application's config file that gets processed through 4130Sstevel@tonic-gate * ENGINE_ctrl_cmd_string(). If this returns zero, it is not available to 4140Sstevel@tonic-gate * ENGINE_ctrl_cmd_string(), only ENGINE_ctrl(). */ 4150Sstevel@tonic-gate int ENGINE_cmd_is_executable(ENGINE *e, int cmd); 4160Sstevel@tonic-gate 4170Sstevel@tonic-gate /* This function works like ENGINE_ctrl() with the exception of taking a 4180Sstevel@tonic-gate * command name instead of a command number, and can handle optional commands. 4190Sstevel@tonic-gate * See the comment on ENGINE_ctrl_cmd_string() for an explanation on how to 4200Sstevel@tonic-gate * use the cmd_name and cmd_optional. */ 4210Sstevel@tonic-gate int ENGINE_ctrl_cmd(ENGINE *e, const char *cmd_name, 422*2139Sjp161948 long i, void *p, void (*f)(void), int cmd_optional); 4230Sstevel@tonic-gate 4240Sstevel@tonic-gate /* This function passes a command-name and argument to an ENGINE. The cmd_name 4250Sstevel@tonic-gate * is converted to a command number and the control command is called using 4260Sstevel@tonic-gate * 'arg' as an argument (unless the ENGINE doesn't support such a command, in 4270Sstevel@tonic-gate * which case no control command is called). The command is checked for input 4280Sstevel@tonic-gate * flags, and if necessary the argument will be converted to a numeric value. If 4290Sstevel@tonic-gate * cmd_optional is non-zero, then if the ENGINE doesn't support the given 4300Sstevel@tonic-gate * cmd_name the return value will be success anyway. This function is intended 4310Sstevel@tonic-gate * for applications to use so that users (or config files) can supply 4320Sstevel@tonic-gate * engine-specific config data to the ENGINE at run-time to control behaviour of 4330Sstevel@tonic-gate * specific engines. As such, it shouldn't be used for calling ENGINE_ctrl() 4340Sstevel@tonic-gate * functions that return data, deal with binary data, or that are otherwise 4350Sstevel@tonic-gate * supposed to be used directly through ENGINE_ctrl() in application code. Any 4360Sstevel@tonic-gate * "return" data from an ENGINE_ctrl() operation in this function will be lost - 4370Sstevel@tonic-gate * the return value is interpreted as failure if the return value is zero, 4380Sstevel@tonic-gate * success otherwise, and this function returns a boolean value as a result. In 4390Sstevel@tonic-gate * other words, vendors of 'ENGINE'-enabled devices should write ENGINE 4400Sstevel@tonic-gate * implementations with parameterisations that work in this scheme, so that 4410Sstevel@tonic-gate * compliant ENGINE-based applications can work consistently with the same 4420Sstevel@tonic-gate * configuration for the same ENGINE-enabled devices, across applications. */ 4430Sstevel@tonic-gate int ENGINE_ctrl_cmd_string(ENGINE *e, const char *cmd_name, const char *arg, 4440Sstevel@tonic-gate int cmd_optional); 4450Sstevel@tonic-gate 4460Sstevel@tonic-gate /* These functions are useful for manufacturing new ENGINE structures. They 4470Sstevel@tonic-gate * don't address reference counting at all - one uses them to populate an ENGINE 4480Sstevel@tonic-gate * structure with personalised implementations of things prior to using it 4490Sstevel@tonic-gate * directly or adding it to the builtin ENGINE list in OpenSSL. These are also 4500Sstevel@tonic-gate * here so that the ENGINE structure doesn't have to be exposed and break binary 4510Sstevel@tonic-gate * compatibility! */ 4520Sstevel@tonic-gate ENGINE *ENGINE_new(void); 4530Sstevel@tonic-gate int ENGINE_free(ENGINE *e); 4540Sstevel@tonic-gate int ENGINE_up_ref(ENGINE *e); 4550Sstevel@tonic-gate int ENGINE_set_id(ENGINE *e, const char *id); 4560Sstevel@tonic-gate int ENGINE_set_name(ENGINE *e, const char *name); 4570Sstevel@tonic-gate int ENGINE_set_RSA(ENGINE *e, const RSA_METHOD *rsa_meth); 4580Sstevel@tonic-gate int ENGINE_set_DSA(ENGINE *e, const DSA_METHOD *dsa_meth); 459*2139Sjp161948 int ENGINE_set_ECDH(ENGINE *e, const ECDH_METHOD *ecdh_meth); 460*2139Sjp161948 int ENGINE_set_ECDSA(ENGINE *e, const ECDSA_METHOD *ecdsa_meth); 4610Sstevel@tonic-gate int ENGINE_set_DH(ENGINE *e, const DH_METHOD *dh_meth); 4620Sstevel@tonic-gate int ENGINE_set_RAND(ENGINE *e, const RAND_METHOD *rand_meth); 463*2139Sjp161948 int ENGINE_set_STORE(ENGINE *e, const STORE_METHOD *store_meth); 4640Sstevel@tonic-gate int ENGINE_set_destroy_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR destroy_f); 4650Sstevel@tonic-gate int ENGINE_set_init_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR init_f); 4660Sstevel@tonic-gate int ENGINE_set_finish_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR finish_f); 4670Sstevel@tonic-gate int ENGINE_set_ctrl_function(ENGINE *e, ENGINE_CTRL_FUNC_PTR ctrl_f); 4680Sstevel@tonic-gate int ENGINE_set_load_privkey_function(ENGINE *e, ENGINE_LOAD_KEY_PTR loadpriv_f); 4690Sstevel@tonic-gate int ENGINE_set_load_pubkey_function(ENGINE *e, ENGINE_LOAD_KEY_PTR loadpub_f); 4700Sstevel@tonic-gate int ENGINE_set_ciphers(ENGINE *e, ENGINE_CIPHERS_PTR f); 4710Sstevel@tonic-gate int ENGINE_set_digests(ENGINE *e, ENGINE_DIGESTS_PTR f); 4720Sstevel@tonic-gate int ENGINE_set_flags(ENGINE *e, int flags); 4730Sstevel@tonic-gate int ENGINE_set_cmd_defns(ENGINE *e, const ENGINE_CMD_DEFN *defns); 474*2139Sjp161948 /* These functions allow control over any per-structure ENGINE data. */ 4750Sstevel@tonic-gate int ENGINE_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, 4760Sstevel@tonic-gate CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func); 4770Sstevel@tonic-gate int ENGINE_set_ex_data(ENGINE *e, int idx, void *arg); 478*2139Sjp161948 void *ENGINE_get_ex_data(const ENGINE *e, int idx); 4790Sstevel@tonic-gate 4800Sstevel@tonic-gate /* This function cleans up anything that needs it. Eg. the ENGINE_add() function 4810Sstevel@tonic-gate * automatically ensures the list cleanup function is registered to be called 4820Sstevel@tonic-gate * from ENGINE_cleanup(). Similarly, all ENGINE_register_*** functions ensure 4830Sstevel@tonic-gate * ENGINE_cleanup() will clean up after them. */ 4840Sstevel@tonic-gate void ENGINE_cleanup(void); 4850Sstevel@tonic-gate 4860Sstevel@tonic-gate /* These return values from within the ENGINE structure. These can be useful 4870Sstevel@tonic-gate * with functional references as well as structural references - it depends 4880Sstevel@tonic-gate * which you obtained. Using the result for functional purposes if you only 4890Sstevel@tonic-gate * obtained a structural reference may be problematic! */ 4900Sstevel@tonic-gate const char *ENGINE_get_id(const ENGINE *e); 4910Sstevel@tonic-gate const char *ENGINE_get_name(const ENGINE *e); 4920Sstevel@tonic-gate const RSA_METHOD *ENGINE_get_RSA(const ENGINE *e); 4930Sstevel@tonic-gate const DSA_METHOD *ENGINE_get_DSA(const ENGINE *e); 494*2139Sjp161948 const ECDH_METHOD *ENGINE_get_ECDH(const ENGINE *e); 495*2139Sjp161948 const ECDSA_METHOD *ENGINE_get_ECDSA(const ENGINE *e); 4960Sstevel@tonic-gate const DH_METHOD *ENGINE_get_DH(const ENGINE *e); 4970Sstevel@tonic-gate const RAND_METHOD *ENGINE_get_RAND(const ENGINE *e); 498*2139Sjp161948 const STORE_METHOD *ENGINE_get_STORE(const ENGINE *e); 4990Sstevel@tonic-gate ENGINE_GEN_INT_FUNC_PTR ENGINE_get_destroy_function(const ENGINE *e); 5000Sstevel@tonic-gate ENGINE_GEN_INT_FUNC_PTR ENGINE_get_init_function(const ENGINE *e); 5010Sstevel@tonic-gate ENGINE_GEN_INT_FUNC_PTR ENGINE_get_finish_function(const ENGINE *e); 5020Sstevel@tonic-gate ENGINE_CTRL_FUNC_PTR ENGINE_get_ctrl_function(const ENGINE *e); 5030Sstevel@tonic-gate ENGINE_LOAD_KEY_PTR ENGINE_get_load_privkey_function(const ENGINE *e); 5040Sstevel@tonic-gate ENGINE_LOAD_KEY_PTR ENGINE_get_load_pubkey_function(const ENGINE *e); 5050Sstevel@tonic-gate ENGINE_CIPHERS_PTR ENGINE_get_ciphers(const ENGINE *e); 5060Sstevel@tonic-gate ENGINE_DIGESTS_PTR ENGINE_get_digests(const ENGINE *e); 5070Sstevel@tonic-gate const EVP_CIPHER *ENGINE_get_cipher(ENGINE *e, int nid); 5080Sstevel@tonic-gate const EVP_MD *ENGINE_get_digest(ENGINE *e, int nid); 5090Sstevel@tonic-gate const ENGINE_CMD_DEFN *ENGINE_get_cmd_defns(const ENGINE *e); 5100Sstevel@tonic-gate int ENGINE_get_flags(const ENGINE *e); 5110Sstevel@tonic-gate 5120Sstevel@tonic-gate /* FUNCTIONAL functions. These functions deal with ENGINE structures 5130Sstevel@tonic-gate * that have (or will) be initialised for use. Broadly speaking, the 5140Sstevel@tonic-gate * structural functions are useful for iterating the list of available 5150Sstevel@tonic-gate * engine types, creating new engine types, and other "list" operations. 5160Sstevel@tonic-gate * These functions actually deal with ENGINEs that are to be used. As 5170Sstevel@tonic-gate * such these functions can fail (if applicable) when particular 5180Sstevel@tonic-gate * engines are unavailable - eg. if a hardware accelerator is not 5190Sstevel@tonic-gate * attached or not functioning correctly. Each ENGINE has 2 reference 5200Sstevel@tonic-gate * counts; structural and functional. Every time a functional reference 5210Sstevel@tonic-gate * is obtained or released, a corresponding structural reference is 5220Sstevel@tonic-gate * automatically obtained or released too. */ 5230Sstevel@tonic-gate 5240Sstevel@tonic-gate /* Initialise a engine type for use (or up its reference count if it's 5250Sstevel@tonic-gate * already in use). This will fail if the engine is not currently 5260Sstevel@tonic-gate * operational and cannot initialise. */ 5270Sstevel@tonic-gate int ENGINE_init(ENGINE *e); 5280Sstevel@tonic-gate /* Free a functional reference to a engine type. This does not require 5290Sstevel@tonic-gate * a corresponding call to ENGINE_free as it also releases a structural 5300Sstevel@tonic-gate * reference. */ 5310Sstevel@tonic-gate int ENGINE_finish(ENGINE *e); 5320Sstevel@tonic-gate 5330Sstevel@tonic-gate /* The following functions handle keys that are stored in some secondary 5340Sstevel@tonic-gate * location, handled by the engine. The storage may be on a card or 5350Sstevel@tonic-gate * whatever. */ 5360Sstevel@tonic-gate EVP_PKEY *ENGINE_load_private_key(ENGINE *e, const char *key_id, 5370Sstevel@tonic-gate UI_METHOD *ui_method, void *callback_data); 5380Sstevel@tonic-gate EVP_PKEY *ENGINE_load_public_key(ENGINE *e, const char *key_id, 5390Sstevel@tonic-gate UI_METHOD *ui_method, void *callback_data); 5400Sstevel@tonic-gate 5410Sstevel@tonic-gate /* This returns a pointer for the current ENGINE structure that 5420Sstevel@tonic-gate * is (by default) performing any RSA operations. The value returned 5430Sstevel@tonic-gate * is an incremented reference, so it should be free'd (ENGINE_finish) 5440Sstevel@tonic-gate * before it is discarded. */ 5450Sstevel@tonic-gate ENGINE *ENGINE_get_default_RSA(void); 5460Sstevel@tonic-gate /* Same for the other "methods" */ 5470Sstevel@tonic-gate ENGINE *ENGINE_get_default_DSA(void); 548*2139Sjp161948 ENGINE *ENGINE_get_default_ECDH(void); 549*2139Sjp161948 ENGINE *ENGINE_get_default_ECDSA(void); 5500Sstevel@tonic-gate ENGINE *ENGINE_get_default_DH(void); 5510Sstevel@tonic-gate ENGINE *ENGINE_get_default_RAND(void); 5520Sstevel@tonic-gate /* These functions can be used to get a functional reference to perform 5530Sstevel@tonic-gate * ciphering or digesting corresponding to "nid". */ 5540Sstevel@tonic-gate ENGINE *ENGINE_get_cipher_engine(int nid); 5550Sstevel@tonic-gate ENGINE *ENGINE_get_digest_engine(int nid); 5560Sstevel@tonic-gate 5570Sstevel@tonic-gate /* This sets a new default ENGINE structure for performing RSA 5580Sstevel@tonic-gate * operations. If the result is non-zero (success) then the ENGINE 5590Sstevel@tonic-gate * structure will have had its reference count up'd so the caller 5600Sstevel@tonic-gate * should still free their own reference 'e'. */ 5610Sstevel@tonic-gate int ENGINE_set_default_RSA(ENGINE *e); 5620Sstevel@tonic-gate int ENGINE_set_default_string(ENGINE *e, const char *def_list); 5630Sstevel@tonic-gate /* Same for the other "methods" */ 5640Sstevel@tonic-gate int ENGINE_set_default_DSA(ENGINE *e); 565*2139Sjp161948 int ENGINE_set_default_ECDH(ENGINE *e); 566*2139Sjp161948 int ENGINE_set_default_ECDSA(ENGINE *e); 5670Sstevel@tonic-gate int ENGINE_set_default_DH(ENGINE *e); 5680Sstevel@tonic-gate int ENGINE_set_default_RAND(ENGINE *e); 5690Sstevel@tonic-gate int ENGINE_set_default_ciphers(ENGINE *e); 5700Sstevel@tonic-gate int ENGINE_set_default_digests(ENGINE *e); 5710Sstevel@tonic-gate 5720Sstevel@tonic-gate /* The combination "set" - the flags are bitwise "OR"d from the 5730Sstevel@tonic-gate * ENGINE_METHOD_*** defines above. As with the "ENGINE_register_complete()" 5740Sstevel@tonic-gate * function, this function can result in unnecessary static linkage. If your 5750Sstevel@tonic-gate * application requires only specific functionality, consider using more 5760Sstevel@tonic-gate * selective functions. */ 5770Sstevel@tonic-gate int ENGINE_set_default(ENGINE *e, unsigned int flags); 5780Sstevel@tonic-gate 5790Sstevel@tonic-gate void ENGINE_add_conf_module(void); 5800Sstevel@tonic-gate 5810Sstevel@tonic-gate /* Deprecated functions ... */ 5820Sstevel@tonic-gate /* int ENGINE_clear_defaults(void); */ 5830Sstevel@tonic-gate 5840Sstevel@tonic-gate /**************************/ 5850Sstevel@tonic-gate /* DYNAMIC ENGINE SUPPORT */ 5860Sstevel@tonic-gate /**************************/ 5870Sstevel@tonic-gate 5880Sstevel@tonic-gate /* Binary/behaviour compatibility levels */ 589*2139Sjp161948 #define OSSL_DYNAMIC_VERSION (unsigned long)0x00020000 5900Sstevel@tonic-gate /* Binary versions older than this are too old for us (whether we're a loader or 5910Sstevel@tonic-gate * a loadee) */ 592*2139Sjp161948 #define OSSL_DYNAMIC_OLDEST (unsigned long)0x00020000 5930Sstevel@tonic-gate 5940Sstevel@tonic-gate /* When compiling an ENGINE entirely as an external shared library, loadable by 5950Sstevel@tonic-gate * the "dynamic" ENGINE, these types are needed. The 'dynamic_fns' structure 5960Sstevel@tonic-gate * type provides the calling application's (or library's) error functionality 5970Sstevel@tonic-gate * and memory management function pointers to the loaded library. These should 5980Sstevel@tonic-gate * be used/set in the loaded library code so that the loading application's 599*2139Sjp161948 * 'state' will be used/changed in all operations. The 'static_state' pointer 600*2139Sjp161948 * allows the loaded library to know if it shares the same static data as the 601*2139Sjp161948 * calling application (or library), and thus whether these callbacks need to be 602*2139Sjp161948 * set or not. */ 6030Sstevel@tonic-gate typedef void *(*dyn_MEM_malloc_cb)(size_t); 6040Sstevel@tonic-gate typedef void *(*dyn_MEM_realloc_cb)(void *, size_t); 6050Sstevel@tonic-gate typedef void (*dyn_MEM_free_cb)(void *); 6060Sstevel@tonic-gate typedef struct st_dynamic_MEM_fns { 6070Sstevel@tonic-gate dyn_MEM_malloc_cb malloc_cb; 6080Sstevel@tonic-gate dyn_MEM_realloc_cb realloc_cb; 6090Sstevel@tonic-gate dyn_MEM_free_cb free_cb; 6100Sstevel@tonic-gate } dynamic_MEM_fns; 6110Sstevel@tonic-gate /* FIXME: Perhaps the memory and locking code (crypto.h) should declare and use 6120Sstevel@tonic-gate * these types so we (and any other dependant code) can simplify a bit?? */ 6130Sstevel@tonic-gate typedef void (*dyn_lock_locking_cb)(int,int,const char *,int); 6140Sstevel@tonic-gate typedef int (*dyn_lock_add_lock_cb)(int*,int,int,const char *,int); 6150Sstevel@tonic-gate typedef struct CRYPTO_dynlock_value *(*dyn_dynlock_create_cb)( 6160Sstevel@tonic-gate const char *,int); 6170Sstevel@tonic-gate typedef void (*dyn_dynlock_lock_cb)(int,struct CRYPTO_dynlock_value *, 6180Sstevel@tonic-gate const char *,int); 6190Sstevel@tonic-gate typedef void (*dyn_dynlock_destroy_cb)(struct CRYPTO_dynlock_value *, 6200Sstevel@tonic-gate const char *,int); 6210Sstevel@tonic-gate typedef struct st_dynamic_LOCK_fns { 6220Sstevel@tonic-gate dyn_lock_locking_cb lock_locking_cb; 6230Sstevel@tonic-gate dyn_lock_add_lock_cb lock_add_lock_cb; 6240Sstevel@tonic-gate dyn_dynlock_create_cb dynlock_create_cb; 6250Sstevel@tonic-gate dyn_dynlock_lock_cb dynlock_lock_cb; 6260Sstevel@tonic-gate dyn_dynlock_destroy_cb dynlock_destroy_cb; 6270Sstevel@tonic-gate } dynamic_LOCK_fns; 6280Sstevel@tonic-gate /* The top-level structure */ 6290Sstevel@tonic-gate typedef struct st_dynamic_fns { 630*2139Sjp161948 void *static_state; 6310Sstevel@tonic-gate const ERR_FNS *err_fns; 6320Sstevel@tonic-gate const CRYPTO_EX_DATA_IMPL *ex_data_fns; 6330Sstevel@tonic-gate dynamic_MEM_fns mem_fns; 6340Sstevel@tonic-gate dynamic_LOCK_fns lock_fns; 6350Sstevel@tonic-gate } dynamic_fns; 6360Sstevel@tonic-gate 6370Sstevel@tonic-gate /* The version checking function should be of this prototype. NB: The 6380Sstevel@tonic-gate * ossl_version value passed in is the OSSL_DYNAMIC_VERSION of the loading code. 6390Sstevel@tonic-gate * If this function returns zero, it indicates a (potential) version 6400Sstevel@tonic-gate * incompatibility and the loaded library doesn't believe it can proceed. 6410Sstevel@tonic-gate * Otherwise, the returned value is the (latest) version supported by the 6420Sstevel@tonic-gate * loading library. The loader may still decide that the loaded code's version 6430Sstevel@tonic-gate * is unsatisfactory and could veto the load. The function is expected to 6440Sstevel@tonic-gate * be implemented with the symbol name "v_check", and a default implementation 6450Sstevel@tonic-gate * can be fully instantiated with IMPLEMENT_DYNAMIC_CHECK_FN(). */ 6460Sstevel@tonic-gate typedef unsigned long (*dynamic_v_check_fn)(unsigned long ossl_version); 6470Sstevel@tonic-gate #define IMPLEMENT_DYNAMIC_CHECK_FN() \ 6480Sstevel@tonic-gate unsigned long v_check(unsigned long v) { \ 6490Sstevel@tonic-gate if(v >= OSSL_DYNAMIC_OLDEST) return OSSL_DYNAMIC_VERSION; \ 6500Sstevel@tonic-gate return 0; } 6510Sstevel@tonic-gate 6520Sstevel@tonic-gate /* This function is passed the ENGINE structure to initialise with its own 6530Sstevel@tonic-gate * function and command settings. It should not adjust the structural or 6540Sstevel@tonic-gate * functional reference counts. If this function returns zero, (a) the load will 6550Sstevel@tonic-gate * be aborted, (b) the previous ENGINE state will be memcpy'd back onto the 6560Sstevel@tonic-gate * structure, and (c) the shared library will be unloaded. So implementations 6570Sstevel@tonic-gate * should do their own internal cleanup in failure circumstances otherwise they 6580Sstevel@tonic-gate * could leak. The 'id' parameter, if non-NULL, represents the ENGINE id that 6590Sstevel@tonic-gate * the loader is looking for. If this is NULL, the shared library can choose to 6600Sstevel@tonic-gate * return failure or to initialise a 'default' ENGINE. If non-NULL, the shared 6610Sstevel@tonic-gate * library must initialise only an ENGINE matching the passed 'id'. The function 6620Sstevel@tonic-gate * is expected to be implemented with the symbol name "bind_engine". A standard 6630Sstevel@tonic-gate * implementation can be instantiated with IMPLEMENT_DYNAMIC_BIND_FN(fn) where 6640Sstevel@tonic-gate * the parameter 'fn' is a callback function that populates the ENGINE structure 6650Sstevel@tonic-gate * and returns an int value (zero for failure). 'fn' should have prototype; 6660Sstevel@tonic-gate * [static] int fn(ENGINE *e, const char *id); */ 6670Sstevel@tonic-gate typedef int (*dynamic_bind_engine)(ENGINE *e, const char *id, 6680Sstevel@tonic-gate const dynamic_fns *fns); 6690Sstevel@tonic-gate #define IMPLEMENT_DYNAMIC_BIND_FN(fn) \ 6700Sstevel@tonic-gate int bind_engine(ENGINE *e, const char *id, const dynamic_fns *fns) { \ 671*2139Sjp161948 if(ENGINE_get_static_state() == fns->static_state) goto skip_cbs; \ 672*2139Sjp161948 if(!CRYPTO_set_mem_functions(fns->mem_fns.malloc_cb, \ 673*2139Sjp161948 fns->mem_fns.realloc_cb, fns->mem_fns.free_cb)) \ 674*2139Sjp161948 return 0; \ 675*2139Sjp161948 CRYPTO_set_locking_callback(fns->lock_fns.lock_locking_cb); \ 676*2139Sjp161948 CRYPTO_set_add_lock_callback(fns->lock_fns.lock_add_lock_cb); \ 677*2139Sjp161948 CRYPTO_set_dynlock_create_callback(fns->lock_fns.dynlock_create_cb); \ 678*2139Sjp161948 CRYPTO_set_dynlock_lock_callback(fns->lock_fns.dynlock_lock_cb); \ 679*2139Sjp161948 CRYPTO_set_dynlock_destroy_callback(fns->lock_fns.dynlock_destroy_cb); \ 680*2139Sjp161948 if(!CRYPTO_set_ex_data_implementation(fns->ex_data_fns)) \ 681*2139Sjp161948 return 0; \ 682*2139Sjp161948 if(!ERR_set_implementation(fns->err_fns)) return 0; \ 683*2139Sjp161948 skip_cbs: \ 6840Sstevel@tonic-gate if(!fn(e,id)) return 0; \ 6850Sstevel@tonic-gate return 1; } 6860Sstevel@tonic-gate 687*2139Sjp161948 /* If the loading application (or library) and the loaded ENGINE library share 688*2139Sjp161948 * the same static data (eg. they're both dynamically linked to the same 689*2139Sjp161948 * libcrypto.so) we need a way to avoid trying to set system callbacks - this 690*2139Sjp161948 * would fail, and for the same reason that it's unnecessary to try. If the 691*2139Sjp161948 * loaded ENGINE has (or gets from through the loader) its own copy of the 692*2139Sjp161948 * libcrypto static data, we will need to set the callbacks. The easiest way to 693*2139Sjp161948 * detect this is to have a function that returns a pointer to some static data 694*2139Sjp161948 * and let the loading application and loaded ENGINE compare their respective 695*2139Sjp161948 * values. */ 696*2139Sjp161948 void *ENGINE_get_static_state(void); 697*2139Sjp161948 6980Sstevel@tonic-gate #if defined(__OpenBSD__) || defined(__FreeBSD__) 6990Sstevel@tonic-gate void ENGINE_setup_bsd_cryptodev(void); 7000Sstevel@tonic-gate #endif 7010Sstevel@tonic-gate 7020Sstevel@tonic-gate /* BEGIN ERROR CODES */ 7030Sstevel@tonic-gate /* The following lines are auto generated by the script mkerr.pl. Any changes 7040Sstevel@tonic-gate * made after this point may be overwritten when the script is next run. 7050Sstevel@tonic-gate */ 7060Sstevel@tonic-gate void ERR_load_ENGINE_strings(void); 7070Sstevel@tonic-gate 7080Sstevel@tonic-gate /* Error codes for the ENGINE functions. */ 7090Sstevel@tonic-gate 7100Sstevel@tonic-gate /* Function codes. */ 7110Sstevel@tonic-gate #define ENGINE_F_DYNAMIC_CTRL 180 7120Sstevel@tonic-gate #define ENGINE_F_DYNAMIC_GET_DATA_CTX 181 7130Sstevel@tonic-gate #define ENGINE_F_DYNAMIC_LOAD 182 714*2139Sjp161948 #define ENGINE_F_DYNAMIC_SET_DATA_CTX 183 7150Sstevel@tonic-gate #define ENGINE_F_ENGINE_ADD 105 7160Sstevel@tonic-gate #define ENGINE_F_ENGINE_BY_ID 106 7170Sstevel@tonic-gate #define ENGINE_F_ENGINE_CMD_IS_EXECUTABLE 170 7180Sstevel@tonic-gate #define ENGINE_F_ENGINE_CTRL 142 7190Sstevel@tonic-gate #define ENGINE_F_ENGINE_CTRL_CMD 178 7200Sstevel@tonic-gate #define ENGINE_F_ENGINE_CTRL_CMD_STRING 171 7210Sstevel@tonic-gate #define ENGINE_F_ENGINE_FINISH 107 722*2139Sjp161948 #define ENGINE_F_ENGINE_FREE_UTIL 108 7230Sstevel@tonic-gate #define ENGINE_F_ENGINE_GET_CIPHER 185 7240Sstevel@tonic-gate #define ENGINE_F_ENGINE_GET_DEFAULT_TYPE 177 7250Sstevel@tonic-gate #define ENGINE_F_ENGINE_GET_DIGEST 186 7260Sstevel@tonic-gate #define ENGINE_F_ENGINE_GET_NEXT 115 7270Sstevel@tonic-gate #define ENGINE_F_ENGINE_GET_PREV 116 7280Sstevel@tonic-gate #define ENGINE_F_ENGINE_INIT 119 7290Sstevel@tonic-gate #define ENGINE_F_ENGINE_LIST_ADD 120 7300Sstevel@tonic-gate #define ENGINE_F_ENGINE_LIST_REMOVE 121 7310Sstevel@tonic-gate #define ENGINE_F_ENGINE_LOAD_PRIVATE_KEY 150 7320Sstevel@tonic-gate #define ENGINE_F_ENGINE_LOAD_PUBLIC_KEY 151 7330Sstevel@tonic-gate #define ENGINE_F_ENGINE_NEW 122 7340Sstevel@tonic-gate #define ENGINE_F_ENGINE_REMOVE 123 7350Sstevel@tonic-gate #define ENGINE_F_ENGINE_SET_DEFAULT_STRING 189 7360Sstevel@tonic-gate #define ENGINE_F_ENGINE_SET_DEFAULT_TYPE 126 7370Sstevel@tonic-gate #define ENGINE_F_ENGINE_SET_ID 129 7380Sstevel@tonic-gate #define ENGINE_F_ENGINE_SET_NAME 130 7390Sstevel@tonic-gate #define ENGINE_F_ENGINE_TABLE_REGISTER 184 7400Sstevel@tonic-gate #define ENGINE_F_ENGINE_UNLOAD_KEY 152 741*2139Sjp161948 #define ENGINE_F_ENGINE_UNLOCKED_FINISH 191 7420Sstevel@tonic-gate #define ENGINE_F_ENGINE_UP_REF 190 7430Sstevel@tonic-gate #define ENGINE_F_INT_CTRL_HELPER 172 7440Sstevel@tonic-gate #define ENGINE_F_INT_ENGINE_CONFIGURE 188 745*2139Sjp161948 #define ENGINE_F_INT_ENGINE_MODULE_INIT 187 7460Sstevel@tonic-gate #define ENGINE_F_LOG_MESSAGE 141 7470Sstevel@tonic-gate 7480Sstevel@tonic-gate /* Reason codes. */ 7490Sstevel@tonic-gate #define ENGINE_R_ALREADY_LOADED 100 7500Sstevel@tonic-gate #define ENGINE_R_ARGUMENT_IS_NOT_A_NUMBER 133 7510Sstevel@tonic-gate #define ENGINE_R_CMD_NOT_EXECUTABLE 134 7520Sstevel@tonic-gate #define ENGINE_R_COMMAND_TAKES_INPUT 135 7530Sstevel@tonic-gate #define ENGINE_R_COMMAND_TAKES_NO_INPUT 136 7540Sstevel@tonic-gate #define ENGINE_R_CONFLICTING_ENGINE_ID 103 7550Sstevel@tonic-gate #define ENGINE_R_CTRL_COMMAND_NOT_IMPLEMENTED 119 7560Sstevel@tonic-gate #define ENGINE_R_DH_NOT_IMPLEMENTED 139 7570Sstevel@tonic-gate #define ENGINE_R_DSA_NOT_IMPLEMENTED 140 7580Sstevel@tonic-gate #define ENGINE_R_DSO_FAILURE 104 7590Sstevel@tonic-gate #define ENGINE_R_DSO_NOT_FOUND 132 7600Sstevel@tonic-gate #define ENGINE_R_ENGINES_SECTION_ERROR 148 7610Sstevel@tonic-gate #define ENGINE_R_ENGINE_IS_NOT_IN_LIST 105 7620Sstevel@tonic-gate #define ENGINE_R_ENGINE_SECTION_ERROR 149 7630Sstevel@tonic-gate #define ENGINE_R_FAILED_LOADING_PRIVATE_KEY 128 7640Sstevel@tonic-gate #define ENGINE_R_FAILED_LOADING_PUBLIC_KEY 129 7650Sstevel@tonic-gate #define ENGINE_R_FINISH_FAILED 106 7660Sstevel@tonic-gate #define ENGINE_R_GET_HANDLE_FAILED 107 7670Sstevel@tonic-gate #define ENGINE_R_ID_OR_NAME_MISSING 108 7680Sstevel@tonic-gate #define ENGINE_R_INIT_FAILED 109 7690Sstevel@tonic-gate #define ENGINE_R_INTERNAL_LIST_ERROR 110 7700Sstevel@tonic-gate #define ENGINE_R_INVALID_ARGUMENT 143 7710Sstevel@tonic-gate #define ENGINE_R_INVALID_CMD_NAME 137 7720Sstevel@tonic-gate #define ENGINE_R_INVALID_CMD_NUMBER 138 7730Sstevel@tonic-gate #define ENGINE_R_INVALID_INIT_VALUE 151 7740Sstevel@tonic-gate #define ENGINE_R_INVALID_STRING 150 7750Sstevel@tonic-gate #define ENGINE_R_NOT_INITIALISED 117 7760Sstevel@tonic-gate #define ENGINE_R_NOT_LOADED 112 7770Sstevel@tonic-gate #define ENGINE_R_NO_CONTROL_FUNCTION 120 7780Sstevel@tonic-gate #define ENGINE_R_NO_INDEX 144 7790Sstevel@tonic-gate #define ENGINE_R_NO_LOAD_FUNCTION 125 7800Sstevel@tonic-gate #define ENGINE_R_NO_REFERENCE 130 7810Sstevel@tonic-gate #define ENGINE_R_NO_SUCH_ENGINE 116 7820Sstevel@tonic-gate #define ENGINE_R_NO_UNLOAD_FUNCTION 126 7830Sstevel@tonic-gate #define ENGINE_R_PROVIDE_PARAMETERS 113 7840Sstevel@tonic-gate #define ENGINE_R_RSA_NOT_IMPLEMENTED 141 7850Sstevel@tonic-gate #define ENGINE_R_UNIMPLEMENTED_CIPHER 146 7860Sstevel@tonic-gate #define ENGINE_R_UNIMPLEMENTED_DIGEST 147 7870Sstevel@tonic-gate #define ENGINE_R_VERSION_INCOMPATIBILITY 145 7880Sstevel@tonic-gate 7890Sstevel@tonic-gate #ifdef __cplusplus 7900Sstevel@tonic-gate } 7910Sstevel@tonic-gate #endif 7920Sstevel@tonic-gate #endif 793