Use "==0" instead of "!strcmp" etc
[openssl.git] / engines / ccgost / gost_pmeth.c
index eb63d425c07ddb9f270a8922a721276c79917942..af1d29e35c55abf9772791e5ba67ccb0b6e65bd2 100644 (file)
@@ -24,10 +24,11 @@ static int pkey_gost_init(EVP_PKEY_CTX *ctx)
 {
     struct gost_pmeth_data *data;
     EVP_PKEY *pkey = EVP_PKEY_CTX_get0_pkey(ctx);
 {
     struct gost_pmeth_data *data;
     EVP_PKEY *pkey = EVP_PKEY_CTX_get0_pkey(ctx);
-    data = OPENSSL_malloc(sizeof(struct gost_pmeth_data));
+
+    data = OPENSSL_malloc(sizeof(*data));
     if (!data)
         return 0;
     if (!data)
         return 0;
-    memset(data, 0, sizeof(struct gost_pmeth_data));
+    memset(data, 0, sizeof(*data));
     if (pkey && EVP_PKEY_get0(pkey)) {
         switch (EVP_PKEY_base_id(pkey)) {
         case NID_id_GostR3410_94:
     if (pkey && EVP_PKEY_get0(pkey)) {
         switch (EVP_PKEY_base_id(pkey)) {
         case NID_id_GostR3410_94:
@@ -66,8 +67,8 @@ static int pkey_gost_copy(EVP_PKEY_CTX *dst, EVP_PKEY_CTX *src)
 static void pkey_gost_cleanup(EVP_PKEY_CTX *ctx)
 {
     struct gost_pmeth_data *data = EVP_PKEY_CTX_get_data(ctx);
 static void pkey_gost_cleanup(EVP_PKEY_CTX *ctx)
 {
     struct gost_pmeth_data *data = EVP_PKEY_CTX_get_data(ctx);
-    if (data->shared_ukm)
-        OPENSSL_free(data->shared_ukm);
+
+    OPENSSL_free(data->shared_ukm);
     OPENSSL_free(data);
 }
 
     OPENSSL_free(data);
 }
 
@@ -86,7 +87,6 @@ static int pkey_gost_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
             pctx->md = (EVP_MD *)p2;
             return 1;
         }
             pctx->md = (EVP_MD *)p2;
             return 1;
         }
-        break;
 
     case EVP_PKEY_CTRL_GET_MD:
         *(const EVP_MD **)p2 = pctx->md;
 
     case EVP_PKEY_CTRL_GET_MD:
         *(const EVP_MD **)p2 = pctx->md;
@@ -130,7 +130,8 @@ static int pkey_gost_ctrl94_str(EVP_PKEY_CTX *ctx,
                                 const char *type, const char *value)
 {
     int param_nid = 0;
                                 const char *type, const char *value)
 {
     int param_nid = 0;
-    if (!strcmp(type, param_ctrl_string)) {
+
+    if (strcmp(type, param_ctrl_string) == 0) {
         if (!value) {
             return 0;
         }
         if (!value) {
             return 0;
         }
@@ -150,7 +151,6 @@ static int pkey_gost_ctrl94_str(EVP_PKEY_CTX *ctx,
                 break;
             default:
                 return 0;
                 break;
             default:
                 return 0;
-                break;
             }
         } else if ((strlen(value) == 2)
                    && (toupper((unsigned char)value[0]) == 'X')) {
             }
         } else if ((strlen(value) == 2)
                    && (toupper((unsigned char)value[0]) == 'X')) {
@@ -166,7 +166,6 @@ static int pkey_gost_ctrl94_str(EVP_PKEY_CTX *ctx,
                 break;
             default:
                 return 0;
                 break;
             default:
                 return 0;
-                break;
             }
         } else {
             R3410_params *p = R3410_paramset;
             }
         } else {
             R3410_params *p = R3410_paramset;
@@ -194,7 +193,8 @@ static int pkey_gost_ctrl01_str(EVP_PKEY_CTX *ctx,
                                 const char *type, const char *value)
 {
     int param_nid = 0;
                                 const char *type, const char *value)
 {
     int param_nid = 0;
-    if (!strcmp(type, param_ctrl_string)) {
+
+    if (strcmp(type, param_ctrl_string) == 0) {
         if (!value) {
             return 0;
         }
         if (!value) {
             return 0;
         }
@@ -214,7 +214,6 @@ static int pkey_gost_ctrl01_str(EVP_PKEY_CTX *ctx,
                 break;
             default:
                 return 0;
                 break;
             default:
                 return 0;
-                break;
             }
         } else if ((strlen(value) == 2)
                    && (toupper((unsigned char)value[0]) == 'X')) {
             }
         } else if ((strlen(value) == 2)
                    && (toupper((unsigned char)value[0]) == 'X')) {
@@ -227,7 +226,6 @@ static int pkey_gost_ctrl01_str(EVP_PKEY_CTX *ctx,
                 break;
             default:
                 return 0;
                 break;
             default:
                 return 0;
-                break;
             }
         } else {
             R3410_2001_params *p = R3410_2001_paramset;
             }
         } else {
             R3410_2001_params *p = R3410_2001_paramset;
@@ -411,11 +409,11 @@ static int pkey_gost_derive_init(EVP_PKEY_CTX *ctx)
 /* -------- PKEY_METHOD for GOST MAC algorithm --------------------*/
 static int pkey_gost_mac_init(EVP_PKEY_CTX *ctx)
 {
 /* -------- PKEY_METHOD for GOST MAC algorithm --------------------*/
 static int pkey_gost_mac_init(EVP_PKEY_CTX *ctx)
 {
-    struct gost_mac_pmeth_data *data;
-    data = OPENSSL_malloc(sizeof(struct gost_mac_pmeth_data));
+    struct gost_mac_pmeth_data *data = OPENSSL_malloc(sizeof(*data));
+
     if (!data)
         return 0;
     if (!data)
         return 0;
-    memset(data, 0, sizeof(struct gost_mac_pmeth_data));
+    memset(data, 0, sizeof(*data));
     EVP_PKEY_CTX_set_data(ctx, data);
     return 1;
 }
     EVP_PKEY_CTX_set_data(ctx, data);
     return 1;
 }
@@ -454,7 +452,6 @@ static int pkey_gost_mac_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
             data->md = (EVP_MD *)p2;
             return 1;
         }
             data->md = (EVP_MD *)p2;
             return 1;
         }
-        break;
 
     case EVP_PKEY_CTRL_GET_MD:
         *(const EVP_MD **)p2 = data->md;
 
     case EVP_PKEY_CTRL_GET_MD:
         *(const EVP_MD **)p2 = data->md;
@@ -502,7 +499,7 @@ static int pkey_gost_mac_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
 static int pkey_gost_mac_ctrl_str(EVP_PKEY_CTX *ctx,
                                   const char *type, const char *value)
 {
 static int pkey_gost_mac_ctrl_str(EVP_PKEY_CTX *ctx,
                                   const char *type, const char *value)
 {
-    if (!strcmp(type, key_ctrl_string)) {
+    if (strcmp(type, key_ctrl_string) == 0) {
         if (strlen(value) != 32) {
             GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL_STR,
                     GOST_R_INVALID_MAC_KEY_LENGTH);
         if (strlen(value) != 32) {
             GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL_STR,
                     GOST_R_INVALID_MAC_KEY_LENGTH);
@@ -511,11 +508,11 @@ static int pkey_gost_mac_ctrl_str(EVP_PKEY_CTX *ctx,
         return pkey_gost_mac_ctrl(ctx, EVP_PKEY_CTRL_SET_MAC_KEY,
                                   32, (char *)value);
     }
         return pkey_gost_mac_ctrl(ctx, EVP_PKEY_CTRL_SET_MAC_KEY,
                                   32, (char *)value);
     }
-    if (!strcmp(type, hexkey_ctrl_string)) {
+    if (strcmp(type, hexkey_ctrl_string) == 0) {
         long keylen;
         int ret;
         unsigned char *keybuf = string_to_hex(value, &keylen);
         long keylen;
         int ret;
         unsigned char *keybuf = string_to_hex(value, &keylen);
-        if (keylen != 32) {
+        if (!keybuf || keylen != 32) {
             GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL_STR,
                     GOST_R_INVALID_MAC_KEY_LENGTH);
             OPENSSL_free(keybuf);
             GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL_STR,
                     GOST_R_INVALID_MAC_KEY_LENGTH);
             OPENSSL_free(keybuf);