memset, memcpy, sizeof consistency fixes
[openssl.git] / engines / e_cswift.c
index 70c2f226c33e3d57299f27625af3d9c22c248ca8..5dcee7cdc7ec9c5a59d9a6b8ea9fa87c6c77f49c 100644 (file)
@@ -338,8 +338,7 @@ static const char *get_CSWIFT_LIBNAME(void)
 
 static void free_CSWIFT_LIBNAME(void)
 {
-    if (CSWIFT_LIBNAME)
-        OPENSSL_free((void *)CSWIFT_LIBNAME);
+    OPENSSL_free(CSWIFT_LIBNAME);
     CSWIFT_LIBNAME = NULL;
 }
 
@@ -432,10 +431,8 @@ static int cswift_init(ENGINE *e)
     /* Everything's fine. */
     return 1;
  err:
-    if (cswift_dso) {
-        DSO_free(cswift_dso);
-        cswift_dso = NULL;
-    }
+    DSO_free(cswift_dso);
+    cswift_dso = NULL;
     p_CSwift_AcquireAccContext = NULL;
     p_CSwift_AttachKeyParam = NULL;
     p_CSwift_SimpleRequest = NULL;
@@ -586,7 +583,7 @@ int cswift_bn_32copy(SW_LARGENUMBER *out, const BIGNUM *in)
     while (((out->nbytes = (numbytes + mod)) % 32)) {
         mod++;
     }
-    out->value = (unsigned char *)OPENSSL_malloc(out->nbytes);
+    out->value = OPENSSL_malloc(out->nbytes);
     if (!out->value) {
         return 0;
     }
@@ -707,20 +704,13 @@ static int cswift_mod_exp_crt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
     BN_bin2bn((unsigned char *)result->d, res.nbytes, r);
     to_return = 1;
  err:
-    if (sw_param.up.crt.p.value)
-        OPENSSL_free(sw_param.up.crt.p.value);
-    if (sw_param.up.crt.q.value)
-        OPENSSL_free(sw_param.up.crt.q.value);
-    if (sw_param.up.crt.dmp1.value)
-        OPENSSL_free(sw_param.up.crt.dmp1.value);
-    if (sw_param.up.crt.dmq1.value)
-        OPENSSL_free(sw_param.up.crt.dmq1.value);
-    if (sw_param.up.crt.iqmp.value)
-        OPENSSL_free(sw_param.up.crt.iqmp.value);
-    if (result)
-        BN_free(result);
-    if (argument)
-        BN_free(argument);
+    OPENSSL_free(sw_param.up.crt.p.value);
+    OPENSSL_free(sw_param.up.crt.q.value);
+    OPENSSL_free(sw_param.up.crt.dmp1.value);
+    OPENSSL_free(sw_param.up.crt.dmq1.value);
+    OPENSSL_free(sw_param.up.crt.iqmp.value);
+    BN_free(result);
+    BN_free(argument);
     if (acquired)
         release_context(hac);
     return to_return;
@@ -748,11 +738,7 @@ static int cswift_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa,
 #   ifdef RSA_NULL
         def_rsa_method = RSA_null_method();
 #   else
-#    if 0
-        def_rsa_method = RSA_PKCS1_RSAref();
-#    else
         def_rsa_method = RSA_PKCS1_SSLeay();
-#    endif
 #   endif
         if (def_rsa_method)
             return def_rsa_method->rsa_mod_exp(r0, I, rsa, ctx);
@@ -777,11 +763,7 @@ static int cswift_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
 #   ifdef RSA_NULL
         def_rsa_method = RSA_null_method();
 #   else
-#    if 0
-        def_rsa_method = RSA_PKCS1_RSAref();
-#    else
         def_rsa_method = RSA_PKCS1_SSLeay();
-#    endif
 #   endif
         if (def_rsa_method)
             return def_rsa_method->bn_mod_exp(r, a, p, m, ctx, m_ctx);
@@ -885,10 +867,9 @@ static DSA_SIG *cswift_dsa_sign(const unsigned char *dgst, int dlen, DSA *dsa)
  err:
     if (acquired)
         release_context(hac);
-    if (ctx) {
+    if (ctx)
         BN_CTX_end(ctx);
-        BN_CTX_free(ctx);
-    }
+    BN_CTX_free(ctx);
     return to_return;
 }
 
@@ -988,10 +969,9 @@ static int cswift_dsa_verify(const unsigned char *dgst, int dgst_len,
  err:
     if (acquired)
         release_context(hac);
-    if (ctx) {
+    if (ctx)
         BN_CTX_end(ctx);
-        BN_CTX_free(ctx);
-    }
+    BN_CTX_free(ctx);
     return to_return;
 }
 #  endif
@@ -1037,11 +1017,11 @@ static int cswift_rand_bytes(unsigned char *buf, int num)
     while (num >= (int)sizeof(buf32)) {
         largenum.value = buf;
         largenum.nbytes = sizeof(buf32);
-                /*-
-                 * tell CryptoSwift how many bytes we want and where we want it.
-                 * Note: - CryptoSwift cannot do more than 4096 bytes at a time.
-                 *       - CryptoSwift can only do multiple of 32-bits.
-                 */
+        /*-
+         * tell CryptoSwift how many bytes we want and where we want it.
+         * Note: - CryptoSwift cannot do more than 4096 bytes at a time.
+         *       - CryptoSwift can only do multiple of 32-bits.
+         */
         swrc =
             p_CSwift_SimpleRequest(hac, SW_CMD_RAND, NULL, 0, &largenum, 1);
         if (swrc != SW_OK) {