Commit 3ed524048f3dee3a57c980f0d0f42832bbdb5bdf

Steffen Jaeckel 2018-12-25T15:15:30

`make astyle` + some manual adjustments

diff --git a/bn_mp_get_bit.c b/bn_mp_get_bit.c
index e1e95f5..b124325 100644
--- a/bn_mp_get_bit.c
+++ b/bn_mp_get_bit.c
@@ -34,7 +34,7 @@ int mp_get_bit(const mp_int *a, int b)
     * otherwise (limb >= a->used) would be true for a = 0
     */
 
-   if(mp_iszero(a)) {
+   if (mp_iszero(a)) {
       return MP_NO;
    }
 
diff --git a/bn_mp_prime_frobenius_underwood.c b/bn_mp_prime_frobenius_underwood.c
index 8cabcb6..7e7c714 100644
--- a/bn_mp_prime_frobenius_underwood.c
+++ b/bn_mp_prime_frobenius_underwood.c
@@ -153,7 +153,9 @@ int mp_prime_frobenius_underwood(const mp_int *N, int *result)
           *  sz   = temp
           */
          if (a == 0) {
-            if ((e = mp_mul_2(&sz,&T1z)) != MP_OKAY) {               goto LBL_FU_ERR;            }
+            if ((e = mp_mul_2(&sz,&T1z)) != MP_OKAY) {
+               goto LBL_FU_ERR;
+            }
          } else {
             if ((e = mp_mul_d(&sz, (mp_digit) ap2, &T1z)) != MP_OKAY) {
                goto LBL_FU_ERR;
diff --git a/bn_mp_prime_is_prime.c b/bn_mp_prime_is_prime.c
index 4ad3659..ee68adb 100644
--- a/bn_mp_prime_is_prime.c
+++ b/bn_mp_prime_is_prime.c
@@ -113,11 +113,11 @@ int mp_prime_is_prime(const mp_int *a, int t, int *result)
       goto LBL_B;
    }
 
-/*
- * Both, the Frobenius-Underwood test and the the Lucas-Selfridge test are quite
- * slow so if speed is an issue, define LTM_USE_FIPS_ONLY to use M-R tests with
- * bases 2, 3 and t random bases.
- */
+   /*
+    * Both, the Frobenius-Underwood test and the the Lucas-Selfridge test are quite
+    * slow so if speed is an issue, define LTM_USE_FIPS_ONLY to use M-R tests with
+    * bases 2, 3 and t random bases.
+    */
 #ifndef LTM_USE_FIPS_ONLY
    if (t >= 0) {
       /*
@@ -145,7 +145,7 @@ int mp_prime_is_prime(const mp_int *a, int t, int *result)
 #endif
 
    /* run at least one Miller-Rabin test with a random base */
-   if(t == 0) {
+   if (t == 0) {
       t = 1;
    }
 
@@ -192,23 +192,22 @@ int mp_prime_is_prime(const mp_int *a, int t, int *result)
           Sorenson, Jonathan; Webster, Jonathan (2015).
            "Strong Pseudoprimes to Twelve Prime Bases".
        */
-                                   /* 318665857834031151167461 */
+      /* 0x437ae92817f9fc85b7e5 = 318665857834031151167461 */
       if ((err =   mp_read_radix(&b, "437ae92817f9fc85b7e5", 16)) != MP_OKAY) {
          goto LBL_B;
       }
 
       if (mp_cmp(a,&b) == MP_LT) {
          p_max = 12;
-      }
-      else {                       /* 3317044064679887385961981 */
+      } else {
+         /* 0x2be6951adc5b22410a5fd = 3317044064679887385961981 */
          if ((err = mp_read_radix(&b, "2be6951adc5b22410a5fd", 16)) != MP_OKAY) {
             goto LBL_B;
          }
 
          if (mp_cmp(a,&b) == MP_LT) {
             p_max = 13;
-         }
-         else {
+         } else {
             err = MP_VAL;
             goto LBL_B;
          }
@@ -219,7 +218,7 @@ int mp_prime_is_prime(const mp_int *a, int t, int *result)
          p_max = t;
       }
 
-      if(p_max > PRIME_SIZE) {
+      if (p_max > PRIME_SIZE) {
          err = MP_VAL;
          goto LBL_B;
       }
@@ -292,13 +291,13 @@ int mp_prime_is_prime(const mp_int *a, int t, int *result)
           * Reduce digit before casting because mp_digit might be bigger than
           * an unsigned int and "mask" on the other side is most probably not.
           */
-         fips_rand = (unsigned int) (b.dp[0] & (mp_digit) mask);
+         fips_rand = (unsigned int)(b.dp[0] & (mp_digit) mask);
 #ifdef MP_8BIT
          /*
           * One 8-bit digit is too small, so concatenate two if the size of
           * unsigned int allows for it.
           */
-         if( (sizeof(unsigned int) * CHAR_BIT)/2 >= (sizeof(mp_digit) * CHAR_BIT) ) {
+         if ((sizeof(unsigned int) * CHAR_BIT)/2 >= (sizeof(mp_digit) * CHAR_BIT)) {
             if ((err = mp_rand(&b, 1)) != MP_OKAY) {
                goto LBL_B;
             }
@@ -308,9 +307,9 @@ int mp_prime_is_prime(const mp_int *a, int t, int *result)
          }
 #endif
          /* Ceil, because small numbers have a right to live, too, */
-         len = (int) ( (fips_rand + DIGIT_BIT) / DIGIT_BIT);
+         len = (int)((fips_rand + DIGIT_BIT) / DIGIT_BIT);
          /*  Unlikely. */
-         if(len < 0){
+         if (len < 0) {
             ix--;
             continue;
          }
@@ -322,7 +321,7 @@ int mp_prime_is_prime(const mp_int *a, int t, int *result)
           */
 #ifdef MP_8BIT
          /* All "a" < 2^8 have been caught before */
-         if(len == 1){
+         if (len == 1) {
             len++;
          }
 #endif
diff --git a/bn_mp_prime_strong_lucas_selfridge.c b/bn_mp_prime_strong_lucas_selfridge.c
index 6558386..0be4915 100644
--- a/bn_mp_prime_strong_lucas_selfridge.c
+++ b/bn_mp_prime_strong_lucas_selfridge.c
@@ -118,7 +118,7 @@ int mp_prime_strong_lucas_selfridge(const mp_int *a, int *result)
       /* if 1 < GCD < N then N is composite with factor "D", and
          Jacobi(D,N) is technically undefined (but often returned
          as zero). */
-      if ( mp_cmp_d(&gcd,1u) == MP_GT  && mp_cmp(&gcd,a) == MP_LT) {
+      if ((mp_cmp_d(&gcd,1u) == MP_GT) && (mp_cmp(&gcd,a) == MP_LT)) {
          goto LBL_LS_ERR;
       }
       if (Ds < 0) {
@@ -313,7 +313,7 @@ int mp_prime_strong_lucas_selfridge(const mp_int *a, int *result)
          if ((e = mp_div_2(&Uz,&Uz)) != MP_OKAY) {
             goto LBL_LS_ERR;
          }
-         if (Uz.sign == MP_NEG && mp_isodd(&Uz)) {
+         if ((Uz.sign == MP_NEG) && mp_isodd(&Uz)) {
             if ((e = mp_sub_d(&Uz,1u,&Uz)) != MP_OKAY) {
                goto LBL_LS_ERR;
             }
diff --git a/demo/demo.c b/demo/demo.c
index d8e52e8..b0ac10c 100644
--- a/demo/demo.c
+++ b/demo/demo.c
@@ -124,7 +124,7 @@ struct mp_kronecker_st {
    int c[21];
 };
 static struct mp_kronecker_st kronecker[] = {
-         /*-10, -9, -8, -7,-6, -5, -4, -3, -2, -1, 0, 1,  2,  3, 4,  5,  6,  7,  8, 9, 10*/
+   /*-10, -9, -8, -7,-6, -5, -4, -3, -2, -1, 0, 1,  2,  3, 4,  5,  6,  7,  8, 9, 10*/
    { -10, {  0, -1,  0, -1, 0,  0,  0,  1,  0, -1, 0, 1,  0, -1, 0,  0,  0,  1,  0, 1,  0  } },
    {  -9, { -1,  0, -1,  1, 0, -1, -1,  0, -1, -1, 0, 1,  1,  0, 1,  1,  0, -1,  1, 0,  1  } },
    {  -8, {  0, -1,  0,  1, 0,  1,  0, -1,  0, -1, 0, 1,  0,  1, 0, -1,  0, -1,  0, 1,  0  } },
@@ -305,19 +305,17 @@ int main(void)
    for (cnt = 0; cnt < (int)(sizeof(kronecker)/sizeof(kronecker[0])); ++cnt) {
       k = kronecker[cnt].n;
       if (k < 0) {
-          mp_set_int(&a, (unsigned long) (-k));
-          mp_neg(&a, &a);
-      }
-      else {
-          mp_set_int(&a, (unsigned long) k);
+         mp_set_int(&a, (unsigned long)(-k));
+         mp_neg(&a, &a);
+      } else {
+         mp_set_int(&a, (unsigned long) k);
       }
       /* only test positive values of a */
       for (m = -10; m <= 10; m++) {
          if (m < 0) {
-            mp_set_int(&b,(unsigned long) (-m));
+            mp_set_int(&b,(unsigned long)(-m));
             mp_neg(&b, &b);
-         }
-         else {
+         } else {
             mp_set_int(&b, (unsigned long) m);
          }
          if ((err = mp_kronecker(&a, &b, &i)) != MP_OKAY) {
@@ -676,7 +674,9 @@ int main(void)
 
    /* strong Miller-Rabin pseudoprime to the first 200 primes (F. Arnault) */
    puts("Testing mp_prime_is_prime() with Arnault's pseudoprime  803...901 \n");
-   mp_read_radix(&a,"91xLNF3roobhzgTzoFIG6P13ZqhOVYSN60Fa7Cj2jVR1g0k89zdahO9/kAiRprpfO1VAp1aBHucLFV/qLKLFb+zonV7R2Vxp1K13ClwUXStpV0oxTNQVjwybmFb5NBEHImZ6V7P6+udRJuH8VbMEnS0H8/pSqQrg82OoQQ2fPpAk6G1hkjqoCv5s/Yr",64);
+   mp_read_radix(&a,
+                 "91xLNF3roobhzgTzoFIG6P13ZqhOVYSN60Fa7Cj2jVR1g0k89zdahO9/kAiRprpfO1VAp1aBHucLFV/qLKLFb+zonV7R2Vxp1K13ClwUXStpV0oxTNQVjwybmFb5NBEHImZ6V7P6+udRJuH8VbMEnS0H8/pSqQrg82OoQQ2fPpAk6G1hkjqoCv5s/Yr",
+                 64);
    mp_prime_is_prime(&a, 8, &cnt);
    if (cnt == MP_YES) {
       printf("Arnault's pseudoprime is not prime but mp_prime_is_prime says it is.\n");
diff --git a/demo/timing.c b/demo/timing.c
index 819cb5f..7a5da20 100644
--- a/demo/timing.c
+++ b/demo/timing.c
@@ -104,7 +104,7 @@ int main(void)
    FILE *log, *logb, *logc, *logd;
    mp_int a, b, c, d, e, f;
 #ifdef LTM_TIMING_PRIME_IS_PRIME
-   const char* name;
+   const char *name;
    int m;
 #endif
    int n, cnt, ix, old_kara_m, old_kara_s, old_toom_m, old_toom_s;
@@ -130,7 +130,9 @@ int main(void)
    for (m = 0; m < 2; ++m) {
       if (m == 0) {
          name = "    Arnault";
-         mp_read_radix(&a,"91xLNF3roobhzgTzoFIG6P13ZqhOVYSN60Fa7Cj2jVR1g0k89zdahO9/kAiRprpfO1VAp1aBHucLFV/qLKLFb+zonV7R2Vxp1K13ClwUXStpV0oxTNQVjwybmFb5NBEHImZ6V7P6+udRJuH8VbMEnS0H8/pSqQrg82OoQQ2fPpAk6G1hkjqoCv5s/Yr",64);
+         mp_read_radix(&a,
+                       "91xLNF3roobhzgTzoFIG6P13ZqhOVYSN60Fa7Cj2jVR1g0k89zdahO9/kAiRprpfO1VAp1aBHucLFV/qLKLFb+zonV7R2Vxp1K13ClwUXStpV0oxTNQVjwybmFb5NBEHImZ6V7P6+udRJuH8VbMEnS0H8/pSqQrg82OoQQ2fPpAk6G1hkjqoCv5s/Yr",
+                       64);
       } else {
          name = "2^1119 + 53";
          mp_set(&a,1u);
diff --git a/etc/2kprime.c b/etc/2kprime.c
index 829474a..bba3e62 100644
--- a/etc/2kprime.c
+++ b/etc/2kprime.c
@@ -37,7 +37,7 @@ top:
             if ((clock() - t1) > CLOCKS_PER_SEC) {
                printf(".");
                fflush(stdout);
-/*            sleep((clock() - t1 + CLOCKS_PER_SEC/2)/CLOCKS_PER_SEC); */
+               /*            sleep((clock() - t1 + CLOCKS_PER_SEC/2)/CLOCKS_PER_SEC); */
                t1 = clock();
             }
 
diff --git a/mtest/mtest.c b/mtest/mtest.c
index 3492f73..06c9afb 100644
--- a/mtest/mtest.c
+++ b/mtest/mtest.c
@@ -293,7 +293,7 @@ int main(int argc, char *argv[])
          rand_num2(&a);
          rand_num2(&b);
          rand_num2(&c);
-/*      if (c.dp[0]&1) mp_add_d(&c, 1, &c); */
+         /*      if (c.dp[0]&1) mp_add_d(&c, 1, &c); */
          a.sign = b.sign = c.sign = 0;
          mp_exptmod(&a, &b, &c, &d);
          printf("expt\n");