65 #ifndef OPENSSL_NO_RSA
68 #ifndef OPENSSL_NO_DSA
77 #ifndef OPENSSL_NO_HW_ATALLA
85 #define ATALLA_LIB_NAME "atalla engine"
88 static int atalla_destroy(
ENGINE *
e);
89 static int atalla_init(
ENGINE *
e);
90 static int atalla_finish(
ENGINE *
e);
91 static int atalla_ctrl(
ENGINE *
e,
int cmd,
long i,
void *
p,
void (*
f)(
void));
97 #ifndef OPENSSL_NO_RSA
105 #ifndef OPENSSL_NO_DSA
115 #ifndef OPENSSL_NO_DH
118 static int atalla_mod_exp_dh(
const DH *dh,
BIGNUM *r,
124 #define ATALLA_CMD_SO_PATH ENGINE_CMD_BASE
128 "Specifies the path to the 'atasi' shared library",
133 #ifndef OPENSSL_NO_RSA
154 #ifndef OPENSSL_NO_DSA
173 #ifndef OPENSSL_NO_DH
190 static const char *engine_atalla_id =
"atalla";
191 static const char *engine_atalla_name =
"Atalla hardware engine support";
195 static int bind_helper(
ENGINE *e)
197 #ifndef OPENSSL_NO_RSA
200 #ifndef OPENSSL_NO_DSA
203 #ifndef OPENSSL_NO_DH
208 #ifndef OPENSSL_NO_RSA
211 #ifndef OPENSSL_NO_DSA
214 #ifndef OPENSSL_NO_DH
224 #ifndef OPENSSL_NO_RSA
239 #ifndef OPENSSL_NO_DSA
248 #ifndef OPENSSL_NO_DH
256 ERR_load_ATALLA_strings();
260 #ifdef OPENSSL_NO_DYNAMIC_ENGINE
261 static ENGINE *engine_atalla(
void)
266 if(!bind_helper(ret))
277 ENGINE *toadd = engine_atalla();
290 static DSO *atalla_dso = NULL;
306 static const char *ATALLA_LIBNAME = NULL;
307 static const char *get_ATALLA_LIBNAME(
void)
310 return ATALLA_LIBNAME;
313 static void free_ATALLA_LIBNAME(
void)
317 ATALLA_LIBNAME = NULL;
319 static long set_ATALLA_LIBNAME(
const char *name)
321 free_ATALLA_LIBNAME();
322 return (((ATALLA_LIBNAME =
BUF_strdup(name)) != NULL) ? 1 : 0);
324 static const char *ATALLA_F1 =
"ASI_GetHardwareConfig";
325 static const char *ATALLA_F2 =
"ASI_RSAPrivateKeyOpFn";
326 static const char *ATALLA_F3 =
"ASI_GetPerformanceStatistics";
329 static int atalla_destroy(
ENGINE *e)
331 free_ATALLA_LIBNAME();
335 ERR_unload_ATALLA_strings();
340 static int atalla_init(
ENGINE *e)
347 unsigned int config_buf[1024];
349 if(atalla_dso != NULL)
361 atalla_dso =
DSO_load(NULL, get_ATALLA_LIBNAME(), NULL, 0);
362 if(atalla_dso == NULL)
368 atalla_dso, ATALLA_F1)) ||
370 atalla_dso, ATALLA_F2)) ||
372 atalla_dso, ATALLA_F3)))
378 p_Atalla_GetHardwareConfig = p1;
379 p_Atalla_RSAPrivateKeyOpFn = p2;
380 p_Atalla_GetPerformanceStatistics = p3;
383 if(p1(0L, config_buf) != 0)
394 p_Atalla_GetHardwareConfig = NULL;
395 p_Atalla_RSAPrivateKeyOpFn = NULL;
396 p_Atalla_GetPerformanceStatistics = NULL;
400 static int atalla_finish(
ENGINE *e)
402 free_ATALLA_LIBNAME();
403 if(atalla_dso == NULL)
414 p_Atalla_GetHardwareConfig = NULL;
415 p_Atalla_RSAPrivateKeyOpFn = NULL;
416 p_Atalla_GetPerformanceStatistics = NULL;
420 static int atalla_ctrl(
ENGINE *e,
int cmd,
long i,
void *p,
void (*
f)(
void))
422 int initialised = ((atalla_dso == NULL) ? 0 : 1);
436 return set_ATALLA_LIBNAME((
const char *)p);
457 int to_return, numbytes;
459 modulus = exponent = argument = result = NULL;
485 memset(&keydata, 0,
sizeof keydata);
487 memset(exponent->
d, 0, numbytes);
488 memset(modulus->
d, 0, numbytes);
496 memset(argument->
d, 0, numbytes);
497 memset(result->
d, 0, numbytes);
500 if(p_Atalla_RSAPrivateKeyOpFn(&keydata, (
unsigned char *)result->
d,
501 (
unsigned char *)argument->
d,
508 BN_bin2bn((
unsigned char *)result->
d, numbytes, r);
515 #ifndef OPENSSL_NO_RSA
525 if(!rsa->
d || !rsa->
n)
530 to_return = atalla_mod_exp(r0, I, rsa->
d, rsa->
n, ctx);
536 #ifndef OPENSSL_NO_DSA
553 if (!atalla_mod_exp(rr,a1,p1,m,ctx))
goto end;
555 if (!atalla_mod_exp(&t,a2,p2,m,ctx))
goto end;
568 return atalla_mod_exp(r, a, p, m, ctx);
572 #ifndef OPENSSL_NO_RSA
577 return atalla_mod_exp(r, a, p, m, ctx);
581 #ifndef OPENSSL_NO_DH
583 static int atalla_mod_exp_dh(
const DH *dh,
BIGNUM *r,
587 return atalla_mod_exp(r, a, p, m, ctx);
593 #ifndef OPENSSL_NO_DYNAMIC_ENGINE
594 static int bind_fn(
ENGINE *e,
const char *
id)
596 if(
id && (strcmp(
id, engine_atalla_id) != 0))