68 #ifndef NO_HW_CLUSTER_LABS
73 #include "vendor_defns/cluster_labs.h"
76 #define CL_LIB_NAME "cluster_labs engine"
80 static int cluster_labs_destroy(
ENGINE *
e);
81 static int cluster_labs_init(
ENGINE *
e);
82 static int cluster_labs_finish(
ENGINE *
e);
83 static int cluster_labs_ctrl(
ENGINE *
e,
int cmd,
long i,
void *
p,
void (*
f)());
92 #ifndef OPENSSL_NO_RSA
93 static int cluster_labs_rsa_pub_enc(
int flen,
const unsigned char *from,
94 unsigned char *to,
RSA *rsa,
int padding);
95 static int cluster_labs_rsa_pub_dec(
int flen,
const unsigned char *from,
96 unsigned char *to,
RSA *rsa,
int padding);
97 static int cluster_labs_rsa_priv_enc(
int flen,
const unsigned char *from,
98 unsigned char *to,
RSA *rsa,
int padding);
99 static int cluster_labs_rsa_priv_dec(
int flen,
const unsigned char *from,
100 unsigned char *to,
RSA *rsa,
int padding);
105 #ifndef OPENSSL_NO_DSA
106 static DSA_SIG *cluster_labs_dsa_sign(
const unsigned char *dgst,
int dlen,
DSA *dsa);
107 static int cluster_labs_dsa_verify(
const unsigned char *dgst,
int dgst_len,
118 #ifndef OPENSSL_NO_DH
125 static int cluster_labs_rand_bytes(
unsigned char *buf,
int num);
128 #define CLUSTER_LABS_CMD_SO_PATH ENGINE_CMD_BASE
133 "Specifies the path to the 'cluster labs' shared library",
140 #ifndef OPENSSL_NO_RSA
143 "Cluster Labs RSA method",
144 cluster_labs_rsa_pub_enc,
145 cluster_labs_rsa_pub_dec,
146 cluster_labs_rsa_priv_enc,
147 cluster_labs_rsa_priv_dec,
148 cluster_labs_rsa_mod_exp,
149 cluster_labs_mod_exp_mont,
160 #ifndef OPENSSL_NO_DSA
163 "Cluster Labs DSA method",
164 cluster_labs_dsa_sign,
166 cluster_labs_dsa_verify,
167 cluster_labs_dsa_mod_exp,
168 cluster_labs_mod_exp_dsa,
177 #ifndef OPENSSL_NO_DH
180 "Cluster Labs DH method",
183 cluster_labs_mod_exp_dh,
195 cluster_labs_rand_bytes,
198 cluster_labs_rand_bytes,
202 static const char *engine_cluster_labs_id =
"cluster_labs";
203 static const char *engine_cluster_labs_name =
"Cluster Labs hardware engine support";
207 static int bind_helper(
ENGINE *e)
212 #ifndef OPENSSL_NO_RSA
215 #ifndef OPENSSL_NO_DSA
218 #ifndef OPENSSL_NO_DH
229 ERR_load_CL_strings();
233 #ifndef ENGINE_DYNAMIC_SUPPORT
234 static ENGINE *engine_cluster_labs(
void)
240 if(!bind_helper(ret))
248 #ifdef ENGINE_DYNAMIC_SUPPORT
254 ENGINE *cluster_labs = engine_cluster_labs();
256 if(!cluster_labs)
return;
263 static int cluster_labs_destroy(
ENGINE *e)
266 ERR_unload_CL_strings();
277 static DSO *cluster_labs_dso = NULL;
294 int cluster_labs_init(
ENGINE *e)
310 if(cluster_labs_dso != NULL)
316 cluster_labs_dso =
DSO_load(NULL, CLUSTER_LABS_LIB_NAME, NULL,0);
317 if(cluster_labs_dso == NULL)
324 cluster_labs_dso, CLUSTER_LABS_F1)) ||
326 cluster_labs_dso, CLUSTER_LABS_F2)) ||
328 cluster_labs_dso, CLUSTER_LABS_F3)) ||
330 cluster_labs_dso, CLUSTER_LABS_F4)) ||
332 cluster_labs_dso, CLUSTER_LABS_F5)) ||
334 cluster_labs_dso, CLUSTER_LABS_F6)) ||
336 cluster_labs_dso, CLUSTER_LABS_F7)) ||
338 cluster_labs_dso, CLUSTER_LABS_F8)) ||
340 cluster_labs_dso, CLUSTER_LABS_F20)) ||
342 cluster_labs_dso, CLUSTER_LABS_F30)) ||
344 cluster_labs_dso, CLUSTER_LABS_F31)))
351 p_cl_engine_init = p1;
353 p_cl_mod_exp_crt = p3;
354 p_cl_rsa_mod_exp = p4;
355 p_cl_rsa_priv_enc = p5;
356 p_cl_rsa_priv_dec = p6;
357 p_cl_rsa_pub_enc = p7;
358 p_cl_rsa_pub_dec = p8;
359 p_cl_rand_bytes = p20;
361 p_cl_dsa_verify = p31;
366 if(p_cl_engine_init()== 0){
378 cluster_labs_dso = NULL;
379 p_cl_engine_init = NULL;
381 p_cl_mod_exp_crt = NULL;
382 p_cl_rsa_mod_exp = NULL;
383 p_cl_rsa_priv_enc = NULL;
384 p_cl_rsa_priv_dec = NULL;
385 p_cl_rsa_pub_enc = NULL;
386 p_cl_rsa_pub_dec = NULL;
387 p_cl_rand_bytes = NULL;
388 p_cl_dsa_sign = NULL;
389 p_cl_dsa_verify = NULL;
395 static int cluster_labs_finish(
ENGINE *e)
398 if(cluster_labs_dso == NULL)
409 cluster_labs_dso = NULL;
410 p_cl_engine_init = NULL;
412 p_cl_rsa_mod_exp = NULL;
413 p_cl_mod_exp_crt = NULL;
414 p_cl_rsa_priv_enc = NULL;
415 p_cl_rsa_priv_dec = NULL;
416 p_cl_rsa_pub_enc = NULL;
417 p_cl_rsa_pub_dec = NULL;
418 p_cl_rand_bytes = NULL;
419 p_cl_dsa_sign = NULL;
420 p_cl_dsa_verify = NULL;
426 static int cluster_labs_ctrl(
ENGINE *e,
int cmd,
long i,
void *p,
void (*
f)())
428 int initialised = ((cluster_labs_dso == NULL) ? 0 : 1);
443 CLUSTER_LABS_LIB_NAME = (
const char *)p;
457 if(cluster_labs_dso == NULL)
462 if(p_cl_mod_exp == NULL)
468 return p_cl_mod_exp(r, a, p, m, ctx);
477 if(cluster_labs_dso == NULL)
482 if(p_cl_mod_exp_crt == NULL)
488 return p_cl_mod_exp_crt(r, a, p, q,dmp1, dmq1, iqmp, ctx);
495 if(cluster_labs_dso == NULL)
500 if(p_cl_rsa_mod_exp == NULL)
506 return p_cl_rsa_mod_exp(r0, I, rsa);
510 static DSA_SIG *cluster_labs_dsa_sign(
const unsigned char *dgst,
int dlen,
DSA *dsa)
513 if(cluster_labs_dso == NULL)
518 if(p_cl_dsa_sign == NULL)
524 return p_cl_dsa_sign(dgst, dlen, dsa);
528 static int cluster_labs_dsa_verify(
const unsigned char *dgst,
int dgst_len,
532 if(cluster_labs_dso == NULL)
538 if(p_cl_dsa_verify == NULL)
544 return p_cl_dsa_verify(dgst, dgst_len, sig, dsa);
557 if (!cluster_labs_mod_exp(rr,a1,p1,m,ctx))
goto end;
559 if (!cluster_labs_mod_exp(&t,a2,p2,m,ctx))
goto end;
574 return cluster_labs_mod_exp(r, a, p, m, ctx);
581 return cluster_labs_mod_exp(r, a, p, m, ctx);
589 return cluster_labs_mod_exp(r, a, p, m, ctx);
593 static int cluster_labs_rsa_pub_enc(
int flen,
const unsigned char *from,
594 unsigned char *to,
RSA *rsa,
int padding)
597 if(cluster_labs_dso == NULL)
602 if(p_cl_rsa_priv_enc == NULL)
608 return p_cl_rsa_pub_enc(flen, from, to, rsa, padding);
612 static int cluster_labs_rsa_pub_dec(
int flen,
const unsigned char *from,
613 unsigned char *to,
RSA *rsa,
int padding)
616 if(cluster_labs_dso == NULL)
621 if(p_cl_rsa_priv_enc == NULL)
627 return p_cl_rsa_pub_dec(flen, from, to, rsa, padding);
632 static int cluster_labs_rsa_priv_enc(
int flen,
const unsigned char *from,
633 unsigned char *to,
RSA *rsa,
int padding)
636 if(cluster_labs_dso == NULL)
642 if(p_cl_rsa_priv_enc == NULL)
648 return p_cl_rsa_priv_enc(flen, from, to, rsa, padding);
652 static int cluster_labs_rsa_priv_dec(
int flen,
const unsigned char *from,
653 unsigned char *to,
RSA *rsa,
int padding)
656 if(cluster_labs_dso == NULL)
661 if(p_cl_rsa_priv_dec == NULL)
667 return p_cl_rsa_priv_dec(flen, from, to, rsa, padding);
680 static int cluster_labs_rand_bytes(
unsigned char *buf,
int num){
682 if(cluster_labs_dso == NULL)
687 if(p_cl_mod_exp_crt == NULL)
693 return p_cl_rand_bytes(buf, num);
700 #ifdef ENGINE_DYNAMIC_SUPPORT
701 static int bind_fn(
ENGINE *e,
const char *
id)
703 fprintf(stderr,
"bind_fn CLUSTER_LABS\n");
704 if(
id && (strcmp(
id, engine_cluster_labs_id) != 0)) {
705 fprintf(stderr,
"bind_fn return(0) first\n");
708 if(!bind_helper(e)) {
709 fprintf(stderr,
"bind_fn return(1) first\n");
712 fprintf(stderr,
"bind_fn return(1)\n");