diff options
| author | markus <> | 2002-09-03 09:21:21 +0000 |
|---|---|---|
| committer | markus <> | 2002-09-03 09:21:21 +0000 |
| commit | 2a403cf17b91db1355403be2649b62a15f65d0b1 (patch) | |
| tree | ccb7f731e62b49ca25d700356d1d89a66fce9fde /src/lib/libcrypto/engine | |
| parent | 0417492a9cd47355e6322690a822134d099084b8 (diff) | |
| download | openbsd-2a403cf17b91db1355403be2649b62a15f65d0b1.tar.gz openbsd-2a403cf17b91db1355403be2649b62a15f65d0b1.tar.bz2 openbsd-2a403cf17b91db1355403be2649b62a15f65d0b1.zip | |
unused files, not part of OpenSSL 0.9.7
Diffstat (limited to 'src/lib/libcrypto/engine')
| -rw-r--r-- | src/lib/libcrypto/engine/engine_err.c | 183 | ||||
| -rw-r--r-- | src/lib/libcrypto/engine/engine_int.h | 160 | ||||
| -rw-r--r-- | src/lib/libcrypto/engine/engine_lib.c | 489 | ||||
| -rw-r--r-- | src/lib/libcrypto/engine/engine_list.c | 675 | ||||
| -rw-r--r-- | src/lib/libcrypto/engine/engine_openssl.c | 174 |
5 files changed, 0 insertions, 1681 deletions
diff --git a/src/lib/libcrypto/engine/engine_err.c b/src/lib/libcrypto/engine/engine_err.c deleted file mode 100644 index 0d7a31f6d5..0000000000 --- a/src/lib/libcrypto/engine/engine_err.c +++ /dev/null | |||
| @@ -1,183 +0,0 @@ | |||
| 1 | /* crypto/engine/engine_err.c */ | ||
| 2 | /* ==================================================================== | ||
| 3 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
| 4 | * | ||
| 5 | * Redistribution and use in source and binary forms, with or without | ||
| 6 | * modification, are permitted provided that the following conditions | ||
| 7 | * are met: | ||
| 8 | * | ||
| 9 | * 1. Redistributions of source code must retain the above copyright | ||
| 10 | * notice, this list of conditions and the following disclaimer. | ||
| 11 | * | ||
| 12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer in | ||
| 14 | * the documentation and/or other materials provided with the | ||
| 15 | * distribution. | ||
| 16 | * | ||
| 17 | * 3. All advertising materials mentioning features or use of this | ||
| 18 | * software must display the following acknowledgment: | ||
| 19 | * "This product includes software developed by the OpenSSL Project | ||
| 20 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 21 | * | ||
| 22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 23 | * endorse or promote products derived from this software without | ||
| 24 | * prior written permission. For written permission, please contact | ||
| 25 | * openssl-core@OpenSSL.org. | ||
| 26 | * | ||
| 27 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 28 | * nor may "OpenSSL" appear in their names without prior written | ||
| 29 | * permission of the OpenSSL Project. | ||
| 30 | * | ||
| 31 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 32 | * acknowledgment: | ||
| 33 | * "This product includes software developed by the OpenSSL Project | ||
| 34 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 35 | * | ||
| 36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 48 | * ==================================================================== | ||
| 49 | * | ||
| 50 | * This product includes cryptographic software written by Eric Young | ||
| 51 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 52 | * Hudson (tjh@cryptsoft.com). | ||
| 53 | * | ||
| 54 | */ | ||
| 55 | |||
| 56 | /* NOTE: this file was auto generated by the mkerr.pl script: any changes | ||
| 57 | * made to it will be overwritten when the script next updates this file, | ||
| 58 | * only reason strings will be preserved. | ||
| 59 | */ | ||
| 60 | |||
| 61 | #include <stdio.h> | ||
| 62 | #include <openssl/err.h> | ||
| 63 | #include <openssl/engine.h> | ||
| 64 | |||
| 65 | /* BEGIN ERROR CODES */ | ||
| 66 | #ifndef NO_ERR | ||
| 67 | static ERR_STRING_DATA ENGINE_str_functs[]= | ||
| 68 | { | ||
| 69 | {ERR_PACK(0,ENGINE_F_ATALLA_FINISH,0), "ATALLA_FINISH"}, | ||
| 70 | {ERR_PACK(0,ENGINE_F_ATALLA_INIT,0), "ATALLA_INIT"}, | ||
| 71 | {ERR_PACK(0,ENGINE_F_ATALLA_MOD_EXP,0), "ATALLA_MOD_EXP"}, | ||
| 72 | {ERR_PACK(0,ENGINE_F_ATALLA_RSA_MOD_EXP,0), "ATALLA_RSA_MOD_EXP"}, | ||
| 73 | {ERR_PACK(0,ENGINE_F_CSWIFT_DSA_SIGN,0), "CSWIFT_DSA_SIGN"}, | ||
| 74 | {ERR_PACK(0,ENGINE_F_CSWIFT_DSA_VERIFY,0), "CSWIFT_DSA_VERIFY"}, | ||
| 75 | {ERR_PACK(0,ENGINE_F_CSWIFT_FINISH,0), "CSWIFT_FINISH"}, | ||
| 76 | {ERR_PACK(0,ENGINE_F_CSWIFT_INIT,0), "CSWIFT_INIT"}, | ||
| 77 | {ERR_PACK(0,ENGINE_F_CSWIFT_MOD_EXP,0), "CSWIFT_MOD_EXP"}, | ||
| 78 | {ERR_PACK(0,ENGINE_F_CSWIFT_MOD_EXP_CRT,0), "CSWIFT_MOD_EXP_CRT"}, | ||
| 79 | {ERR_PACK(0,ENGINE_F_CSWIFT_RSA_MOD_EXP,0), "CSWIFT_RSA_MOD_EXP"}, | ||
| 80 | {ERR_PACK(0,ENGINE_F_ENGINE_ADD,0), "ENGINE_add"}, | ||
| 81 | {ERR_PACK(0,ENGINE_F_ENGINE_BY_ID,0), "ENGINE_by_id"}, | ||
| 82 | {ERR_PACK(0,ENGINE_F_ENGINE_CTRL,0), "ENGINE_ctrl"}, | ||
| 83 | {ERR_PACK(0,ENGINE_F_ENGINE_FINISH,0), "ENGINE_finish"}, | ||
| 84 | {ERR_PACK(0,ENGINE_F_ENGINE_FREE,0), "ENGINE_free"}, | ||
| 85 | {ERR_PACK(0,ENGINE_F_ENGINE_GET_BN_MOD_EXP,0), "ENGINE_get_BN_mod_exp"}, | ||
| 86 | {ERR_PACK(0,ENGINE_F_ENGINE_GET_BN_MOD_EXP_CRT,0), "ENGINE_get_BN_mod_exp_crt"}, | ||
| 87 | {ERR_PACK(0,ENGINE_F_ENGINE_GET_CTRL_FUNCTION,0), "ENGINE_get_ctrl_function"}, | ||
| 88 | {ERR_PACK(0,ENGINE_F_ENGINE_GET_DH,0), "ENGINE_get_DH"}, | ||
| 89 | {ERR_PACK(0,ENGINE_F_ENGINE_GET_DSA,0), "ENGINE_get_DSA"}, | ||
| 90 | {ERR_PACK(0,ENGINE_F_ENGINE_GET_FINISH_FUNCTION,0), "ENGINE_get_finish_function"}, | ||
| 91 | {ERR_PACK(0,ENGINE_F_ENGINE_GET_ID,0), "ENGINE_get_id"}, | ||
| 92 | {ERR_PACK(0,ENGINE_F_ENGINE_GET_INIT_FUNCTION,0), "ENGINE_get_init_function"}, | ||
| 93 | {ERR_PACK(0,ENGINE_F_ENGINE_GET_NAME,0), "ENGINE_get_name"}, | ||
| 94 | {ERR_PACK(0,ENGINE_F_ENGINE_GET_NEXT,0), "ENGINE_get_next"}, | ||
| 95 | {ERR_PACK(0,ENGINE_F_ENGINE_GET_PREV,0), "ENGINE_get_prev"}, | ||
| 96 | {ERR_PACK(0,ENGINE_F_ENGINE_GET_RAND,0), "ENGINE_get_RAND"}, | ||
| 97 | {ERR_PACK(0,ENGINE_F_ENGINE_GET_RSA,0), "ENGINE_get_RSA"}, | ||
| 98 | {ERR_PACK(0,ENGINE_F_ENGINE_INIT,0), "ENGINE_init"}, | ||
| 99 | {ERR_PACK(0,ENGINE_F_ENGINE_LIST_ADD,0), "ENGINE_LIST_ADD"}, | ||
| 100 | {ERR_PACK(0,ENGINE_F_ENGINE_LIST_REMOVE,0), "ENGINE_LIST_REMOVE"}, | ||
| 101 | {ERR_PACK(0,ENGINE_F_ENGINE_LOAD_PRIVATE_KEY,0), "ENGINE_load_private_key"}, | ||
| 102 | {ERR_PACK(0,ENGINE_F_ENGINE_LOAD_PUBLIC_KEY,0), "ENGINE_load_public_key"}, | ||
| 103 | {ERR_PACK(0,ENGINE_F_ENGINE_NEW,0), "ENGINE_new"}, | ||
| 104 | {ERR_PACK(0,ENGINE_F_ENGINE_REMOVE,0), "ENGINE_remove"}, | ||
| 105 | {ERR_PACK(0,ENGINE_F_ENGINE_SET_BN_MOD_EXP,0), "ENGINE_set_BN_mod_exp"}, | ||
| 106 | {ERR_PACK(0,ENGINE_F_ENGINE_SET_BN_MOD_EXP_CRT,0), "ENGINE_set_BN_mod_exp_crt"}, | ||
| 107 | {ERR_PACK(0,ENGINE_F_ENGINE_SET_CTRL_FUNCTION,0), "ENGINE_set_ctrl_function"}, | ||
| 108 | {ERR_PACK(0,ENGINE_F_ENGINE_SET_DEFAULT_TYPE,0), "ENGINE_SET_DEFAULT_TYPE"}, | ||
| 109 | {ERR_PACK(0,ENGINE_F_ENGINE_SET_DH,0), "ENGINE_set_DH"}, | ||
| 110 | {ERR_PACK(0,ENGINE_F_ENGINE_SET_DSA,0), "ENGINE_set_DSA"}, | ||
| 111 | {ERR_PACK(0,ENGINE_F_ENGINE_SET_FINISH_FUNCTION,0), "ENGINE_set_finish_function"}, | ||
| 112 | {ERR_PACK(0,ENGINE_F_ENGINE_SET_ID,0), "ENGINE_set_id"}, | ||
| 113 | {ERR_PACK(0,ENGINE_F_ENGINE_SET_INIT_FUNCTION,0), "ENGINE_set_init_function"}, | ||
| 114 | {ERR_PACK(0,ENGINE_F_ENGINE_SET_NAME,0), "ENGINE_set_name"}, | ||
| 115 | {ERR_PACK(0,ENGINE_F_ENGINE_SET_RAND,0), "ENGINE_set_RAND"}, | ||
| 116 | {ERR_PACK(0,ENGINE_F_ENGINE_SET_RSA,0), "ENGINE_set_RSA"}, | ||
| 117 | {ERR_PACK(0,ENGINE_F_ENGINE_UNLOAD_KEY,0), "ENGINE_UNLOAD_KEY"}, | ||
| 118 | {ERR_PACK(0,ENGINE_F_HWCRHK_CTRL,0), "HWCRHK_CTRL"}, | ||
| 119 | {ERR_PACK(0,ENGINE_F_HWCRHK_FINISH,0), "HWCRHK_FINISH"}, | ||
| 120 | {ERR_PACK(0,ENGINE_F_HWCRHK_GET_PASS,0), "HWCRHK_GET_PASS"}, | ||
| 121 | {ERR_PACK(0,ENGINE_F_HWCRHK_INIT,0), "HWCRHK_INIT"}, | ||
| 122 | {ERR_PACK(0,ENGINE_F_HWCRHK_LOAD_PRIVKEY,0), "HWCRHK_LOAD_PRIVKEY"}, | ||
| 123 | {ERR_PACK(0,ENGINE_F_HWCRHK_LOAD_PUBKEY,0), "HWCRHK_LOAD_PUBKEY"}, | ||
| 124 | {ERR_PACK(0,ENGINE_F_HWCRHK_MOD_EXP,0), "HWCRHK_MOD_EXP"}, | ||
| 125 | {ERR_PACK(0,ENGINE_F_HWCRHK_MOD_EXP_CRT,0), "HWCRHK_MOD_EXP_CRT"}, | ||
| 126 | {ERR_PACK(0,ENGINE_F_HWCRHK_RAND_BYTES,0), "HWCRHK_RAND_BYTES"}, | ||
| 127 | {ERR_PACK(0,ENGINE_F_HWCRHK_RSA_MOD_EXP,0), "HWCRHK_RSA_MOD_EXP"}, | ||
| 128 | {ERR_PACK(0,ENGINE_F_LOG_MESSAGE,0), "LOG_MESSAGE"}, | ||
| 129 | {0,NULL} | ||
| 130 | }; | ||
| 131 | |||
| 132 | static ERR_STRING_DATA ENGINE_str_reasons[]= | ||
| 133 | { | ||
| 134 | {ENGINE_R_ALREADY_LOADED ,"already loaded"}, | ||
| 135 | {ENGINE_R_BIO_WAS_FREED ,"bio was freed"}, | ||
| 136 | {ENGINE_R_BN_CTX_FULL ,"BN_CTX full"}, | ||
| 137 | {ENGINE_R_BN_EXPAND_FAIL ,"bn_expand fail"}, | ||
| 138 | {ENGINE_R_CHIL_ERROR ,"chil error"}, | ||
| 139 | {ENGINE_R_CONFLICTING_ENGINE_ID ,"conflicting engine id"}, | ||
| 140 | {ENGINE_R_CTRL_COMMAND_NOT_IMPLEMENTED ,"ctrl command not implemented"}, | ||
| 141 | {ENGINE_R_DSO_FAILURE ,"DSO failure"}, | ||
| 142 | {ENGINE_R_ENGINE_IS_NOT_IN_LIST ,"engine is not in the list"}, | ||
| 143 | {ENGINE_R_FAILED_LOADING_PRIVATE_KEY ,"failed loading private key"}, | ||
| 144 | {ENGINE_R_FAILED_LOADING_PUBLIC_KEY ,"failed loading public key"}, | ||
| 145 | {ENGINE_R_FINISH_FAILED ,"finish failed"}, | ||
| 146 | {ENGINE_R_GET_HANDLE_FAILED ,"could not obtain hardware handle"}, | ||
| 147 | {ENGINE_R_ID_OR_NAME_MISSING ,"'id' or 'name' missing"}, | ||
| 148 | {ENGINE_R_INIT_FAILED ,"init failed"}, | ||
| 149 | {ENGINE_R_INTERNAL_LIST_ERROR ,"internal list error"}, | ||
| 150 | {ENGINE_R_MISSING_KEY_COMPONENTS ,"missing key components"}, | ||
| 151 | {ENGINE_R_NOT_INITIALISED ,"not initialised"}, | ||
| 152 | {ENGINE_R_NOT_LOADED ,"not loaded"}, | ||
| 153 | {ENGINE_R_NO_CALLBACK ,"no callback"}, | ||
| 154 | {ENGINE_R_NO_CONTROL_FUNCTION ,"no control function"}, | ||
| 155 | {ENGINE_R_NO_KEY ,"no key"}, | ||
| 156 | {ENGINE_R_NO_LOAD_FUNCTION ,"no load function"}, | ||
| 157 | {ENGINE_R_NO_REFERENCE ,"no reference"}, | ||
| 158 | {ENGINE_R_NO_SUCH_ENGINE ,"no such engine"}, | ||
| 159 | {ENGINE_R_NO_UNLOAD_FUNCTION ,"no unload function"}, | ||
| 160 | {ENGINE_R_PROVIDE_PARAMETERS ,"provide parameters"}, | ||
| 161 | {ENGINE_R_REQUEST_FAILED ,"request failed"}, | ||
| 162 | {ENGINE_R_REQUEST_FALLBACK ,"request fallback"}, | ||
| 163 | {ENGINE_R_SIZE_TOO_LARGE_OR_TOO_SMALL ,"size too large or too small"}, | ||
| 164 | {ENGINE_R_UNIT_FAILURE ,"unit failure"}, | ||
| 165 | {0,NULL} | ||
| 166 | }; | ||
| 167 | |||
| 168 | #endif | ||
| 169 | |||
| 170 | void ERR_load_ENGINE_strings(void) | ||
| 171 | { | ||
| 172 | static int init=1; | ||
| 173 | |||
| 174 | if (init) | ||
| 175 | { | ||
| 176 | init=0; | ||
| 177 | #ifndef NO_ERR | ||
| 178 | ERR_load_strings(ERR_LIB_ENGINE,ENGINE_str_functs); | ||
| 179 | ERR_load_strings(ERR_LIB_ENGINE,ENGINE_str_reasons); | ||
| 180 | #endif | ||
| 181 | |||
| 182 | } | ||
| 183 | } | ||
diff --git a/src/lib/libcrypto/engine/engine_int.h b/src/lib/libcrypto/engine/engine_int.h deleted file mode 100644 index 447fa2a320..0000000000 --- a/src/lib/libcrypto/engine/engine_int.h +++ /dev/null | |||
| @@ -1,160 +0,0 @@ | |||
| 1 | /* crypto/engine/engine_int.h */ | ||
| 2 | /* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL | ||
| 3 | * project 2000. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | |||
| 59 | #ifndef HEADER_ENGINE_INT_H | ||
| 60 | #define HEADER_ENGINE_INT_H | ||
| 61 | |||
| 62 | #include <openssl/rsa.h> | ||
| 63 | #include <openssl/dsa.h> | ||
| 64 | #include <openssl/dh.h> | ||
| 65 | #include <openssl/rand.h> | ||
| 66 | #include <openssl/bn.h> | ||
| 67 | #include <openssl/evp.h> | ||
| 68 | |||
| 69 | #ifdef __cplusplus | ||
| 70 | extern "C" { | ||
| 71 | #endif | ||
| 72 | |||
| 73 | /* Bitwise OR-able values for the "flags" variable in ENGINE. */ | ||
| 74 | #define ENGINE_FLAGS_MALLOCED 0x0001 | ||
| 75 | |||
| 76 | #ifndef HEADER_ENGINE_H | ||
| 77 | /* Regrettably, we need to reproduce the "BN" function types here | ||
| 78 | * because there is no such "BIGNUM_METHOD" as there is with RSA, | ||
| 79 | * DSA, etc. We do this so that we don't have a case where engine.h | ||
| 80 | * and engine_int.h conflict with each other. */ | ||
| 81 | typedef int (*BN_MOD_EXP)(BIGNUM *r, BIGNUM *a, const BIGNUM *p, | ||
| 82 | const BIGNUM *m, BN_CTX *ctx); | ||
| 83 | |||
| 84 | /* private key operation for RSA, provided seperately in case other | ||
| 85 | * RSA implementations wish to use it. */ | ||
| 86 | typedef int (*BN_MOD_EXP_CRT)(BIGNUM *r, BIGNUM *a, const BIGNUM *p, | ||
| 87 | const BIGNUM *q, const BIGNUM *dmp1, const BIGNUM *dmq1, | ||
| 88 | const BIGNUM *iqmp, BN_CTX *ctx); | ||
| 89 | |||
| 90 | /* Generic function pointer */ | ||
| 91 | typedef int (*ENGINE_GEN_FUNC_PTR)(); | ||
| 92 | /* Generic function pointer taking no arguments */ | ||
| 93 | typedef int (*ENGINE_GEN_INT_FUNC_PTR)(void); | ||
| 94 | /* Specific control function pointer */ | ||
| 95 | typedef int (*ENGINE_CTRL_FUNC_PTR)(int cmd, long i, void *p, void (*f)()); | ||
| 96 | |||
| 97 | #endif | ||
| 98 | |||
| 99 | /* This is a structure for storing implementations of various crypto | ||
| 100 | * algorithms and functions. */ | ||
| 101 | typedef struct engine_st | ||
| 102 | { | ||
| 103 | const char *id; | ||
| 104 | const char *name; | ||
| 105 | RSA_METHOD *rsa_meth; | ||
| 106 | DSA_METHOD *dsa_meth; | ||
| 107 | DH_METHOD *dh_meth; | ||
| 108 | RAND_METHOD *rand_meth; | ||
| 109 | BN_MOD_EXP bn_mod_exp; | ||
| 110 | BN_MOD_EXP_CRT bn_mod_exp_crt; | ||
| 111 | int (*init)(void); | ||
| 112 | int (*finish)(void); | ||
| 113 | int (*ctrl)(int cmd, long i, void *p, void (*f)()); | ||
| 114 | EVP_PKEY *(*load_privkey)(const char *key_id, const char *passphrase); | ||
| 115 | EVP_PKEY *(*load_pubkey)(const char *key_id, const char *passphrase); | ||
| 116 | int flags; | ||
| 117 | /* reference count on the structure itself */ | ||
| 118 | int struct_ref; | ||
| 119 | /* reference count on usability of the engine type. NB: This | ||
| 120 | * controls the loading and initialisation of any functionlity | ||
| 121 | * required by this engine, whereas the previous count is | ||
| 122 | * simply to cope with (de)allocation of this structure. Hence, | ||
| 123 | * running_ref <= struct_ref at all times. */ | ||
| 124 | int funct_ref; | ||
| 125 | /* Used to maintain the linked-list of engines. */ | ||
| 126 | struct engine_st *prev; | ||
| 127 | struct engine_st *next; | ||
| 128 | } ENGINE; | ||
| 129 | |||
| 130 | /* BUILT-IN ENGINES. (these functions are only ever called once and | ||
| 131 | * do not return references - they are purely for bootstrapping). */ | ||
| 132 | |||
| 133 | /* Returns a structure of software only methods (the default). */ | ||
| 134 | ENGINE *ENGINE_openssl(); | ||
| 135 | |||
| 136 | #ifndef NO_HW | ||
| 137 | |||
| 138 | #ifndef NO_HW_CSWIFT | ||
| 139 | /* Returns a structure of cswift methods ... NB: This can exist and be | ||
| 140 | * "used" even on non-cswift systems because the "init" will fail if the | ||
| 141 | * card/library are not found. */ | ||
| 142 | ENGINE *ENGINE_cswift(); | ||
| 143 | #endif /* !NO_HW_CSWIFT */ | ||
| 144 | |||
| 145 | #ifndef NO_HW_NCIPHER | ||
| 146 | ENGINE *ENGINE_ncipher(); | ||
| 147 | #endif /* !NO_HW_NCIPHER */ | ||
| 148 | |||
| 149 | #ifndef NO_HW_ATALLA | ||
| 150 | /* Returns a structure of atalla methods. */ | ||
| 151 | ENGINE *ENGINE_atalla(); | ||
| 152 | #endif /* !NO_HW_ATALLA */ | ||
| 153 | |||
| 154 | #endif /* !NO_HW */ | ||
| 155 | |||
| 156 | #ifdef __cplusplus | ||
| 157 | } | ||
| 158 | #endif | ||
| 159 | |||
| 160 | #endif /* HEADER_ENGINE_INT_H */ | ||
diff --git a/src/lib/libcrypto/engine/engine_lib.c b/src/lib/libcrypto/engine/engine_lib.c deleted file mode 100644 index d6e9109f6e..0000000000 --- a/src/lib/libcrypto/engine/engine_lib.c +++ /dev/null | |||
| @@ -1,489 +0,0 @@ | |||
| 1 | /* crypto/engine/engine_lib.c */ | ||
| 2 | /* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL | ||
| 3 | * project 2000. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <openssl/crypto.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include "engine_int.h" | ||
| 62 | #include <openssl/engine.h> | ||
| 63 | |||
| 64 | /* These pointers each have their own "functional reference" when they | ||
| 65 | * are non-NULL. Similarly, when they are retrieved by a call to | ||
| 66 | * ENGINE_get_default_[RSA|DSA|...] the returned pointer is also a | ||
| 67 | * reference and the caller is responsible for freeing that when they | ||
| 68 | * are finished with it (with a call to ENGINE_finish() *NOT* just | ||
| 69 | * ENGINE_free()!!!!!!). */ | ||
| 70 | static ENGINE *engine_def_rsa = NULL; | ||
| 71 | static ENGINE *engine_def_dsa = NULL; | ||
| 72 | static ENGINE *engine_def_dh = NULL; | ||
| 73 | static ENGINE *engine_def_rand = NULL; | ||
| 74 | static ENGINE *engine_def_bn_mod_exp = NULL; | ||
| 75 | static ENGINE *engine_def_bn_mod_exp_crt = NULL; | ||
| 76 | /* A static "once-only" flag used to control if/when the above were | ||
| 77 | * initialised to suitable start-up defaults. */ | ||
| 78 | static int engine_def_flag = 0; | ||
| 79 | |||
| 80 | /* This is used in certain static utility functions to save code | ||
| 81 | * repetition for per-algorithm functions. */ | ||
| 82 | typedef enum { | ||
| 83 | ENGINE_TYPE_RSA, | ||
| 84 | ENGINE_TYPE_DSA, | ||
| 85 | ENGINE_TYPE_DH, | ||
| 86 | ENGINE_TYPE_RAND, | ||
| 87 | ENGINE_TYPE_BN_MOD_EXP, | ||
| 88 | ENGINE_TYPE_BN_MOD_EXP_CRT | ||
| 89 | } ENGINE_TYPE; | ||
| 90 | |||
| 91 | static void engine_def_check_util(ENGINE **def, ENGINE *val) | ||
| 92 | { | ||
| 93 | *def = val; | ||
| 94 | val->struct_ref++; | ||
| 95 | val->funct_ref++; | ||
| 96 | } | ||
| 97 | |||
| 98 | /* In a slight break with convention - this static function must be | ||
| 99 | * called *outside* any locking of CRYPTO_LOCK_ENGINE. */ | ||
| 100 | static void engine_def_check(void) | ||
| 101 | { | ||
| 102 | ENGINE *e; | ||
| 103 | if(engine_def_flag) | ||
| 104 | return; | ||
| 105 | e = ENGINE_get_first(); | ||
| 106 | if(e == NULL) | ||
| 107 | /* The list is empty ... not much we can do! */ | ||
| 108 | return; | ||
| 109 | /* We have a structural reference, see if getting a functional | ||
| 110 | * reference is possible. This is done to cope with init errors | ||
| 111 | * in the engine - the following locked code does a bunch of | ||
| 112 | * manual "ENGINE_init"s which do *not* allow such an init | ||
| 113 | * error so this is worth doing. */ | ||
| 114 | if(ENGINE_init(e)) | ||
| 115 | { | ||
| 116 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | ||
| 117 | /* Doing another check here prevents an obvious race | ||
| 118 | * condition because the whole function itself cannot | ||
| 119 | * be locked. */ | ||
| 120 | if(engine_def_flag) | ||
| 121 | goto skip_set_defaults; | ||
| 122 | /* OK, we got a functional reference, so we get one each | ||
| 123 | * for the defaults too. */ | ||
| 124 | engine_def_check_util(&engine_def_rsa, e); | ||
| 125 | engine_def_check_util(&engine_def_dsa, e); | ||
| 126 | engine_def_check_util(&engine_def_dh, e); | ||
| 127 | engine_def_check_util(&engine_def_rand, e); | ||
| 128 | engine_def_check_util(&engine_def_bn_mod_exp, e); | ||
| 129 | engine_def_check_util(&engine_def_bn_mod_exp_crt, e); | ||
| 130 | engine_def_flag = 1; | ||
| 131 | skip_set_defaults: | ||
| 132 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | ||
| 133 | /* The "if" needs to be balanced out. */ | ||
| 134 | ENGINE_finish(e); | ||
| 135 | } | ||
| 136 | /* We need to balance out the fact we obtained a structural | ||
| 137 | * reference to begin with from ENGINE_get_first(). */ | ||
| 138 | ENGINE_free(e); | ||
| 139 | } | ||
| 140 | |||
| 141 | /* Initialise a engine type for use (or up its functional reference count | ||
| 142 | * if it's already in use). */ | ||
| 143 | int ENGINE_init(ENGINE *e) | ||
| 144 | { | ||
| 145 | int to_return = 1; | ||
| 146 | |||
| 147 | if(e == NULL) | ||
| 148 | { | ||
| 149 | ENGINEerr(ENGINE_F_ENGINE_INIT,ERR_R_PASSED_NULL_PARAMETER); | ||
| 150 | return 0; | ||
| 151 | } | ||
| 152 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | ||
| 153 | if((e->funct_ref == 0) && e->init) | ||
| 154 | /* This is the first functional reference and the engine | ||
| 155 | * requires initialisation so we do it now. */ | ||
| 156 | to_return = e->init(); | ||
| 157 | if(to_return) | ||
| 158 | { | ||
| 159 | /* OK, we return a functional reference which is also a | ||
| 160 | * structural reference. */ | ||
| 161 | e->struct_ref++; | ||
| 162 | e->funct_ref++; | ||
| 163 | } | ||
| 164 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | ||
| 165 | return to_return; | ||
| 166 | } | ||
| 167 | |||
| 168 | /* Free a functional reference to a engine type */ | ||
| 169 | int ENGINE_finish(ENGINE *e) | ||
| 170 | { | ||
| 171 | int to_return = 1; | ||
| 172 | |||
| 173 | if(e == NULL) | ||
| 174 | { | ||
| 175 | ENGINEerr(ENGINE_F_ENGINE_FINISH,ERR_R_PASSED_NULL_PARAMETER); | ||
| 176 | return 0; | ||
| 177 | } | ||
| 178 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | ||
| 179 | if((e->funct_ref == 1) && e->finish) | ||
| 180 | #if 0 | ||
| 181 | /* This is the last functional reference and the engine | ||
| 182 | * requires cleanup so we do it now. */ | ||
| 183 | to_return = e->finish(); | ||
| 184 | if(to_return) | ||
| 185 | { | ||
| 186 | /* Cleanup the functional reference which is also a | ||
| 187 | * structural reference. */ | ||
| 188 | e->struct_ref--; | ||
| 189 | e->funct_ref--; | ||
| 190 | } | ||
| 191 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | ||
| 192 | #else | ||
| 193 | /* I'm going to deliberately do a convoluted version of this | ||
| 194 | * piece of code because we don't want "finish" functions | ||
| 195 | * being called inside a locked block of code, if at all | ||
| 196 | * possible. I'd rather have this call take an extra couple | ||
| 197 | * of ticks than have throughput serialised on a externally- | ||
| 198 | * provided callback function that may conceivably never come | ||
| 199 | * back. :-( */ | ||
| 200 | { | ||
| 201 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | ||
| 202 | /* CODE ALERT: This *IS* supposed to be "=" and NOT "==" :-) */ | ||
| 203 | if((to_return = e->finish())) | ||
| 204 | { | ||
| 205 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | ||
| 206 | /* Cleanup the functional reference which is also a | ||
| 207 | * structural reference. */ | ||
| 208 | e->struct_ref--; | ||
| 209 | e->funct_ref--; | ||
| 210 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | ||
| 211 | } | ||
| 212 | } | ||
| 213 | else | ||
| 214 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | ||
| 215 | #endif | ||
| 216 | return to_return; | ||
| 217 | } | ||
| 218 | |||
| 219 | EVP_PKEY *ENGINE_load_private_key(ENGINE *e, const char *key_id, | ||
| 220 | const char *passphrase) | ||
| 221 | { | ||
| 222 | EVP_PKEY *pkey; | ||
| 223 | |||
| 224 | if(e == NULL) | ||
| 225 | { | ||
| 226 | ENGINEerr(ENGINE_F_ENGINE_LOAD_PRIVATE_KEY, | ||
| 227 | ERR_R_PASSED_NULL_PARAMETER); | ||
| 228 | return 0; | ||
| 229 | } | ||
| 230 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | ||
| 231 | if(e->funct_ref == 0) | ||
| 232 | { | ||
| 233 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | ||
| 234 | ENGINEerr(ENGINE_F_ENGINE_LOAD_PRIVATE_KEY, | ||
| 235 | ENGINE_R_NOT_INITIALISED); | ||
| 236 | return 0; | ||
| 237 | } | ||
| 238 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | ||
| 239 | if (!e->load_privkey) | ||
| 240 | { | ||
| 241 | ENGINEerr(ENGINE_F_ENGINE_LOAD_PRIVATE_KEY, | ||
| 242 | ENGINE_R_NO_LOAD_FUNCTION); | ||
| 243 | return 0; | ||
| 244 | } | ||
| 245 | pkey = e->load_privkey(key_id, passphrase); | ||
| 246 | if (!pkey) | ||
| 247 | { | ||
| 248 | ENGINEerr(ENGINE_F_ENGINE_LOAD_PRIVATE_KEY, | ||
| 249 | ENGINE_R_FAILED_LOADING_PRIVATE_KEY); | ||
| 250 | return 0; | ||
| 251 | } | ||
| 252 | return pkey; | ||
| 253 | } | ||
| 254 | |||
| 255 | EVP_PKEY *ENGINE_load_public_key(ENGINE *e, const char *key_id, | ||
| 256 | const char *passphrase) | ||
| 257 | { | ||
| 258 | EVP_PKEY *pkey; | ||
| 259 | |||
| 260 | if(e == NULL) | ||
| 261 | { | ||
| 262 | ENGINEerr(ENGINE_F_ENGINE_LOAD_PUBLIC_KEY, | ||
| 263 | ERR_R_PASSED_NULL_PARAMETER); | ||
| 264 | return 0; | ||
| 265 | } | ||
| 266 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | ||
| 267 | if(e->funct_ref == 0) | ||
| 268 | { | ||
| 269 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | ||
| 270 | ENGINEerr(ENGINE_F_ENGINE_LOAD_PUBLIC_KEY, | ||
| 271 | ENGINE_R_NOT_INITIALISED); | ||
| 272 | return 0; | ||
| 273 | } | ||
| 274 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | ||
| 275 | if (!e->load_pubkey) | ||
| 276 | { | ||
| 277 | ENGINEerr(ENGINE_F_ENGINE_LOAD_PUBLIC_KEY, | ||
| 278 | ENGINE_R_NO_LOAD_FUNCTION); | ||
| 279 | return 0; | ||
| 280 | } | ||
| 281 | pkey = e->load_pubkey(key_id, passphrase); | ||
| 282 | if (!pkey) | ||
| 283 | { | ||
| 284 | ENGINEerr(ENGINE_F_ENGINE_LOAD_PUBLIC_KEY, | ||
| 285 | ENGINE_R_FAILED_LOADING_PUBLIC_KEY); | ||
| 286 | return 0; | ||
| 287 | } | ||
| 288 | return pkey; | ||
| 289 | } | ||
| 290 | |||
| 291 | int ENGINE_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)()) | ||
| 292 | { | ||
| 293 | if(e == NULL) | ||
| 294 | { | ||
| 295 | ENGINEerr(ENGINE_F_ENGINE_CTRL,ERR_R_PASSED_NULL_PARAMETER); | ||
| 296 | return 0; | ||
| 297 | } | ||
| 298 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | ||
| 299 | if(e->struct_ref == 0) | ||
| 300 | { | ||
| 301 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | ||
| 302 | ENGINEerr(ENGINE_F_ENGINE_CTRL,ENGINE_R_NO_REFERENCE); | ||
| 303 | return 0; | ||
| 304 | } | ||
| 305 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | ||
| 306 | if (!e->ctrl) | ||
| 307 | { | ||
| 308 | ENGINEerr(ENGINE_F_ENGINE_CTRL,ENGINE_R_NO_CONTROL_FUNCTION); | ||
| 309 | return 0; | ||
| 310 | } | ||
| 311 | return e->ctrl(cmd, i, p, f); | ||
| 312 | } | ||
| 313 | |||
| 314 | static ENGINE *engine_get_default_type(ENGINE_TYPE t) | ||
| 315 | { | ||
| 316 | ENGINE *ret = NULL; | ||
| 317 | |||
| 318 | /* engine_def_check is lean and mean and won't replace any | ||
| 319 | * prior default engines ... so we must ensure that it is always | ||
| 320 | * the first function to get to touch the default values. */ | ||
| 321 | engine_def_check(); | ||
| 322 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | ||
| 323 | switch(t) | ||
| 324 | { | ||
| 325 | case ENGINE_TYPE_RSA: | ||
| 326 | ret = engine_def_rsa; break; | ||
| 327 | case ENGINE_TYPE_DSA: | ||
| 328 | ret = engine_def_dsa; break; | ||
| 329 | case ENGINE_TYPE_DH: | ||
| 330 | ret = engine_def_dh; break; | ||
| 331 | case ENGINE_TYPE_RAND: | ||
| 332 | ret = engine_def_rand; break; | ||
| 333 | case ENGINE_TYPE_BN_MOD_EXP: | ||
| 334 | ret = engine_def_bn_mod_exp; break; | ||
| 335 | case ENGINE_TYPE_BN_MOD_EXP_CRT: | ||
| 336 | ret = engine_def_bn_mod_exp_crt; break; | ||
| 337 | } | ||
| 338 | /* Unforunately we can't do this work outside the lock with a | ||
| 339 | * call to ENGINE_init() because that would leave a race | ||
| 340 | * condition open. */ | ||
| 341 | if(ret) | ||
| 342 | { | ||
| 343 | ret->struct_ref++; | ||
| 344 | ret->funct_ref++; | ||
| 345 | } | ||
| 346 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | ||
| 347 | return ret; | ||
| 348 | } | ||
| 349 | |||
| 350 | ENGINE *ENGINE_get_default_RSA(void) | ||
| 351 | { | ||
| 352 | return engine_get_default_type(ENGINE_TYPE_RSA); | ||
| 353 | } | ||
| 354 | |||
| 355 | ENGINE *ENGINE_get_default_DSA(void) | ||
| 356 | { | ||
| 357 | return engine_get_default_type(ENGINE_TYPE_DSA); | ||
| 358 | } | ||
| 359 | |||
| 360 | ENGINE *ENGINE_get_default_DH(void) | ||
| 361 | { | ||
| 362 | return engine_get_default_type(ENGINE_TYPE_DH); | ||
| 363 | } | ||
| 364 | |||
| 365 | ENGINE *ENGINE_get_default_RAND(void) | ||
| 366 | { | ||
| 367 | return engine_get_default_type(ENGINE_TYPE_RAND); | ||
| 368 | } | ||
| 369 | |||
| 370 | ENGINE *ENGINE_get_default_BN_mod_exp(void) | ||
| 371 | { | ||
| 372 | return engine_get_default_type(ENGINE_TYPE_BN_MOD_EXP); | ||
| 373 | } | ||
| 374 | |||
| 375 | ENGINE *ENGINE_get_default_BN_mod_exp_crt(void) | ||
| 376 | { | ||
| 377 | return engine_get_default_type(ENGINE_TYPE_BN_MOD_EXP_CRT); | ||
| 378 | } | ||
| 379 | |||
| 380 | static int engine_set_default_type(ENGINE_TYPE t, ENGINE *e) | ||
| 381 | { | ||
| 382 | ENGINE *old = NULL; | ||
| 383 | |||
| 384 | if(e == NULL) | ||
| 385 | { | ||
| 386 | ENGINEerr(ENGINE_F_ENGINE_SET_DEFAULT_TYPE, | ||
| 387 | ERR_R_PASSED_NULL_PARAMETER); | ||
| 388 | return 0; | ||
| 389 | } | ||
| 390 | /* engine_def_check is lean and mean and won't replace any | ||
| 391 | * prior default engines ... so we must ensure that it is always | ||
| 392 | * the first function to get to touch the default values. */ | ||
| 393 | engine_def_check(); | ||
| 394 | /* Attempt to get a functional reference (we need one anyway, but | ||
| 395 | * also, 'e' may be just a structural reference being passed in so | ||
| 396 | * this call may actually be the first). */ | ||
| 397 | if(!ENGINE_init(e)) | ||
| 398 | { | ||
| 399 | ENGINEerr(ENGINE_F_ENGINE_SET_DEFAULT_TYPE, | ||
| 400 | ENGINE_R_INIT_FAILED); | ||
| 401 | return 0; | ||
| 402 | } | ||
| 403 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | ||
| 404 | switch(t) | ||
| 405 | { | ||
| 406 | case ENGINE_TYPE_RSA: | ||
| 407 | old = engine_def_rsa; | ||
| 408 | engine_def_rsa = e; break; | ||
| 409 | case ENGINE_TYPE_DSA: | ||
| 410 | old = engine_def_dsa; | ||
| 411 | engine_def_dsa = e; break; | ||
| 412 | case ENGINE_TYPE_DH: | ||
| 413 | old = engine_def_dh; | ||
| 414 | engine_def_dh = e; break; | ||
| 415 | case ENGINE_TYPE_RAND: | ||
| 416 | old = engine_def_rand; | ||
| 417 | engine_def_rand = e; break; | ||
| 418 | case ENGINE_TYPE_BN_MOD_EXP: | ||
| 419 | old = engine_def_bn_mod_exp; | ||
| 420 | engine_def_bn_mod_exp = e; break; | ||
| 421 | case ENGINE_TYPE_BN_MOD_EXP_CRT: | ||
| 422 | old = engine_def_bn_mod_exp_crt; | ||
| 423 | engine_def_bn_mod_exp_crt = e; break; | ||
| 424 | } | ||
| 425 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | ||
| 426 | /* If we've replaced a previous value, then we need to remove the | ||
| 427 | * functional reference we had. */ | ||
| 428 | if(old && !ENGINE_finish(old)) | ||
| 429 | { | ||
| 430 | ENGINEerr(ENGINE_F_ENGINE_SET_DEFAULT_TYPE, | ||
| 431 | ENGINE_R_FINISH_FAILED); | ||
| 432 | return 0; | ||
| 433 | } | ||
| 434 | return 1; | ||
| 435 | } | ||
| 436 | |||
| 437 | int ENGINE_set_default_RSA(ENGINE *e) | ||
| 438 | { | ||
| 439 | return engine_set_default_type(ENGINE_TYPE_RSA, e); | ||
| 440 | } | ||
| 441 | |||
| 442 | int ENGINE_set_default_DSA(ENGINE *e) | ||
| 443 | { | ||
| 444 | return engine_set_default_type(ENGINE_TYPE_DSA, e); | ||
| 445 | } | ||
| 446 | |||
| 447 | int ENGINE_set_default_DH(ENGINE *e) | ||
| 448 | { | ||
| 449 | return engine_set_default_type(ENGINE_TYPE_DH, e); | ||
| 450 | } | ||
| 451 | |||
| 452 | int ENGINE_set_default_RAND(ENGINE *e) | ||
| 453 | { | ||
| 454 | return engine_set_default_type(ENGINE_TYPE_RAND, e); | ||
| 455 | } | ||
| 456 | |||
| 457 | int ENGINE_set_default_BN_mod_exp(ENGINE *e) | ||
| 458 | { | ||
| 459 | return engine_set_default_type(ENGINE_TYPE_BN_MOD_EXP, e); | ||
| 460 | } | ||
| 461 | |||
| 462 | int ENGINE_set_default_BN_mod_exp_crt(ENGINE *e) | ||
| 463 | { | ||
| 464 | return engine_set_default_type(ENGINE_TYPE_BN_MOD_EXP_CRT, e); | ||
| 465 | } | ||
| 466 | |||
| 467 | int ENGINE_set_default(ENGINE *e, unsigned int flags) | ||
| 468 | { | ||
| 469 | if((flags & ENGINE_METHOD_RSA) && e->rsa_meth && | ||
| 470 | !ENGINE_set_default_RSA(e)) | ||
| 471 | return 0; | ||
| 472 | if((flags & ENGINE_METHOD_DSA) && e->dsa_meth && | ||
| 473 | !ENGINE_set_default_DSA(e)) | ||
| 474 | return 0; | ||
| 475 | if((flags & ENGINE_METHOD_DH) && e->dh_meth && | ||
| 476 | !ENGINE_set_default_DH(e)) | ||
| 477 | return 0; | ||
| 478 | if((flags & ENGINE_METHOD_RAND) && e->rand_meth && | ||
| 479 | !ENGINE_set_default_RAND(e)) | ||
| 480 | return 0; | ||
| 481 | if((flags & ENGINE_METHOD_BN_MOD_EXP) && e->bn_mod_exp && | ||
| 482 | !ENGINE_set_default_BN_mod_exp(e)) | ||
| 483 | return 0; | ||
| 484 | if((flags & ENGINE_METHOD_BN_MOD_EXP_CRT) && e->bn_mod_exp_crt && | ||
| 485 | !ENGINE_set_default_BN_mod_exp_crt(e)) | ||
| 486 | return 0; | ||
| 487 | return 1; | ||
| 488 | } | ||
| 489 | |||
diff --git a/src/lib/libcrypto/engine/engine_list.c b/src/lib/libcrypto/engine/engine_list.c deleted file mode 100644 index d764c60661..0000000000 --- a/src/lib/libcrypto/engine/engine_list.c +++ /dev/null | |||
| @@ -1,675 +0,0 @@ | |||
| 1 | /* crypto/engine/engine_list.c */ | ||
| 2 | /* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL | ||
| 3 | * project 2000. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <openssl/crypto.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include "engine_int.h" | ||
| 62 | #include <openssl/engine.h> | ||
| 63 | |||
| 64 | /* The linked-list of pointers to engine types. engine_list_head | ||
| 65 | * incorporates an implicit structural reference but engine_list_tail | ||
| 66 | * does not - the latter is a computational niceity and only points | ||
| 67 | * to something that is already pointed to by its predecessor in the | ||
| 68 | * list (or engine_list_head itself). In the same way, the use of the | ||
| 69 | * "prev" pointer in each ENGINE is to save excessive list iteration, | ||
| 70 | * it doesn't correspond to an extra structural reference. Hence, | ||
| 71 | * engine_list_head, and each non-null "next" pointer account for | ||
| 72 | * the list itself assuming exactly 1 structural reference on each | ||
| 73 | * list member. */ | ||
| 74 | static ENGINE *engine_list_head = NULL; | ||
| 75 | static ENGINE *engine_list_tail = NULL; | ||
| 76 | /* A boolean switch, used to ensure we only initialise once. This | ||
| 77 | * is needed because the engine list may genuinely become empty during | ||
| 78 | * use (so we can't use engine_list_head as an indicator for example. */ | ||
| 79 | static int engine_list_flag = 0; | ||
| 80 | |||
| 81 | /* These static functions starting with a lower case "engine_" always | ||
| 82 | * take place when CRYPTO_LOCK_ENGINE has been locked up. */ | ||
| 83 | static int engine_list_add(ENGINE *e) | ||
| 84 | { | ||
| 85 | int conflict = 0; | ||
| 86 | ENGINE *iterator = NULL; | ||
| 87 | |||
| 88 | if(e == NULL) | ||
| 89 | { | ||
| 90 | ENGINEerr(ENGINE_F_ENGINE_LIST_ADD, | ||
| 91 | ERR_R_PASSED_NULL_PARAMETER); | ||
| 92 | return 0; | ||
| 93 | } | ||
| 94 | iterator = engine_list_head; | ||
| 95 | while(iterator && !conflict) | ||
| 96 | { | ||
| 97 | conflict = (strcmp(iterator->id, e->id) == 0); | ||
| 98 | iterator = iterator->next; | ||
| 99 | } | ||
| 100 | if(conflict) | ||
| 101 | { | ||
| 102 | ENGINEerr(ENGINE_F_ENGINE_LIST_ADD, | ||
| 103 | ENGINE_R_CONFLICTING_ENGINE_ID); | ||
| 104 | return 0; | ||
| 105 | } | ||
| 106 | if(engine_list_head == NULL) | ||
| 107 | { | ||
| 108 | /* We are adding to an empty list. */ | ||
| 109 | if(engine_list_tail) | ||
| 110 | { | ||
| 111 | ENGINEerr(ENGINE_F_ENGINE_LIST_ADD, | ||
| 112 | ENGINE_R_INTERNAL_LIST_ERROR); | ||
| 113 | return 0; | ||
| 114 | } | ||
| 115 | engine_list_head = e; | ||
| 116 | e->prev = NULL; | ||
| 117 | } | ||
| 118 | else | ||
| 119 | { | ||
| 120 | /* We are adding to the tail of an existing list. */ | ||
| 121 | if((engine_list_tail == NULL) || | ||
| 122 | (engine_list_tail->next != NULL)) | ||
| 123 | { | ||
| 124 | ENGINEerr(ENGINE_F_ENGINE_LIST_ADD, | ||
| 125 | ENGINE_R_INTERNAL_LIST_ERROR); | ||
| 126 | return 0; | ||
| 127 | } | ||
| 128 | engine_list_tail->next = e; | ||
| 129 | e->prev = engine_list_tail; | ||
| 130 | } | ||
| 131 | /* Having the engine in the list assumes a structural | ||
| 132 | * reference. */ | ||
| 133 | e->struct_ref++; | ||
| 134 | /* However it came to be, e is the last item in the list. */ | ||
| 135 | engine_list_tail = e; | ||
| 136 | e->next = NULL; | ||
| 137 | return 1; | ||
| 138 | } | ||
| 139 | |||
| 140 | static int engine_list_remove(ENGINE *e) | ||
| 141 | { | ||
| 142 | ENGINE *iterator; | ||
| 143 | |||
| 144 | if(e == NULL) | ||
| 145 | { | ||
| 146 | ENGINEerr(ENGINE_F_ENGINE_LIST_REMOVE, | ||
| 147 | ERR_R_PASSED_NULL_PARAMETER); | ||
| 148 | return 0; | ||
| 149 | } | ||
| 150 | /* We need to check that e is in our linked list! */ | ||
| 151 | iterator = engine_list_head; | ||
| 152 | while(iterator && (iterator != e)) | ||
| 153 | iterator = iterator->next; | ||
| 154 | if(iterator == NULL) | ||
| 155 | { | ||
| 156 | ENGINEerr(ENGINE_F_ENGINE_LIST_REMOVE, | ||
| 157 | ENGINE_R_ENGINE_IS_NOT_IN_LIST); | ||
| 158 | return 0; | ||
| 159 | } | ||
| 160 | /* un-link e from the chain. */ | ||
| 161 | if(e->next) | ||
| 162 | e->next->prev = e->prev; | ||
| 163 | if(e->prev) | ||
| 164 | e->prev->next = e->next; | ||
| 165 | /* Correct our head/tail if necessary. */ | ||
| 166 | if(engine_list_head == e) | ||
| 167 | engine_list_head = e->next; | ||
| 168 | if(engine_list_tail == e) | ||
| 169 | engine_list_tail = e->prev; | ||
| 170 | /* remove our structural reference. */ | ||
| 171 | e->struct_ref--; | ||
| 172 | return 1; | ||
| 173 | } | ||
| 174 | |||
| 175 | /* This check always takes place with CRYPTO_LOCK_ENGINE locked up | ||
| 176 | * so we're synchronised, but we can't call anything that tries to | ||
| 177 | * lock it again! :-) NB: For convenience (and code-clarity) we | ||
| 178 | * don't output errors for failures of the engine_list_add function | ||
| 179 | * as it will generate errors itself. */ | ||
| 180 | static int engine_internal_check(void) | ||
| 181 | { | ||
| 182 | if(engine_list_flag) | ||
| 183 | return 1; | ||
| 184 | /* This is our first time up, we need to populate the list | ||
| 185 | * with our statically compiled-in engines. */ | ||
| 186 | if(!engine_list_add(ENGINE_openssl())) | ||
| 187 | return 0; | ||
| 188 | #ifndef NO_HW | ||
| 189 | #ifndef NO_HW_CSWIFT | ||
| 190 | if(!engine_list_add(ENGINE_cswift())) | ||
| 191 | return 0; | ||
| 192 | #endif /* !NO_HW_CSWIFT */ | ||
| 193 | #ifndef NO_HW_NCIPHER | ||
| 194 | if(!engine_list_add(ENGINE_ncipher())) | ||
| 195 | return 0; | ||
| 196 | #endif /* !NO_HW_NCIPHER */ | ||
| 197 | #ifndef NO_HW_ATALLA | ||
| 198 | if(!engine_list_add(ENGINE_atalla())) | ||
| 199 | return 0; | ||
| 200 | #endif /* !NO_HW_ATALLA */ | ||
| 201 | #endif /* !NO_HW */ | ||
| 202 | engine_list_flag = 1; | ||
| 203 | return 1; | ||
| 204 | } | ||
| 205 | |||
| 206 | /* Get the first/last "ENGINE" type available. */ | ||
| 207 | ENGINE *ENGINE_get_first(void) | ||
| 208 | { | ||
| 209 | ENGINE *ret = NULL; | ||
| 210 | |||
| 211 | CRYPTO_r_lock(CRYPTO_LOCK_ENGINE); | ||
| 212 | if(engine_internal_check()) | ||
| 213 | { | ||
| 214 | ret = engine_list_head; | ||
| 215 | if(ret) | ||
| 216 | ret->struct_ref++; | ||
| 217 | } | ||
| 218 | CRYPTO_r_unlock(CRYPTO_LOCK_ENGINE); | ||
| 219 | return ret; | ||
| 220 | } | ||
| 221 | ENGINE *ENGINE_get_last(void) | ||
| 222 | { | ||
| 223 | ENGINE *ret = NULL; | ||
| 224 | |||
| 225 | CRYPTO_r_lock(CRYPTO_LOCK_ENGINE); | ||
| 226 | if(engine_internal_check()) | ||
| 227 | { | ||
| 228 | ret = engine_list_tail; | ||
| 229 | if(ret) | ||
| 230 | ret->struct_ref++; | ||
| 231 | } | ||
| 232 | CRYPTO_r_unlock(CRYPTO_LOCK_ENGINE); | ||
| 233 | return ret; | ||
| 234 | } | ||
| 235 | |||
| 236 | /* Iterate to the next/previous "ENGINE" type (NULL = end of the list). */ | ||
| 237 | ENGINE *ENGINE_get_next(ENGINE *e) | ||
| 238 | { | ||
| 239 | ENGINE *ret = NULL; | ||
| 240 | if(e == NULL) | ||
| 241 | { | ||
| 242 | ENGINEerr(ENGINE_F_ENGINE_GET_NEXT, | ||
| 243 | ERR_R_PASSED_NULL_PARAMETER); | ||
| 244 | return 0; | ||
| 245 | } | ||
| 246 | CRYPTO_r_lock(CRYPTO_LOCK_ENGINE); | ||
| 247 | ret = e->next; | ||
| 248 | e->struct_ref--; | ||
| 249 | if(ret) | ||
| 250 | ret->struct_ref++; | ||
| 251 | CRYPTO_r_unlock(CRYPTO_LOCK_ENGINE); | ||
| 252 | return ret; | ||
| 253 | } | ||
| 254 | ENGINE *ENGINE_get_prev(ENGINE *e) | ||
| 255 | { | ||
| 256 | ENGINE *ret = NULL; | ||
| 257 | if(e == NULL) | ||
| 258 | { | ||
| 259 | ENGINEerr(ENGINE_F_ENGINE_GET_PREV, | ||
| 260 | ERR_R_PASSED_NULL_PARAMETER); | ||
| 261 | return 0; | ||
| 262 | } | ||
| 263 | CRYPTO_r_lock(CRYPTO_LOCK_ENGINE); | ||
| 264 | ret = e->prev; | ||
| 265 | e->struct_ref--; | ||
| 266 | if(ret) | ||
| 267 | ret->struct_ref++; | ||
| 268 | CRYPTO_r_unlock(CRYPTO_LOCK_ENGINE); | ||
| 269 | return ret; | ||
| 270 | } | ||
| 271 | |||
| 272 | /* Add another "ENGINE" type into the list. */ | ||
| 273 | int ENGINE_add(ENGINE *e) | ||
| 274 | { | ||
| 275 | int to_return = 1; | ||
| 276 | if(e == NULL) | ||
| 277 | { | ||
| 278 | ENGINEerr(ENGINE_F_ENGINE_ADD, | ||
| 279 | ERR_R_PASSED_NULL_PARAMETER); | ||
| 280 | return 0; | ||
| 281 | } | ||
| 282 | if((e->id == NULL) || (e->name == NULL)) | ||
| 283 | { | ||
| 284 | ENGINEerr(ENGINE_F_ENGINE_ADD, | ||
| 285 | ENGINE_R_ID_OR_NAME_MISSING); | ||
| 286 | } | ||
| 287 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | ||
| 288 | if(!engine_internal_check() || !engine_list_add(e)) | ||
| 289 | { | ||
| 290 | ENGINEerr(ENGINE_F_ENGINE_ADD, | ||
| 291 | ENGINE_R_INTERNAL_LIST_ERROR); | ||
| 292 | to_return = 0; | ||
| 293 | } | ||
| 294 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | ||
| 295 | return to_return; | ||
| 296 | } | ||
| 297 | |||
| 298 | /* Remove an existing "ENGINE" type from the array. */ | ||
| 299 | int ENGINE_remove(ENGINE *e) | ||
| 300 | { | ||
| 301 | int to_return = 1; | ||
| 302 | if(e == NULL) | ||
| 303 | { | ||
| 304 | ENGINEerr(ENGINE_F_ENGINE_REMOVE, | ||
| 305 | ERR_R_PASSED_NULL_PARAMETER); | ||
| 306 | return 0; | ||
| 307 | } | ||
| 308 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | ||
| 309 | if(!engine_internal_check() || !engine_list_remove(e)) | ||
| 310 | { | ||
| 311 | ENGINEerr(ENGINE_F_ENGINE_REMOVE, | ||
| 312 | ENGINE_R_INTERNAL_LIST_ERROR); | ||
| 313 | to_return = 0; | ||
| 314 | } | ||
| 315 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | ||
| 316 | return to_return; | ||
| 317 | } | ||
| 318 | |||
| 319 | ENGINE *ENGINE_by_id(const char *id) | ||
| 320 | { | ||
| 321 | ENGINE *iterator = NULL; | ||
| 322 | if(id == NULL) | ||
| 323 | { | ||
| 324 | ENGINEerr(ENGINE_F_ENGINE_BY_ID, | ||
| 325 | ERR_R_PASSED_NULL_PARAMETER); | ||
| 326 | return NULL; | ||
| 327 | } | ||
| 328 | CRYPTO_r_lock(CRYPTO_LOCK_ENGINE); | ||
| 329 | if(!engine_internal_check()) | ||
| 330 | ENGINEerr(ENGINE_F_ENGINE_BY_ID, | ||
| 331 | ENGINE_R_INTERNAL_LIST_ERROR); | ||
| 332 | else | ||
| 333 | { | ||
| 334 | iterator = engine_list_head; | ||
| 335 | while(iterator && (strcmp(id, iterator->id) != 0)) | ||
| 336 | iterator = iterator->next; | ||
| 337 | if(iterator) | ||
| 338 | /* We need to return a structural reference */ | ||
| 339 | iterator->struct_ref++; | ||
| 340 | } | ||
| 341 | CRYPTO_r_unlock(CRYPTO_LOCK_ENGINE); | ||
| 342 | if(iterator == NULL) | ||
| 343 | ENGINEerr(ENGINE_F_ENGINE_BY_ID, | ||
| 344 | ENGINE_R_NO_SUCH_ENGINE); | ||
| 345 | return iterator; | ||
| 346 | } | ||
| 347 | |||
| 348 | /* As per the comments in engine.h, it is generally better all round | ||
| 349 | * if the ENGINE structure is allocated within this framework. */ | ||
| 350 | #if 0 | ||
| 351 | int ENGINE_get_struct_size(void) | ||
| 352 | { | ||
| 353 | return sizeof(ENGINE); | ||
| 354 | } | ||
| 355 | |||
| 356 | ENGINE *ENGINE_new(ENGINE *e) | ||
| 357 | { | ||
| 358 | ENGINE *ret; | ||
| 359 | |||
| 360 | if(e == NULL) | ||
| 361 | { | ||
| 362 | ret = (ENGINE *)(OPENSSL_malloc(sizeof(ENGINE)); | ||
| 363 | if(ret == NULL) | ||
| 364 | { | ||
| 365 | ENGINEerr(ENGINE_F_ENGINE_NEW, | ||
| 366 | ERR_R_MALLOC_FAILURE); | ||
| 367 | return NULL; | ||
| 368 | } | ||
| 369 | } | ||
| 370 | else | ||
| 371 | ret = e; | ||
| 372 | memset(ret, 0, sizeof(ENGINE)); | ||
| 373 | if(e) | ||
| 374 | ret->flags = ENGINE_FLAGS_MALLOCED; | ||
| 375 | ret->struct_ref = 1; | ||
| 376 | return ret; | ||
| 377 | } | ||
| 378 | #else | ||
| 379 | ENGINE *ENGINE_new(void) | ||
| 380 | { | ||
| 381 | ENGINE *ret; | ||
| 382 | |||
| 383 | ret = (ENGINE *)OPENSSL_malloc(sizeof(ENGINE)); | ||
| 384 | if(ret == NULL) | ||
| 385 | { | ||
| 386 | ENGINEerr(ENGINE_F_ENGINE_NEW, ERR_R_MALLOC_FAILURE); | ||
| 387 | return NULL; | ||
| 388 | } | ||
| 389 | memset(ret, 0, sizeof(ENGINE)); | ||
| 390 | ret->flags = ENGINE_FLAGS_MALLOCED; | ||
| 391 | ret->struct_ref = 1; | ||
| 392 | return ret; | ||
| 393 | } | ||
| 394 | #endif | ||
| 395 | |||
| 396 | int ENGINE_free(ENGINE *e) | ||
| 397 | { | ||
| 398 | int i; | ||
| 399 | |||
| 400 | if(e == NULL) | ||
| 401 | { | ||
| 402 | ENGINEerr(ENGINE_F_ENGINE_FREE, | ||
| 403 | ERR_R_PASSED_NULL_PARAMETER); | ||
| 404 | return 0; | ||
| 405 | } | ||
| 406 | i = CRYPTO_add(&e->struct_ref,-1,CRYPTO_LOCK_ENGINE); | ||
| 407 | #ifdef REF_PRINT | ||
| 408 | REF_PRINT("ENGINE",e); | ||
| 409 | #endif | ||
| 410 | if (i > 0) return 1; | ||
| 411 | #ifdef REF_CHECK | ||
| 412 | if (i < 0) | ||
| 413 | { | ||
| 414 | fprintf(stderr,"ENGINE_free, bad reference count\n"); | ||
| 415 | abort(); | ||
| 416 | } | ||
| 417 | #endif | ||
| 418 | if(e->flags & ENGINE_FLAGS_MALLOCED) | ||
| 419 | OPENSSL_free(e); | ||
| 420 | return 1; | ||
| 421 | } | ||
| 422 | |||
| 423 | int ENGINE_set_id(ENGINE *e, const char *id) | ||
| 424 | { | ||
| 425 | if((e == NULL) || (id == NULL)) | ||
| 426 | { | ||
| 427 | ENGINEerr(ENGINE_F_ENGINE_SET_ID, | ||
| 428 | ERR_R_PASSED_NULL_PARAMETER); | ||
| 429 | return 0; | ||
| 430 | } | ||
| 431 | e->id = id; | ||
| 432 | return 1; | ||
| 433 | } | ||
| 434 | |||
| 435 | int ENGINE_set_name(ENGINE *e, const char *name) | ||
| 436 | { | ||
| 437 | if((e == NULL) || (name == NULL)) | ||
| 438 | { | ||
| 439 | ENGINEerr(ENGINE_F_ENGINE_SET_NAME, | ||
| 440 | ERR_R_PASSED_NULL_PARAMETER); | ||
| 441 | return 0; | ||
| 442 | } | ||
| 443 | e->name = name; | ||
| 444 | return 1; | ||
| 445 | } | ||
| 446 | |||
| 447 | int ENGINE_set_RSA(ENGINE *e, RSA_METHOD *rsa_meth) | ||
| 448 | { | ||
| 449 | if((e == NULL) || (rsa_meth == NULL)) | ||
| 450 | { | ||
| 451 | ENGINEerr(ENGINE_F_ENGINE_SET_RSA, | ||
| 452 | ERR_R_PASSED_NULL_PARAMETER); | ||
| 453 | return 0; | ||
| 454 | } | ||
| 455 | e->rsa_meth = rsa_meth; | ||
| 456 | return 1; | ||
| 457 | } | ||
| 458 | |||
| 459 | int ENGINE_set_DSA(ENGINE *e, DSA_METHOD *dsa_meth) | ||
| 460 | { | ||
| 461 | if((e == NULL) || (dsa_meth == NULL)) | ||
| 462 | { | ||
| 463 | ENGINEerr(ENGINE_F_ENGINE_SET_DSA, | ||
| 464 | ERR_R_PASSED_NULL_PARAMETER); | ||
| 465 | return 0; | ||
| 466 | } | ||
| 467 | e->dsa_meth = dsa_meth; | ||
| 468 | return 1; | ||
| 469 | } | ||
| 470 | |||
| 471 | int ENGINE_set_DH(ENGINE *e, DH_METHOD *dh_meth) | ||
| 472 | { | ||
| 473 | if((e == NULL) || (dh_meth == NULL)) | ||
| 474 | { | ||
| 475 | ENGINEerr(ENGINE_F_ENGINE_SET_DH, | ||
| 476 | ERR_R_PASSED_NULL_PARAMETER); | ||
| 477 | return 0; | ||
| 478 | } | ||
| 479 | e->dh_meth = dh_meth; | ||
| 480 | return 1; | ||
| 481 | } | ||
| 482 | |||
| 483 | int ENGINE_set_RAND(ENGINE *e, RAND_METHOD *rand_meth) | ||
| 484 | { | ||
| 485 | if((e == NULL) || (rand_meth == NULL)) | ||
| 486 | { | ||
| 487 | ENGINEerr(ENGINE_F_ENGINE_SET_RAND, | ||
| 488 | ERR_R_PASSED_NULL_PARAMETER); | ||
| 489 | return 0; | ||
| 490 | } | ||
| 491 | e->rand_meth = rand_meth; | ||
| 492 | return 1; | ||
| 493 | } | ||
| 494 | |||
| 495 | int ENGINE_set_BN_mod_exp(ENGINE *e, BN_MOD_EXP bn_mod_exp) | ||
| 496 | { | ||
| 497 | if((e == NULL) || (bn_mod_exp == NULL)) | ||
| 498 | { | ||
| 499 | ENGINEerr(ENGINE_F_ENGINE_SET_BN_MOD_EXP, | ||
| 500 | ERR_R_PASSED_NULL_PARAMETER); | ||
| 501 | return 0; | ||
| 502 | } | ||
| 503 | e->bn_mod_exp = bn_mod_exp; | ||
| 504 | return 1; | ||
| 505 | } | ||
| 506 | |||
| 507 | int ENGINE_set_BN_mod_exp_crt(ENGINE *e, BN_MOD_EXP_CRT bn_mod_exp_crt) | ||
| 508 | { | ||
| 509 | if((e == NULL) || (bn_mod_exp_crt == NULL)) | ||
| 510 | { | ||
| 511 | ENGINEerr(ENGINE_F_ENGINE_SET_BN_MOD_EXP_CRT, | ||
| 512 | ERR_R_PASSED_NULL_PARAMETER); | ||
| 513 | return 0; | ||
| 514 | } | ||
| 515 | e->bn_mod_exp_crt = bn_mod_exp_crt; | ||
| 516 | return 1; | ||
| 517 | } | ||
| 518 | |||
| 519 | int ENGINE_set_init_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR init_f) | ||
| 520 | { | ||
| 521 | if((e == NULL) || (init_f == NULL)) | ||
| 522 | { | ||
| 523 | ENGINEerr(ENGINE_F_ENGINE_SET_INIT_FUNCTION, | ||
| 524 | ERR_R_PASSED_NULL_PARAMETER); | ||
| 525 | return 0; | ||
| 526 | } | ||
| 527 | e->init = init_f; | ||
| 528 | return 1; | ||
| 529 | } | ||
| 530 | |||
| 531 | int ENGINE_set_finish_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR finish_f) | ||
| 532 | { | ||
| 533 | if((e == NULL) || (finish_f == NULL)) | ||
| 534 | { | ||
| 535 | ENGINEerr(ENGINE_F_ENGINE_SET_FINISH_FUNCTION, | ||
| 536 | ERR_R_PASSED_NULL_PARAMETER); | ||
| 537 | return 0; | ||
| 538 | } | ||
| 539 | e->finish = finish_f; | ||
| 540 | return 1; | ||
| 541 | } | ||
| 542 | |||
| 543 | int ENGINE_set_ctrl_function(ENGINE *e, ENGINE_CTRL_FUNC_PTR ctrl_f) | ||
| 544 | { | ||
| 545 | if((e == NULL) || (ctrl_f == NULL)) | ||
| 546 | { | ||
| 547 | ENGINEerr(ENGINE_F_ENGINE_SET_CTRL_FUNCTION, | ||
| 548 | ERR_R_PASSED_NULL_PARAMETER); | ||
| 549 | return 0; | ||
| 550 | } | ||
| 551 | e->ctrl = ctrl_f; | ||
| 552 | return 1; | ||
| 553 | } | ||
| 554 | |||
| 555 | const char *ENGINE_get_id(ENGINE *e) | ||
| 556 | { | ||
| 557 | if(e == NULL) | ||
| 558 | { | ||
| 559 | ENGINEerr(ENGINE_F_ENGINE_GET_ID, | ||
| 560 | ERR_R_PASSED_NULL_PARAMETER); | ||
| 561 | return 0; | ||
| 562 | } | ||
| 563 | return e->id; | ||
| 564 | } | ||
| 565 | |||
| 566 | const char *ENGINE_get_name(ENGINE *e) | ||
| 567 | { | ||
| 568 | if(e == NULL) | ||
| 569 | { | ||
| 570 | ENGINEerr(ENGINE_F_ENGINE_GET_NAME, | ||
| 571 | ERR_R_PASSED_NULL_PARAMETER); | ||
| 572 | return 0; | ||
| 573 | } | ||
| 574 | return e->name; | ||
| 575 | } | ||
| 576 | |||
| 577 | RSA_METHOD *ENGINE_get_RSA(ENGINE *e) | ||
| 578 | { | ||
| 579 | if(e == NULL) | ||
| 580 | { | ||
| 581 | ENGINEerr(ENGINE_F_ENGINE_GET_RSA, | ||
| 582 | ERR_R_PASSED_NULL_PARAMETER); | ||
| 583 | return NULL; | ||
| 584 | } | ||
| 585 | return e->rsa_meth; | ||
| 586 | } | ||
| 587 | |||
| 588 | DSA_METHOD *ENGINE_get_DSA(ENGINE *e) | ||
| 589 | { | ||
| 590 | if(e == NULL) | ||
| 591 | { | ||
| 592 | ENGINEerr(ENGINE_F_ENGINE_GET_DSA, | ||
| 593 | ERR_R_PASSED_NULL_PARAMETER); | ||
| 594 | return NULL; | ||
| 595 | } | ||
| 596 | return e->dsa_meth; | ||
| 597 | } | ||
| 598 | |||
| 599 | DH_METHOD *ENGINE_get_DH(ENGINE *e) | ||
| 600 | { | ||
| 601 | if(e == NULL) | ||
| 602 | { | ||
| 603 | ENGINEerr(ENGINE_F_ENGINE_GET_DH, | ||
| 604 | ERR_R_PASSED_NULL_PARAMETER); | ||
| 605 | return NULL; | ||
| 606 | } | ||
| 607 | return e->dh_meth; | ||
| 608 | } | ||
| 609 | |||
| 610 | RAND_METHOD *ENGINE_get_RAND(ENGINE *e) | ||
| 611 | { | ||
| 612 | if(e == NULL) | ||
| 613 | { | ||
| 614 | ENGINEerr(ENGINE_F_ENGINE_GET_RAND, | ||
| 615 | ERR_R_PASSED_NULL_PARAMETER); | ||
| 616 | return NULL; | ||
| 617 | } | ||
| 618 | return e->rand_meth; | ||
| 619 | } | ||
| 620 | |||
| 621 | BN_MOD_EXP ENGINE_get_BN_mod_exp(ENGINE *e) | ||
| 622 | { | ||
| 623 | if(e == NULL) | ||
| 624 | { | ||
| 625 | ENGINEerr(ENGINE_F_ENGINE_GET_BN_MOD_EXP, | ||
| 626 | ERR_R_PASSED_NULL_PARAMETER); | ||
| 627 | return NULL; | ||
| 628 | } | ||
| 629 | return e->bn_mod_exp; | ||
| 630 | } | ||
| 631 | |||
| 632 | BN_MOD_EXP_CRT ENGINE_get_BN_mod_exp_crt(ENGINE *e) | ||
| 633 | { | ||
| 634 | if(e == NULL) | ||
| 635 | { | ||
| 636 | ENGINEerr(ENGINE_F_ENGINE_GET_BN_MOD_EXP_CRT, | ||
| 637 | ERR_R_PASSED_NULL_PARAMETER); | ||
| 638 | return NULL; | ||
| 639 | } | ||
| 640 | return e->bn_mod_exp_crt; | ||
| 641 | } | ||
| 642 | |||
| 643 | ENGINE_GEN_INT_FUNC_PTR ENGINE_get_init_function(ENGINE *e) | ||
| 644 | { | ||
| 645 | if(e == NULL) | ||
| 646 | { | ||
| 647 | ENGINEerr(ENGINE_F_ENGINE_GET_INIT_FUNCTION, | ||
| 648 | ERR_R_PASSED_NULL_PARAMETER); | ||
| 649 | return NULL; | ||
| 650 | } | ||
| 651 | return e->init; | ||
| 652 | } | ||
| 653 | |||
| 654 | ENGINE_GEN_INT_FUNC_PTR ENGINE_get_finish_function(ENGINE *e) | ||
| 655 | { | ||
| 656 | if(e == NULL) | ||
| 657 | { | ||
| 658 | ENGINEerr(ENGINE_F_ENGINE_GET_FINISH_FUNCTION, | ||
| 659 | ERR_R_PASSED_NULL_PARAMETER); | ||
| 660 | return NULL; | ||
| 661 | } | ||
| 662 | return e->finish; | ||
| 663 | } | ||
| 664 | |||
| 665 | ENGINE_CTRL_FUNC_PTR ENGINE_get_ctrl_function(ENGINE *e) | ||
| 666 | { | ||
| 667 | if(e == NULL) | ||
| 668 | { | ||
| 669 | ENGINEerr(ENGINE_F_ENGINE_GET_CTRL_FUNCTION, | ||
| 670 | ERR_R_PASSED_NULL_PARAMETER); | ||
| 671 | return NULL; | ||
| 672 | } | ||
| 673 | return e->ctrl; | ||
| 674 | } | ||
| 675 | |||
diff --git a/src/lib/libcrypto/engine/engine_openssl.c b/src/lib/libcrypto/engine/engine_openssl.c deleted file mode 100644 index 9636f51168..0000000000 --- a/src/lib/libcrypto/engine/engine_openssl.c +++ /dev/null | |||
| @@ -1,174 +0,0 @@ | |||
| 1 | /* crypto/engine/engine_openssl.c */ | ||
| 2 | /* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL | ||
| 3 | * project 2000. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | |||
| 59 | |||
| 60 | #include <stdio.h> | ||
| 61 | #include <openssl/crypto.h> | ||
| 62 | #include "cryptlib.h" | ||
| 63 | #include "engine_int.h" | ||
| 64 | #include <openssl/engine.h> | ||
| 65 | #include <openssl/dso.h> | ||
| 66 | #include <openssl/rsa.h> | ||
| 67 | #include <openssl/dsa.h> | ||
| 68 | #include <openssl/dh.h> | ||
| 69 | #include <openssl/rand.h> | ||
| 70 | #include <openssl/bn.h> | ||
| 71 | |||
| 72 | /* This is the only function we need to implement as OpenSSL | ||
| 73 | * doesn't have a native CRT mod_exp. Perhaps this should be | ||
| 74 | * BN_mod_exp_crt and moved into crypto/bn/ ?? ... dunno. */ | ||
| 75 | static int openssl_mod_exp_crt(BIGNUM *r, BIGNUM *a, const BIGNUM *p, | ||
| 76 | const BIGNUM *q, const BIGNUM *dmp1, const BIGNUM *dmq1, | ||
| 77 | const BIGNUM *iqmp, BN_CTX *ctx); | ||
| 78 | |||
| 79 | /* The ENGINE structure that can be pointed to. */ | ||
| 80 | static ENGINE engine_openssl = | ||
| 81 | { | ||
| 82 | "openssl", | ||
| 83 | "Software default engine support", | ||
| 84 | NULL, | ||
| 85 | NULL, | ||
| 86 | NULL, /* these methods are "stolen" in ENGINE_openssl() */ | ||
| 87 | NULL, | ||
| 88 | NULL, | ||
| 89 | openssl_mod_exp_crt, | ||
| 90 | NULL, /* no init() */ | ||
| 91 | NULL, /* no finish() */ | ||
| 92 | NULL, /* no ctrl() */ | ||
| 93 | NULL, /* no load_privkey() */ | ||
| 94 | NULL, /* no load_pubkey() */ | ||
| 95 | 0, /* no flags */ | ||
| 96 | 0, 0, /* no references. */ | ||
| 97 | NULL, NULL /* unlinked */ | ||
| 98 | }; | ||
| 99 | |||
| 100 | /* As this is only ever called once, there's no need for locking | ||
| 101 | * (indeed - the lock will already be held by our caller!!!) */ | ||
| 102 | ENGINE *ENGINE_openssl() | ||
| 103 | { | ||
| 104 | /* We need to populate our structure with the software pointers | ||
| 105 | * that we want to steal. */ | ||
| 106 | engine_openssl.rsa_meth = RSA_get_default_openssl_method(); | ||
| 107 | engine_openssl.dsa_meth = DSA_get_default_openssl_method(); | ||
| 108 | engine_openssl.dh_meth = DH_get_default_openssl_method(); | ||
| 109 | engine_openssl.rand_meth = RAND_SSLeay(); | ||
| 110 | engine_openssl.bn_mod_exp = BN_mod_exp; | ||
| 111 | return &engine_openssl; | ||
| 112 | } | ||
| 113 | |||
| 114 | /* Chinese Remainder Theorem, taken and adapted from rsa_eay.c */ | ||
| 115 | static int openssl_mod_exp_crt(BIGNUM *r, BIGNUM *a, const BIGNUM *p, | ||
| 116 | const BIGNUM *q, const BIGNUM *dmp1, | ||
| 117 | const BIGNUM *dmq1, const BIGNUM *iqmp, BN_CTX *ctx) | ||
| 118 | { | ||
| 119 | BIGNUM r1,m1; | ||
| 120 | int ret=0; | ||
| 121 | BN_CTX *bn_ctx; | ||
| 122 | BIGNUM *temp_bn = NULL; | ||
| 123 | |||
| 124 | if (ctx) | ||
| 125 | bn_ctx = ctx; | ||
| 126 | else | ||
| 127 | if ((bn_ctx=BN_CTX_new()) == NULL) goto err; | ||
| 128 | BN_init(&m1); | ||
| 129 | BN_init(&r1); | ||
| 130 | /* BN_mul() cannot accept const BIGNUMs so I use the BN_CTX | ||
| 131 | * to duplicate what I need. <sigh> */ | ||
| 132 | if ((temp_bn = BN_CTX_get(bn_ctx)) == NULL) goto err; | ||
| 133 | if (!BN_copy(temp_bn, iqmp)) goto err; | ||
| 134 | |||
| 135 | if (!BN_mod(&r1, a, q, bn_ctx)) goto err; | ||
| 136 | if (!engine_openssl.bn_mod_exp(&m1, &r1, dmq1, q, bn_ctx)) | ||
| 137 | goto err; | ||
| 138 | |||
| 139 | if (!BN_mod(&r1, a, p, bn_ctx)) goto err; | ||
| 140 | if (!engine_openssl.bn_mod_exp(r, &r1, dmp1, p, bn_ctx)) | ||
| 141 | goto err; | ||
| 142 | |||
| 143 | if (!BN_sub(r, r, &m1)) goto err; | ||
| 144 | /* This will help stop the size of r0 increasing, which does | ||
| 145 | * affect the multiply if it optimised for a power of 2 size */ | ||
| 146 | if (r->neg) | ||
| 147 | if (!BN_add(r, r, p)) goto err; | ||
| 148 | |||
| 149 | if (!BN_mul(&r1, r, temp_bn, bn_ctx)) goto err; | ||
| 150 | if (!BN_mod(r, &r1, p, bn_ctx)) goto err; | ||
| 151 | /* If p < q it is occasionally possible for the correction of | ||
| 152 | * adding 'p' if r is negative above to leave the result still | ||
| 153 | * negative. This can break the private key operations: the following | ||
| 154 | * second correction should *always* correct this rare occurrence. | ||
| 155 | * This will *never* happen with OpenSSL generated keys because | ||
| 156 | * they ensure p > q [steve] | ||
| 157 | */ | ||
| 158 | if (r->neg) | ||
| 159 | if (!BN_add(r, r, p)) goto err; | ||
| 160 | /* Again, BN_mul() will need non-const values. */ | ||
| 161 | if (!BN_copy(temp_bn, q)) goto err; | ||
| 162 | if (!BN_mul(&r1, r, temp_bn, bn_ctx)) goto err; | ||
| 163 | if (!BN_add(r, &r1, &m1)) goto err; | ||
| 164 | |||
| 165 | ret=1; | ||
| 166 | err: | ||
| 167 | BN_clear_free(&m1); | ||
| 168 | BN_clear_free(&r1); | ||
| 169 | if (temp_bn) | ||
| 170 | bn_ctx->tos--; | ||
| 171 | if (!ctx) | ||
| 172 | BN_CTX_free(bn_ctx); | ||
| 173 | return(ret); | ||
| 174 | } | ||
