]> www.wagner.pp.ru Git - openssl-gost/engine.git/blobdiff - gost_grasshopper_math.h
tcl_tests: ca.try: Ignore openssl crl exit status for 'corrupted CRL' test
[openssl-gost/engine.git] / gost_grasshopper_math.h
index fb42606b30aaa8b6021a2786866e2b875be40cca..91f276fd3bf36122992fcc76d96af531380fcf6d 100644 (file)
@@ -57,7 +57,8 @@ static GRASSHOPPER_INLINE void grasshopper_zero128(grasshopper_w128_t* x) {
 #if(GRASSHOPPER_BITS == 8 || GRASSHOPPER_BITS == 16)
     memset(&x, 0, sizeof(x));
 #else
-    for (int i = 0; i < GRASSHOPPER_BIT_PARTS; i++) {
+               int i;
+    for (i = 0; i < GRASSHOPPER_BIT_PARTS; i++) {
         GRASSHOPPER_ACCESS_128_VALUE(*x, i) = 0;
     }
 #endif
@@ -65,18 +66,26 @@ static GRASSHOPPER_INLINE void grasshopper_zero128(grasshopper_w128_t* x) {
 
 static GRASSHOPPER_INLINE void grasshopper_copy128(grasshopper_w128_t* to, const grasshopper_w128_t* from) {
 #if(GRASSHOPPER_BITS == 8 || GRASSHOPPER_BITS == 16)
-    __builtin_memcpy(&to, &from, sizeof(w128_t));
+    __builtin_memcpy(&to, &from, sizeof(grasshopper_w128_t));
 #else
-    for (int i = 0; i < GRASSHOPPER_BIT_PARTS; i++) {
+               int i;
+    for (i = 0; i < GRASSHOPPER_BIT_PARTS; i++) {
         GRASSHOPPER_ACCESS_128_VALUE(*to, i) = GRASSHOPPER_ACCESS_128_VALUE(*from, i);
     }
 #endif
 }
 
 static GRASSHOPPER_INLINE void grasshopper_append128(grasshopper_w128_t* x, const grasshopper_w128_t* y) {
-    for (int i = 0; i < GRASSHOPPER_BIT_PARTS; i++) {
+               int i;
+#ifdef STRICT_ALIGNMENT
+    for (i = 0; i < 16; i++) {
+        GRASSHOPPER_ACCESS_128_VALUE_8(*x, i) ^= GRASSHOPPER_ACCESS_128_VALUE_8(*y, i);
+    }
+#else
+    for (i = 0; i < GRASSHOPPER_BIT_PARTS; i++) {
         GRASSHOPPER_ACCESS_128_VALUE(*x, i) ^= GRASSHOPPER_ACCESS_128_VALUE(*y, i);
     }
+#endif
 }
 
 static GRASSHOPPER_INLINE void grasshopper_plus128(grasshopper_w128_t* result, const grasshopper_w128_t* x,
@@ -88,8 +97,9 @@ static GRASSHOPPER_INLINE void grasshopper_plus128(grasshopper_w128_t* result, c
 // result & x must be different
 static GRASSHOPPER_INLINE void grasshopper_plus128multi(grasshopper_w128_t* result, const grasshopper_w128_t* x,
                                                     const grasshopper_w128_t array[][256]) {
+               int i;
     grasshopper_zero128(result);
-    for (int i = 0; i < GRASSHOPPER_MAX_BIT_PARTS; i++) {
+    for (i = 0; i < GRASSHOPPER_MAX_BIT_PARTS; i++) {
         grasshopper_append128(result, &array[i][GRASSHOPPER_ACCESS_128_VALUE_8(*x, i)]);
     }
 }
@@ -101,7 +111,8 @@ static GRASSHOPPER_INLINE void grasshopper_append128multi(grasshopper_w128_t* re
 }
 
 static GRASSHOPPER_INLINE void grasshopper_convert128(grasshopper_w128_t* x, const uint8_t* array) {
-    for (int i = 0; i < GRASSHOPPER_MAX_BIT_PARTS; i++) {
+               int i;
+    for (i = 0; i < GRASSHOPPER_MAX_BIT_PARTS; i++) {
         GRASSHOPPER_ACCESS_128_VALUE_8(*x, i) = array[GRASSHOPPER_ACCESS_128_VALUE_8(*x, i)];
     }
 }
@@ -114,7 +125,7 @@ extern uint8_t grasshopper_galois_alpha_to[256];
 extern uint8_t grasshopper_galois_index_of[256];
 
 static GRASSHOPPER_INLINE uint8_t grasshopper_galois_mul(uint8_t x, uint8_t y) {
-    if (__builtin_expect(x != 0 && y != 0, 1)) {
+    if (likely(x != 0 && y != 0)) {
         return grasshopper_galois_alpha_to[(grasshopper_galois_index_of[x] + grasshopper_galois_index_of[y]) %
                                          GRASSHOPPER_GALOIS_FIELD_SIZE];
     } else {