]> www.wagner.pp.ru Git - openssl-gost/engine.git/blobdiff - gost_grasshopper_core.c
tcl_tests: ca.try: Ignore openssl crl exit status for 'corrupted CRL' test
[openssl-gost/engine.git] / gost_grasshopper_core.c
index 6eb749021513d49fc3dacb68170db97430602e8c..19c6567a422c1540576727f058589eab2e7837f2 100644 (file)
@@ -13,15 +13,17 @@ 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;
 
     // 16 rounds
-    for (unsigned int j = 0; j < sizeof(grasshopper_lvec) / sizeof(grasshopper_lvec[0]); j++) {
+    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
 
-        for (int i = 14; i >= 0; i--) {
+        for (i = 14; i >= 0; i--) {
             w->b[i + 1] = w->b[i];
             x ^= grasshopper_galois_mul(w->b[i], grasshopper_lvec[i]);
         }
@@ -30,13 +32,13 @@ 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;
 
     // 16 rounds
-    for (unsigned int j = 0; j < sizeof(grasshopper_lvec) / sizeof(grasshopper_lvec[0]); j++) {
-
-        x = w->b[0];
-        for (int i = 0; i < 15; i++) {
+    for (j = 0; j < sizeof(grasshopper_lvec) / sizeof(grasshopper_lvec[0]); j++) {
+        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]);
         }
@@ -48,8 +50,9 @@ 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;
 
-    for (int i = 0; i < 16; i++) {
+    for (i = 0; i < 16; i++) {
         // this will be have to changed for little-endian systems
         x.b[i] = key->k.b[i];
         y.b[i] = key->k.b[i + 16];
@@ -58,7 +61,7 @@ void grasshopper_set_encrypt_key(grasshopper_round_keys_t* subkeys, const grassh
     grasshopper_copy128(&subkeys->k[0], &x);
     grasshopper_copy128(&subkeys->k[1], &y);
 
-    for (int i = 1; i <= 32; i++) {
+    for (i = 1; i <= 32; i++) {
 
         // C Value
         grasshopper_zero128(&c);
@@ -88,18 +91,20 @@ void grasshopper_set_encrypt_key(grasshopper_round_keys_t* subkeys, const grassh
 }
 
 void grasshopper_set_decrypt_key(grasshopper_round_keys_t* subkeys, const grasshopper_key_t* key) {
+               int i;
     grasshopper_set_encrypt_key(subkeys, key);
 
-    for (int i = 1; i < 10; i++) {
+    for (i = 1; i < 10; i++) {
         grasshopper_l_inv(&subkeys->k[i]);
     }
 }
 
 void grasshopper_encrypt_block(grasshopper_round_keys_t* subkeys, grasshopper_w128_t* source,
                                grasshopper_w128_t* target, grasshopper_w128_t* buffer) {
+    int i;
     grasshopper_copy128(target, source);
 
-    for (int i = 0; i < 9; i++) {
+    for (i = 0; i < 9; i++) {
         grasshopper_append128(target, &subkeys->k[i]);
         grasshopper_append128multi(buffer, target, grasshopper_pil_enc128);
     }
@@ -107,20 +112,14 @@ void grasshopper_encrypt_block(grasshopper_round_keys_t* subkeys, grasshopper_w1
     grasshopper_append128(target, &subkeys->k[9]);
 }
 
-void grasshopper_encrypt_block2(grasshopper_round_keys_t* subkeys, grasshopper_w128_t* source,
-                                grasshopper_w128_t* target) {
-    grasshopper_w128_t buffer;
-    grasshopper_encrypt_block(subkeys, source, target, &buffer);
-    grasshopper_zero128(&buffer);
-}
-
 void grasshopper_decrypt_block(grasshopper_round_keys_t* subkeys, grasshopper_w128_t* source,
                                grasshopper_w128_t* target, grasshopper_w128_t* buffer) {
+    int i;
     grasshopper_copy128(target, source);
 
     grasshopper_append128multi(buffer, target, grasshopper_l_dec128);
 
-    for (int i = 9; i > 1; i--) {
+    for (i = 9; i > 1; i--) {
         grasshopper_append128(target, &subkeys->k[i]);
         grasshopper_append128multi(buffer, target, grasshopper_pil_dec128);
     }
@@ -130,13 +129,6 @@ void grasshopper_decrypt_block(grasshopper_round_keys_t* subkeys, grasshopper_w1
     grasshopper_append128(target, &subkeys->k[0]);
 }
 
-void grasshopper_decrypt_block2(grasshopper_round_keys_t* subkeys, grasshopper_w128_t* source,
-                                grasshopper_w128_t* target) {
-    grasshopper_w128_t buffer;
-    grasshopper_decrypt_block(subkeys, source, target, &buffer);
-    grasshopper_zero128(&buffer);
-}
-
 #if defined(__cplusplus)
 }
 #endif