summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/engine
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/engine')
-rw-r--r--src/lib/libcrypto/engine/eng_all.c31
-rw-r--r--src/lib/libcrypto/engine/eng_cnf.c7
-rw-r--r--src/lib/libcrypto/engine/eng_ctrl.c12
-rw-r--r--src/lib/libcrypto/engine/eng_dyn.c108
-rw-r--r--src/lib/libcrypto/engine/eng_err.c16
-rw-r--r--src/lib/libcrypto/engine/eng_fat.c26
-rw-r--r--src/lib/libcrypto/engine/eng_init.c5
-rw-r--r--src/lib/libcrypto/engine/eng_int.h9
-rw-r--r--src/lib/libcrypto/engine/eng_lib.c18
-rw-r--r--src/lib/libcrypto/engine/eng_list.c43
-rw-r--r--src/lib/libcrypto/engine/eng_openssl.c25
-rw-r--r--src/lib/libcrypto/engine/eng_pkey.c3
-rw-r--r--src/lib/libcrypto/engine/eng_table.c94
-rw-r--r--src/lib/libcrypto/engine/engine.h158
-rw-r--r--src/lib/libcrypto/engine/enginetest.c2
-rw-r--r--src/lib/libcrypto/engine/tb_cipher.c2
-rw-r--r--src/lib/libcrypto/engine/tb_dh.c2
-rw-r--r--src/lib/libcrypto/engine/tb_digest.c2
-rw-r--r--src/lib/libcrypto/engine/tb_dsa.c2
-rw-r--r--src/lib/libcrypto/engine/tb_rand.c2
-rw-r--r--src/lib/libcrypto/engine/tb_rsa.c2
21 files changed, 374 insertions, 195 deletions
diff --git a/src/lib/libcrypto/engine/eng_all.c b/src/lib/libcrypto/engine/eng_all.c
index 0f6992a40d..8599046717 100644
--- a/src/lib/libcrypto/engine/eng_all.c
+++ b/src/lib/libcrypto/engine/eng_all.c
@@ -56,8 +56,7 @@
56 * 56 *
57 */ 57 */
58 58
59#include <openssl/err.h> 59#include "cryptlib.h"
60#include <openssl/engine.h>
61#include "eng_int.h" 60#include "eng_int.h"
62 61
63void ENGINE_load_builtin_engines(void) 62void ENGINE_load_builtin_engines(void)
@@ -69,32 +68,42 @@ void ENGINE_load_builtin_engines(void)
69#if 0 68#if 0
70 ENGINE_load_openssl(); 69 ENGINE_load_openssl();
71#endif 70#endif
71#if !defined(OPENSSL_NO_HW) && !defined(OPENSSL_NO_HW_PADLOCK)
72 ENGINE_load_padlock();
73#endif
72 ENGINE_load_dynamic(); 74 ENGINE_load_dynamic();
75#ifndef OPENSSL_NO_STATIC_ENGINE
73#ifndef OPENSSL_NO_HW 76#ifndef OPENSSL_NO_HW
77#ifndef OPENSSL_NO_HW_4758_CCA
78 ENGINE_load_4758cca();
79#endif
80#ifndef OPENSSL_NO_HW_AEP
81 ENGINE_load_aep();
82#endif
83#ifndef OPENSSL_NO_HW_ATALLA
84 ENGINE_load_atalla();
85#endif
74#ifndef OPENSSL_NO_HW_CSWIFT 86#ifndef OPENSSL_NO_HW_CSWIFT
75 ENGINE_load_cswift(); 87 ENGINE_load_cswift();
76#endif 88#endif
77#ifndef OPENSSL_NO_HW_NCIPHER 89#ifndef OPENSSL_NO_HW_NCIPHER
78 ENGINE_load_chil(); 90 ENGINE_load_chil();
79#endif 91#endif
80#ifndef OPENSSL_NO_HW_ATALLA
81 ENGINE_load_atalla();
82#endif
83#ifndef OPENSSL_NO_HW_NURON 92#ifndef OPENSSL_NO_HW_NURON
84 ENGINE_load_nuron(); 93 ENGINE_load_nuron();
85#endif 94#endif
95#ifndef OPENSSL_NO_HW_SUREWARE
96 ENGINE_load_sureware();
97#endif
86#ifndef OPENSSL_NO_HW_UBSEC 98#ifndef OPENSSL_NO_HW_UBSEC
87 ENGINE_load_ubsec(); 99 ENGINE_load_ubsec();
88#endif 100#endif
89#ifndef OPENSSL_NO_HW_AEP
90 ENGINE_load_aep();
91#endif 101#endif
92#ifndef OPENSSL_NO_HW_SUREWARE 102#if !defined(OPENSSL_NO_GMP) && !defined(OPENSSL_NO_HW_GMP)
93 ENGINE_load_sureware(); 103 ENGINE_load_gmp();
94#endif 104#endif
95#ifndef OPENSSL_NO_HW_4758_CCA
96 ENGINE_load_4758cca();
97#endif 105#endif
106#ifndef OPENSSL_NO_HW
98#if defined(__OpenBSD__) || defined(__FreeBSD__) 107#if defined(__OpenBSD__) || defined(__FreeBSD__)
99 ENGINE_load_cryptodev(); 108 ENGINE_load_cryptodev();
100#endif 109#endif
diff --git a/src/lib/libcrypto/engine/eng_cnf.c b/src/lib/libcrypto/engine/eng_cnf.c
index 4225760af1..a97e01e619 100644
--- a/src/lib/libcrypto/engine/eng_cnf.c
+++ b/src/lib/libcrypto/engine/eng_cnf.c
@@ -56,11 +56,8 @@
56 * 56 *
57 */ 57 */
58 58
59#include <stdio.h> 59#include "eng_int.h"
60#include <openssl/crypto.h>
61#include "cryptlib.h"
62#include <openssl/conf.h> 60#include <openssl/conf.h>
63#include <openssl/engine.h>
64 61
65/* #define ENGINE_CONF_DEBUG */ 62/* #define ENGINE_CONF_DEBUG */
66 63
@@ -210,7 +207,7 @@ static int int_engine_module_init(CONF_IMODULE *md, const CONF *cnf)
210 207
211 if (!elist) 208 if (!elist)
212 { 209 {
213 ENGINEerr(ENGINE_F_ENGINE_MODULE_INIT, ENGINE_R_ENGINES_SECTION_ERROR); 210 ENGINEerr(ENGINE_F_INT_ENGINE_MODULE_INIT, ENGINE_R_ENGINES_SECTION_ERROR);
214 return 0; 211 return 0;
215 } 212 }
216 213
diff --git a/src/lib/libcrypto/engine/eng_ctrl.c b/src/lib/libcrypto/engine/eng_ctrl.c
index 412c73fb0f..95b6b455aa 100644
--- a/src/lib/libcrypto/engine/eng_ctrl.c
+++ b/src/lib/libcrypto/engine/eng_ctrl.c
@@ -53,10 +53,7 @@
53 * 53 *
54 */ 54 */
55 55
56#include <openssl/crypto.h>
57#include "cryptlib.h"
58#include "eng_int.h" 56#include "eng_int.h"
59#include <openssl/engine.h>
60 57
61/* When querying a ENGINE-specific control command's 'description', this string 58/* When querying a ENGINE-specific control command's 'description', this string
62 * is used if the ENGINE_CMD_DEFN has cmd_desc set to NULL. */ 59 * is used if the ENGINE_CMD_DEFN has cmd_desc set to NULL. */
@@ -103,7 +100,8 @@ static int int_ctrl_cmd_by_num(const ENGINE_CMD_DEFN *defn, unsigned int num)
103 return -1; 100 return -1;
104 } 101 }
105 102
106static int int_ctrl_helper(ENGINE *e, int cmd, long i, void *p, void (*f)()) 103static int int_ctrl_helper(ENGINE *e, int cmd, long i, void *p,
104 void (*f)(void))
107 { 105 {
108 int idx; 106 int idx;
109 char *s = (char *)p; 107 char *s = (char *)p;
@@ -181,7 +179,7 @@ static int int_ctrl_helper(ENGINE *e, int cmd, long i, void *p, void (*f)())
181 return -1; 179 return -1;
182 } 180 }
183 181
184int ENGINE_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)()) 182int ENGINE_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void))
185 { 183 {
186 int ctrl_exists, ref_exists; 184 int ctrl_exists, ref_exists;
187 if(e == NULL) 185 if(e == NULL)
@@ -251,13 +249,13 @@ int ENGINE_cmd_is_executable(ENGINE *e, int cmd)
251 } 249 }
252 250
253int ENGINE_ctrl_cmd(ENGINE *e, const char *cmd_name, 251int ENGINE_ctrl_cmd(ENGINE *e, const char *cmd_name,
254 long i, void *p, void (*f)(), int cmd_optional) 252 long i, void *p, void (*f)(void), int cmd_optional)
255 { 253 {
256 int num; 254 int num;
257 255
258 if((e == NULL) || (cmd_name == NULL)) 256 if((e == NULL) || (cmd_name == NULL))
259 { 257 {
260 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING, 258 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD,
261 ERR_R_PASSED_NULL_PARAMETER); 259 ERR_R_PASSED_NULL_PARAMETER);
262 return 0; 260 return 0;
263 } 261 }
diff --git a/src/lib/libcrypto/engine/eng_dyn.c b/src/lib/libcrypto/engine/eng_dyn.c
index 4139a16e76..acb30c34d8 100644
--- a/src/lib/libcrypto/engine/eng_dyn.c
+++ b/src/lib/libcrypto/engine/eng_dyn.c
@@ -57,11 +57,7 @@
57 */ 57 */
58 58
59 59
60#include <stdio.h>
61#include <openssl/crypto.h>
62#include "cryptlib.h"
63#include "eng_int.h" 60#include "eng_int.h"
64#include <openssl/engine.h>
65#include <openssl/dso.h> 61#include <openssl/dso.h>
66 62
67/* Shared libraries implementing ENGINEs for use by the "dynamic" ENGINE loader 63/* Shared libraries implementing ENGINEs for use by the "dynamic" ENGINE loader
@@ -70,7 +66,7 @@
70/* Our ENGINE handlers */ 66/* Our ENGINE handlers */
71static int dynamic_init(ENGINE *e); 67static int dynamic_init(ENGINE *e);
72static int dynamic_finish(ENGINE *e); 68static int dynamic_finish(ENGINE *e);
73static int dynamic_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)()); 69static int dynamic_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void));
74/* Predeclare our context type */ 70/* Predeclare our context type */
75typedef struct st_dynamic_data_ctx dynamic_data_ctx; 71typedef struct st_dynamic_data_ctx dynamic_data_ctx;
76/* The implementation for the important control command */ 72/* The implementation for the important control command */
@@ -80,7 +76,9 @@ static int dynamic_load(ENGINE *e, dynamic_data_ctx *ctx);
80#define DYNAMIC_CMD_NO_VCHECK (ENGINE_CMD_BASE + 1) 76#define DYNAMIC_CMD_NO_VCHECK (ENGINE_CMD_BASE + 1)
81#define DYNAMIC_CMD_ID (ENGINE_CMD_BASE + 2) 77#define DYNAMIC_CMD_ID (ENGINE_CMD_BASE + 2)
82#define DYNAMIC_CMD_LIST_ADD (ENGINE_CMD_BASE + 3) 78#define DYNAMIC_CMD_LIST_ADD (ENGINE_CMD_BASE + 3)
83#define DYNAMIC_CMD_LOAD (ENGINE_CMD_BASE + 4) 79#define DYNAMIC_CMD_DIR_LOAD (ENGINE_CMD_BASE + 4)
80#define DYNAMIC_CMD_DIR_ADD (ENGINE_CMD_BASE + 5)
81#define DYNAMIC_CMD_LOAD (ENGINE_CMD_BASE + 6)
84 82
85/* The constants used when creating the ENGINE */ 83/* The constants used when creating the ENGINE */
86static const char *engine_dynamic_id = "dynamic"; 84static const char *engine_dynamic_id = "dynamic";
@@ -102,6 +100,14 @@ static const ENGINE_CMD_DEFN dynamic_cmd_defns[] = {
102 "LIST_ADD", 100 "LIST_ADD",
103 "Whether to add a loaded ENGINE to the internal list (0=no,1=yes,2=mandatory)", 101 "Whether to add a loaded ENGINE to the internal list (0=no,1=yes,2=mandatory)",
104 ENGINE_CMD_FLAG_NUMERIC}, 102 ENGINE_CMD_FLAG_NUMERIC},
103 {DYNAMIC_CMD_DIR_LOAD,
104 "DIR_LOAD",
105 "Specifies whether to load from 'DIR_ADD' directories (0=no,1=yes,2=mandatory)",
106 ENGINE_CMD_FLAG_NUMERIC},
107 {DYNAMIC_CMD_DIR_ADD,
108 "DIR_ADD",
109 "Adds a directory from which ENGINEs can be loaded",
110 ENGINE_CMD_FLAG_STRING},
105 {DYNAMIC_CMD_LOAD, 111 {DYNAMIC_CMD_LOAD,
106 "LOAD", 112 "LOAD",
107 "Load up the ENGINE specified by other settings", 113 "Load up the ENGINE specified by other settings",
@@ -136,12 +142,18 @@ struct st_dynamic_data_ctx
136 const char *DYNAMIC_F1; 142 const char *DYNAMIC_F1;
137 /* The symbol name for the "initialise ENGINE structure" function */ 143 /* The symbol name for the "initialise ENGINE structure" function */
138 const char *DYNAMIC_F2; 144 const char *DYNAMIC_F2;
145 /* Whether to never use 'dirs', use 'dirs' as a fallback, or only use
146 * 'dirs' for loading. Default is to use 'dirs' as a fallback. */
147 int dir_load;
148 /* A stack of directories from which ENGINEs could be loaded */
149 STACK *dirs;
139 }; 150 };
140 151
141/* This is the "ex_data" index we obtain and reserve for use with our context 152/* This is the "ex_data" index we obtain and reserve for use with our context
142 * structure. */ 153 * structure. */
143static int dynamic_ex_data_idx = -1; 154static int dynamic_ex_data_idx = -1;
144 155
156static void int_free_str(void *s) { OPENSSL_free(s); }
145/* Because our ex_data element may or may not get allocated depending on whether 157/* Because our ex_data element may or may not get allocated depending on whether
146 * a "first-use" occurs before the ENGINE is freed, we have a memory leak 158 * a "first-use" occurs before the ENGINE is freed, we have a memory leak
147 * problem to solve. We can't declare a "new" handler for the ex_data as we 159 * problem to solve. We can't declare a "new" handler for the ex_data as we
@@ -161,6 +173,8 @@ static void dynamic_data_ctx_free_func(void *parent, void *ptr,
161 OPENSSL_free((void*)ctx->DYNAMIC_LIBNAME); 173 OPENSSL_free((void*)ctx->DYNAMIC_LIBNAME);
162 if(ctx->engine_id) 174 if(ctx->engine_id)
163 OPENSSL_free((void*)ctx->engine_id); 175 OPENSSL_free((void*)ctx->engine_id);
176 if(ctx->dirs)
177 sk_pop_free(ctx->dirs, int_free_str);
164 OPENSSL_free(ctx); 178 OPENSSL_free(ctx);
165 } 179 }
166 } 180 }
@@ -175,7 +189,7 @@ static int dynamic_set_data_ctx(ENGINE *e, dynamic_data_ctx **ctx)
175 c = OPENSSL_malloc(sizeof(dynamic_data_ctx)); 189 c = OPENSSL_malloc(sizeof(dynamic_data_ctx));
176 if(!c) 190 if(!c)
177 { 191 {
178 ENGINEerr(ENGINE_F_SET_DATA_CTX,ERR_R_MALLOC_FAILURE); 192 ENGINEerr(ENGINE_F_DYNAMIC_SET_DATA_CTX,ERR_R_MALLOC_FAILURE);
179 return 0; 193 return 0;
180 } 194 }
181 memset(c, 0, sizeof(dynamic_data_ctx)); 195 memset(c, 0, sizeof(dynamic_data_ctx));
@@ -188,6 +202,14 @@ static int dynamic_set_data_ctx(ENGINE *e, dynamic_data_ctx **ctx)
188 c->list_add_value = 0; 202 c->list_add_value = 0;
189 c->DYNAMIC_F1 = "v_check"; 203 c->DYNAMIC_F1 = "v_check";
190 c->DYNAMIC_F2 = "bind_engine"; 204 c->DYNAMIC_F2 = "bind_engine";
205 c->dir_load = 1;
206 c->dirs = sk_new_null();
207 if(!c->dirs)
208 {
209 ENGINEerr(ENGINE_F_DYNAMIC_SET_DATA_CTX,ERR_R_MALLOC_FAILURE);
210 OPENSSL_free(c);
211 return 0;
212 }
191 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); 213 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
192 if((*ctx = (dynamic_data_ctx *)ENGINE_get_ex_data(e, 214 if((*ctx = (dynamic_data_ctx *)ENGINE_get_ex_data(e,
193 dynamic_ex_data_idx)) == NULL) 215 dynamic_ex_data_idx)) == NULL)
@@ -290,7 +312,7 @@ static int dynamic_finish(ENGINE *e)
290 return 0; 312 return 0;
291 } 313 }
292 314
293static int dynamic_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)()) 315static int dynamic_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void))
294 { 316 {
295 dynamic_data_ctx *ctx = dynamic_get_data_ctx(e); 317 dynamic_data_ctx *ctx = dynamic_get_data_ctx(e);
296 int initialised; 318 int initialised;
@@ -346,6 +368,34 @@ static int dynamic_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)())
346 return 1; 368 return 1;
347 case DYNAMIC_CMD_LOAD: 369 case DYNAMIC_CMD_LOAD:
348 return dynamic_load(e, ctx); 370 return dynamic_load(e, ctx);
371 case DYNAMIC_CMD_DIR_LOAD:
372 if((i < 0) || (i > 2))
373 {
374 ENGINEerr(ENGINE_F_DYNAMIC_CTRL,
375 ENGINE_R_INVALID_ARGUMENT);
376 return 0;
377 }
378 ctx->dir_load = (int)i;
379 return 1;
380 case DYNAMIC_CMD_DIR_ADD:
381 /* a NULL 'p' or a string of zero-length is the same thing */
382 if(!p || (strlen((const char *)p) < 1))
383 {
384 ENGINEerr(ENGINE_F_DYNAMIC_CTRL,
385 ENGINE_R_INVALID_ARGUMENT);
386 return 0;
387 }
388 {
389 char *tmp_str = BUF_strdup(p);
390 if(!tmp_str)
391 {
392 ENGINEerr(ENGINE_F_DYNAMIC_CTRL,
393 ERR_R_MALLOC_FAILURE);
394 return 0;
395 }
396 sk_insert(ctx->dirs, tmp_str, -1);
397 }
398 return 1;
349 default: 399 default:
350 break; 400 break;
351 } 401 }
@@ -353,16 +403,53 @@ static int dynamic_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)())
353 return 0; 403 return 0;
354 } 404 }
355 405
406static int int_load(dynamic_data_ctx *ctx)
407 {
408 int num, loop;
409 /* Unless told not to, try a direct load */
410 if((ctx->dir_load != 2) && (DSO_load(ctx->dynamic_dso,
411 ctx->DYNAMIC_LIBNAME, NULL, 0)) != NULL)
412 return 1;
413 /* If we're not allowed to use 'dirs' or we have none, fail */
414 if(!ctx->dir_load || ((num = sk_num(ctx->dirs)) < 1))
415 return 0;
416 for(loop = 0; loop < num; loop++)
417 {
418 const char *s = sk_value(ctx->dirs, loop);
419 char *merge = DSO_merge(ctx->dynamic_dso, ctx->DYNAMIC_LIBNAME, s);
420 if(!merge)
421 return 0;
422 if(DSO_load(ctx->dynamic_dso, merge, NULL, 0))
423 {
424 /* Found what we're looking for */
425 OPENSSL_free(merge);
426 return 1;
427 }
428 OPENSSL_free(merge);
429 }
430 return 0;
431 }
432
356static int dynamic_load(ENGINE *e, dynamic_data_ctx *ctx) 433static int dynamic_load(ENGINE *e, dynamic_data_ctx *ctx)
357 { 434 {
358 ENGINE cpy; 435 ENGINE cpy;
359 dynamic_fns fns; 436 dynamic_fns fns;
360 437
361 if(!ctx->DYNAMIC_LIBNAME || ((ctx->dynamic_dso = DSO_load(NULL, 438 if(!ctx->dynamic_dso)
362 ctx->DYNAMIC_LIBNAME, NULL, 0)) == NULL)) 439 ctx->dynamic_dso = DSO_new();
440 if(!ctx->DYNAMIC_LIBNAME)
441 {
442 if(!ctx->engine_id)
443 return 0;
444 ctx->DYNAMIC_LIBNAME =
445 DSO_convert_filename(ctx->dynamic_dso, ctx->engine_id);
446 }
447 if(!int_load(ctx))
363 { 448 {
364 ENGINEerr(ENGINE_F_DYNAMIC_LOAD, 449 ENGINEerr(ENGINE_F_DYNAMIC_LOAD,
365 ENGINE_R_DSO_NOT_FOUND); 450 ENGINE_R_DSO_NOT_FOUND);
451 DSO_free(ctx->dynamic_dso);
452 ctx->dynamic_dso = NULL;
366 return 0; 453 return 0;
367 } 454 }
368 /* We have to find a bind function otherwise it'll always end badly */ 455 /* We have to find a bind function otherwise it'll always end badly */
@@ -409,6 +496,7 @@ static int dynamic_load(ENGINE *e, dynamic_data_ctx *ctx)
409 * engine.h, much of this would be simplified if each area of code 496 * engine.h, much of this would be simplified if each area of code
410 * provided its own "summary" structure of all related callbacks. It 497 * provided its own "summary" structure of all related callbacks. It
411 * would also increase opaqueness. */ 498 * would also increase opaqueness. */
499 fns.static_state = ENGINE_get_static_state();
412 fns.err_fns = ERR_get_implementation(); 500 fns.err_fns = ERR_get_implementation();
413 fns.ex_data_fns = CRYPTO_get_ex_data_implementation(); 501 fns.ex_data_fns = CRYPTO_get_ex_data_implementation();
414 CRYPTO_get_mem_functions(&fns.mem_fns.malloc_cb, 502 CRYPTO_get_mem_functions(&fns.mem_fns.malloc_cb,
diff --git a/src/lib/libcrypto/engine/eng_err.c b/src/lib/libcrypto/engine/eng_err.c
index fdc0e7be0f..369f2e22d3 100644
--- a/src/lib/libcrypto/engine/eng_err.c
+++ b/src/lib/libcrypto/engine/eng_err.c
@@ -73,6 +73,7 @@ static ERR_STRING_DATA ENGINE_str_functs[]=
73{ERR_FUNC(ENGINE_F_DYNAMIC_CTRL), "DYNAMIC_CTRL"}, 73{ERR_FUNC(ENGINE_F_DYNAMIC_CTRL), "DYNAMIC_CTRL"},
74{ERR_FUNC(ENGINE_F_DYNAMIC_GET_DATA_CTX), "DYNAMIC_GET_DATA_CTX"}, 74{ERR_FUNC(ENGINE_F_DYNAMIC_GET_DATA_CTX), "DYNAMIC_GET_DATA_CTX"},
75{ERR_FUNC(ENGINE_F_DYNAMIC_LOAD), "DYNAMIC_LOAD"}, 75{ERR_FUNC(ENGINE_F_DYNAMIC_LOAD), "DYNAMIC_LOAD"},
76{ERR_FUNC(ENGINE_F_DYNAMIC_SET_DATA_CTX), "DYNAMIC_SET_DATA_CTX"},
76{ERR_FUNC(ENGINE_F_ENGINE_ADD), "ENGINE_add"}, 77{ERR_FUNC(ENGINE_F_ENGINE_ADD), "ENGINE_add"},
77{ERR_FUNC(ENGINE_F_ENGINE_BY_ID), "ENGINE_by_id"}, 78{ERR_FUNC(ENGINE_F_ENGINE_BY_ID), "ENGINE_by_id"},
78{ERR_FUNC(ENGINE_F_ENGINE_CMD_IS_EXECUTABLE), "ENGINE_cmd_is_executable"}, 79{ERR_FUNC(ENGINE_F_ENGINE_CMD_IS_EXECUTABLE), "ENGINE_cmd_is_executable"},
@@ -80,7 +81,7 @@ static ERR_STRING_DATA ENGINE_str_functs[]=
80{ERR_FUNC(ENGINE_F_ENGINE_CTRL_CMD), "ENGINE_ctrl_cmd"}, 81{ERR_FUNC(ENGINE_F_ENGINE_CTRL_CMD), "ENGINE_ctrl_cmd"},
81{ERR_FUNC(ENGINE_F_ENGINE_CTRL_CMD_STRING), "ENGINE_ctrl_cmd_string"}, 82{ERR_FUNC(ENGINE_F_ENGINE_CTRL_CMD_STRING), "ENGINE_ctrl_cmd_string"},
82{ERR_FUNC(ENGINE_F_ENGINE_FINISH), "ENGINE_finish"}, 83{ERR_FUNC(ENGINE_F_ENGINE_FINISH), "ENGINE_finish"},
83{ERR_FUNC(ENGINE_F_ENGINE_FREE), "ENGINE_free"}, 84{ERR_FUNC(ENGINE_F_ENGINE_FREE_UTIL), "ENGINE_FREE_UTIL"},
84{ERR_FUNC(ENGINE_F_ENGINE_GET_CIPHER), "ENGINE_get_cipher"}, 85{ERR_FUNC(ENGINE_F_ENGINE_GET_CIPHER), "ENGINE_get_cipher"},
85{ERR_FUNC(ENGINE_F_ENGINE_GET_DEFAULT_TYPE), "ENGINE_GET_DEFAULT_TYPE"}, 86{ERR_FUNC(ENGINE_F_ENGINE_GET_DEFAULT_TYPE), "ENGINE_GET_DEFAULT_TYPE"},
86{ERR_FUNC(ENGINE_F_ENGINE_GET_DIGEST), "ENGINE_get_digest"}, 87{ERR_FUNC(ENGINE_F_ENGINE_GET_DIGEST), "ENGINE_get_digest"},
@@ -91,7 +92,6 @@ static ERR_STRING_DATA ENGINE_str_functs[]=
91{ERR_FUNC(ENGINE_F_ENGINE_LIST_REMOVE), "ENGINE_LIST_REMOVE"}, 92{ERR_FUNC(ENGINE_F_ENGINE_LIST_REMOVE), "ENGINE_LIST_REMOVE"},
92{ERR_FUNC(ENGINE_F_ENGINE_LOAD_PRIVATE_KEY), "ENGINE_load_private_key"}, 93{ERR_FUNC(ENGINE_F_ENGINE_LOAD_PRIVATE_KEY), "ENGINE_load_private_key"},
93{ERR_FUNC(ENGINE_F_ENGINE_LOAD_PUBLIC_KEY), "ENGINE_load_public_key"}, 94{ERR_FUNC(ENGINE_F_ENGINE_LOAD_PUBLIC_KEY), "ENGINE_load_public_key"},
94{ERR_FUNC(ENGINE_F_ENGINE_MODULE_INIT), "ENGINE_MODULE_INIT"},
95{ERR_FUNC(ENGINE_F_ENGINE_NEW), "ENGINE_new"}, 95{ERR_FUNC(ENGINE_F_ENGINE_NEW), "ENGINE_new"},
96{ERR_FUNC(ENGINE_F_ENGINE_REMOVE), "ENGINE_remove"}, 96{ERR_FUNC(ENGINE_F_ENGINE_REMOVE), "ENGINE_remove"},
97{ERR_FUNC(ENGINE_F_ENGINE_SET_DEFAULT_STRING), "ENGINE_set_default_string"}, 97{ERR_FUNC(ENGINE_F_ENGINE_SET_DEFAULT_STRING), "ENGINE_set_default_string"},
@@ -100,11 +100,12 @@ static ERR_STRING_DATA ENGINE_str_functs[]=
100{ERR_FUNC(ENGINE_F_ENGINE_SET_NAME), "ENGINE_set_name"}, 100{ERR_FUNC(ENGINE_F_ENGINE_SET_NAME), "ENGINE_set_name"},
101{ERR_FUNC(ENGINE_F_ENGINE_TABLE_REGISTER), "ENGINE_TABLE_REGISTER"}, 101{ERR_FUNC(ENGINE_F_ENGINE_TABLE_REGISTER), "ENGINE_TABLE_REGISTER"},
102{ERR_FUNC(ENGINE_F_ENGINE_UNLOAD_KEY), "ENGINE_UNLOAD_KEY"}, 102{ERR_FUNC(ENGINE_F_ENGINE_UNLOAD_KEY), "ENGINE_UNLOAD_KEY"},
103{ERR_FUNC(ENGINE_F_ENGINE_UNLOCKED_FINISH), "ENGINE_UNLOCKED_FINISH"},
103{ERR_FUNC(ENGINE_F_ENGINE_UP_REF), "ENGINE_up_ref"}, 104{ERR_FUNC(ENGINE_F_ENGINE_UP_REF), "ENGINE_up_ref"},
104{ERR_FUNC(ENGINE_F_INT_CTRL_HELPER), "INT_CTRL_HELPER"}, 105{ERR_FUNC(ENGINE_F_INT_CTRL_HELPER), "INT_CTRL_HELPER"},
105{ERR_FUNC(ENGINE_F_INT_ENGINE_CONFIGURE), "INT_ENGINE_CONFIGURE"}, 106{ERR_FUNC(ENGINE_F_INT_ENGINE_CONFIGURE), "INT_ENGINE_CONFIGURE"},
107{ERR_FUNC(ENGINE_F_INT_ENGINE_MODULE_INIT), "INT_ENGINE_MODULE_INIT"},
106{ERR_FUNC(ENGINE_F_LOG_MESSAGE), "LOG_MESSAGE"}, 108{ERR_FUNC(ENGINE_F_LOG_MESSAGE), "LOG_MESSAGE"},
107{ERR_FUNC(ENGINE_F_SET_DATA_CTX), "SET_DATA_CTX"},
108{0,NULL} 109{0,NULL}
109 }; 110 };
110 111
@@ -156,15 +157,12 @@ static ERR_STRING_DATA ENGINE_str_reasons[]=
156 157
157void ERR_load_ENGINE_strings(void) 158void ERR_load_ENGINE_strings(void)
158 { 159 {
159 static int init=1; 160#ifndef OPENSSL_NO_ERR
160 161
161 if (init) 162 if (ERR_func_error_string(ENGINE_str_functs[0].error) == NULL)
162 { 163 {
163 init=0;
164#ifndef OPENSSL_NO_ERR
165 ERR_load_strings(0,ENGINE_str_functs); 164 ERR_load_strings(0,ENGINE_str_functs);
166 ERR_load_strings(0,ENGINE_str_reasons); 165 ERR_load_strings(0,ENGINE_str_reasons);
167#endif
168
169 } 166 }
167#endif
170 } 168 }
diff --git a/src/lib/libcrypto/engine/eng_fat.c b/src/lib/libcrypto/engine/eng_fat.c
index 7ccf7022ee..27c1662f62 100644
--- a/src/lib/libcrypto/engine/eng_fat.c
+++ b/src/lib/libcrypto/engine/eng_fat.c
@@ -52,11 +52,13 @@
52 * Hudson (tjh@cryptsoft.com). 52 * Hudson (tjh@cryptsoft.com).
53 * 53 *
54 */ 54 */
55/* ====================================================================
56 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
57 * ECDH support in OpenSSL originally developed by
58 * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.
59 */
55 60
56#include <openssl/crypto.h>
57#include "cryptlib.h"
58#include "eng_int.h" 61#include "eng_int.h"
59#include <openssl/engine.h>
60#include <openssl/conf.h> 62#include <openssl/conf.h>
61 63
62int ENGINE_set_default(ENGINE *e, unsigned int flags) 64int ENGINE_set_default(ENGINE *e, unsigned int flags)
@@ -77,6 +79,14 @@ int ENGINE_set_default(ENGINE *e, unsigned int flags)
77 if((flags & ENGINE_METHOD_DH) && !ENGINE_set_default_DH(e)) 79 if((flags & ENGINE_METHOD_DH) && !ENGINE_set_default_DH(e))
78 return 0; 80 return 0;
79#endif 81#endif
82#ifndef OPENSSL_NO_ECDH
83 if((flags & ENGINE_METHOD_ECDH) && !ENGINE_set_default_ECDH(e))
84 return 0;
85#endif
86#ifndef OPENSSL_NO_ECDSA
87 if((flags & ENGINE_METHOD_ECDSA) && !ENGINE_set_default_ECDSA(e))
88 return 0;
89#endif
80 if((flags & ENGINE_METHOD_RAND) && !ENGINE_set_default_RAND(e)) 90 if((flags & ENGINE_METHOD_RAND) && !ENGINE_set_default_RAND(e))
81 return 0; 91 return 0;
82 return 1; 92 return 1;
@@ -93,6 +103,10 @@ static int int_def_cb(const char *alg, int len, void *arg)
93 *pflags |= ENGINE_METHOD_RSA; 103 *pflags |= ENGINE_METHOD_RSA;
94 else if (!strncmp(alg, "DSA", len)) 104 else if (!strncmp(alg, "DSA", len))
95 *pflags |= ENGINE_METHOD_DSA; 105 *pflags |= ENGINE_METHOD_DSA;
106 else if (!strncmp(alg, "ECDH", len))
107 *pflags |= ENGINE_METHOD_ECDH;
108 else if (!strncmp(alg, "ECDSA", len))
109 *pflags |= ENGINE_METHOD_ECDSA;
96 else if (!strncmp(alg, "DH", len)) 110 else if (!strncmp(alg, "DH", len))
97 *pflags |= ENGINE_METHOD_DH; 111 *pflags |= ENGINE_METHOD_DH;
98 else if (!strncmp(alg, "RAND", len)) 112 else if (!strncmp(alg, "RAND", len))
@@ -133,6 +147,12 @@ int ENGINE_register_complete(ENGINE *e)
133#ifndef OPENSSL_NO_DH 147#ifndef OPENSSL_NO_DH
134 ENGINE_register_DH(e); 148 ENGINE_register_DH(e);
135#endif 149#endif
150#ifndef OPENSSL_NO_ECDH
151 ENGINE_register_ECDH(e);
152#endif
153#ifndef OPENSSL_NO_ECDSA
154 ENGINE_register_ECDSA(e);
155#endif
136 ENGINE_register_RAND(e); 156 ENGINE_register_RAND(e);
137 return 1; 157 return 1;
138 } 158 }
diff --git a/src/lib/libcrypto/engine/eng_init.c b/src/lib/libcrypto/engine/eng_init.c
index 170c1791b3..7633cf5f1d 100644
--- a/src/lib/libcrypto/engine/eng_init.c
+++ b/src/lib/libcrypto/engine/eng_init.c
@@ -53,10 +53,7 @@
53 * 53 *
54 */ 54 */
55 55
56#include <openssl/crypto.h>
57#include "cryptlib.h"
58#include "eng_int.h" 56#include "eng_int.h"
59#include <openssl/engine.h>
60 57
61/* Initialise a engine type for use (or up its functional reference count 58/* Initialise a engine type for use (or up its functional reference count
62 * if it's already in use). This version is only used internally. */ 59 * if it's already in use). This version is only used internally. */
@@ -114,7 +111,7 @@ int engine_unlocked_finish(ENGINE *e, int unlock_for_handlers)
114 /* Release the structural reference too */ 111 /* Release the structural reference too */
115 if(!engine_free_util(e, 0)) 112 if(!engine_free_util(e, 0))
116 { 113 {
117 ENGINEerr(ENGINE_F_ENGINE_FINISH,ENGINE_R_FINISH_FAILED); 114 ENGINEerr(ENGINE_F_ENGINE_UNLOCKED_FINISH,ENGINE_R_FINISH_FAILED);
118 return 0; 115 return 0;
119 } 116 }
120 return to_return; 117 return to_return;
diff --git a/src/lib/libcrypto/engine/eng_int.h b/src/lib/libcrypto/engine/eng_int.h
index 38335f99cd..a5b1edebf4 100644
--- a/src/lib/libcrypto/engine/eng_int.h
+++ b/src/lib/libcrypto/engine/eng_int.h
@@ -55,10 +55,16 @@
55 * Hudson (tjh@cryptsoft.com). 55 * Hudson (tjh@cryptsoft.com).
56 * 56 *
57 */ 57 */
58/* ====================================================================
59 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
60 * ECDH support in OpenSSL originally developed by
61 * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.
62 */
58 63
59#ifndef HEADER_ENGINE_INT_H 64#ifndef HEADER_ENGINE_INT_H
60#define HEADER_ENGINE_INT_H 65#define HEADER_ENGINE_INT_H
61 66
67#include "cryptlib.h"
62/* Take public definitions from engine.h */ 68/* Take public definitions from engine.h */
63#include <openssl/engine.h> 69#include <openssl/engine.h>
64 70
@@ -146,7 +152,10 @@ struct engine_st
146 const RSA_METHOD *rsa_meth; 152 const RSA_METHOD *rsa_meth;
147 const DSA_METHOD *dsa_meth; 153 const DSA_METHOD *dsa_meth;
148 const DH_METHOD *dh_meth; 154 const DH_METHOD *dh_meth;
155 const ECDH_METHOD *ecdh_meth;
156 const ECDSA_METHOD *ecdsa_meth;
149 const RAND_METHOD *rand_meth; 157 const RAND_METHOD *rand_meth;
158 const STORE_METHOD *store_meth;
150 /* Cipher handling is via this callback */ 159 /* Cipher handling is via this callback */
151 ENGINE_CIPHERS_PTR ciphers; 160 ENGINE_CIPHERS_PTR ciphers;
152 /* Digest handling is via this callback */ 161 /* Digest handling is via this callback */
diff --git a/src/lib/libcrypto/engine/eng_lib.c b/src/lib/libcrypto/engine/eng_lib.c
index a66d0f08af..5815b867f4 100644
--- a/src/lib/libcrypto/engine/eng_lib.c
+++ b/src/lib/libcrypto/engine/eng_lib.c
@@ -56,11 +56,8 @@
56 * 56 *
57 */ 57 */
58 58
59#include <openssl/crypto.h>
60#include "cryptlib.h"
61#include "eng_int.h" 59#include "eng_int.h"
62#include <openssl/rand.h> /* FIXME: This shouldn't be needed */ 60#include <openssl/rand.h>
63#include <openssl/engine.h>
64 61
65/* The "new"/"free" stuff first */ 62/* The "new"/"free" stuff first */
66 63
@@ -92,6 +89,7 @@ void engine_set_all_null(ENGINE *e)
92 e->dsa_meth = NULL; 89 e->dsa_meth = NULL;
93 e->dh_meth = NULL; 90 e->dh_meth = NULL;
94 e->rand_meth = NULL; 91 e->rand_meth = NULL;
92 e->store_meth = NULL;
95 e->ciphers = NULL; 93 e->ciphers = NULL;
96 e->digests = NULL; 94 e->digests = NULL;
97 e->destroy = NULL; 95 e->destroy = NULL;
@@ -110,7 +108,7 @@ int engine_free_util(ENGINE *e, int locked)
110 108
111 if(e == NULL) 109 if(e == NULL)
112 { 110 {
113 ENGINEerr(ENGINE_F_ENGINE_FREE, 111 ENGINEerr(ENGINE_F_ENGINE_FREE_UTIL,
114 ERR_R_PASSED_NULL_PARAMETER); 112 ERR_R_PASSED_NULL_PARAMETER);
115 return 0; 113 return 0;
116 } 114 }
@@ -319,3 +317,13 @@ const ENGINE_CMD_DEFN *ENGINE_get_cmd_defns(const ENGINE *e)
319 { 317 {
320 return e->cmd_defns; 318 return e->cmd_defns;
321 } 319 }
320
321/* eng_lib.o is pretty much linked into anything that touches ENGINE already, so
322 * put the "static_state" hack here. */
323
324static int internal_static_hack = 0;
325
326void *ENGINE_get_static_state(void)
327 {
328 return &internal_static_hack;
329 }
diff --git a/src/lib/libcrypto/engine/eng_list.c b/src/lib/libcrypto/engine/eng_list.c
index 1cc3217f4c..bd511944ba 100644
--- a/src/lib/libcrypto/engine/eng_list.c
+++ b/src/lib/libcrypto/engine/eng_list.c
@@ -55,11 +55,13 @@
55 * Hudson (tjh@cryptsoft.com). 55 * Hudson (tjh@cryptsoft.com).
56 * 56 *
57 */ 57 */
58/* ====================================================================
59 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
60 * ECDH support in OpenSSL originally developed by
61 * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.
62 */
58 63
59#include <openssl/crypto.h>
60#include "cryptlib.h"
61#include "eng_int.h" 64#include "eng_int.h"
62#include <openssl/engine.h>
63 65
64/* The linked-list of pointers to engine types. engine_list_head 66/* The linked-list of pointers to engine types. engine_list_head
65 * incorporates an implicit structural reference but engine_list_tail 67 * incorporates an implicit structural reference but engine_list_tail
@@ -324,7 +326,14 @@ static void engine_cpy(ENGINE *dest, const ENGINE *src)
324#ifndef OPENSSL_NO_DH 326#ifndef OPENSSL_NO_DH
325 dest->dh_meth = src->dh_meth; 327 dest->dh_meth = src->dh_meth;
326#endif 328#endif
329#ifndef OPENSSL_NO_ECDH
330 dest->ecdh_meth = src->ecdh_meth;
331#endif
332#ifndef OPENSSL_NO_ECDSA
333 dest->ecdsa_meth = src->ecdsa_meth;
334#endif
327 dest->rand_meth = src->rand_meth; 335 dest->rand_meth = src->rand_meth;
336 dest->store_meth = src->store_meth;
328 dest->ciphers = src->ciphers; 337 dest->ciphers = src->ciphers;
329 dest->digests = src->digests; 338 dest->digests = src->digests;
330 dest->destroy = src->destroy; 339 dest->destroy = src->destroy;
@@ -340,6 +349,7 @@ static void engine_cpy(ENGINE *dest, const ENGINE *src)
340ENGINE *ENGINE_by_id(const char *id) 349ENGINE *ENGINE_by_id(const char *id)
341 { 350 {
342 ENGINE *iterator; 351 ENGINE *iterator;
352 char *load_dir = NULL;
343 if(id == NULL) 353 if(id == NULL)
344 { 354 {
345 ENGINEerr(ENGINE_F_ENGINE_BY_ID, 355 ENGINEerr(ENGINE_F_ENGINE_BY_ID,
@@ -373,6 +383,7 @@ ENGINE *ENGINE_by_id(const char *id)
373 } 383 }
374 } 384 }
375 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); 385 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
386#if 0
376 if(iterator == NULL) 387 if(iterator == NULL)
377 { 388 {
378 ENGINEerr(ENGINE_F_ENGINE_BY_ID, 389 ENGINEerr(ENGINE_F_ENGINE_BY_ID,
@@ -380,6 +391,32 @@ ENGINE *ENGINE_by_id(const char *id)
380 ERR_add_error_data(2, "id=", id); 391 ERR_add_error_data(2, "id=", id);
381 } 392 }
382 return iterator; 393 return iterator;
394#else
395 /* EEK! Experimental code starts */
396 if(iterator) return iterator;
397 /* Prevent infinite recusrion if we're looking for the dynamic engine. */
398 if (strcmp(id, "dynamic"))
399 {
400#ifdef OPENSSL_SYS_VMS
401 if((load_dir = getenv("OPENSSL_ENGINES")) == 0) load_dir = "SSLROOT:[ENGINES]";
402#else
403 if((load_dir = getenv("OPENSSL_ENGINES")) == 0) load_dir = ENGINESDIR;
404#endif
405 iterator = ENGINE_by_id("dynamic");
406 if(!iterator || !ENGINE_ctrl_cmd_string(iterator, "ID", id, 0) ||
407 !ENGINE_ctrl_cmd_string(iterator, "DIR_LOAD", "2", 0) ||
408 !ENGINE_ctrl_cmd_string(iterator, "DIR_ADD",
409 load_dir, 0) ||
410 !ENGINE_ctrl_cmd_string(iterator, "LOAD", NULL, 0))
411 goto notfound;
412 return iterator;
413 }
414notfound:
415 ENGINEerr(ENGINE_F_ENGINE_BY_ID,ENGINE_R_NO_SUCH_ENGINE);
416 ERR_add_error_data(2, "id=", id);
417 return NULL;
418 /* EEK! Experimental code ends */
419#endif
383 } 420 }
384 421
385int ENGINE_up_ref(ENGINE *e) 422int ENGINE_up_ref(ENGINE *e)
diff --git a/src/lib/libcrypto/engine/eng_openssl.c b/src/lib/libcrypto/engine/eng_openssl.c
index 54579eea2e..7c139ae2ef 100644
--- a/src/lib/libcrypto/engine/eng_openssl.c
+++ b/src/lib/libcrypto/engine/eng_openssl.c
@@ -55,6 +55,11 @@
55 * Hudson (tjh@cryptsoft.com). 55 * Hudson (tjh@cryptsoft.com).
56 * 56 *
57 */ 57 */
58/* ====================================================================
59 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
60 * ECDH support in OpenSSL originally developed by
61 * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.
62 */
58 63
59 64
60#include <stdio.h> 65#include <stdio.h>
@@ -64,6 +69,16 @@
64#include <openssl/dso.h> 69#include <openssl/dso.h>
65#include <openssl/pem.h> 70#include <openssl/pem.h>
66#include <openssl/evp.h> 71#include <openssl/evp.h>
72#include <openssl/rand.h>
73#ifndef OPENSSL_NO_RSA
74#include <openssl/rsa.h>
75#endif
76#ifndef OPENSSL_NO_DSA
77#include <openssl/dsa.h>
78#endif
79#ifndef OPENSSL_NO_DH
80#include <openssl/dh.h>
81#endif
67 82
68/* This testing gunk is implemented (and explained) lower down. It also assumes 83/* This testing gunk is implemented (and explained) lower down. It also assumes
69 * the application explicitly calls "ENGINE_load_openssl()" because this is no 84 * the application explicitly calls "ENGINE_load_openssl()" because this is no
@@ -125,6 +140,12 @@ static int bind_helper(ENGINE *e)
125#ifndef OPENSSL_NO_DSA 140#ifndef OPENSSL_NO_DSA
126 || !ENGINE_set_DSA(e, DSA_get_default_method()) 141 || !ENGINE_set_DSA(e, DSA_get_default_method())
127#endif 142#endif
143#ifndef OPENSSL_NO_ECDH
144 || !ENGINE_set_ECDH(e, ECDH_OpenSSL())
145#endif
146#ifndef OPENSSL_NO_ECDSA
147 || !ENGINE_set_ECDSA(e, ECDSA_OpenSSL())
148#endif
128#ifndef OPENSSL_NO_DH 149#ifndef OPENSSL_NO_DH
129 || !ENGINE_set_DH(e, DH_get_default_method()) 150 || !ENGINE_set_DH(e, DH_get_default_method())
130#endif 151#endif
@@ -236,6 +257,7 @@ static const EVP_CIPHER test_r4_cipher=
236 sizeof(TEST_RC4_KEY), 257 sizeof(TEST_RC4_KEY),
237 NULL, 258 NULL,
238 NULL, 259 NULL,
260 NULL,
239 NULL 261 NULL
240 }; 262 };
241static const EVP_CIPHER test_r4_40_cipher= 263static const EVP_CIPHER test_r4_40_cipher=
@@ -249,6 +271,7 @@ static const EVP_CIPHER test_r4_40_cipher=
249 sizeof(TEST_RC4_KEY), 271 sizeof(TEST_RC4_KEY),
250 NULL, 272 NULL,
251 NULL, 273 NULL,
274 NULL,
252 NULL 275 NULL
253 }; 276 };
254static int openssl_ciphers(ENGINE *e, const EVP_CIPHER **cipher, 277static int openssl_ciphers(ENGINE *e, const EVP_CIPHER **cipher,
@@ -290,7 +313,7 @@ static int test_sha1_init(EVP_MD_CTX *ctx)
290#endif 313#endif
291 return SHA1_Init(ctx->md_data); 314 return SHA1_Init(ctx->md_data);
292 } 315 }
293static int test_sha1_update(EVP_MD_CTX *ctx,const void *data,unsigned long count) 316static int test_sha1_update(EVP_MD_CTX *ctx,const void *data,size_t count)
294 { 317 {
295#ifdef TEST_ENG_OPENSSL_SHA_P_UPDATE 318#ifdef TEST_ENG_OPENSSL_SHA_P_UPDATE
296 fprintf(stderr, "(TEST_ENG_OPENSSL_SHA) test_sha1_update() called\n"); 319 fprintf(stderr, "(TEST_ENG_OPENSSL_SHA) test_sha1_update() called\n");
diff --git a/src/lib/libcrypto/engine/eng_pkey.c b/src/lib/libcrypto/engine/eng_pkey.c
index 8c69171511..bc8b21abec 100644
--- a/src/lib/libcrypto/engine/eng_pkey.c
+++ b/src/lib/libcrypto/engine/eng_pkey.c
@@ -53,10 +53,7 @@
53 * 53 *
54 */ 54 */
55 55
56#include <openssl/crypto.h>
57#include "cryptlib.h"
58#include "eng_int.h" 56#include "eng_int.h"
59#include <openssl/engine.h>
60 57
61/* Basic get/set stuff */ 58/* Basic get/set stuff */
62 59
diff --git a/src/lib/libcrypto/engine/eng_table.c b/src/lib/libcrypto/engine/eng_table.c
index c69a84a8bf..8879a267d1 100644
--- a/src/lib/libcrypto/engine/eng_table.c
+++ b/src/lib/libcrypto/engine/eng_table.c
@@ -52,49 +52,31 @@
52 * 52 *
53 */ 53 */
54 54
55#include "cryptlib.h"
55#include <openssl/evp.h> 56#include <openssl/evp.h>
56#include <openssl/engine.h> 57#include <openssl/lhash.h>
57#include "eng_int.h" 58#include "eng_int.h"
58 59
59/* This is the type of item in the 'implementation' table. Each 'nid' hashes to
60 * a (potentially NULL) ENGINE_PILE structure which contains a stack of ENGINE*
61 * pointers. These pointers aren't references, because they're inserted and
62 * removed during ENGINE creation and ENGINE destruction. They point to ENGINEs
63 * that *exist* (ie. have a structural reference count greater than zero) rather
64 * than ENGINEs that are *functional*. Each pointer in those stacks are to
65 * ENGINEs that implements the algorithm corresponding to each 'nid'. */
66
67/* The type of the items in the table */ 60/* The type of the items in the table */
68typedef struct st_engine_pile 61typedef struct st_engine_pile
69 { 62 {
70 /* The 'nid' of the algorithm/mode this ENGINE_PILE structure represents 63 /* The 'nid' of this algorithm/mode */
71 * */
72 int nid; 64 int nid;
73 /* A stack of ENGINE pointers for ENGINEs that support this 65 /* ENGINEs that implement this algorithm/mode. */
74 * algorithm/mode. In the event that 'funct' is NULL, the first entry in
75 * this stack that initialises will be set as 'funct' and assumed as the
76 * default for operations of this type. */
77 STACK_OF(ENGINE) *sk; 66 STACK_OF(ENGINE) *sk;
78 /* The default ENGINE to perform this algorithm/mode. */ 67 /* The default ENGINE to perform this algorithm/mode. */
79 ENGINE *funct; 68 ENGINE *funct;
80 /* This value optimises engine_table_select(). If it is called it sets 69 /* Zero if 'sk' is newer than the cached 'funct', non-zero otherwise */
81 * this value to 1. Any changes to this ENGINE_PILE resets it to zero.
82 * As such, no ENGINE_init() thrashing is done unless ENGINEs
83 * continually register (and/or unregister). */
84 int uptodate; 70 int uptodate;
85 } ENGINE_PILE; 71 } ENGINE_PILE;
86 72
87/* The type of the hash table of ENGINE_PILE structures such that each are 73/* The type exposed in eng_int.h */
88 * unique and keyed by the 'nid' value. */
89struct st_engine_table 74struct st_engine_table
90 { 75 {
91 LHASH piles; 76 LHASH piles;
92 }; /* ENGINE_TABLE */ 77 }; /* ENGINE_TABLE */
93 78
94/* This value stores global options controlling behaviour of (mostly) the 79/* Global flags (ENGINE_TABLE_FLAG_***). */
95 * engine_table_select() function. It's a bitmask of flag values of the form
96 * ENGINE_TABLE_FLAG_*** (as defined in engine.h) and is controlled by the
97 * ENGINE_[get|set]_table_flags() function. */
98static unsigned int table_flags = 0; 80static unsigned int table_flags = 0;
99 81
100/* API function manipulating 'table_flags' */ 82/* API function manipulating 'table_flags' */
@@ -121,10 +103,8 @@ static IMPLEMENT_LHASH_COMP_FN(engine_pile_cmp, const ENGINE_PILE *)
121static int int_table_check(ENGINE_TABLE **t, int create) 103static int int_table_check(ENGINE_TABLE **t, int create)
122 { 104 {
123 LHASH *lh; 105 LHASH *lh;
124 if(*t) 106 if(*t) return 1;
125 return 1; 107 if(!create) return 0;
126 if(!create)
127 return 0;
128 if((lh = lh_new(LHASH_HASH_FN(engine_pile_hash), 108 if((lh = lh_new(LHASH_HASH_FN(engine_pile_hash),
129 LHASH_COMP_FN(engine_pile_cmp))) == NULL) 109 LHASH_COMP_FN(engine_pile_cmp))) == NULL)
130 return 0; 110 return 0;
@@ -154,8 +134,7 @@ int engine_table_register(ENGINE_TABLE **table, ENGINE_CLEANUP_CB *cleanup,
154 if(!fnd) 134 if(!fnd)
155 { 135 {
156 fnd = OPENSSL_malloc(sizeof(ENGINE_PILE)); 136 fnd = OPENSSL_malloc(sizeof(ENGINE_PILE));
157 if(!fnd) 137 if(!fnd) goto end;
158 goto end;
159 fnd->uptodate = 1; 138 fnd->uptodate = 1;
160 fnd->nid = *nids; 139 fnd->nid = *nids;
161 fnd->sk = sk_ENGINE_new_null(); 140 fnd->sk = sk_ENGINE_new_null();
@@ -164,11 +143,11 @@ int engine_table_register(ENGINE_TABLE **table, ENGINE_CLEANUP_CB *cleanup,
164 OPENSSL_free(fnd); 143 OPENSSL_free(fnd);
165 goto end; 144 goto end;
166 } 145 }
167 fnd->funct= NULL; 146 fnd->funct = NULL;
168 lh_insert(&(*table)->piles, fnd); 147 lh_insert(&(*table)->piles, fnd);
169 } 148 }
170 /* A registration shouldn't add duplciate entries */ 149 /* A registration shouldn't add duplciate entries */
171 sk_ENGINE_delete_ptr(fnd->sk, e); 150 (void)sk_ENGINE_delete_ptr(fnd->sk, e);
172 /* if 'setdefault', this ENGINE goes to the head of the list */ 151 /* if 'setdefault', this ENGINE goes to the head of the list */
173 if(!sk_ENGINE_push(fnd->sk, e)) 152 if(!sk_ENGINE_push(fnd->sk, e))
174 goto end; 153 goto end;
@@ -185,6 +164,7 @@ int engine_table_register(ENGINE_TABLE **table, ENGINE_CLEANUP_CB *cleanup,
185 if(fnd->funct) 164 if(fnd->funct)
186 engine_unlocked_finish(fnd->funct, 0); 165 engine_unlocked_finish(fnd->funct, 0);
187 fnd->funct = e; 166 fnd->funct = e;
167 fnd->uptodate = 1;
188 } 168 }
189 nids++; 169 nids++;
190 } 170 }
@@ -199,8 +179,7 @@ static void int_unregister_cb(ENGINE_PILE *pile, ENGINE *e)
199 /* Iterate the 'c->sk' stack removing any occurance of 'e' */ 179 /* Iterate the 'c->sk' stack removing any occurance of 'e' */
200 while((n = sk_ENGINE_find(pile->sk, e)) >= 0) 180 while((n = sk_ENGINE_find(pile->sk, e)) >= 0)
201 { 181 {
202 sk_ENGINE_delete(pile->sk, n); 182 (void)sk_ENGINE_delete(pile->sk, n);
203 /* "touch" this ENGINE_CIPHER */
204 pile->uptodate = 0; 183 pile->uptodate = 0;
205 } 184 }
206 if(pile->funct == e) 185 if(pile->funct == e)
@@ -239,9 +218,7 @@ void engine_table_cleanup(ENGINE_TABLE **table)
239 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); 218 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
240 } 219 }
241 220
242/* Exposed API function to get a functional reference from the implementation 221/* return a functional reference for a given 'nid' */
243 * table (ie. try to get a functional reference from the tabled structural
244 * references) for a given cipher 'nid' */
245#ifndef ENGINE_TABLE_DEBUG 222#ifndef ENGINE_TABLE_DEBUG
246ENGINE *engine_table_select(ENGINE_TABLE **table, int nid) 223ENGINE *engine_table_select(ENGINE_TABLE **table, int nid)
247#else 224#else
@@ -252,25 +229,21 @@ ENGINE *engine_table_select_tmp(ENGINE_TABLE **table, int nid, const char *f, in
252 ENGINE_PILE tmplate, *fnd=NULL; 229 ENGINE_PILE tmplate, *fnd=NULL;
253 int initres, loop = 0; 230 int initres, loop = 0;
254 231
255 /* If 'engine_ciphers' is NULL, then it's absolutely *sure* that no
256 * ENGINEs have registered any implementations! */
257 if(!(*table)) 232 if(!(*table))
258 { 233 {
259#ifdef ENGINE_TABLE_DEBUG 234#ifdef ENGINE_TABLE_DEBUG
260 fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, no " 235 fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, nothing "
261 "registered for anything!\n", f, l, nid); 236 "registered!\n", f, l, nid);
262#endif 237#endif
263 return NULL; 238 return NULL;
264 } 239 }
265 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); 240 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
266 /* Check again inside the lock otherwise we could race against cleanup 241 /* Check again inside the lock otherwise we could race against cleanup
267 * operations. But don't worry about a fprintf(stderr). */ 242 * operations. But don't worry about a fprintf(stderr). */
268 if(!int_table_check(table, 0)) 243 if(!int_table_check(table, 0)) goto end;
269 goto end;
270 tmplate.nid = nid; 244 tmplate.nid = nid;
271 fnd = lh_retrieve(&(*table)->piles, &tmplate); 245 fnd = lh_retrieve(&(*table)->piles, &tmplate);
272 if(!fnd) 246 if(!fnd) goto end;
273 goto end;
274 if(fnd->funct && engine_unlocked_init(fnd->funct)) 247 if(fnd->funct && engine_unlocked_init(fnd->funct))
275 { 248 {
276#ifdef ENGINE_TABLE_DEBUG 249#ifdef ENGINE_TABLE_DEBUG
@@ -296,34 +269,19 @@ trynext:
296#endif 269#endif
297 goto end; 270 goto end;
298 } 271 }
299#if 0 272 /* Try to initialise the ENGINE? */
300 /* Don't need to get a reference if we hold the lock. If the locking has
301 * to change in future, that would be different ... */
302 ret->struct_ref++; engine_ref_debug(ret, 0, 1)
303#endif
304 /* Try and initialise the ENGINE if it's already functional *or* if the
305 * ENGINE_TABLE_FLAG_NOINIT flag is not set. */
306 if((ret->funct_ref > 0) || !(table_flags & ENGINE_TABLE_FLAG_NOINIT)) 273 if((ret->funct_ref > 0) || !(table_flags & ENGINE_TABLE_FLAG_NOINIT))
307 initres = engine_unlocked_init(ret); 274 initres = engine_unlocked_init(ret);
308 else 275 else
309 initres = 0; 276 initres = 0;
310#if 0
311 /* Release the structural reference */
312 ret->struct_ref--; engine_ref_debug(ret, 0, -1);
313#endif
314 if(initres) 277 if(initres)
315 { 278 {
316 /* If we didn't have a default (functional reference) for this 279 /* Update 'funct' */
317 * 'nid' (or we had one but for whatever reason we're now
318 * initialising a different one), use this opportunity to set
319 * 'funct'. */
320 if((fnd->funct != ret) && engine_unlocked_init(ret)) 280 if((fnd->funct != ret) && engine_unlocked_init(ret))
321 { 281 {
322 /* If there was a previous default we release it. */ 282 /* If there was a previous default we release it. */
323 if(fnd->funct) 283 if(fnd->funct)
324 engine_unlocked_finish(fnd->funct, 0); 284 engine_unlocked_finish(fnd->funct, 0);
325 /* We got an extra functional reference for the
326 * per-'nid' default */
327 fnd->funct = ret; 285 fnd->funct = ret;
328#ifdef ENGINE_TABLE_DEBUG 286#ifdef ENGINE_TABLE_DEBUG
329 fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, " 287 fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, "
@@ -338,13 +296,9 @@ trynext:
338 } 296 }
339 goto trynext; 297 goto trynext;
340end: 298end:
341 /* Whatever happened - we should "untouch" our uptodate file seeing as 299 /* If it failed, it is unlikely to succeed again until some future
342 * we have tried our best to find a functional reference for 'nid'. If 300 * registrations have taken place. In all cases, we cache. */
343 * it failed, it is unlikely to succeed again until some future 301 if(fnd) fnd->uptodate = 1;
344 * registrations (or unregistrations) have taken place that affect that
345 * 'nid'. */
346 if(fnd)
347 fnd->uptodate = 1;
348#ifdef ENGINE_TABLE_DEBUG 302#ifdef ENGINE_TABLE_DEBUG
349 if(ret) 303 if(ret)
350 fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, caching " 304 fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, caching "
diff --git a/src/lib/libcrypto/engine/engine.h b/src/lib/libcrypto/engine/engine.h
index 900f75ce8d..3ec59338ff 100644
--- a/src/lib/libcrypto/engine/engine.h
+++ b/src/lib/libcrypto/engine/engine.h
@@ -3,7 +3,7 @@
3 * project 2000. 3 * project 2000.
4 */ 4 */
5/* ==================================================================== 5/* ====================================================================
6 * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved. 6 * Copyright (c) 1999-2004 The OpenSSL Project. All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
@@ -55,6 +55,11 @@
55 * Hudson (tjh@cryptsoft.com). 55 * Hudson (tjh@cryptsoft.com).
56 * 56 *
57 */ 57 */
58/* ====================================================================
59 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
60 * ECDH support in OpenSSL originally developed by
61 * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.
62 */
58 63
59#ifndef HEADER_ENGINE_H 64#ifndef HEADER_ENGINE_H
60#define HEADER_ENGINE_H 65#define HEADER_ENGINE_H
@@ -65,7 +70,7 @@
65#error ENGINE is disabled. 70#error ENGINE is disabled.
66#endif 71#endif
67 72
68#include <openssl/ossl_typ.h> 73#ifndef OPENSSL_NO_DEPRECATED
69#include <openssl/bn.h> 74#include <openssl/bn.h>
70#ifndef OPENSSL_NO_RSA 75#ifndef OPENSSL_NO_RSA
71#include <openssl/rsa.h> 76#include <openssl/rsa.h>
@@ -76,34 +81,36 @@
76#ifndef OPENSSL_NO_DH 81#ifndef OPENSSL_NO_DH
77#include <openssl/dh.h> 82#include <openssl/dh.h>
78#endif 83#endif
84#ifndef OPENSSL_NO_ECDH
85#include <openssl/ecdh.h>
86#endif
87#ifndef OPENSSL_NO_ECDSA
88#include <openssl/ecdsa.h>
89#endif
79#include <openssl/rand.h> 90#include <openssl/rand.h>
91#include <openssl/store.h>
80#include <openssl/ui.h> 92#include <openssl/ui.h>
81#include <openssl/symhacks.h>
82#include <openssl/err.h> 93#include <openssl/err.h>
94#endif
95
96#include <openssl/ossl_typ.h>
97#include <openssl/symhacks.h>
83 98
84#ifdef __cplusplus 99#ifdef __cplusplus
85extern "C" { 100extern "C" {
86#endif 101#endif
87 102
88/* Fixups for missing algorithms */
89#ifdef OPENSSL_NO_RSA
90typedef void RSA_METHOD;
91#endif
92#ifdef OPENSSL_NO_DSA
93typedef void DSA_METHOD;
94#endif
95#ifdef OPENSSL_NO_DH
96typedef void DH_METHOD;
97#endif
98
99/* These flags are used to control combinations of algorithm (methods) 103/* These flags are used to control combinations of algorithm (methods)
100 * by bitwise "OR"ing. */ 104 * by bitwise "OR"ing. */
101#define ENGINE_METHOD_RSA (unsigned int)0x0001 105#define ENGINE_METHOD_RSA (unsigned int)0x0001
102#define ENGINE_METHOD_DSA (unsigned int)0x0002 106#define ENGINE_METHOD_DSA (unsigned int)0x0002
103#define ENGINE_METHOD_DH (unsigned int)0x0004 107#define ENGINE_METHOD_DH (unsigned int)0x0004
104#define ENGINE_METHOD_RAND (unsigned int)0x0008 108#define ENGINE_METHOD_RAND (unsigned int)0x0008
109#define ENGINE_METHOD_ECDH (unsigned int)0x0010
110#define ENGINE_METHOD_ECDSA (unsigned int)0x0020
105#define ENGINE_METHOD_CIPHERS (unsigned int)0x0040 111#define ENGINE_METHOD_CIPHERS (unsigned int)0x0040
106#define ENGINE_METHOD_DIGESTS (unsigned int)0x0080 112#define ENGINE_METHOD_DIGESTS (unsigned int)0x0080
113#define ENGINE_METHOD_STORE (unsigned int)0x0100
107/* Obvious all-or-nothing cases. */ 114/* Obvious all-or-nothing cases. */
108#define ENGINE_METHOD_ALL (unsigned int)0xFFFF 115#define ENGINE_METHOD_ALL (unsigned int)0xFFFF
109#define ENGINE_METHOD_NONE (unsigned int)0x0000 116#define ENGINE_METHOD_NONE (unsigned int)0x0000
@@ -173,9 +180,15 @@ typedef void DH_METHOD;
173 handles/connections etc. */ 180 handles/connections etc. */
174#define ENGINE_CTRL_SET_USER_INTERFACE 4 /* Alternative to callback */ 181#define ENGINE_CTRL_SET_USER_INTERFACE 4 /* Alternative to callback */
175#define ENGINE_CTRL_SET_CALLBACK_DATA 5 /* User-specific data, used 182#define ENGINE_CTRL_SET_CALLBACK_DATA 5 /* User-specific data, used
176 when calling the password 183 when calling the password
177 callback and the user 184 callback and the user
178 interface */ 185 interface */
186#define ENGINE_CTRL_LOAD_CONFIGURATION 6 /* Load a configuration, given
187 a string that represents a
188 file name or so */
189#define ENGINE_CTRL_LOAD_SECTION 7 /* Load data from a given
190 section in the already loaded
191 configuration */
179 192
180/* These control commands allow an application to deal with an arbitrary engine 193/* These control commands allow an application to deal with an arbitrary engine
181 * in a dynamic way. Warn: Negative return values indicate errors FOR THESE 194 * in a dynamic way. Warn: Negative return values indicate errors FOR THESE
@@ -222,7 +235,7 @@ typedef void DH_METHOD;
222 235
223/* ENGINE implementations should start the numbering of their own control 236/* ENGINE implementations should start the numbering of their own control
224 * commands from this value. (ie. ENGINE_CMD_BASE, ENGINE_CMD_BASE + 1, etc). */ 237 * commands from this value. (ie. ENGINE_CMD_BASE, ENGINE_CMD_BASE + 1, etc). */
225#define ENGINE_CMD_BASE 200 238#define ENGINE_CMD_BASE 200
226 239
227/* NB: These 2 nCipher "chil" control commands are deprecated, and their 240/* NB: These 2 nCipher "chil" control commands are deprecated, and their
228 * functionality is now available through ENGINE-specific control commands 241 * functionality is now available through ENGINE-specific control commands
@@ -257,11 +270,11 @@ typedef struct ENGINE_CMD_DEFN_st
257 } ENGINE_CMD_DEFN; 270 } ENGINE_CMD_DEFN;
258 271
259/* Generic function pointer */ 272/* Generic function pointer */
260typedef int (*ENGINE_GEN_FUNC_PTR)(); 273typedef int (*ENGINE_GEN_FUNC_PTR)(void);
261/* Generic function pointer taking no arguments */ 274/* Generic function pointer taking no arguments */
262typedef int (*ENGINE_GEN_INT_FUNC_PTR)(ENGINE *); 275typedef int (*ENGINE_GEN_INT_FUNC_PTR)(ENGINE *);
263/* Specific control function pointer */ 276/* Specific control function pointer */
264typedef int (*ENGINE_CTRL_FUNC_PTR)(ENGINE *, int, long, void *, void (*f)()); 277typedef int (*ENGINE_CTRL_FUNC_PTR)(ENGINE *, int, long, void *, void (*f)(void));
265/* Generic load_key function pointer */ 278/* Generic load_key function pointer */
266typedef EVP_PKEY * (*ENGINE_LOAD_KEY_PTR)(ENGINE *, const char *, 279typedef EVP_PKEY * (*ENGINE_LOAD_KEY_PTR)(ENGINE *, const char *,
267 UI_METHOD *ui_method, void *callback_data); 280 UI_METHOD *ui_method, void *callback_data);
@@ -305,15 +318,21 @@ ENGINE *ENGINE_by_id(const char *id);
305/* Add all the built-in engines. */ 318/* Add all the built-in engines. */
306void ENGINE_load_openssl(void); 319void ENGINE_load_openssl(void);
307void ENGINE_load_dynamic(void); 320void ENGINE_load_dynamic(void);
308void ENGINE_load_cswift(void); 321#ifndef OPENSSL_NO_STATIC_ENGINE
309void ENGINE_load_chil(void); 322void ENGINE_load_4758cca(void);
323void ENGINE_load_aep(void);
310void ENGINE_load_atalla(void); 324void ENGINE_load_atalla(void);
325void ENGINE_load_chil(void);
326void ENGINE_load_cswift(void);
327#ifndef OPENSSL_NO_GMP
328void ENGINE_load_gmp(void);
329#endif
311void ENGINE_load_nuron(void); 330void ENGINE_load_nuron(void);
312void ENGINE_load_ubsec(void);
313void ENGINE_load_aep(void);
314void ENGINE_load_sureware(void); 331void ENGINE_load_sureware(void);
315void ENGINE_load_4758cca(void); 332void ENGINE_load_ubsec(void);
333#endif
316void ENGINE_load_cryptodev(void); 334void ENGINE_load_cryptodev(void);
335void ENGINE_load_padlock(void);
317void ENGINE_load_builtin_engines(void); 336void ENGINE_load_builtin_engines(void);
318 337
319/* Get and set global flags (ENGINE_TABLE_FLAG_***) for the implementation 338/* Get and set global flags (ENGINE_TABLE_FLAG_***) for the implementation
@@ -337,6 +356,14 @@ int ENGINE_register_DSA(ENGINE *e);
337void ENGINE_unregister_DSA(ENGINE *e); 356void ENGINE_unregister_DSA(ENGINE *e);
338void ENGINE_register_all_DSA(void); 357void ENGINE_register_all_DSA(void);
339 358
359int ENGINE_register_ECDH(ENGINE *e);
360void ENGINE_unregister_ECDH(ENGINE *e);
361void ENGINE_register_all_ECDH(void);
362
363int ENGINE_register_ECDSA(ENGINE *e);
364void ENGINE_unregister_ECDSA(ENGINE *e);
365void ENGINE_register_all_ECDSA(void);
366
340int ENGINE_register_DH(ENGINE *e); 367int ENGINE_register_DH(ENGINE *e);
341void ENGINE_unregister_DH(ENGINE *e); 368void ENGINE_unregister_DH(ENGINE *e);
342void ENGINE_register_all_DH(void); 369void ENGINE_register_all_DH(void);
@@ -345,6 +372,10 @@ int ENGINE_register_RAND(ENGINE *e);
345void ENGINE_unregister_RAND(ENGINE *e); 372void ENGINE_unregister_RAND(ENGINE *e);
346void ENGINE_register_all_RAND(void); 373void ENGINE_register_all_RAND(void);
347 374
375int ENGINE_register_STORE(ENGINE *e);
376void ENGINE_unregister_STORE(ENGINE *e);
377void ENGINE_register_all_STORE(void);
378
348int ENGINE_register_ciphers(ENGINE *e); 379int ENGINE_register_ciphers(ENGINE *e);
349void ENGINE_unregister_ciphers(ENGINE *e); 380void ENGINE_unregister_ciphers(ENGINE *e);
350void ENGINE_register_all_ciphers(void); 381void ENGINE_register_all_ciphers(void);
@@ -367,7 +398,7 @@ int ENGINE_register_all_complete(void);
367 * reference to an engine, but many control commands may require the engine be 398 * reference to an engine, but many control commands may require the engine be
368 * functional. The caller should be aware of trying commands that require an 399 * functional. The caller should be aware of trying commands that require an
369 * operational ENGINE, and only use functional references in such situations. */ 400 * operational ENGINE, and only use functional references in such situations. */
370int ENGINE_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)()); 401int ENGINE_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void));
371 402
372/* This function tests if an ENGINE-specific command is usable as a "setting". 403/* This function tests if an ENGINE-specific command is usable as a "setting".
373 * Eg. in an application's config file that gets processed through 404 * Eg. in an application's config file that gets processed through
@@ -380,7 +411,7 @@ int ENGINE_cmd_is_executable(ENGINE *e, int cmd);
380 * See the comment on ENGINE_ctrl_cmd_string() for an explanation on how to 411 * See the comment on ENGINE_ctrl_cmd_string() for an explanation on how to
381 * use the cmd_name and cmd_optional. */ 412 * use the cmd_name and cmd_optional. */
382int ENGINE_ctrl_cmd(ENGINE *e, const char *cmd_name, 413int ENGINE_ctrl_cmd(ENGINE *e, const char *cmd_name,
383 long i, void *p, void (*f)(), int cmd_optional); 414 long i, void *p, void (*f)(void), int cmd_optional);
384 415
385/* This function passes a command-name and argument to an ENGINE. The cmd_name 416/* This function passes a command-name and argument to an ENGINE. The cmd_name
386 * is converted to a command number and the control command is called using 417 * is converted to a command number and the control command is called using
@@ -417,8 +448,11 @@ int ENGINE_set_id(ENGINE *e, const char *id);
417int ENGINE_set_name(ENGINE *e, const char *name); 448int ENGINE_set_name(ENGINE *e, const char *name);
418int ENGINE_set_RSA(ENGINE *e, const RSA_METHOD *rsa_meth); 449int ENGINE_set_RSA(ENGINE *e, const RSA_METHOD *rsa_meth);
419int ENGINE_set_DSA(ENGINE *e, const DSA_METHOD *dsa_meth); 450int ENGINE_set_DSA(ENGINE *e, const DSA_METHOD *dsa_meth);
451int ENGINE_set_ECDH(ENGINE *e, const ECDH_METHOD *ecdh_meth);
452int ENGINE_set_ECDSA(ENGINE *e, const ECDSA_METHOD *ecdsa_meth);
420int ENGINE_set_DH(ENGINE *e, const DH_METHOD *dh_meth); 453int ENGINE_set_DH(ENGINE *e, const DH_METHOD *dh_meth);
421int ENGINE_set_RAND(ENGINE *e, const RAND_METHOD *rand_meth); 454int ENGINE_set_RAND(ENGINE *e, const RAND_METHOD *rand_meth);
455int ENGINE_set_STORE(ENGINE *e, const STORE_METHOD *store_meth);
422int ENGINE_set_destroy_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR destroy_f); 456int ENGINE_set_destroy_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR destroy_f);
423int ENGINE_set_init_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR init_f); 457int ENGINE_set_init_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR init_f);
424int ENGINE_set_finish_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR finish_f); 458int ENGINE_set_finish_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR finish_f);
@@ -429,11 +463,11 @@ int ENGINE_set_ciphers(ENGINE *e, ENGINE_CIPHERS_PTR f);
429int ENGINE_set_digests(ENGINE *e, ENGINE_DIGESTS_PTR f); 463int ENGINE_set_digests(ENGINE *e, ENGINE_DIGESTS_PTR f);
430int ENGINE_set_flags(ENGINE *e, int flags); 464int ENGINE_set_flags(ENGINE *e, int flags);
431int ENGINE_set_cmd_defns(ENGINE *e, const ENGINE_CMD_DEFN *defns); 465int ENGINE_set_cmd_defns(ENGINE *e, const ENGINE_CMD_DEFN *defns);
432/* These functions (and the "get" function lower down) allow control over any 466/* These functions allow control over any per-structure ENGINE data. */
433 * per-structure ENGINE data. */
434int ENGINE_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, 467int ENGINE_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
435 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func); 468 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
436int ENGINE_set_ex_data(ENGINE *e, int idx, void *arg); 469int ENGINE_set_ex_data(ENGINE *e, int idx, void *arg);
470void *ENGINE_get_ex_data(const ENGINE *e, int idx);
437 471
438/* This function cleans up anything that needs it. Eg. the ENGINE_add() function 472/* This function cleans up anything that needs it. Eg. the ENGINE_add() function
439 * automatically ensures the list cleanup function is registered to be called 473 * automatically ensures the list cleanup function is registered to be called
@@ -449,8 +483,11 @@ const char *ENGINE_get_id(const ENGINE *e);
449const char *ENGINE_get_name(const ENGINE *e); 483const char *ENGINE_get_name(const ENGINE *e);
450const RSA_METHOD *ENGINE_get_RSA(const ENGINE *e); 484const RSA_METHOD *ENGINE_get_RSA(const ENGINE *e);
451const DSA_METHOD *ENGINE_get_DSA(const ENGINE *e); 485const DSA_METHOD *ENGINE_get_DSA(const ENGINE *e);
486const ECDH_METHOD *ENGINE_get_ECDH(const ENGINE *e);
487const ECDSA_METHOD *ENGINE_get_ECDSA(const ENGINE *e);
452const DH_METHOD *ENGINE_get_DH(const ENGINE *e); 488const DH_METHOD *ENGINE_get_DH(const ENGINE *e);
453const RAND_METHOD *ENGINE_get_RAND(const ENGINE *e); 489const RAND_METHOD *ENGINE_get_RAND(const ENGINE *e);
490const STORE_METHOD *ENGINE_get_STORE(const ENGINE *e);
454ENGINE_GEN_INT_FUNC_PTR ENGINE_get_destroy_function(const ENGINE *e); 491ENGINE_GEN_INT_FUNC_PTR ENGINE_get_destroy_function(const ENGINE *e);
455ENGINE_GEN_INT_FUNC_PTR ENGINE_get_init_function(const ENGINE *e); 492ENGINE_GEN_INT_FUNC_PTR ENGINE_get_init_function(const ENGINE *e);
456ENGINE_GEN_INT_FUNC_PTR ENGINE_get_finish_function(const ENGINE *e); 493ENGINE_GEN_INT_FUNC_PTR ENGINE_get_finish_function(const ENGINE *e);
@@ -463,7 +500,6 @@ const EVP_CIPHER *ENGINE_get_cipher(ENGINE *e, int nid);
463const EVP_MD *ENGINE_get_digest(ENGINE *e, int nid); 500const EVP_MD *ENGINE_get_digest(ENGINE *e, int nid);
464const ENGINE_CMD_DEFN *ENGINE_get_cmd_defns(const ENGINE *e); 501const ENGINE_CMD_DEFN *ENGINE_get_cmd_defns(const ENGINE *e);
465int ENGINE_get_flags(const ENGINE *e); 502int ENGINE_get_flags(const ENGINE *e);
466void *ENGINE_get_ex_data(const ENGINE *e, int idx);
467 503
468/* FUNCTIONAL functions. These functions deal with ENGINE structures 504/* FUNCTIONAL functions. These functions deal with ENGINE structures
469 * that have (or will) be initialised for use. Broadly speaking, the 505 * that have (or will) be initialised for use. Broadly speaking, the
@@ -501,6 +537,8 @@ EVP_PKEY *ENGINE_load_public_key(ENGINE *e, const char *key_id,
501ENGINE *ENGINE_get_default_RSA(void); 537ENGINE *ENGINE_get_default_RSA(void);
502/* Same for the other "methods" */ 538/* Same for the other "methods" */
503ENGINE *ENGINE_get_default_DSA(void); 539ENGINE *ENGINE_get_default_DSA(void);
540ENGINE *ENGINE_get_default_ECDH(void);
541ENGINE *ENGINE_get_default_ECDSA(void);
504ENGINE *ENGINE_get_default_DH(void); 542ENGINE *ENGINE_get_default_DH(void);
505ENGINE *ENGINE_get_default_RAND(void); 543ENGINE *ENGINE_get_default_RAND(void);
506/* These functions can be used to get a functional reference to perform 544/* These functions can be used to get a functional reference to perform
@@ -516,6 +554,8 @@ int ENGINE_set_default_RSA(ENGINE *e);
516int ENGINE_set_default_string(ENGINE *e, const char *def_list); 554int ENGINE_set_default_string(ENGINE *e, const char *def_list);
517/* Same for the other "methods" */ 555/* Same for the other "methods" */
518int ENGINE_set_default_DSA(ENGINE *e); 556int ENGINE_set_default_DSA(ENGINE *e);
557int ENGINE_set_default_ECDH(ENGINE *e);
558int ENGINE_set_default_ECDSA(ENGINE *e);
519int ENGINE_set_default_DH(ENGINE *e); 559int ENGINE_set_default_DH(ENGINE *e);
520int ENGINE_set_default_RAND(ENGINE *e); 560int ENGINE_set_default_RAND(ENGINE *e);
521int ENGINE_set_default_ciphers(ENGINE *e); 561int ENGINE_set_default_ciphers(ENGINE *e);
@@ -538,17 +578,20 @@ void ENGINE_add_conf_module(void);
538/**************************/ 578/**************************/
539 579
540/* Binary/behaviour compatibility levels */ 580/* Binary/behaviour compatibility levels */
541#define OSSL_DYNAMIC_VERSION (unsigned long)0x00010200 581#define OSSL_DYNAMIC_VERSION (unsigned long)0x00020000
542/* Binary versions older than this are too old for us (whether we're a loader or 582/* Binary versions older than this are too old for us (whether we're a loader or
543 * a loadee) */ 583 * a loadee) */
544#define OSSL_DYNAMIC_OLDEST (unsigned long)0x00010200 584#define OSSL_DYNAMIC_OLDEST (unsigned long)0x00020000
545 585
546/* When compiling an ENGINE entirely as an external shared library, loadable by 586/* When compiling an ENGINE entirely as an external shared library, loadable by
547 * the "dynamic" ENGINE, these types are needed. The 'dynamic_fns' structure 587 * the "dynamic" ENGINE, these types are needed. The 'dynamic_fns' structure
548 * type provides the calling application's (or library's) error functionality 588 * type provides the calling application's (or library's) error functionality
549 * and memory management function pointers to the loaded library. These should 589 * and memory management function pointers to the loaded library. These should
550 * be used/set in the loaded library code so that the loading application's 590 * be used/set in the loaded library code so that the loading application's
551 * 'state' will be used/changed in all operations. */ 591 * 'state' will be used/changed in all operations. The 'static_state' pointer
592 * allows the loaded library to know if it shares the same static data as the
593 * calling application (or library), and thus whether these callbacks need to be
594 * set or not. */
552typedef void *(*dyn_MEM_malloc_cb)(size_t); 595typedef void *(*dyn_MEM_malloc_cb)(size_t);
553typedef void *(*dyn_MEM_realloc_cb)(void *, size_t); 596typedef void *(*dyn_MEM_realloc_cb)(void *, size_t);
554typedef void (*dyn_MEM_free_cb)(void *); 597typedef void (*dyn_MEM_free_cb)(void *);
@@ -576,6 +619,7 @@ typedef struct st_dynamic_LOCK_fns {
576 } dynamic_LOCK_fns; 619 } dynamic_LOCK_fns;
577/* The top-level structure */ 620/* The top-level structure */
578typedef struct st_dynamic_fns { 621typedef struct st_dynamic_fns {
622 void *static_state;
579 const ERR_FNS *err_fns; 623 const ERR_FNS *err_fns;
580 const CRYPTO_EX_DATA_IMPL *ex_data_fns; 624 const CRYPTO_EX_DATA_IMPL *ex_data_fns;
581 dynamic_MEM_fns mem_fns; 625 dynamic_MEM_fns mem_fns;
@@ -593,7 +637,7 @@ typedef struct st_dynamic_fns {
593 * can be fully instantiated with IMPLEMENT_DYNAMIC_CHECK_FN(). */ 637 * can be fully instantiated with IMPLEMENT_DYNAMIC_CHECK_FN(). */
594typedef unsigned long (*dynamic_v_check_fn)(unsigned long ossl_version); 638typedef unsigned long (*dynamic_v_check_fn)(unsigned long ossl_version);
595#define IMPLEMENT_DYNAMIC_CHECK_FN() \ 639#define IMPLEMENT_DYNAMIC_CHECK_FN() \
596 unsigned long v_check(unsigned long v) { \ 640 OPENSSL_EXPORT unsigned long v_check(unsigned long v) { \
597 if(v >= OSSL_DYNAMIC_OLDEST) return OSSL_DYNAMIC_VERSION; \ 641 if(v >= OSSL_DYNAMIC_OLDEST) return OSSL_DYNAMIC_VERSION; \
598 return 0; } 642 return 0; }
599 643
@@ -615,24 +659,35 @@ typedef unsigned long (*dynamic_v_check_fn)(unsigned long ossl_version);
615typedef int (*dynamic_bind_engine)(ENGINE *e, const char *id, 659typedef int (*dynamic_bind_engine)(ENGINE *e, const char *id,
616 const dynamic_fns *fns); 660 const dynamic_fns *fns);
617#define IMPLEMENT_DYNAMIC_BIND_FN(fn) \ 661#define IMPLEMENT_DYNAMIC_BIND_FN(fn) \
662 OPENSSL_EXPORT \
618 int bind_engine(ENGINE *e, const char *id, const dynamic_fns *fns) { \ 663 int bind_engine(ENGINE *e, const char *id, const dynamic_fns *fns) { \
619 if (ERR_get_implementation() != fns->err_fns) \ 664 if(ENGINE_get_static_state() == fns->static_state) goto skip_cbs; \
620 { \ 665 if(!CRYPTO_set_mem_functions(fns->mem_fns.malloc_cb, \
621 if(!CRYPTO_set_mem_functions(fns->mem_fns.malloc_cb, \ 666 fns->mem_fns.realloc_cb, fns->mem_fns.free_cb)) \
622 fns->mem_fns.realloc_cb, fns->mem_fns.free_cb)) \ 667 return 0; \
623 return 0; \ 668 CRYPTO_set_locking_callback(fns->lock_fns.lock_locking_cb); \
624 CRYPTO_set_locking_callback(fns->lock_fns.lock_locking_cb); \ 669 CRYPTO_set_add_lock_callback(fns->lock_fns.lock_add_lock_cb); \
625 CRYPTO_set_add_lock_callback(fns->lock_fns.lock_add_lock_cb); \ 670 CRYPTO_set_dynlock_create_callback(fns->lock_fns.dynlock_create_cb); \
626 CRYPTO_set_dynlock_create_callback(fns->lock_fns.dynlock_create_cb); \ 671 CRYPTO_set_dynlock_lock_callback(fns->lock_fns.dynlock_lock_cb); \
627 CRYPTO_set_dynlock_lock_callback(fns->lock_fns.dynlock_lock_cb); \ 672 CRYPTO_set_dynlock_destroy_callback(fns->lock_fns.dynlock_destroy_cb); \
628 CRYPTO_set_dynlock_destroy_callback(fns->lock_fns.dynlock_destroy_cb); \ 673 if(!CRYPTO_set_ex_data_implementation(fns->ex_data_fns)) \
629 if(!CRYPTO_set_ex_data_implementation(fns->ex_data_fns)) \ 674 return 0; \
630 return 0; \ 675 if(!ERR_set_implementation(fns->err_fns)) return 0; \
631 if(!ERR_set_implementation(fns->err_fns)) return 0; \ 676 skip_cbs: \
632 } \
633 if(!fn(e,id)) return 0; \ 677 if(!fn(e,id)) return 0; \
634 return 1; } 678 return 1; }
635 679
680/* If the loading application (or library) and the loaded ENGINE library share
681 * the same static data (eg. they're both dynamically linked to the same
682 * libcrypto.so) we need a way to avoid trying to set system callbacks - this
683 * would fail, and for the same reason that it's unnecessary to try. If the
684 * loaded ENGINE has (or gets from through the loader) its own copy of the
685 * libcrypto static data, we will need to set the callbacks. The easiest way to
686 * detect this is to have a function that returns a pointer to some static data
687 * and let the loading application and loaded ENGINE compare their respective
688 * values. */
689void *ENGINE_get_static_state(void);
690
636#if defined(__OpenBSD__) || defined(__FreeBSD__) 691#if defined(__OpenBSD__) || defined(__FreeBSD__)
637void ENGINE_setup_bsd_cryptodev(void); 692void ENGINE_setup_bsd_cryptodev(void);
638#endif 693#endif
@@ -649,6 +704,7 @@ void ERR_load_ENGINE_strings(void);
649#define ENGINE_F_DYNAMIC_CTRL 180 704#define ENGINE_F_DYNAMIC_CTRL 180
650#define ENGINE_F_DYNAMIC_GET_DATA_CTX 181 705#define ENGINE_F_DYNAMIC_GET_DATA_CTX 181
651#define ENGINE_F_DYNAMIC_LOAD 182 706#define ENGINE_F_DYNAMIC_LOAD 182
707#define ENGINE_F_DYNAMIC_SET_DATA_CTX 183
652#define ENGINE_F_ENGINE_ADD 105 708#define ENGINE_F_ENGINE_ADD 105
653#define ENGINE_F_ENGINE_BY_ID 106 709#define ENGINE_F_ENGINE_BY_ID 106
654#define ENGINE_F_ENGINE_CMD_IS_EXECUTABLE 170 710#define ENGINE_F_ENGINE_CMD_IS_EXECUTABLE 170
@@ -656,7 +712,7 @@ void ERR_load_ENGINE_strings(void);
656#define ENGINE_F_ENGINE_CTRL_CMD 178 712#define ENGINE_F_ENGINE_CTRL_CMD 178
657#define ENGINE_F_ENGINE_CTRL_CMD_STRING 171 713#define ENGINE_F_ENGINE_CTRL_CMD_STRING 171
658#define ENGINE_F_ENGINE_FINISH 107 714#define ENGINE_F_ENGINE_FINISH 107
659#define ENGINE_F_ENGINE_FREE 108 715#define ENGINE_F_ENGINE_FREE_UTIL 108
660#define ENGINE_F_ENGINE_GET_CIPHER 185 716#define ENGINE_F_ENGINE_GET_CIPHER 185
661#define ENGINE_F_ENGINE_GET_DEFAULT_TYPE 177 717#define ENGINE_F_ENGINE_GET_DEFAULT_TYPE 177
662#define ENGINE_F_ENGINE_GET_DIGEST 186 718#define ENGINE_F_ENGINE_GET_DIGEST 186
@@ -667,7 +723,6 @@ void ERR_load_ENGINE_strings(void);
667#define ENGINE_F_ENGINE_LIST_REMOVE 121 723#define ENGINE_F_ENGINE_LIST_REMOVE 121
668#define ENGINE_F_ENGINE_LOAD_PRIVATE_KEY 150 724#define ENGINE_F_ENGINE_LOAD_PRIVATE_KEY 150
669#define ENGINE_F_ENGINE_LOAD_PUBLIC_KEY 151 725#define ENGINE_F_ENGINE_LOAD_PUBLIC_KEY 151
670#define ENGINE_F_ENGINE_MODULE_INIT 187
671#define ENGINE_F_ENGINE_NEW 122 726#define ENGINE_F_ENGINE_NEW 122
672#define ENGINE_F_ENGINE_REMOVE 123 727#define ENGINE_F_ENGINE_REMOVE 123
673#define ENGINE_F_ENGINE_SET_DEFAULT_STRING 189 728#define ENGINE_F_ENGINE_SET_DEFAULT_STRING 189
@@ -676,11 +731,12 @@ void ERR_load_ENGINE_strings(void);
676#define ENGINE_F_ENGINE_SET_NAME 130 731#define ENGINE_F_ENGINE_SET_NAME 130
677#define ENGINE_F_ENGINE_TABLE_REGISTER 184 732#define ENGINE_F_ENGINE_TABLE_REGISTER 184
678#define ENGINE_F_ENGINE_UNLOAD_KEY 152 733#define ENGINE_F_ENGINE_UNLOAD_KEY 152
734#define ENGINE_F_ENGINE_UNLOCKED_FINISH 191
679#define ENGINE_F_ENGINE_UP_REF 190 735#define ENGINE_F_ENGINE_UP_REF 190
680#define ENGINE_F_INT_CTRL_HELPER 172 736#define ENGINE_F_INT_CTRL_HELPER 172
681#define ENGINE_F_INT_ENGINE_CONFIGURE 188 737#define ENGINE_F_INT_ENGINE_CONFIGURE 188
738#define ENGINE_F_INT_ENGINE_MODULE_INIT 187
682#define ENGINE_F_LOG_MESSAGE 141 739#define ENGINE_F_LOG_MESSAGE 141
683#define ENGINE_F_SET_DATA_CTX 183
684 740
685/* Reason codes. */ 741/* Reason codes. */
686#define ENGINE_R_ALREADY_LOADED 100 742#define ENGINE_R_ALREADY_LOADED 100
diff --git a/src/lib/libcrypto/engine/enginetest.c b/src/lib/libcrypto/engine/enginetest.c
index c2d0297392..cf82f490db 100644
--- a/src/lib/libcrypto/engine/enginetest.c
+++ b/src/lib/libcrypto/engine/enginetest.c
@@ -72,7 +72,7 @@ int main(int argc, char *argv[])
72#include <openssl/engine.h> 72#include <openssl/engine.h>
73#include <openssl/err.h> 73#include <openssl/err.h>
74 74
75static void display_engine_list() 75static void display_engine_list(void)
76 { 76 {
77 ENGINE *h; 77 ENGINE *h;
78 int loop; 78 int loop;
diff --git a/src/lib/libcrypto/engine/tb_cipher.c b/src/lib/libcrypto/engine/tb_cipher.c
index 50b3cec1fa..177fc1fb73 100644
--- a/src/lib/libcrypto/engine/tb_cipher.c
+++ b/src/lib/libcrypto/engine/tb_cipher.c
@@ -52,8 +52,6 @@
52 * 52 *
53 */ 53 */
54 54
55#include <openssl/evp.h>
56#include <openssl/engine.h>
57#include "eng_int.h" 55#include "eng_int.h"
58 56
59/* If this symbol is defined then ENGINE_get_cipher_engine(), the function that 57/* If this symbol is defined then ENGINE_get_cipher_engine(), the function that
diff --git a/src/lib/libcrypto/engine/tb_dh.c b/src/lib/libcrypto/engine/tb_dh.c
index e290e1702b..6e9d428761 100644
--- a/src/lib/libcrypto/engine/tb_dh.c
+++ b/src/lib/libcrypto/engine/tb_dh.c
@@ -52,8 +52,6 @@
52 * 52 *
53 */ 53 */
54 54
55#include <openssl/evp.h>
56#include <openssl/engine.h>
57#include "eng_int.h" 55#include "eng_int.h"
58 56
59/* If this symbol is defined then ENGINE_get_default_DH(), the function that is 57/* If this symbol is defined then ENGINE_get_default_DH(), the function that is
diff --git a/src/lib/libcrypto/engine/tb_digest.c b/src/lib/libcrypto/engine/tb_digest.c
index e82d2a17c9..d3f4bb2747 100644
--- a/src/lib/libcrypto/engine/tb_digest.c
+++ b/src/lib/libcrypto/engine/tb_digest.c
@@ -52,8 +52,6 @@
52 * 52 *
53 */ 53 */
54 54
55#include <openssl/evp.h>
56#include <openssl/engine.h>
57#include "eng_int.h" 55#include "eng_int.h"
58 56
59/* If this symbol is defined then ENGINE_get_digest_engine(), the function that 57/* If this symbol is defined then ENGINE_get_digest_engine(), the function that
diff --git a/src/lib/libcrypto/engine/tb_dsa.c b/src/lib/libcrypto/engine/tb_dsa.c
index 7efe181927..e4674f5f07 100644
--- a/src/lib/libcrypto/engine/tb_dsa.c
+++ b/src/lib/libcrypto/engine/tb_dsa.c
@@ -52,8 +52,6 @@
52 * 52 *
53 */ 53 */
54 54
55#include <openssl/evp.h>
56#include <openssl/engine.h>
57#include "eng_int.h" 55#include "eng_int.h"
58 56
59/* If this symbol is defined then ENGINE_get_default_DSA(), the function that is 57/* If this symbol is defined then ENGINE_get_default_DSA(), the function that is
diff --git a/src/lib/libcrypto/engine/tb_rand.c b/src/lib/libcrypto/engine/tb_rand.c
index 69b67111bc..f36f67c0f6 100644
--- a/src/lib/libcrypto/engine/tb_rand.c
+++ b/src/lib/libcrypto/engine/tb_rand.c
@@ -52,8 +52,6 @@
52 * 52 *
53 */ 53 */
54 54
55#include <openssl/evp.h>
56#include <openssl/engine.h>
57#include "eng_int.h" 55#include "eng_int.h"
58 56
59/* If this symbol is defined then ENGINE_get_default_RAND(), the function that is 57/* If this symbol is defined then ENGINE_get_default_RAND(), the function that is
diff --git a/src/lib/libcrypto/engine/tb_rsa.c b/src/lib/libcrypto/engine/tb_rsa.c
index fee4867f52..fbc707fd26 100644
--- a/src/lib/libcrypto/engine/tb_rsa.c
+++ b/src/lib/libcrypto/engine/tb_rsa.c
@@ -52,8 +52,6 @@
52 * 52 *
53 */ 53 */
54 54
55#include <openssl/evp.h>
56#include <openssl/engine.h>
57#include "eng_int.h" 55#include "eng_int.h"
58 56
59/* If this symbol is defined then ENGINE_get_default_RSA(), the function that is 57/* If this symbol is defined then ENGINE_get_default_RSA(), the function that is