Use p==NULL not !p (in if statements, mainly)
[openssl.git] / engines / ccgost / gost_ameth.c
index bc4532558c69b077890391a0ec5a9e382f7e51c3..5ca3a6e62954129f61f58be9cb9ae2fe0a341177 100644 (file)
@@ -115,7 +115,7 @@ static int decode_gost_algor_params(EVP_PKEY *pkey, X509_ALGOR *palg)
     }
     param_nid = OBJ_obj2nid(gkp->key_params);
     GOST_KEY_PARAMS_free(gkp);
-    if(!EVP_PKEY_set_type(pkey, pkey_nid)) {
+    if (!EVP_PKEY_set_type(pkey, pkey_nid)) {
         GOSTerr(GOST_F_DECODE_GOST_ALGOR_PARAMS, ERR_R_INTERNAL_ERROR);
         return 0;
     }
@@ -200,7 +200,7 @@ BIGNUM *gost_get0_priv_key(const EVP_PKEY *pkey)
             if (!ec) {
                 return NULL;
             }
-            if (!(priv = EC_KEY_get0_private_key(ec)))
+            if ((priv = EC_KEY_get0_private_key(ec)) == NULL)
                 return NULL;
             return (BIGNUM *)priv;
         }
@@ -284,9 +284,7 @@ static void pkey_free_gost94(EVP_PKEY *key)
 
 static void pkey_free_gost01(EVP_PKEY *key)
 {
-    if (key->pkey.ec) {
-        EC_KEY_free(key->pkey.ec);
-    }
+    EC_KEY_free(key->pkey.ec);
 }
 
 /* ------------------ private key functions  -----------------------------*/
@@ -527,12 +525,14 @@ static int param_copy_gost94(EVP_PKEY *to, const EVP_PKEY *from)
         dto = DSA_new();
         EVP_PKEY_assign(to, EVP_PKEY_base_id(from), dto);
     }
-#define COPYBIGNUM(a,b,x) if (a->x) BN_free(a->x); a->x=BN_dup(b->x);
-    COPYBIGNUM(dto, dfrom, p)
-        COPYBIGNUM(dto, dfrom, q)
-        COPYBIGNUM(dto, dfrom, g)
+    BN_free(dto->p);
+    dto->p = BN_dup(dfrom->p);
+    BN_free(dto->q);
+    dto->q = BN_dup(dfrom->q);
+    BN_free(dto->g);
+    dto->g = BN_dup(dfrom->g);
 
-        if (dto->priv_key)
+    if (dto->priv_key)
         gost94_compute_public(dto);
     return 1;
 }
@@ -551,16 +551,16 @@ static int param_copy_gost01(EVP_PKEY *to, const EVP_PKEY *from)
     }
     if (!eto) {
         eto = EC_KEY_new();
-        if(!eto) {
+        if (!eto) {
             GOSTerr(GOST_F_PARAM_COPY_GOST01, ERR_R_MALLOC_FAILURE);
             return 0;
         }
-        if(!EVP_PKEY_assign(to, EVP_PKEY_base_id(from), eto)) {
+        if (!EVP_PKEY_assign(to, EVP_PKEY_base_id(from), eto)) {
             GOSTerr(GOST_F_PARAM_COPY_GOST01, ERR_R_INTERNAL_ERROR);
             return 0;
         }
     }
-    if(!EC_KEY_set_group(eto, EC_KEY_get0_group(efrom))) {
+    if (!EC_KEY_set_group(eto, EC_KEY_get0_group(efrom))) {
         GOSTerr(GOST_F_PARAM_COPY_GOST01, ERR_R_INTERNAL_ERROR);
         return 0;
     }
@@ -758,14 +758,14 @@ static int pub_encode_gost01(X509_PUBKEY *pub, const EVP_PKEY *pk)
     }
     X = BN_new();
     Y = BN_new();
-    if(!X || !Y) {
+    if (!X || !Y) {
         GOSTerr(GOST_F_PUB_ENCODE_GOST01, ERR_R_MALLOC_FAILURE);
-        if(X) BN_free(X);
-        if(Y) BN_free(Y);
+        BN_free(X);
+        BN_free(Y);
         BN_free(order);
         return 0;
     }
-    if(!EC_POINT_get_affine_coordinates_GFp(EC_KEY_get0_group(ec),
+    if (!EC_POINT_get_affine_coordinates_GFp(EC_KEY_get0_group(ec),
                                         pub_key, X, Y, NULL)) {
         GOSTerr(GOST_F_PUB_ENCODE_GOST01, ERR_R_INTERNAL_ERROR);
         BN_free(X);
@@ -848,9 +848,7 @@ static int pkey_bits_gost(const EVP_PKEY *pk)
 /* ---------------------- ASN1 METHOD for GOST MAC  -------------------*/
 static void mackey_free_gost(EVP_PKEY *pk)
 {
-    if (pk->pkey.ptr) {
-        OPENSSL_free(pk->pkey.ptr);
-    }
+    OPENSSL_free(pk->pkey.ptr);
 }
 
 static int mac_ctrl_gost(EVP_PKEY *pkey, int op, long arg1, void *arg2)