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_cnf.c2
-rw-r--r--src/lib/libcrypto/engine/eng_err.c158
-rw-r--r--src/lib/libcrypto/engine/hw_aep.c1
-rw-r--r--src/lib/libcrypto/engine/hw_atalla.c1
-rw-r--r--src/lib/libcrypto/engine/hw_cswift.c204
-rw-r--r--src/lib/libcrypto/engine/hw_ubsec.c1
-rw-r--r--src/lib/libcrypto/engine/tb_dsa.c2
7 files changed, 244 insertions, 125 deletions
diff --git a/src/lib/libcrypto/engine/eng_cnf.c b/src/lib/libcrypto/engine/eng_cnf.c
index cdf670901a..4225760af1 100644
--- a/src/lib/libcrypto/engine/eng_cnf.c
+++ b/src/lib/libcrypto/engine/eng_cnf.c
@@ -158,7 +158,7 @@ static int int_engine_configure(char *name, char *value, const CONF *cnf)
158 */ 158 */
159 if (!strcmp(ctrlvalue, "EMPTY")) 159 if (!strcmp(ctrlvalue, "EMPTY"))
160 ctrlvalue = NULL; 160 ctrlvalue = NULL;
161 else if (!strcmp(ctrlname, "init")) 161 if (!strcmp(ctrlname, "init"))
162 { 162 {
163 if (!NCONF_get_number_e(cnf, value, "init", &do_init)) 163 if (!NCONF_get_number_e(cnf, value, "init", &do_init))
164 goto err; 164 goto err;
diff --git a/src/lib/libcrypto/engine/eng_err.c b/src/lib/libcrypto/engine/eng_err.c
index 814d95ee32..fdc0e7be0f 100644
--- a/src/lib/libcrypto/engine/eng_err.c
+++ b/src/lib/libcrypto/engine/eng_err.c
@@ -1,6 +1,6 @@
1/* crypto/engine/eng_err.c */ 1/* crypto/engine/eng_err.c */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 1999-2002 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
@@ -64,87 +64,91 @@
64 64
65/* BEGIN ERROR CODES */ 65/* BEGIN ERROR CODES */
66#ifndef OPENSSL_NO_ERR 66#ifndef OPENSSL_NO_ERR
67
68#define ERR_FUNC(func) ERR_PACK(ERR_LIB_ENGINE,func,0)
69#define ERR_REASON(reason) ERR_PACK(ERR_LIB_ENGINE,0,reason)
70
67static ERR_STRING_DATA ENGINE_str_functs[]= 71static ERR_STRING_DATA ENGINE_str_functs[]=
68 { 72 {
69{ERR_PACK(0,ENGINE_F_DYNAMIC_CTRL,0), "DYNAMIC_CTRL"}, 73{ERR_FUNC(ENGINE_F_DYNAMIC_CTRL), "DYNAMIC_CTRL"},
70{ERR_PACK(0,ENGINE_F_DYNAMIC_GET_DATA_CTX,0), "DYNAMIC_GET_DATA_CTX"}, 74{ERR_FUNC(ENGINE_F_DYNAMIC_GET_DATA_CTX), "DYNAMIC_GET_DATA_CTX"},
71{ERR_PACK(0,ENGINE_F_DYNAMIC_LOAD,0), "DYNAMIC_LOAD"}, 75{ERR_FUNC(ENGINE_F_DYNAMIC_LOAD), "DYNAMIC_LOAD"},
72{ERR_PACK(0,ENGINE_F_ENGINE_ADD,0), "ENGINE_add"}, 76{ERR_FUNC(ENGINE_F_ENGINE_ADD), "ENGINE_add"},
73{ERR_PACK(0,ENGINE_F_ENGINE_BY_ID,0), "ENGINE_by_id"}, 77{ERR_FUNC(ENGINE_F_ENGINE_BY_ID), "ENGINE_by_id"},
74{ERR_PACK(0,ENGINE_F_ENGINE_CMD_IS_EXECUTABLE,0), "ENGINE_cmd_is_executable"}, 78{ERR_FUNC(ENGINE_F_ENGINE_CMD_IS_EXECUTABLE), "ENGINE_cmd_is_executable"},
75{ERR_PACK(0,ENGINE_F_ENGINE_CTRL,0), "ENGINE_ctrl"}, 79{ERR_FUNC(ENGINE_F_ENGINE_CTRL), "ENGINE_ctrl"},
76{ERR_PACK(0,ENGINE_F_ENGINE_CTRL_CMD,0), "ENGINE_ctrl_cmd"}, 80{ERR_FUNC(ENGINE_F_ENGINE_CTRL_CMD), "ENGINE_ctrl_cmd"},
77{ERR_PACK(0,ENGINE_F_ENGINE_CTRL_CMD_STRING,0), "ENGINE_ctrl_cmd_string"}, 81{ERR_FUNC(ENGINE_F_ENGINE_CTRL_CMD_STRING), "ENGINE_ctrl_cmd_string"},
78{ERR_PACK(0,ENGINE_F_ENGINE_FINISH,0), "ENGINE_finish"}, 82{ERR_FUNC(ENGINE_F_ENGINE_FINISH), "ENGINE_finish"},
79{ERR_PACK(0,ENGINE_F_ENGINE_FREE,0), "ENGINE_free"}, 83{ERR_FUNC(ENGINE_F_ENGINE_FREE), "ENGINE_free"},
80{ERR_PACK(0,ENGINE_F_ENGINE_GET_CIPHER,0), "ENGINE_get_cipher"}, 84{ERR_FUNC(ENGINE_F_ENGINE_GET_CIPHER), "ENGINE_get_cipher"},
81{ERR_PACK(0,ENGINE_F_ENGINE_GET_DEFAULT_TYPE,0), "ENGINE_GET_DEFAULT_TYPE"}, 85{ERR_FUNC(ENGINE_F_ENGINE_GET_DEFAULT_TYPE), "ENGINE_GET_DEFAULT_TYPE"},
82{ERR_PACK(0,ENGINE_F_ENGINE_GET_DIGEST,0), "ENGINE_get_digest"}, 86{ERR_FUNC(ENGINE_F_ENGINE_GET_DIGEST), "ENGINE_get_digest"},
83{ERR_PACK(0,ENGINE_F_ENGINE_GET_NEXT,0), "ENGINE_get_next"}, 87{ERR_FUNC(ENGINE_F_ENGINE_GET_NEXT), "ENGINE_get_next"},
84{ERR_PACK(0,ENGINE_F_ENGINE_GET_PREV,0), "ENGINE_get_prev"}, 88{ERR_FUNC(ENGINE_F_ENGINE_GET_PREV), "ENGINE_get_prev"},
85{ERR_PACK(0,ENGINE_F_ENGINE_INIT,0), "ENGINE_init"}, 89{ERR_FUNC(ENGINE_F_ENGINE_INIT), "ENGINE_init"},
86{ERR_PACK(0,ENGINE_F_ENGINE_LIST_ADD,0), "ENGINE_LIST_ADD"}, 90{ERR_FUNC(ENGINE_F_ENGINE_LIST_ADD), "ENGINE_LIST_ADD"},
87{ERR_PACK(0,ENGINE_F_ENGINE_LIST_REMOVE,0), "ENGINE_LIST_REMOVE"}, 91{ERR_FUNC(ENGINE_F_ENGINE_LIST_REMOVE), "ENGINE_LIST_REMOVE"},
88{ERR_PACK(0,ENGINE_F_ENGINE_LOAD_PRIVATE_KEY,0), "ENGINE_load_private_key"}, 92{ERR_FUNC(ENGINE_F_ENGINE_LOAD_PRIVATE_KEY), "ENGINE_load_private_key"},
89{ERR_PACK(0,ENGINE_F_ENGINE_LOAD_PUBLIC_KEY,0), "ENGINE_load_public_key"}, 93{ERR_FUNC(ENGINE_F_ENGINE_LOAD_PUBLIC_KEY), "ENGINE_load_public_key"},
90{ERR_PACK(0,ENGINE_F_ENGINE_MODULE_INIT,0), "ENGINE_MODULE_INIT"}, 94{ERR_FUNC(ENGINE_F_ENGINE_MODULE_INIT), "ENGINE_MODULE_INIT"},
91{ERR_PACK(0,ENGINE_F_ENGINE_NEW,0), "ENGINE_new"}, 95{ERR_FUNC(ENGINE_F_ENGINE_NEW), "ENGINE_new"},
92{ERR_PACK(0,ENGINE_F_ENGINE_REMOVE,0), "ENGINE_remove"}, 96{ERR_FUNC(ENGINE_F_ENGINE_REMOVE), "ENGINE_remove"},
93{ERR_PACK(0,ENGINE_F_ENGINE_SET_DEFAULT_STRING,0), "ENGINE_set_default_string"}, 97{ERR_FUNC(ENGINE_F_ENGINE_SET_DEFAULT_STRING), "ENGINE_set_default_string"},
94{ERR_PACK(0,ENGINE_F_ENGINE_SET_DEFAULT_TYPE,0), "ENGINE_SET_DEFAULT_TYPE"}, 98{ERR_FUNC(ENGINE_F_ENGINE_SET_DEFAULT_TYPE), "ENGINE_SET_DEFAULT_TYPE"},
95{ERR_PACK(0,ENGINE_F_ENGINE_SET_ID,0), "ENGINE_set_id"}, 99{ERR_FUNC(ENGINE_F_ENGINE_SET_ID), "ENGINE_set_id"},
96{ERR_PACK(0,ENGINE_F_ENGINE_SET_NAME,0), "ENGINE_set_name"}, 100{ERR_FUNC(ENGINE_F_ENGINE_SET_NAME), "ENGINE_set_name"},
97{ERR_PACK(0,ENGINE_F_ENGINE_TABLE_REGISTER,0), "ENGINE_TABLE_REGISTER"}, 101{ERR_FUNC(ENGINE_F_ENGINE_TABLE_REGISTER), "ENGINE_TABLE_REGISTER"},
98{ERR_PACK(0,ENGINE_F_ENGINE_UNLOAD_KEY,0), "ENGINE_UNLOAD_KEY"}, 102{ERR_FUNC(ENGINE_F_ENGINE_UNLOAD_KEY), "ENGINE_UNLOAD_KEY"},
99{ERR_PACK(0,ENGINE_F_ENGINE_UP_REF,0), "ENGINE_up_ref"}, 103{ERR_FUNC(ENGINE_F_ENGINE_UP_REF), "ENGINE_up_ref"},
100{ERR_PACK(0,ENGINE_F_INT_CTRL_HELPER,0), "INT_CTRL_HELPER"}, 104{ERR_FUNC(ENGINE_F_INT_CTRL_HELPER), "INT_CTRL_HELPER"},
101{ERR_PACK(0,ENGINE_F_INT_ENGINE_CONFIGURE,0), "INT_ENGINE_CONFIGURE"}, 105{ERR_FUNC(ENGINE_F_INT_ENGINE_CONFIGURE), "INT_ENGINE_CONFIGURE"},
102{ERR_PACK(0,ENGINE_F_LOG_MESSAGE,0), "LOG_MESSAGE"}, 106{ERR_FUNC(ENGINE_F_LOG_MESSAGE), "LOG_MESSAGE"},
103{ERR_PACK(0,ENGINE_F_SET_DATA_CTX,0), "SET_DATA_CTX"}, 107{ERR_FUNC(ENGINE_F_SET_DATA_CTX), "SET_DATA_CTX"},
104{0,NULL} 108{0,NULL}
105 }; 109 };
106 110
107static ERR_STRING_DATA ENGINE_str_reasons[]= 111static ERR_STRING_DATA ENGINE_str_reasons[]=
108 { 112 {
109{ENGINE_R_ALREADY_LOADED ,"already loaded"}, 113{ERR_REASON(ENGINE_R_ALREADY_LOADED) ,"already loaded"},
110{ENGINE_R_ARGUMENT_IS_NOT_A_NUMBER ,"argument is not a number"}, 114{ERR_REASON(ENGINE_R_ARGUMENT_IS_NOT_A_NUMBER),"argument is not a number"},
111{ENGINE_R_CMD_NOT_EXECUTABLE ,"cmd not executable"}, 115{ERR_REASON(ENGINE_R_CMD_NOT_EXECUTABLE) ,"cmd not executable"},
112{ENGINE_R_COMMAND_TAKES_INPUT ,"command takes input"}, 116{ERR_REASON(ENGINE_R_COMMAND_TAKES_INPUT),"command takes input"},
113{ENGINE_R_COMMAND_TAKES_NO_INPUT ,"command takes no input"}, 117{ERR_REASON(ENGINE_R_COMMAND_TAKES_NO_INPUT),"command takes no input"},
114{ENGINE_R_CONFLICTING_ENGINE_ID ,"conflicting engine id"}, 118{ERR_REASON(ENGINE_R_CONFLICTING_ENGINE_ID),"conflicting engine id"},
115{ENGINE_R_CTRL_COMMAND_NOT_IMPLEMENTED ,"ctrl command not implemented"}, 119{ERR_REASON(ENGINE_R_CTRL_COMMAND_NOT_IMPLEMENTED),"ctrl command not implemented"},
116{ENGINE_R_DH_NOT_IMPLEMENTED ,"dh not implemented"}, 120{ERR_REASON(ENGINE_R_DH_NOT_IMPLEMENTED) ,"dh not implemented"},
117{ENGINE_R_DSA_NOT_IMPLEMENTED ,"dsa not implemented"}, 121{ERR_REASON(ENGINE_R_DSA_NOT_IMPLEMENTED),"dsa not implemented"},
118{ENGINE_R_DSO_FAILURE ,"DSO failure"}, 122{ERR_REASON(ENGINE_R_DSO_FAILURE) ,"DSO failure"},
119{ENGINE_R_DSO_NOT_FOUND ,"dso not found"}, 123{ERR_REASON(ENGINE_R_DSO_NOT_FOUND) ,"dso not found"},
120{ENGINE_R_ENGINES_SECTION_ERROR ,"engines section error"}, 124{ERR_REASON(ENGINE_R_ENGINES_SECTION_ERROR),"engines section error"},
121{ENGINE_R_ENGINE_IS_NOT_IN_LIST ,"engine is not in the list"}, 125{ERR_REASON(ENGINE_R_ENGINE_IS_NOT_IN_LIST),"engine is not in the list"},
122{ENGINE_R_ENGINE_SECTION_ERROR ,"engine section error"}, 126{ERR_REASON(ENGINE_R_ENGINE_SECTION_ERROR),"engine section error"},
123{ENGINE_R_FAILED_LOADING_PRIVATE_KEY ,"failed loading private key"}, 127{ERR_REASON(ENGINE_R_FAILED_LOADING_PRIVATE_KEY),"failed loading private key"},
124{ENGINE_R_FAILED_LOADING_PUBLIC_KEY ,"failed loading public key"}, 128{ERR_REASON(ENGINE_R_FAILED_LOADING_PUBLIC_KEY),"failed loading public key"},
125{ENGINE_R_FINISH_FAILED ,"finish failed"}, 129{ERR_REASON(ENGINE_R_FINISH_FAILED) ,"finish failed"},
126{ENGINE_R_GET_HANDLE_FAILED ,"could not obtain hardware handle"}, 130{ERR_REASON(ENGINE_R_GET_HANDLE_FAILED) ,"could not obtain hardware handle"},
127{ENGINE_R_ID_OR_NAME_MISSING ,"'id' or 'name' missing"}, 131{ERR_REASON(ENGINE_R_ID_OR_NAME_MISSING) ,"'id' or 'name' missing"},
128{ENGINE_R_INIT_FAILED ,"init failed"}, 132{ERR_REASON(ENGINE_R_INIT_FAILED) ,"init failed"},
129{ENGINE_R_INTERNAL_LIST_ERROR ,"internal list error"}, 133{ERR_REASON(ENGINE_R_INTERNAL_LIST_ERROR),"internal list error"},
130{ENGINE_R_INVALID_ARGUMENT ,"invalid argument"}, 134{ERR_REASON(ENGINE_R_INVALID_ARGUMENT) ,"invalid argument"},
131{ENGINE_R_INVALID_CMD_NAME ,"invalid cmd name"}, 135{ERR_REASON(ENGINE_R_INVALID_CMD_NAME) ,"invalid cmd name"},
132{ENGINE_R_INVALID_CMD_NUMBER ,"invalid cmd number"}, 136{ERR_REASON(ENGINE_R_INVALID_CMD_NUMBER) ,"invalid cmd number"},
133{ENGINE_R_INVALID_INIT_VALUE ,"invalid init value"}, 137{ERR_REASON(ENGINE_R_INVALID_INIT_VALUE) ,"invalid init value"},
134{ENGINE_R_INVALID_STRING ,"invalid string"}, 138{ERR_REASON(ENGINE_R_INVALID_STRING) ,"invalid string"},
135{ENGINE_R_NOT_INITIALISED ,"not initialised"}, 139{ERR_REASON(ENGINE_R_NOT_INITIALISED) ,"not initialised"},
136{ENGINE_R_NOT_LOADED ,"not loaded"}, 140{ERR_REASON(ENGINE_R_NOT_LOADED) ,"not loaded"},
137{ENGINE_R_NO_CONTROL_FUNCTION ,"no control function"}, 141{ERR_REASON(ENGINE_R_NO_CONTROL_FUNCTION),"no control function"},
138{ENGINE_R_NO_INDEX ,"no index"}, 142{ERR_REASON(ENGINE_R_NO_INDEX) ,"no index"},
139{ENGINE_R_NO_LOAD_FUNCTION ,"no load function"}, 143{ERR_REASON(ENGINE_R_NO_LOAD_FUNCTION) ,"no load function"},
140{ENGINE_R_NO_REFERENCE ,"no reference"}, 144{ERR_REASON(ENGINE_R_NO_REFERENCE) ,"no reference"},
141{ENGINE_R_NO_SUCH_ENGINE ,"no such engine"}, 145{ERR_REASON(ENGINE_R_NO_SUCH_ENGINE) ,"no such engine"},
142{ENGINE_R_NO_UNLOAD_FUNCTION ,"no unload function"}, 146{ERR_REASON(ENGINE_R_NO_UNLOAD_FUNCTION) ,"no unload function"},
143{ENGINE_R_PROVIDE_PARAMETERS ,"provide parameters"}, 147{ERR_REASON(ENGINE_R_PROVIDE_PARAMETERS) ,"provide parameters"},
144{ENGINE_R_RSA_NOT_IMPLEMENTED ,"rsa not implemented"}, 148{ERR_REASON(ENGINE_R_RSA_NOT_IMPLEMENTED),"rsa not implemented"},
145{ENGINE_R_UNIMPLEMENTED_CIPHER ,"unimplemented cipher"}, 149{ERR_REASON(ENGINE_R_UNIMPLEMENTED_CIPHER),"unimplemented cipher"},
146{ENGINE_R_UNIMPLEMENTED_DIGEST ,"unimplemented digest"}, 150{ERR_REASON(ENGINE_R_UNIMPLEMENTED_DIGEST),"unimplemented digest"},
147{ENGINE_R_VERSION_INCOMPATIBILITY ,"version incompatibility"}, 151{ERR_REASON(ENGINE_R_VERSION_INCOMPATIBILITY),"version incompatibility"},
148{0,NULL} 152{0,NULL}
149 }; 153 };
150 154
@@ -158,8 +162,8 @@ void ERR_load_ENGINE_strings(void)
158 { 162 {
159 init=0; 163 init=0;
160#ifndef OPENSSL_NO_ERR 164#ifndef OPENSSL_NO_ERR
161 ERR_load_strings(ERR_LIB_ENGINE,ENGINE_str_functs); 165 ERR_load_strings(0,ENGINE_str_functs);
162 ERR_load_strings(ERR_LIB_ENGINE,ENGINE_str_reasons); 166 ERR_load_strings(0,ENGINE_str_reasons);
163#endif 167#endif
164 168
165 } 169 }
diff --git a/src/lib/libcrypto/engine/hw_aep.c b/src/lib/libcrypto/engine/hw_aep.c
index 8b8380a582..5f1772ea99 100644
--- a/src/lib/libcrypto/engine/hw_aep.c
+++ b/src/lib/libcrypto/engine/hw_aep.c
@@ -474,6 +474,7 @@ static int aep_init(ENGINE *e)
474 474
475 if(aep_dso) 475 if(aep_dso)
476 DSO_free(aep_dso); 476 DSO_free(aep_dso);
477 aep_dso = NULL;
477 478
478 p_AEP_OpenConnection = NULL; 479 p_AEP_OpenConnection = NULL;
479 p_AEP_ModExp = NULL; 480 p_AEP_ModExp = NULL;
diff --git a/src/lib/libcrypto/engine/hw_atalla.c b/src/lib/libcrypto/engine/hw_atalla.c
index e9eff9fad1..2b8342bbdd 100644
--- a/src/lib/libcrypto/engine/hw_atalla.c
+++ b/src/lib/libcrypto/engine/hw_atalla.c
@@ -375,6 +375,7 @@ static int atalla_init(ENGINE *e)
375err: 375err:
376 if(atalla_dso) 376 if(atalla_dso)
377 DSO_free(atalla_dso); 377 DSO_free(atalla_dso);
378 atalla_dso = NULL;
378 p_Atalla_GetHardwareConfig = NULL; 379 p_Atalla_GetHardwareConfig = NULL;
379 p_Atalla_RSAPrivateKeyOpFn = NULL; 380 p_Atalla_RSAPrivateKeyOpFn = NULL;
380 p_Atalla_GetPerformanceStatistics = NULL; 381 p_Atalla_GetPerformanceStatistics = NULL;
diff --git a/src/lib/libcrypto/engine/hw_cswift.c b/src/lib/libcrypto/engine/hw_cswift.c
index f128ee5a68..1411fd8333 100644
--- a/src/lib/libcrypto/engine/hw_cswift.c
+++ b/src/lib/libcrypto/engine/hw_cswift.c
@@ -90,6 +90,7 @@ static int cswift_destroy(ENGINE *e);
90static int cswift_init(ENGINE *e); 90static int cswift_init(ENGINE *e);
91static int cswift_finish(ENGINE *e); 91static int cswift_finish(ENGINE *e);
92static int cswift_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)()); 92static int cswift_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)());
93static int cswift_bn_32copy(SW_LARGENUMBER * out, const BIGNUM * in);
93 94
94/* BIGNUM stuff */ 95/* BIGNUM stuff */
95static int cswift_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, 96static int cswift_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
@@ -403,7 +404,10 @@ static int cswift_init(ENGINE *e)
403 return 1; 404 return 1;
404err: 405err:
405 if(cswift_dso) 406 if(cswift_dso)
407 {
406 DSO_free(cswift_dso); 408 DSO_free(cswift_dso);
409 cswift_dso = NULL;
410 }
407 p_CSwift_AcquireAccContext = NULL; 411 p_CSwift_AcquireAccContext = NULL;
408 p_CSwift_AttachKeyParam = NULL; 412 p_CSwift_AttachKeyParam = NULL;
409 p_CSwift_SimpleRequest = NULL; 413 p_CSwift_SimpleRequest = NULL;
@@ -553,6 +557,29 @@ err:
553 return to_return; 557 return to_return;
554 } 558 }
555 559
560
561int cswift_bn_32copy(SW_LARGENUMBER * out, const BIGNUM * in)
562{
563 int mod;
564 int numbytes = BN_num_bytes(in);
565
566 mod = 0;
567 while( ((out->nbytes = (numbytes+mod)) % 32) )
568 {
569 mod++;
570 }
571 out->value = (unsigned char*)OPENSSL_malloc(out->nbytes);
572 if(!out->value)
573 {
574 return 0;
575 }
576 BN_bn2bin(in, &out->value[mod]);
577 if(mod)
578 memset(out->value, 0, mod);
579
580 return 1;
581}
582
556/* Un petit mod_exp chinois */ 583/* Un petit mod_exp chinois */
557static int cswift_mod_exp_crt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, 584static int cswift_mod_exp_crt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
558 const BIGNUM *q, const BIGNUM *dmp1, 585 const BIGNUM *q, const BIGNUM *dmp1,
@@ -562,15 +589,16 @@ static int cswift_mod_exp_crt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
562 SW_LARGENUMBER arg, res; 589 SW_LARGENUMBER arg, res;
563 SW_PARAM sw_param; 590 SW_PARAM sw_param;
564 SW_CONTEXT_HANDLE hac; 591 SW_CONTEXT_HANDLE hac;
565 BIGNUM *rsa_p = NULL;
566 BIGNUM *rsa_q = NULL;
567 BIGNUM *rsa_dmp1 = NULL;
568 BIGNUM *rsa_dmq1 = NULL;
569 BIGNUM *rsa_iqmp = NULL;
570 BIGNUM *argument = NULL;
571 BIGNUM *result = NULL; 592 BIGNUM *result = NULL;
593 BIGNUM *argument = NULL;
572 int to_return = 0; /* expect failure */ 594 int to_return = 0; /* expect failure */
573 int acquired = 0; 595 int acquired = 0;
596
597 sw_param.up.crt.p.value = NULL;
598 sw_param.up.crt.q.value = NULL;
599 sw_param.up.crt.dmp1.value = NULL;
600 sw_param.up.crt.dmq1.value = NULL;
601 sw_param.up.crt.iqmp.value = NULL;
574 602
575 if(!get_context(&hac)) 603 if(!get_context(&hac))
576 { 604 {
@@ -578,44 +606,55 @@ static int cswift_mod_exp_crt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
578 goto err; 606 goto err;
579 } 607 }
580 acquired = 1; 608 acquired = 1;
609
581 /* Prepare the params */ 610 /* Prepare the params */
582 BN_CTX_start(ctx); 611 argument = BN_new();
583 rsa_p = BN_CTX_get(ctx); 612 result = BN_new();
584 rsa_q = BN_CTX_get(ctx); 613 if(!result || !argument)
585 rsa_dmp1 = BN_CTX_get(ctx);
586 rsa_dmq1 = BN_CTX_get(ctx);
587 rsa_iqmp = BN_CTX_get(ctx);
588 argument = BN_CTX_get(ctx);
589 result = BN_CTX_get(ctx);
590 if(!result)
591 { 614 {
592 CSWIFTerr(CSWIFT_F_CSWIFT_MOD_EXP_CRT,CSWIFT_R_BN_CTX_FULL); 615 CSWIFTerr(CSWIFT_F_CSWIFT_MOD_EXP_CRT,CSWIFT_R_BN_CTX_FULL);
593 goto err; 616 goto err;
594 } 617 }
595 if(!bn_wexpand(rsa_p, p->top) || !bn_wexpand(rsa_q, q->top) || 618
596 !bn_wexpand(rsa_dmp1, dmp1->top) || 619
597 !bn_wexpand(rsa_dmq1, dmq1->top) || 620 sw_param.type = SW_ALG_CRT;
598 !bn_wexpand(rsa_iqmp, iqmp->top) || 621 /************************************************************************/
599 !bn_wexpand(argument, a->top) || 622 /* 04/02/2003 */
623 /* Modified by Frederic Giudicelli (deny-all.com) to overcome the */
624 /* limitation of cswift with values not a multiple of 32 */
625 /************************************************************************/
626 if(!cswift_bn_32copy(&sw_param.up.crt.p, p))
627 {
628 CSWIFTerr(CSWIFT_F_CSWIFT_MOD_EXP_CRT,CSWIFT_R_BN_EXPAND_FAIL);
629 goto err;
630 }
631 if(!cswift_bn_32copy(&sw_param.up.crt.q, q))
632 {
633 CSWIFTerr(CSWIFT_F_CSWIFT_MOD_EXP_CRT,CSWIFT_R_BN_EXPAND_FAIL);
634 goto err;
635 }
636 if(!cswift_bn_32copy(&sw_param.up.crt.dmp1, dmp1))
637 {
638 CSWIFTerr(CSWIFT_F_CSWIFT_MOD_EXP_CRT,CSWIFT_R_BN_EXPAND_FAIL);
639 goto err;
640 }
641 if(!cswift_bn_32copy(&sw_param.up.crt.dmq1, dmq1))
642 {
643 CSWIFTerr(CSWIFT_F_CSWIFT_MOD_EXP_CRT,CSWIFT_R_BN_EXPAND_FAIL);
644 goto err;
645 }
646 if(!cswift_bn_32copy(&sw_param.up.crt.iqmp, iqmp))
647 {
648 CSWIFTerr(CSWIFT_F_CSWIFT_MOD_EXP_CRT,CSWIFT_R_BN_EXPAND_FAIL);
649 goto err;
650 }
651 if( !bn_wexpand(argument, a->top) ||
600 !bn_wexpand(result, p->top + q->top)) 652 !bn_wexpand(result, p->top + q->top))
601 { 653 {
602 CSWIFTerr(CSWIFT_F_CSWIFT_MOD_EXP_CRT,CSWIFT_R_BN_EXPAND_FAIL); 654 CSWIFTerr(CSWIFT_F_CSWIFT_MOD_EXP_CRT,CSWIFT_R_BN_EXPAND_FAIL);
603 goto err; 655 goto err;
604 } 656 }
605 sw_param.type = SW_ALG_CRT; 657
606 sw_param.up.crt.p.nbytes = BN_bn2bin(p, (unsigned char *)rsa_p->d);
607 sw_param.up.crt.p.value = (unsigned char *)rsa_p->d;
608 sw_param.up.crt.q.nbytes = BN_bn2bin(q, (unsigned char *)rsa_q->d);
609 sw_param.up.crt.q.value = (unsigned char *)rsa_q->d;
610 sw_param.up.crt.dmp1.nbytes = BN_bn2bin(dmp1,
611 (unsigned char *)rsa_dmp1->d);
612 sw_param.up.crt.dmp1.value = (unsigned char *)rsa_dmp1->d;
613 sw_param.up.crt.dmq1.nbytes = BN_bn2bin(dmq1,
614 (unsigned char *)rsa_dmq1->d);
615 sw_param.up.crt.dmq1.value = (unsigned char *)rsa_dmq1->d;
616 sw_param.up.crt.iqmp.nbytes = BN_bn2bin(iqmp,
617 (unsigned char *)rsa_iqmp->d);
618 sw_param.up.crt.iqmp.value = (unsigned char *)rsa_iqmp->d;
619 /* Attach the key params */ 658 /* Attach the key params */
620 sw_status = p_CSwift_AttachKeyParam(hac, &sw_param); 659 sw_status = p_CSwift_AttachKeyParam(hac, &sw_param);
621 switch(sw_status) 660 switch(sw_status)
@@ -654,9 +693,22 @@ static int cswift_mod_exp_crt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
654 BN_bin2bn((unsigned char *)result->d, res.nbytes, r); 693 BN_bin2bn((unsigned char *)result->d, res.nbytes, r);
655 to_return = 1; 694 to_return = 1;
656err: 695err:
696 if(sw_param.up.crt.p.value)
697 OPENSSL_free(sw_param.up.crt.p.value);
698 if(sw_param.up.crt.q.value)
699 OPENSSL_free(sw_param.up.crt.q.value);
700 if(sw_param.up.crt.dmp1.value)
701 OPENSSL_free(sw_param.up.crt.dmp1.value);
702 if(sw_param.up.crt.dmq1.value)
703 OPENSSL_free(sw_param.up.crt.dmq1.value);
704 if(sw_param.up.crt.iqmp.value)
705 OPENSSL_free(sw_param.up.crt.iqmp.value);
706 if(result)
707 BN_free(result);
708 if(argument)
709 BN_free(argument);
657 if(acquired) 710 if(acquired)
658 release_context(hac); 711 release_context(hac);
659 BN_CTX_end(ctx);
660 return to_return; 712 return to_return;
661 } 713 }
662 714
@@ -665,6 +717,27 @@ static int cswift_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa)
665 { 717 {
666 BN_CTX *ctx; 718 BN_CTX *ctx;
667 int to_return = 0; 719 int to_return = 0;
720 const RSA_METHOD * def_rsa_method;
721
722 /* Try the limits of RSA (2048 bits) */
723 if(BN_num_bytes(rsa->p) > 128 ||
724 BN_num_bytes(rsa->q) > 128 ||
725 BN_num_bytes(rsa->dmp1) > 128 ||
726 BN_num_bytes(rsa->dmq1) > 128 ||
727 BN_num_bytes(rsa->iqmp) > 128)
728 {
729#ifdef RSA_NULL
730 def_rsa_method=RSA_null_method();
731#else
732#if 0
733 def_rsa_method=RSA_PKCS1_RSAref();
734#else
735 def_rsa_method=RSA_PKCS1_SSLeay();
736#endif
737#endif
738 if(def_rsa_method)
739 return def_rsa_method->rsa_mod_exp(r0, I, rsa);
740 }
668 741
669 if((ctx = BN_CTX_new()) == NULL) 742 if((ctx = BN_CTX_new()) == NULL)
670 goto err; 743 goto err;
@@ -686,6 +759,26 @@ err:
686static int cswift_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, 759static int cswift_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
687 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx) 760 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)
688 { 761 {
762 const RSA_METHOD * def_rsa_method;
763
764 /* Try the limits of RSA (2048 bits) */
765 if(BN_num_bytes(r) > 256 ||
766 BN_num_bytes(a) > 256 ||
767 BN_num_bytes(m) > 256)
768 {
769#ifdef RSA_NULL
770 def_rsa_method=RSA_null_method();
771#else
772#if 0
773 def_rsa_method=RSA_PKCS1_RSAref();
774#else
775 def_rsa_method=RSA_PKCS1_SSLeay();
776#endif
777#endif
778 if(def_rsa_method)
779 return def_rsa_method->bn_mod_exp(r, a, p, m, ctx, m_ctx);
780 }
781
689 return cswift_mod_exp(r, a, p, m, ctx); 782 return cswift_mod_exp(r, a, p, m, ctx);
690 } 783 }
691 784
@@ -930,9 +1023,10 @@ static int cswift_rand_bytes(unsigned char *buf, int num)
930 SW_CONTEXT_HANDLE hac; 1023 SW_CONTEXT_HANDLE hac;
931 SW_STATUS swrc; 1024 SW_STATUS swrc;
932 SW_LARGENUMBER largenum; 1025 SW_LARGENUMBER largenum;
933 size_t nbytes = 0;
934 int acquired = 0; 1026 int acquired = 0;
935 int to_return = 0; /* assume failure */ 1027 int to_return = 0; /* assume failure */
1028 unsigned char buf32[1024];
1029
936 1030
937 if (!get_context(&hac)) 1031 if (!get_context(&hac))
938 { 1032 {
@@ -941,17 +1035,19 @@ static int cswift_rand_bytes(unsigned char *buf, int num)
941 } 1035 }
942 acquired = 1; 1036 acquired = 1;
943 1037
944 while (nbytes < (size_t)num) 1038 /************************************************************************/
1039 /* 04/02/2003 */
1040 /* Modified by Frederic Giudicelli (deny-all.com) to overcome the */
1041 /* limitation of cswift with values not a multiple of 32 */
1042 /************************************************************************/
1043
1044 while(num >= sizeof(buf32))
945 { 1045 {
1046 largenum.value = buf;
1047 largenum.nbytes = sizeof(buf32);
946 /* tell CryptoSwift how many bytes we want and where we want it. 1048 /* tell CryptoSwift how many bytes we want and where we want it.
947 * Note: - CryptoSwift cannot do more than 4096 bytes at a time. 1049 * Note: - CryptoSwift cannot do more than 4096 bytes at a time.
948 * - CryptoSwift can only do multiple of 32-bits. */ 1050 * - CryptoSwift can only do multiple of 32-bits. */
949 largenum.value = (SW_BYTE *) buf + nbytes;
950 if (4096 > num - nbytes)
951 largenum.nbytes = num - nbytes;
952 else
953 largenum.nbytes = 4096;
954
955 swrc = p_CSwift_SimpleRequest(hac, SW_CMD_RAND, NULL, 0, &largenum, 1); 1051 swrc = p_CSwift_SimpleRequest(hac, SW_CMD_RAND, NULL, 0, &largenum, 1);
956 if (swrc != SW_OK) 1052 if (swrc != SW_OK)
957 { 1053 {
@@ -961,14 +1057,30 @@ static int cswift_rand_bytes(unsigned char *buf, int num)
961 ERR_add_error_data(2, "CryptoSwift error number is ", tmpbuf); 1057 ERR_add_error_data(2, "CryptoSwift error number is ", tmpbuf);
962 goto err; 1058 goto err;
963 } 1059 }
964 1060 buf += sizeof(buf32);
965 nbytes += largenum.nbytes; 1061 num -= sizeof(buf32);
1062 }
1063 if(num)
1064 {
1065 largenum.nbytes = sizeof(buf32);
1066 largenum.value = buf32;
1067 swrc = p_CSwift_SimpleRequest(hac, SW_CMD_RAND, NULL, 0, &largenum, 1);
1068 if (swrc != SW_OK)
1069 {
1070 char tmpbuf[20];
1071 CSWIFTerr(CSWIFT_F_CSWIFT_CTRL, CSWIFT_R_REQUEST_FAILED);
1072 sprintf(tmpbuf, "%ld", swrc);
1073 ERR_add_error_data(2, "CryptoSwift error number is ", tmpbuf);
1074 goto err;
1075 }
1076 memcpy(buf, largenum.value, num);
966 } 1077 }
967 to_return = 1; /* success */
968 1078
1079 to_return = 1; /* success */
969err: 1080err:
970 if (acquired) 1081 if (acquired)
971 release_context(hac); 1082 release_context(hac);
1083
972 return to_return; 1084 return to_return;
973} 1085}
974 1086
diff --git a/src/lib/libcrypto/engine/hw_ubsec.c b/src/lib/libcrypto/engine/hw_ubsec.c
index 5234a08a07..8fb834af31 100644
--- a/src/lib/libcrypto/engine/hw_ubsec.c
+++ b/src/lib/libcrypto/engine/hw_ubsec.c
@@ -454,6 +454,7 @@ static int ubsec_init(ENGINE *e)
454err: 454err:
455 if(ubsec_dso) 455 if(ubsec_dso)
456 DSO_free(ubsec_dso); 456 DSO_free(ubsec_dso);
457 ubsec_dso = NULL;
457 p_UBSEC_ubsec_bytes_to_bits = NULL; 458 p_UBSEC_ubsec_bytes_to_bits = NULL;
458 p_UBSEC_ubsec_bits_to_bytes = NULL; 459 p_UBSEC_ubsec_bits_to_bytes = NULL;
459 p_UBSEC_ubsec_open = NULL; 460 p_UBSEC_ubsec_open = NULL;
diff --git a/src/lib/libcrypto/engine/tb_dsa.c b/src/lib/libcrypto/engine/tb_dsa.c
index 80170591f2..7efe181927 100644
--- a/src/lib/libcrypto/engine/tb_dsa.c
+++ b/src/lib/libcrypto/engine/tb_dsa.c
@@ -94,7 +94,7 @@ int ENGINE_set_default_DSA(ENGINE *e)
94 { 94 {
95 if(e->dsa_meth) 95 if(e->dsa_meth)
96 return engine_table_register(&dsa_table, 96 return engine_table_register(&dsa_table,
97 engine_unregister_all_DSA, e, &dummy_nid, 1, 0); 97 engine_unregister_all_DSA, e, &dummy_nid, 1, 1);
98 return 1; 98 return 1;
99 } 99 }
100 100