]> www.wagner.pp.ru Git - openssl-gost/engine.git/commitdiff
cppcheck: The scope of the variable can be reduced.
authorNikolay Morozov <nmorozoff77@yandex.ru>
Wed, 26 Feb 2020 09:38:27 +0000 (12:38 +0300)
committerDmitry Belyavskiy <beldmit@users.noreply.github.com>
Wed, 26 Feb 2020 21:14:48 +0000 (00:14 +0300)
getopt.h
gost_crypt.c
gost_grasshopper_cipher.c
gost_grasshopper_core.c
gost_keywrap.c
gost_pmeth.c
gosthash.c
gosthash2012.c

index bcbff179eb20d8b688eb8390e89fd4a53e712c81..aea89a0a2bd45ee1d48f38bc3f5cb6c0d17a6511 100644 (file)
--- a/getopt.h
+++ b/getopt.h
@@ -181,7 +181,7 @@ static void
 permute_args(int panonopt_start, int panonopt_end, int opt_end,
        char * const *nargv)
 {
-       int cstart, cyclelen, i, j, ncycle, nnonopts, nopts, pos;
+       int cyclelen, i, j, ncycle, nnonopts, nopts;
        char *swap;
 
        /*
@@ -193,8 +193,8 @@ permute_args(int panonopt_start, int panonopt_end, int opt_end,
        cyclelen = (opt_end - panonopt_start) / ncycle;
 
        for (i = 0; i < ncycle; i++) {
-               cstart = panonopt_end+i;
-               pos = cstart;
+               int cstart = panonopt_end+i;
+               int pos = cstart;
                for (j = 0; j < cyclelen; j++) {
                        if (pos >= panonopt_end)
                                pos -= nnonopts;
index a649e72ded26c111cb5d92154b01dd3a525439e0..4e22145a46d27097ec4aa44d98b7a5e0c9c9cff4 100644 (file)
@@ -1001,7 +1001,6 @@ int gost89_set_asn1_parameters(EVP_CIPHER_CTX *ctx, ASN1_TYPE *params)
 /* Store parameters into ASN1 structure */
 int gost89_get_asn1_parameters(EVP_CIPHER_CTX *ctx, ASN1_TYPE *params)
 {
-    int ret = -1;
     int len;
     GOST_CIPHER_PARAMS *gcp = NULL;
     unsigned char *p;
@@ -1009,7 +1008,7 @@ int gost89_get_asn1_parameters(EVP_CIPHER_CTX *ctx, ASN1_TYPE *params)
     int nid;
 
     if (ASN1_TYPE_get(params) != V_ASN1_SEQUENCE) {
-        return ret;
+        return -1;
     }
 
     p = params->value.sequence->data;
@@ -1088,12 +1087,13 @@ int gost_imit_update(EVP_MD_CTX *ctx, const void *data, size_t count)
 {
     struct ossl_gost_imit_ctx *c = EVP_MD_CTX_md_data(ctx);
     const unsigned char *p = data;
-    size_t bytes = count, i;
+    size_t bytes = count;
     if (!(c->key_set)) {
         GOSTerr(GOST_F_GOST_IMIT_UPDATE, GOST_R_MAC_KEY_NOT_SET);
         return 0;
     }
     if (c->bytes_left) {
+        size_t i;
         for (i = c->bytes_left; i < 8 && bytes > 0; bytes--, i++, p++) {
             c->partial_block[i] = *p;
         }
index 2955534cb58fca1bad3b417ec106507a87785b62..777ca0a860aa84e407593a21d8b935a560d0906a 100644 (file)
@@ -331,8 +331,6 @@ int gost_grasshopper_cipher_do_cbc(EVP_CIPHER_CTX *ctx, unsigned char *out,
     bool encrypting = (bool) EVP_CIPHER_CTX_encrypting(ctx);
     const unsigned char *current_in = in;
     unsigned char *current_out = out;
-    grasshopper_w128_t *currentInputBlock;
-    grasshopper_w128_t *currentOutputBlock;
     size_t blocks = inl / GRASSHOPPER_BLOCK_SIZE;
     size_t i;
     grasshopper_w128_t *currentBlock;
@@ -342,8 +340,8 @@ int gost_grasshopper_cipher_do_cbc(EVP_CIPHER_CTX *ctx, unsigned char *out,
     for (i = 0; i < blocks;
          i++, current_in += GRASSHOPPER_BLOCK_SIZE, current_out +=
          GRASSHOPPER_BLOCK_SIZE) {
-        currentInputBlock = (grasshopper_w128_t *) current_in;
-        currentOutputBlock = (grasshopper_w128_t *) current_out;
+        grasshopper_w128_t *currentInputBlock = (grasshopper_w128_t *) current_in;
+        grasshopper_w128_t *currentOutputBlock = (grasshopper_w128_t *) current_out;
         if (encrypting) {
             grasshopper_append128(currentBlock, currentInputBlock);
             grasshopper_encrypt_block(&c->encrypt_round_keys, currentBlock,
@@ -366,10 +364,10 @@ int gost_grasshopper_cipher_do_cbc(EVP_CIPHER_CTX *ctx, unsigned char *out,
 
 void inc_counter(unsigned char *counter, size_t counter_bytes)
 {
-    unsigned char c;
     unsigned int n = counter_bytes;
 
     do {
+        unsigned char c;
         --n;
         c = counter[n];
         ++c;
@@ -715,10 +713,8 @@ GRASSHOPPER_INLINE int gost_grasshopper_get_asn1_parameters(EVP_CIPHER_CTX
                                                             *ctx, ASN1_TYPE
                                                             *params)
 {
-    int ret = -1;
-
     if (ASN1_TYPE_get(params) != V_ASN1_SEQUENCE) {
-        return ret;
+        return -1;
     }
 
     return 1;
index ed41459836be09ff2b8af10e5939ea3de5257d6a..2b14640b07f7aaaefa866c4444ac82afbda5f193 100644 (file)
@@ -13,12 +13,12 @@ extern "C" {
 #include "gost_grasshopper_defines.h"
 
 static GRASSHOPPER_INLINE void grasshopper_l(grasshopper_w128_t* w) {
-    uint8_t x;
-               unsigned int j;
-               int i;
+    unsigned int j;
+    int i;
 
     // 16 rounds
     for (j = 0; j < sizeof(grasshopper_lvec) / sizeof(grasshopper_lvec[0]); j++) {
+        uint8_t x;
 
         // An LFSR with 16 elements from GF(2^8)
         x = w->b[15];    // since lvec[15] = 1
@@ -32,14 +32,12 @@ static GRASSHOPPER_INLINE void grasshopper_l(grasshopper_w128_t* w) {
 }
 
 static GRASSHOPPER_INLINE void grasshopper_l_inv(grasshopper_w128_t* w) {
-    uint8_t x;
-               unsigned int j;
-               int i;
+    unsigned int j;
+    int i;
 
     // 16 rounds
     for (j = 0; j < sizeof(grasshopper_lvec) / sizeof(grasshopper_lvec[0]); j++) {
-
-        x = w->b[0];
+        uint8_t x = w->b[0];
         for (i = 0; i < 15; i++) {
             w->b[i] = w->b[i + 1];
             x ^= grasshopper_galois_mul(w->b[i], grasshopper_lvec[i]);
@@ -52,7 +50,7 @@ static GRASSHOPPER_INLINE void grasshopper_l_inv(grasshopper_w128_t* w) {
 
 void grasshopper_set_encrypt_key(grasshopper_round_keys_t* subkeys, const grasshopper_key_t* key) {
     grasshopper_w128_t c, x, y, z;
-               int i;
+    int i;
 
     for (i = 0; i < 16; i++) {
         // this will be have to changed for little-endian systems
index 502a83c62d53e2638f5eb2a4198dc7d785119258..a2134c2e3f9180b455fbf310e5b4c3444cb75e85 100644 (file)
 void keyDiversifyCryptoPro(gost_ctx * ctx, const unsigned char *inputKey,
                            const unsigned char *ukm, unsigned char *outputKey)
 {
-
-    u4 k, s1, s2;
-    int i, j, mask;
-    unsigned char S[8];
+    int i;
     memcpy(outputKey, inputKey, 32);
     for (i = 0; i < 8; i++) {
+        u4 s1 = 0;
+        u4 s2 = 0;
+        int j, mask;
+        unsigned char S[8];
         /* Make array of integers from key */
         /* Compute IV S */
-        s1 = 0, s2 = 0;
         for (j = 0, mask = 1; j < 8; j++, mask <<= 1) {
+            u4 k;
             k = ((u4) outputKey[4 * j]) | (outputKey[4 * j + 1] << 8) |
                 (outputKey[4 * j + 2] << 16) | (outputKey[4 * j + 3] << 24);
             if (mask & ukm[i]) {
index b6f45436975d56783ec4f36e8fa70620d332b2f5..4713e3c07bded81559fdf9288a6809cebbbfc03e 100644 (file)
@@ -180,9 +180,9 @@ static int pkey_gost_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
 static int pkey_gost_ec_ctrl_str_256(EVP_PKEY_CTX *ctx,
                                      const char *type, const char *value)
 {
-    int param_nid = 0;
-
     if (strcmp(type, param_ctrl_string) == 0) {
+        int param_nid = 0;
+
         if (!value) {
             return 0;
         }
@@ -215,9 +215,9 @@ static int pkey_gost_ec_ctrl_str_256(EVP_PKEY_CTX *ctx,
             default:
                 return 0;
             }
-       } else if ((strlen(value) == 3)
-           && (toupper((unsigned char)value[0]) == 'T')
-           && (toupper((unsigned char)value[1]) == 'C')) {
+    } else if ((strlen(value) == 3)
+        && (toupper((unsigned char)value[0]) == 'T')
+        && (toupper((unsigned char)value[1]) == 'C')) {
             switch (toupper((unsigned char)value[2])) {
             case 'A':
                 param_nid = NID_id_tc26_gost_3410_2012_256_paramSetA;
@@ -631,8 +631,8 @@ static int pkey_gost_mac_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
     case EVP_PKEY_CTRL_DIGESTINIT:
         {
             EVP_MD_CTX *mctx = p2;
-            struct gost_mac_key *key;
             if (!data->key_set) {
+                struct gost_mac_key *key;
                 EVP_PKEY *pkey = EVP_PKEY_CTX_get0_pkey(ctx);
                 if (!pkey) {
                     GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL,
@@ -764,8 +764,8 @@ static int pkey_gost_omac_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2, si
     case EVP_PKEY_CTRL_DIGESTINIT:
         {
             EVP_MD_CTX *mctx = p2;
-            struct gost_mac_key *key;
             if (!data->key_set) {
+                struct gost_mac_key *key;
                 EVP_PKEY *pkey = EVP_PKEY_CTX_get0_pkey(ctx);
                 if (!pkey) {
                     GOSTerr(GOST_F_PKEY_GOST_OMAC_CTRL,
index 036a2b3520f85319bc324b7e1ce792943affd314..7fd3cb058b6abf27ddd49c00552708e19825a1c1 100644 (file)
@@ -65,9 +65,8 @@ static int add_blocks(int n, byte * left, const byte * right)
 {
     int i;
     int carry = 0;
-    int sum;
     for (i = 0; i < n; i++) {
-        sum = (int)left[i] + (int)right[i] + carry;
+        int sum = (int)left[i] + (int)right[i] + carry;
         left[i] = sum & 0xff;
         carry = sum >> 8;
     }
index 60fa43696b6bd2efd0c7198d836b183c00a38d11..9548bfb5492318313b83e631256479bbc4d43cc8 100644 (file)
@@ -195,7 +195,6 @@ static INLINE void stage3(gost2012_hash_ctx * CTX)
 void gost2012_hash_block(gost2012_hash_ctx * CTX,
                          const unsigned char *data, size_t len)
 {
-    register size_t chunksize;
     register size_t bufsize = CTX->bufsize;
 
     if (bufsize == 0) {
@@ -208,7 +207,7 @@ void gost2012_hash_block(gost2012_hash_ctx * CTX,
     }
 
     while (len) {
-        chunksize = 64 - bufsize;
+        register size_t chunksize = 64 - bufsize;
         if (chunksize > len)
             chunksize = len;