From 6946b9db4429d68038c01feb0a9e209be46599a6 Mon Sep 17 00:00:00 2001
From: Kaz Kylheku <kaz@kylheku.com>
Date: Mon, 14 Nov 2016 22:15:41 -0800
Subject: mpi: eliminate trailing whitespace.

* mpi/mpi-config.h: Eliminate several trailing spaces.

* mpi/mpi.c: Eliminate all trailing spaces. Removed some
commented-out code, and adjusted brace placement
and indentation in one place. Also removed some spurious
blank lines.
---
 mpi/mpi.c | 171 +++++++++++++++++++++++++-------------------------------------
 1 file changed, 68 insertions(+), 103 deletions(-)

(limited to 'mpi/mpi.c')

diff --git a/mpi/mpi.c b/mpi/mpi.c
index aea72585..2777fa21 100644
--- a/mpi/mpi.c
+++ b/mpi/mpi.c
@@ -46,7 +46,7 @@ extern mem_t *chk_calloc(size_t n, size_t size);
 #define DIAG(T,V)
 #endif
 
-/* 
+/*
    If MP_LOGTAB is not defined, use the math library to compute the
    logarithms on the fly.  Otherwise, use the static table below.
    Pick which works best for your system.
@@ -57,7 +57,7 @@ extern mem_t *chk_calloc(size_t n, size_t size);
 
 /*
   A table of the logs of 2 for various bases (the 0 and 1 entries of
-  this table are meaningless and should not be referenced).  
+  this table are meaningless and should not be referenced).
 
   This table is used to compute output lengths for the mp_toradix()
   function.  Since a number n in radix r takes up about log_r(n)
@@ -67,7 +67,7 @@ extern mem_t *chk_calloc(size_t n, size_t size);
   log_r(n) = log_2(n) * log_r(2)
 
   This table, therefore, is a table of log_r(2) for 2 <= r <= 36,
-  which are the output bases supported.  
+  which are the output bases supported.
  */
 
 #include "logtab.h"
@@ -120,7 +120,7 @@ static const char *mp_err_string[] = {
 /* Value to digit maps for radix conversion   */
 
 /* s_dmap_1 - standard digits and letters */
-static const char *s_dmap_1 = 
+static const char *s_dmap_1 =
   "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/";
 
 #if 0
@@ -133,7 +133,7 @@ static const char *s_dmap_2 =
 
 /* {{{ Static function declarations */
 
-/* 
+/*
    If MP_MACRO is false, these will be defined as actual functions;
    otherwise, suitable macro definitions will be used.  This works
    around the fact that ANSI C89 doesn't support an 'inline' keyword
@@ -278,7 +278,7 @@ mp_err mp_init_array(mp_int mp[], int count)
   return MP_OKAY;
 
  CLEANUP:
-  while(--pos >= 0) 
+  while(--pos >= 0)
     mp_clear(&mp[pos]);
 
   return res;
@@ -377,7 +377,6 @@ mp_err mp_copy(mp_int *from, mp_int *to)
     if(ALLOC(to) >= USED(from)) {
       s_mp_setz(DIGITS(to) + USED(from), ALLOC(to) - USED(from));
       s_mp_copy(DIGITS(from), DIGITS(to), USED(from));
-      
     } else {
       if((tmp = coerce(mp_digit *,
                        s_mp_alloc(USED(from), sizeof (mp_digit)))) == NULL)
@@ -468,7 +467,7 @@ void   mp_clear_array(mp_int mp[], int count)
 {
   ARGCHK(mp != NULL && count > 0, MP_BADARG);
 
-  while(--count >= 0) 
+  while(--count >= 0)
     mp_clear(&mp[count]);
 
 } /* end mp_clear_array() */
@@ -478,7 +477,7 @@ void   mp_clear_array(mp_int mp[], int count)
 /* {{{ mp_zero(mp) */
 
 /*
-  mp_zero(mp) 
+  mp_zero(mp)
 
   Set mp to zero.  Does not change the allocated size of the structure,
   and therefore cannot fail (except on a bad argument, which we ignore)
@@ -977,9 +976,9 @@ mp_err mp_neg(mp_int *a, mp_int *b)
   if((res = mp_copy(a, b)) != MP_OKAY)
     return res;
 
-  if(s_mp_cmp_d(b, 0) == MP_EQ) 
+  if(s_mp_cmp_d(b, 0) == MP_EQ)
     SIGN(b) = MP_ZPOS;
-  else 
+  else
     SIGN(b) = (SIGN(b) == MP_NEG) ? MP_ZPOS : MP_NEG;
 
   return MP_OKAY;
@@ -1006,7 +1005,7 @@ mp_err mp_add(mp_int *a, mp_int *b, mp_int *c)
   if(SIGN(a) == SIGN(b)) { /* same sign:  add values, keep sign */
 
     /* Commutativity of addition lets us do this in either order,
-       so we avoid having to use a temporary even if the result 
+       so we avoid having to use a temporary even if the result
        is supposed to replace the output
      */
     if(c == b) {
@@ -1016,14 +1015,14 @@ mp_err mp_add(mp_int *a, mp_int *b, mp_int *c)
       if(c != a && (res = mp_copy(a, c)) != MP_OKAY)
 	return res;
 
-      if((res = s_mp_add(c, b)) != MP_OKAY) 
+      if((res = s_mp_add(c, b)) != MP_OKAY)
 	return res;
     }
 
   } else if((cmp = s_mp_cmp(a, b)) > 0) {  /* different sign: a > b   */
 
     /* If the output is going to be clobbered, we will use a temporary
-       variable; otherwise, we'll do it without touching the memory 
+       variable; otherwise, we'll do it without touching the memory
        allocator at all, if possible
      */
     if(c == b) {
@@ -1155,7 +1154,7 @@ mp_err mp_sub(mp_int *a, mp_int *b, mp_int *c)
       mp_clear(&tmp);
 
     } else {
-      if(c != b && ((res = mp_copy(b, c)) != MP_OKAY)) 
+      if(c != b && ((res = mp_copy(b, c)) != MP_OKAY))
 	return res;
 
       if((res = s_mp_sub(c, a)) != MP_OKAY)
@@ -1202,12 +1201,12 @@ mp_err mp_mul(mp_int *a, mp_int *b, mp_int *c)
     if((res = s_mp_mul(c, b)) != MP_OKAY)
       return res;
   }
-  
+
   if(sgn == MP_ZPOS || s_mp_cmp_d(c, 0) == MP_EQ)
     SIGN(c) = MP_ZPOS;
   else
     SIGN(c) = sgn;
-  
+
   return MP_OKAY;
 
 } /* end mp_mul() */
@@ -1296,7 +1295,7 @@ mp_err mp_div(mp_int *a, mp_int *b, mp_int *q, mp_int *r)
 	return res;
     }
 
-    if(q) 
+    if(q)
       mp_zero(q);
 
     return MP_OKAY;
@@ -1342,10 +1341,10 @@ mp_err mp_div(mp_int *a, mp_int *b, mp_int *q, mp_int *r)
     SIGN(&rtmp) = MP_ZPOS;
 
   /* Copy output, if it is needed      */
-  if(q) 
+  if(q)
     s_mp_exch(&qtmp, q);
 
-  if(r) 
+  if(r)
     s_mp_exch(&rtmp, r);
 
 CLEANUP:
@@ -1422,12 +1421,12 @@ mp_err mp_expt(mp_int *a, mp_int *b, mp_int *c)
     /* Loop over bits of each non-maximal digit */
     for(bit = 0; bit < DIGIT_BIT; bit++) {
       if(d & 1) {
-	if((res = s_mp_mul(&s, &x)) != MP_OKAY) 
+	if((res = s_mp_mul(&s, &x)) != MP_OKAY)
 	  goto CLEANUP;
       }
 
       d >>= 1;
-      
+
       if((res = s_mp_sqr(&x)) != MP_OKAY)
 	goto CLEANUP;
     }
@@ -1447,7 +1446,7 @@ mp_err mp_expt(mp_int *a, mp_int *b, mp_int *c)
     if((res = s_mp_sqr(&x)) != MP_OKAY)
       goto CLEANUP;
   }
-  
+
   if(mp_iseven(b))
     SIGN(&s) = SIGN(a);
 
@@ -1498,7 +1497,7 @@ mp_err mp_mod(mp_int *a, mp_int *m, mp_int *c)
 
   /*
      If |a| > m, we need to divide to get the remainder and take the
-     absolute value.  
+     absolute value.
 
      If |a| < m, we don't need to do any division, just copy and adjust
      the sign (if a is negative).
@@ -1512,12 +1511,11 @@ mp_err mp_mod(mp_int *a, mp_int *m, mp_int *c)
   if((mag = s_mp_cmp(a, m)) > 0) {
     if((res = mp_div(a, m, NULL, c)) != MP_OKAY)
       return res;
-    
+
     if(SIGN(c) == MP_NEG) {
       if((res = mp_add(c, m, c)) != MP_OKAY)
 	return res;
     }
-
   } else if(mag < 0) {
     if((res = mp_copy(a, c)) != MP_OKAY)
       return res;
@@ -1527,10 +1525,8 @@ mp_err mp_mod(mp_int *a, mp_int *m, mp_int *c)
 	return res;
 
     }
-    
   } else {
     mp_zero(c);
-
   }
 
   return MP_OKAY;
@@ -1743,7 +1739,7 @@ mp_err mp_sqrmod(mp_int *a, mp_int *m, mp_int *c)
   Compute c = (a ** b) mod m.  Uses a standard square-and-multiply
   method with modular reductions at each step. (This is basically the
   same code as mp_expt(), except for the addition of the reductions)
-  
+
   The modular reductions are done using Barrett's algorithm (see
   s_mp_reduce() below for details)
  */
@@ -1772,7 +1768,7 @@ mp_err mp_exptmod(mp_int *a, mp_int *b, mp_int *m, mp_int *c)
   mp_set(&s, 1);
 
   /* mu = b^2k / m */
-  s_mp_add_d(&mu, 1); 
+  s_mp_add_d(&mu, 1);
   s_mp_lshd(&mu, 2 * USED(m));
   if((res = mp_div(&mu, m, &mu, NULL)) != MP_OKAY)
     goto CLEANUP;
@@ -1983,7 +1979,7 @@ int    mp_cmp_int(mp_int *a, long z)
   int     out;
 
   ARGCHK(a != NULL, MP_EQ);
-  
+
   mp_init(&tmp); mp_set_int(&tmp, z);
   out = mp_cmp(a, &tmp);
   mp_clear(&tmp);
@@ -2102,13 +2098,12 @@ mp_err mp_gcd(mp_int *a, mp_int *b, mp_int *c)
   if(mp_isodd(&u)) {
     if((res = mp_copy(&v, &t)) != MP_OKAY)
       goto CLEANUP;
-    
+
     /* t = -v */
     if(SIGN(&v) == MP_ZPOS)
       SIGN(&t) = MP_NEG;
     else
       SIGN(&t) = MP_ZPOS;
-    
   } else {
     if((res = mp_copy(&u, &t)) != MP_OKAY)
       goto CLEANUP;
@@ -2297,13 +2292,13 @@ mp_err mp_xgcd(mp_int *a, mp_int *b, mp_int *g, mp_int *x, mp_int *y)
     /* If we're done, copy results to output */
     if(mp_cmp_z(&u) == 0) {
       if(x)
-	if((res = mp_copy(&C, x)) != MP_OKAY) goto CLEANUP;
+        if((res = mp_copy(&C, x)) != MP_OKAY) goto CLEANUP;
 
       if(y)
-	if((res = mp_copy(&D, y)) != MP_OKAY) goto CLEANUP;
-      
+        if((res = mp_copy(&D, y)) != MP_OKAY) goto CLEANUP;
+
       if(g)
-	if((res = mp_mul(&gx, &v, g)) != MP_OKAY) goto CLEANUP;
+        if((res = mp_mul(&gx, &v, g)) != MP_OKAY) goto CLEANUP;
 
       break;
     }
@@ -2843,7 +2838,7 @@ void   mp_print(mp_int *mp, FILE *ofp)
 
 /* {{{ mp_read_signed_bin(mp, str, len) */
 
-/* 
+/*
    mp_read_signed_bin(mp, str, len)
 
    Read in a raw value (base 256) into the given mp_int
@@ -2920,16 +2915,15 @@ mp_err  mp_read_unsigned_bin(mp_int *mp, unsigned char *str, int len)
     if((res = mp_add_d(mp, str[ix], mp)) != MP_OKAY)
       return res;
   }
-  
+
   return MP_OKAY;
-  
 } /* end mp_read_unsigned_bin() */
 
 /* }}} */
 
 /* {{{ mp_unsigned_bin_size(mp) */
 
-int     mp_unsigned_bin_size(mp_int *mp) 
+int     mp_unsigned_bin_size(mp_int *mp)
 {
   mp_digit   topdig;
   int        count;
@@ -3069,16 +3063,17 @@ mp_err  mp_read_radix(mp_int *mp, unsigned char *str, int radix)
   mp_err  res;
   mp_sign sig = MP_ZPOS;
 
-  ARGCHK(mp != NULL && str != NULL && radix >= 2 && radix <= MAX_RADIX, 
+  ARGCHK(mp != NULL && str != NULL && radix >= 2 && radix <= MAX_RADIX,
 	 MP_BADARG);
 
   mp_zero(mp);
 
   /* Skip leading non-digit characters until a digit or '-' or '+' */
-  while(str[ix] && 
-	(s_mp_tovalue(str[ix], radix) < 0) && 
-	str[ix] != '-' &&
-	str[ix] != '+') {
+  while(str[ix] &&
+        (s_mp_tovalue(str[ix], radix) < 0) &&
+        str[ix] != '-' &&
+        str[ix] != '+')
+  {
     ++ix;
   }
 
@@ -3132,7 +3127,7 @@ int    mp_radix_size(mp_int *mp, int radix)
 /* num = number of digits
    qty = number of bits per digit
    radix = target base
-   
+
    Return the number of digits in the specified radix that would be
    needed to express 'num' digits of 'qty' bits each.
  */
@@ -3201,7 +3196,7 @@ mp_err mp_toradix_case(mp_int *mp, unsigned char *str, int radix, int low)
       ++ix;
       --pos;
     }
-    
+
     mp_clear(&tmp);
   }
 
@@ -3654,11 +3649,11 @@ void     s_mp_exch(mp_int *a, mp_int *b)
 
 /* {{{ s_mp_lshd(mp, p) */
 
-/* 
+/*
    Shift mp leftward by p digits, growing if needed, and zero-filling
    the in-shifted digits at the right end.  This is a convenient
    alternative to multiplication by powers of the radix
- */   
+ */
 
 mp_err   s_mp_lshd(mp_int *mp, mp_size p)
 {
@@ -3677,7 +3672,7 @@ mp_err   s_mp_lshd(mp_int *mp, mp_size p)
   dp = DIGITS(mp);
 
   /* Shift all the significant figures over as needed */
-  for(ix = pos - p; ix >= 0; ix--) 
+  for(ix = pos - p; ix >= 0; ix--)
     dp[ix + p] = dp[ix];
 
   /* Fill the bottom digits with zeroes */
@@ -3692,7 +3687,7 @@ mp_err   s_mp_lshd(mp_int *mp, mp_size p)
 
 /* {{{ s_mp_rshd(mp, p) */
 
-/* 
+/*
    Shift mp rightward by p digits.  Maintains the invariant that
    digits above the precision are all zero.  Digits shifted off the
    end are lost.  Cannot fail.
@@ -3902,7 +3897,7 @@ void     s_mp_div_2d(mp_int *mp, mp_digit d)
   end of the division process).
 
   We multiply by the smallest power of 2 that gives us a leading digit
-  at least half the radix.  By choosing a power of 2, we simplify the 
+  at least half the radix.  By choosing a power of 2, we simplify the
   multiplication and division steps to simple shifts.
  */
 mp_digit s_mp_norm(mp_int *a, mp_int *b)
@@ -3913,7 +3908,7 @@ mp_digit s_mp_norm(mp_int *a, mp_int *b)
 
   d = MP_DIGIT_BIT - s_highest_bit(t);
   t <<= d;
-    
+
   if(d != 0) {
     s_mp_mul_2d(a, d);
     s_mp_mul_2d(b, d);
@@ -4035,14 +4030,13 @@ mp_err   s_mp_mul_d(mp_int *a, mp_digit d)
      test guarantees we have enough storage to do this safely.
    */
   if(k) {
-    dp[max] = k; 
+    dp[max] = k;
     USED(a) = max + 1;
   }
 
   s_mp_clamp(a);
 
   return MP_OKAY;
-  
 } /* end s_mp_mul_d() */
 
 /* }}} */
@@ -4136,7 +4130,7 @@ mp_err   s_mp_add(mp_int *a, mp_int *b)        /* magnitude addition      */
   }
 
   /* If we run out of 'b' digits before we're actually done, make
-     sure the carries get propagated upward...  
+     sure the carries get propagated upward...
    */
   used = USED(a);
   while(w && ix < used) {
@@ -4198,7 +4192,7 @@ mp_err   s_mp_sub(mp_int *a, mp_int *b)        /* magnitude subtract      */
   /* Clobber any leading zeroes we created    */
   s_mp_clamp(a);
 
-  /* 
+  /*
      If there was a borrow out, then |b| > |a| in violation
      of our input invariant.  We've already done the work,
      but we'll at least complain about it...
@@ -4236,7 +4230,7 @@ mp_err   s_mp_mul(mp_int *a, mp_int *b)
 
   pb = DIGITS(b);
   for(ix = 0; ix < ub; ++ix, ++pb) {
-    if(*pb == 0) 
+    if(*pb == 0)
       continue;
 
     /* Inner product:  Digits of a */
@@ -4263,35 +4257,6 @@ mp_err   s_mp_mul(mp_int *a, mp_int *b)
 
 /* }}} */
 
-/* {{{ s_mp_kmul(a, b, out, len) */
-
-#if 0
-void   s_mp_kmul(mp_digit *a, mp_digit *b, mp_digit *out, mp_size len)
-{
-  mp_word   w, k = 0;
-  mp_size   ix, jx;
-  mp_digit *pa, *pt;
-
-  for(ix = 0; ix < len; ++ix, ++b) {
-    if(*b == 0)
-      continue;
-    
-    pa = a;
-    for(jx = 0; jx < len; ++jx, ++pa) {
-      pt = out + ix + jx;
-      w = *b * *pa + k + *pt;
-      *pt = ACCUM(w);
-      k = CARRYOUT(w);
-    }
-
-    out[ix + jx] = k;
-    k = 0;
-  }
-
-} /* end s_mp_kmul() */
-#endif
-
-/* }}} */
 
 /* {{{ s_mp_sqr(a) */
 
@@ -4342,7 +4307,7 @@ mp_err   s_mp_sqr(mp_int *a)
      */
     for(jx = ix + 1, pa2 = DIGITS(a) + jx; jx < used; ++jx, ++pa2) {
       mp_word  u = 0, v;
-      
+
       /* Store this in a temporary to avoid indirections later */
       pt = pbt + ix + jx;
 
@@ -4363,7 +4328,7 @@ mp_err   s_mp_sqr(mp_int *a)
       v = *pt + k;
 
       /* If we do not already have an overflow carry, check to see
-	 if the addition will cause one, and set the carry out if so 
+	 if the addition will cause one, and set the carry out if so
        */
       u |= ((MP_WORD_MAX - v) < w);
 
@@ -4387,7 +4352,7 @@ mp_err   s_mp_sqr(mp_int *a)
     /* If we are carrying out, propagate the carry to the next digit
        in the output.  This may cascade, so we have to be somewhat
        circumspect -- but we will have enough precision in the output
-       that we won't overflow 
+       that we won't overflow
      */
     kx = 1;
     while(k) {
@@ -4459,7 +4424,7 @@ mp_err   s_mp_div(mp_int *a, mp_int *b)
   while(ix >= 0) {
     /* Find a partial substring of a which is at least b */
     while(s_mp_cmp(&rem, b) < 0 && ix >= 0) {
-      if((res = s_mp_lshd(&rem, 1)) != MP_OKAY) 
+      if((res = s_mp_lshd(&rem, 1)) != MP_OKAY)
 	goto CLEANUP;
 
       if((res = s_mp_lshd(&quot, 1)) != MP_OKAY)
@@ -4471,8 +4436,8 @@ mp_err   s_mp_div(mp_int *a, mp_int *b)
     }
 
     /* If we didn't find one, we're finished dividing    */
-    if(s_mp_cmp(&rem, b) < 0) 
-      break;    
+    if(s_mp_cmp(&rem, b) < 0)
+      break;
 
     /* Compute a guess for the next quotient digit       */
     q = DIGIT(&rem, USED(&rem) - 1);
@@ -4490,7 +4455,7 @@ mp_err   s_mp_div(mp_int *a, mp_int *b)
     if((res = s_mp_mul_d(&t, q)) != MP_OKAY)
       goto CLEANUP;
 
-    /* 
+    /*
        If it's too big, back it off.  We should not have to do this
        more than once, or, in rare cases, twice.  Knuth describes a
        method by which this could be reduced to a maximum of once, but
@@ -4514,7 +4479,7 @@ mp_err   s_mp_div(mp_int *a, mp_int *b)
   }
 
   /* Denormalize remainder                */
-  if(d != 0) 
+  if(d != 0)
     s_mp_div_2d(&rem, d);
 
   s_mp_clamp(&quot);
@@ -4522,7 +4487,7 @@ mp_err   s_mp_div(mp_int *a, mp_int *b)
 
   /* Copy quotient back to output         */
   s_mp_exch(&quot, a);
-  
+
   /* Copy remainder back to output        */
   s_mp_exch(&rem, b);
 
@@ -4552,7 +4517,7 @@ mp_err   s_mp_2expt(mp_int *a, mp_digit k)
   mp_zero(a);
   if((res = s_mp_pad(a, dig + 1)) != MP_OKAY)
     return res;
-  
+
   DIGIT(a, dig) |= (convert(mp_digit, 1) << bit);
 
   return MP_OKAY;
@@ -4573,7 +4538,7 @@ mp_err   s_mp_2expt(mp_int *a, mp_digit k)
 
   This algorithm was derived from the _Handbook of Applied
   Cryptography_ by Menezes, Oorschot and VanStone, Ch. 14,
-  pp. 603-604.  
+  pp. 603-604.
  */
 
 mp_err   s_mp_reduce(mp_int *x, mp_int *m, mp_int *mu)
@@ -4670,7 +4635,7 @@ int      s_mp_cmp_d(mp_int *a, mp_digit d)
   if(ua > 1)
     return MP_GT;
 
-  if(*ap < d) 
+  if(*ap < d)
     return MP_LT;
   else if(*ap > d)
     return MP_GT;
@@ -4768,7 +4733,7 @@ int      s_mp_tovalue(int ch, int r)
     val = 62;
   else if(xch == '/')
     val = 63;
-  else 
+  else
     return -1;
 
   if(val < 0 || val >= r)
@@ -4790,7 +4755,7 @@ int      s_mp_tovalue(int ch, int r)
   The results may be odd if you use a radix < 2 or > 64, you are
   expected to know what you're doing.
  */
-  
+
 char     s_mp_todigit(int val, int r, int low)
 {
   int   ch;
@@ -4811,7 +4776,7 @@ char     s_mp_todigit(int val, int r, int low)
 
 /* {{{ s_mp_outlen(bits, radix) */
 
-/* 
+/*
    Return an estimate for how long a string is needed to hold a radix
    r representation of a number with 'bits' significant bits.
 
-- 
cgit v1.2.3