]> git.ipfire.org Git - thirdparty/openssl.git/blobdiff - demos/engines/zencod/hw_zencod.c
Remove /* foo.c */ comments
[thirdparty/openssl.git] / demos / engines / zencod / hw_zencod.c
index 1c7628454455638c3c5ed86560b704e7f13ffcdb..1c34677d43567cfea984cdf33297e68e08de199c 100644 (file)
@@ -1,4 +1,3 @@
-/* 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
@@ -309,14 +308,14 @@ static int bind_helper(ENGINE *e)
     }
 #  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;
@@ -358,9 +357,9 @@ static int bind_helper(ENGINE *e)
 #  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 ; */
@@ -538,46 +537,28 @@ static int zencod_init(ENGINE *e)
     /*
      * 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;
     }
@@ -610,7 +591,7 @@ static int zencod_init(ENGINE *e)
     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 !!
@@ -623,9 +604,7 @@ static int zencod_init(ENGINE *e)
 
     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;
@@ -796,7 +775,7 @@ static int RSA_zencod_rsa_mod_exp(BIGNUM *r0, const BIGNUM *i, RSA *rsa)
     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;
@@ -847,7 +826,7 @@ static int RSA_zencod_bn_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
     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;
@@ -908,7 +887,7 @@ static DSA_SIG *DSA_zencod_do_sign(const unsigned char *dgst, int dlen,
         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;
     }
@@ -937,7 +916,7 @@ static DSA_SIG *DSA_zencod_do_sign(const unsigned char *dgst, int dlen,
         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;
     }
@@ -946,10 +925,8 @@ static DSA_SIG *DSA_zencod_do_sign(const unsigned char *dgst, int dlen,
     return sig;
 
  FAILED:
-    if (bn_r)
-        BN_free(bn_r);
-    if (bn_s)
-        BN_free(bn_s);
+    BN_free(bn_r);
+    BN_free(bn_s);
     return NULL;
 }
 
@@ -1036,7 +1013,7 @@ static int DH_zencod_generate_key(DH *dh)
         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;
         }
@@ -1046,7 +1023,7 @@ static int DH_zencod_generate_key(DH *dh)
     /* 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;
     }
@@ -1083,9 +1060,9 @@ static int DH_zencod_generate_key(DH *dh)
     return 1;
 
  FAILED:
-    if (!dh->priv_key && bn_prv)
+    if (!dh->priv_key)
         BN_free(bn_prv);
-    if (!dh->pub_key && bn_pub)
+    if (!dh->pub_key)
         BN_free(bn_pub);
 
     return 0;
@@ -1550,12 +1527,9 @@ static int engine_md_cleanup(EVP_MD_CTX *ctx)
 
     ZEN_MD_DATA *zen_md_data = (ZEN_MD_DATA *)ctx->md_data;
 
-    if (zen_md_data->HashBuffer != NULL) {
-        OPENSSL_free(zen_md_data->HashBuffer);
-        zen_md_data->HashBufferSize = 0;
-        ctx->md_data = NULL;
-    }
-
+    OPENSSL_free(zen_md_data->HashBuffer);
+    zen_md_data->HashBufferSize = 0;
+    ctx->md_data = NULL;
     return 1;
 }