Convert to C90 from C99
[openssl.git] / crypto / ec / curve448 / f_generic.c
index b8ba0a691d4d9a2cc218c8c28a50dbe18a05d3c9..98d4dc0a24efd67bfc77388196f591b759b5e6c3 100644 (file)
@@ -19,14 +19,16 @@ static const gf MODULUS = {FIELD_LITERAL(
 
 /** Serialize to wire format. */
 void gf_serialize (uint8_t serial[SER_BYTES], const gf x, int with_hibit) {
+    unsigned int j=0, fill=0;
+    dword_t buffer = 0;
+    unsigned int i;
     gf red;
+
     gf_copy(red, x);
     gf_strong_reduce(red);
     if (!with_hibit) { assert(gf_hibit(red) == 0); }
-    
-    unsigned int j=0, fill=0;
-    dword_t buffer = 0;
-    UNROLL for (unsigned int i=0; i<(with_hibit ? X_SER_BYTES : SER_BYTES); i++) {
+
+    UNROLL for (i=0; i<(with_hibit ? X_SER_BYTES : SER_BYTES); i++) {
         if (fill < 8 && j < NLIMBS) {
             buffer |= ((dword_t)red->limb[LIMBPERM(j)]) << fill;
             fill += LIMB_PLACE_VALUE(LIMBPERM(j));
@@ -60,7 +62,10 @@ mask_t gf_deserialize (gf x, const uint8_t serial[SER_BYTES], int with_hibit, ui
     dword_t buffer = 0;
     dsword_t scarry = 0;
     const unsigned nbytes = with_hibit ? X_SER_BYTES : SER_BYTES;
-    UNROLL for (unsigned int i=0; i<NLIMBS; i++) {
+    unsigned int i;
+    mask_t succ;
+
+    UNROLL for (i=0; i<NLIMBS; i++) {
         UNROLL while (fill < LIMB_PLACE_VALUE(LIMBPERM(i)) && j < nbytes) {
             uint8_t sj = serial[j];
             if (j==nbytes-1) sj &= ~hi_nmask;
@@ -73,20 +78,25 @@ mask_t gf_deserialize (gf x, const uint8_t serial[SER_BYTES], int with_hibit, ui
         buffer >>= LIMB_PLACE_VALUE(LIMBPERM(i));
         scarry = (scarry + x->limb[LIMBPERM(i)] - MODULUS->limb[LIMBPERM(i)]) >> (8*sizeof(word_t));
     }
-    mask_t succ = with_hibit ? -(mask_t)1 : ~gf_hibit(x);
+    succ = with_hibit ? -(mask_t)1 : ~gf_hibit(x);
     return succ & word_is_zero(buffer) & ~word_is_zero(scarry);
 }
 
 /** Reduce to canonical form. */
 void gf_strong_reduce (gf a) {
+    dsword_t scarry;
+    word_t scarry_0;
+    dword_t carry = 0;
+    unsigned int i;
+
     /* first, clear high */
     gf_weak_reduce(a); /* Determined to have negligible perf impact. */
 
     /* now the total is less than 2p */
 
     /* compute total_value - p.  No need to reduce mod p. */
-    dsword_t scarry = 0;
-    for (unsigned int i=0; i<NLIMBS; i++) {
+    scarry = 0;
+    for (i=0; i<NLIMBS; i++) {
         scarry = scarry + a->limb[LIMBPERM(i)] - MODULUS->limb[LIMBPERM(i)];
         a->limb[LIMBPERM(i)] = scarry & LIMB_MASK(LIMBPERM(i));
         scarry >>= LIMB_PLACE_VALUE(LIMBPERM(i));
@@ -98,11 +108,10 @@ void gf_strong_reduce (gf a) {
      */
     assert(word_is_zero(scarry) | word_is_zero(scarry+1));
 
-    word_t scarry_0 = scarry;
-    dword_t carry = 0;
+    scarry_0 = scarry;
 
     /* add it back */
-    for (unsigned int i=0; i<NLIMBS; i++) {
+    for (i=0; i<NLIMBS; i++) {
         carry = carry + a->limb[LIMBPERM(i)] + (scarry_0 & MODULUS->limb[LIMBPERM(i)]);
         a->limb[LIMBPERM(i)] = carry & LIMB_MASK(LIMBPERM(i));
         carry >>= LIMB_PLACE_VALUE(LIMBPERM(i));
@@ -127,10 +136,13 @@ void gf_add (gf d, const gf a, const gf b) {
 /** Compare a==b */
 mask_t gf_eq(const gf a, const gf b) {
     gf c;
+    mask_t ret=0;
+    unsigned int i;
+
     gf_sub(c,a,b);
     gf_strong_reduce(c);
-    mask_t ret=0;
-    for (unsigned int i=0; i<NLIMBS; i++) {
+
+    for (i=0; i<NLIMBS; i++) {
         ret |= c->limb[LIMBPERM(i)];
     }