-/* crypto/engine/hw_zencod.c */
/*
* Written by Fred Donnat (frederic.donnat@zencod.com) for "zencod" * engine
* integration in order to redirect crypto computing on a crypto * hardware
}
# ifndef OPENSSL_NO_RSA
/*
- * We know that the "PKCS1_SSLeay()" functions hook properly to the
+ * We know that the "PKCS1_OpenSSL()" functions hook properly to the
* Zencod-specific mod_exp and mod_exp_crt so we use those functions. NB:
* We don't use ENGINE_openssl() or anything "more generic" because
* something like the RSAref code may not hook properly, and if you own
* one of these cards then you have the right to do RSA operations on it
* anyway!
*/
- meth_rsa = RSA_PKCS1_SSLeay();
+ meth_rsa = RSA_PKCS1_OpenSSL();
zencod_rsa.rsa_pub_enc = meth_rsa->rsa_pub_enc;
zencod_rsa.rsa_pub_dec = meth_rsa->rsa_pub_dec;
# endif
/*
- * We use OpenSSL (SSLeay) meth to supply what we don't provide ;-*)
+ * We use OpenSSL meth to supply what we don't provide ;-*)
*/
- meth_rand = RAND_SSLeay();
+ meth_rand = RAND_OpenSSL();
/* meth_rand->seed ; */
/* zencod_rand.seed = meth_rand->seed ; */
/*
* Trying to load Function from the Library
*/
- if (!
- (ptr_1 =
- (t_zencod_bytes2bits *) DSO_bind_func(zencod_dso, ZENCOD_Fct_1))
-|| !(ptr_2 = (t_zencod_bits2bytes *) DSO_bind_func(zencod_dso, ZENCOD_Fct_2))
-|| !(ptr_3 = (t_zencod_new_number *) DSO_bind_func(zencod_dso, ZENCOD_Fct_3))
-|| !(ptr_4 = (t_zencod_init_number *) DSO_bind_func(zencod_dso, ZENCOD_Fct_4))
-|| !(ptr_exp_1 =
- (t_zencod_rsa_mod_exp *) DSO_bind_func(zencod_dso, ZENCOD_Fct_exp_1))
-|| !(ptr_exp_2 =
- (t_zencod_rsa_mod_exp_crt *) DSO_bind_func(zencod_dso, ZENCOD_Fct_exp_2))
-|| !(ptr_dsa_1 =
- (t_zencod_dsa_do_sign *) DSO_bind_func(zencod_dso, ZENCOD_Fct_dsa_1))
-|| !(ptr_dsa_2 =
- (t_zencod_dsa_do_verify *) DSO_bind_func(zencod_dso, ZENCOD_Fct_dsa_2))
-|| !(ptr_dh_1 =
- (t_zencod_dh_generate_key *) DSO_bind_func(zencod_dso, ZENCOD_Fct_dh_1))
-|| !(ptr_dh_2 =
- (t_zencod_dh_compute_key *) DSO_bind_func(zencod_dso, ZENCOD_Fct_dh_2))
-|| !(ptr_rand_1 =
- (t_zencod_rand_bytes *) DSO_bind_func(zencod_dso, ZENCOD_Fct_rand_1))
-|| !(ptr_math_1 =
- (t_zencod_math_mod_exp *) DSO_bind_func(zencod_dso, ZENCOD_Fct_math_1))
-|| !(ptr_0 = (t_zencod_test *) DSO_bind_func(zencod_dso, ZENCOD_Fct_0))
-|| !(ptr_md5_1 =
- (t_zencod_md5_init *) DSO_bind_func(zencod_dso, ZENCOD_Fct_md5_1))
-|| !(ptr_md5_2 =
- (t_zencod_md5_update *) DSO_bind_func(zencod_dso, ZENCOD_Fct_md5_2))
-|| !(ptr_md5_3 =
- (t_zencod_md5_do_final *) DSO_bind_func(zencod_dso, ZENCOD_Fct_md5_3))
-|| !(ptr_sha1_1 =
- (t_zencod_sha1_init *) DSO_bind_func(zencod_dso, ZENCOD_Fct_sha1_1))
-|| !(ptr_sha1_2 =
- (t_zencod_sha1_update *) DSO_bind_func(zencod_dso, ZENCOD_Fct_sha1_2))
-|| !(ptr_sha1_3 =
- (t_zencod_sha1_do_final *) DSO_bind_func(zencod_dso, ZENCOD_Fct_sha1_3))
-|| !(ptr_xdes_1 =
- (t_zencod_xdes_cipher *) DSO_bind_func(zencod_dso, ZENCOD_Fct_xdes_1))
-|| !(ptr_rc4_1 =
- (t_zencod_rc4_cipher *) DSO_bind_func(zencod_dso, ZENCOD_Fct_rc4_1))) {
-
+#define BINDIT(t, name) (t*)DSO_bindfunc(zencod_dso, name)
+ if ((ptr_1 = BINDIT(t_zencod_bytes2bits ZENCOD_Fct_1)) == NULL
+ || (ptr_2 = BINDIT(t_zencod_bits2bytes ZENCOD_Fct_2)) == NULL
+ || (ptr_3 = BINDIT(t_zencod_new_number ZENCOD_Fct_3)) == NULL
+ || (ptr_4 = BINDIT(t_zencod_init_number ZENCOD_Fct_4)) == NULL
+ || (ptr_exp_1 = BINDIT(t_zencod_rsa_mod_exp, ZENCOD_Fct_exp_1)) == NULL
+ || (ptr_exp_2 = BINDIT(t_zencod_rsa_mod_exp_crt, ZENCOD_Fct_exp_2)) == NULL
+ || (ptr_dsa_1 = BINDIT(t_zencod_dsa_do_sign, ZENCOD_Fct_dsa_1)) == NULL
+ || (ptr_dsa_2 = BINDIT(t_zencod_dsa_do_verify, ZENCOD_Fct_dsa_2)) == NULL
+ || (ptr_dh_1 = BINDIT(t_zencod_dh_generate_key, ZENCOD_Fct_dh_1)) == NULL
+ || (ptr_dh_2 = BINDIT(t_zencod_dh_compute_key, ZENCOD_Fct_dh_2)) == NULL
+ || (ptr_rand_1 = BINDIT(t_zencod_rand_bytes, ZENCOD_Fct_rand_1)) == NULL
+ || (ptr_math_1 = BINDIT(t_zencod_math_mod_exp, ZENCOD_Fct_math_1)) == NULL
+ || (ptr_0 = BINDIT(t_zencod_test, ZENCOD_Fct_0)) == NULL
+ || (ptr_md5_1 = BINDIT(t_zencod_md5_init, ZENCOD_Fct_md5_1)) == NULL
+ || (ptr_md5_2 = BINDIT(t_zencod_md5_update, ZENCOD_Fct_md5_2)) == NULL
+ || (ptr_md5_3 = BINDIT(t_zencod_md5_do_final, ZENCOD_Fct_md5_3)) == NULL
+ || (ptr_sha1_1 = BINDIT(t_zencod_sha1_init, ZENCOD_Fct_sha1_1)) == NULL
+ || (ptr_sha1_2 = BINDIT(t_zencod_sha1_update, ZENCOD_Fct_sha1_2)) == NULL
+ || (ptr_sha1_3 = BINDIT(t_zencod_sha1_do_final, ZENCOD_Fct_sha1_3)) == NULL
+ || (ptr_xdes_1 = BINDIT(t_zencod_xdes_cipher, ZENCOD_Fct_xdes_1)) == NULL
+ || (ptr_rc4_1 = BINDIT(t_zencod_rc4_cipher, ZENCOD_Fct_rc4_1)) == NULL) {
ZENCODerr(ZENCOD_F_ZENCOD_INIT, ZENCOD_R_DSO_FAILURE);
goto err;
}
ptr_zencod_rc4_cipher = ptr_rc4_1;
/*
- * We should peform a test to see if there is actually any unit runnig on
+ * We should perform a test to see if there is actually any unit runnig on
* the system ... Even if the cryptozen library is loaded the module coul
* not be loaded on the system ... For now we may just open and close the
* device !!
return 1;
err:
- if (zencod_dso) {
- DSO_free(zencod_dso);
- }
+ DSO_free(zencod_dso);
zencod_dso = NULL;
ptr_zencod_bytes2bits = NULL;
ptr_zencod_bits2bytes = NULL;
if (RSA_size(rsa) * 8 > ZENBRIDGE_MAX_KEYSIZE_RSA_CRT) {
const RSA_METHOD *meth;
- meth = RSA_PKCS1_SSLeay();
+ meth = RSA_PKCS1_OpenSSL();
return meth->rsa_mod_exp(r0, i, rsa);
} else {
zen_nb_t y, x, p, q, dmp1, dmq1, iqmp;
if (BN_num_bits(m) > ZENBRIDGE_MAX_KEYSIZE_RSA) {
const RSA_METHOD *meth;
- meth = RSA_PKCS1_SSLeay();
+ meth = RSA_PKCS1_OpenSSL();
return meth->bn_mod_exp(r, a, p, m, ctx, m_ctx);
} else {
zen_nb_t y, x, e, n;
return meth->dsa_do_sign(dgst, dlen, dsa);
}
- if (!(bn_s = BN_new()) || !(bn_r = BN_new())) {
+ if ((bn_s = BN_new()) == NULL || (bn_r = BN_new()) == NULL) {
ENGINEerr(ZENCOD_F_ZENCOD_DSA_DO_SIGN, ZENCOD_R_BAD_KEY_COMPONENTS);
goto FAILED;
}
goto FAILED;
}
- if (!(sig = DSA_SIG_new())) {
+ if ((sig = DSA_SIG_new()) == NULL) {
ENGINEerr(ZENCOD_F_ZENCOD_DSA_DO_SIGN, ZENCOD_R_REQUEST_FAILED);
goto FAILED;
}
bn_prv = dh->priv_key;
generate_x = 0;
} else {
- if (!(bn_prv = BN_new())) {
+ if ((bn_prv = BN_new()) == NULL) {
ENGINEerr(ZENCOD_F_ZENCOD_DH_GENERATE, ZENCOD_R_BN_EXPAND_FAIL);
goto FAILED;
}
/* Public key */
if (dh->pub_key)
bn_pub = dh->pub_key;
- else if (!(bn_pub = BN_new())) {
+ else if ((bn_pub = BN_new()) == NULL) {
ENGINEerr(ZENCOD_F_ZENCOD_DH_GENERATE, ZENCOD_R_BN_EXPAND_FAIL);
goto FAILED;
}