commit
						489bf69f65
					
				@ -27,7 +27,7 @@ int fast_mp_invmod (mp_int * a, mp_int * b, mp_int * c)
 | 
				
			|||||||
  int     res, neg;
 | 
					  int     res, neg;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /* 2. [modified] b must be odd   */
 | 
					  /* 2. [modified] b must be odd   */
 | 
				
			||||||
  if (mp_iseven (b) == 1) {
 | 
					  if (mp_iseven (b) == MP_YES) {
 | 
				
			||||||
    return MP_VAL;
 | 
					    return MP_VAL;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -57,13 +57,13 @@ int fast_mp_invmod (mp_int * a, mp_int * b, mp_int * c)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
top:
 | 
					top:
 | 
				
			||||||
  /* 4.  while u is even do */
 | 
					  /* 4.  while u is even do */
 | 
				
			||||||
  while (mp_iseven (&u) == 1) {
 | 
					  while (mp_iseven (&u) == MP_YES) {
 | 
				
			||||||
    /* 4.1 u = u/2 */
 | 
					    /* 4.1 u = u/2 */
 | 
				
			||||||
    if ((res = mp_div_2 (&u, &u)) != MP_OKAY) {
 | 
					    if ((res = mp_div_2 (&u, &u)) != MP_OKAY) {
 | 
				
			||||||
      goto LBL_ERR;
 | 
					      goto LBL_ERR;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    /* 4.2 if B is odd then */
 | 
					    /* 4.2 if B is odd then */
 | 
				
			||||||
    if (mp_isodd (&B) == 1) {
 | 
					    if (mp_isodd (&B) == MP_YES) {
 | 
				
			||||||
      if ((res = mp_sub (&B, &x, &B)) != MP_OKAY) {
 | 
					      if ((res = mp_sub (&B, &x, &B)) != MP_OKAY) {
 | 
				
			||||||
        goto LBL_ERR;
 | 
					        goto LBL_ERR;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
@ -75,13 +75,13 @@ top:
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /* 5.  while v is even do */
 | 
					  /* 5.  while v is even do */
 | 
				
			||||||
  while (mp_iseven (&v) == 1) {
 | 
					  while (mp_iseven (&v) == MP_YES) {
 | 
				
			||||||
    /* 5.1 v = v/2 */
 | 
					    /* 5.1 v = v/2 */
 | 
				
			||||||
    if ((res = mp_div_2 (&v, &v)) != MP_OKAY) {
 | 
					    if ((res = mp_div_2 (&v, &v)) != MP_OKAY) {
 | 
				
			||||||
      goto LBL_ERR;
 | 
					      goto LBL_ERR;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    /* 5.2 if D is odd then */
 | 
					    /* 5.2 if D is odd then */
 | 
				
			||||||
    if (mp_isodd (&D) == 1) {
 | 
					    if (mp_isodd (&D) == MP_YES) {
 | 
				
			||||||
      /* D = (D-x)/2 */
 | 
					      /* D = (D-x)/2 */
 | 
				
			||||||
      if ((res = mp_sub (&D, &x, &D)) != MP_OKAY) {
 | 
					      if ((res = mp_sub (&D, &x, &D)) != MP_OKAY) {
 | 
				
			||||||
        goto LBL_ERR;
 | 
					        goto LBL_ERR;
 | 
				
			||||||
@ -115,7 +115,7 @@ top:
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /* if not zero goto step 4 */
 | 
					  /* if not zero goto step 4 */
 | 
				
			||||||
  if (mp_iszero (&u) == 0) {
 | 
					  if (mp_iszero (&u) == MP_NO) {
 | 
				
			||||||
    goto top;
 | 
					    goto top;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -26,12 +26,12 @@ int mp_cnt_lsb(mp_int *a)
 | 
				
			|||||||
   mp_digit q, qq;
 | 
					   mp_digit q, qq;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   /* easy out */
 | 
					   /* easy out */
 | 
				
			||||||
   if (mp_iszero(a) == 1) {
 | 
					   if (mp_iszero(a) == MP_YES) {
 | 
				
			||||||
      return 0;
 | 
					      return 0;
 | 
				
			||||||
   }
 | 
					   }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   /* scan lower digits until non-zero */
 | 
					   /* scan lower digits until non-zero */
 | 
				
			||||||
   for (x = 0; x < a->used && a->dp[x] == 0; x++);
 | 
					   for (x = 0; x < a->used && a->dp[x] == 0; x++) {}
 | 
				
			||||||
   q = a->dp[x];
 | 
					   q = a->dp[x];
 | 
				
			||||||
   x *= DIGIT_BIT;
 | 
					   x *= DIGIT_BIT;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										11
									
								
								bn_mp_div.c
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								bn_mp_div.c
									
									
									
									
									
								
							@ -24,7 +24,7 @@ int mp_div(mp_int * a, mp_int * b, mp_int * c, mp_int * d)
 | 
				
			|||||||
   int    res, n, n2;
 | 
					   int    res, n, n2;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /* is divisor zero ? */
 | 
					  /* is divisor zero ? */
 | 
				
			||||||
  if (mp_iszero (b) == 1) {
 | 
					  if (mp_iszero (b) == MP_YES) {
 | 
				
			||||||
    return MP_VAL;
 | 
					    return MP_VAL;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -106,7 +106,7 @@ int mp_div (mp_int * a, mp_int * b, mp_int * c, mp_int * d)
 | 
				
			|||||||
  int     res, n, t, i, norm, neg;
 | 
					  int     res, n, t, i, norm, neg;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /* is divisor zero ? */
 | 
					  /* is divisor zero ? */
 | 
				
			||||||
  if (mp_iszero (b) == 1) {
 | 
					  if (mp_iszero (b) == MP_YES) {
 | 
				
			||||||
    return MP_VAL;
 | 
					    return MP_VAL;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -196,8 +196,9 @@ int mp_div (mp_int * a, mp_int * b, mp_int * c, mp_int * d)
 | 
				
			|||||||
      tmp = ((mp_word) x.dp[i]) << ((mp_word) DIGIT_BIT);
 | 
					      tmp = ((mp_word) x.dp[i]) << ((mp_word) DIGIT_BIT);
 | 
				
			||||||
      tmp |= ((mp_word) x.dp[i - 1]);
 | 
					      tmp |= ((mp_word) x.dp[i - 1]);
 | 
				
			||||||
      tmp /= ((mp_word) y.dp[t]);
 | 
					      tmp /= ((mp_word) y.dp[t]);
 | 
				
			||||||
      if (tmp > (mp_word) MP_MASK)
 | 
					      if (tmp > (mp_word) MP_MASK) {
 | 
				
			||||||
        tmp = MP_MASK;
 | 
					        tmp = MP_MASK;
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
      q.dp[i - t - 1] = (mp_digit) (tmp & (mp_word) (MP_MASK));
 | 
					      q.dp[i - t - 1] = (mp_digit) (tmp & (mp_word) (MP_MASK));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -269,7 +270,9 @@ int mp_div (mp_int * a, mp_int * b, mp_int * c, mp_int * d)
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (d != NULL) {
 | 
					  if (d != NULL) {
 | 
				
			||||||
    mp_div_2d (&x, norm, &x, NULL);
 | 
					    if ((res = mp_div_2d (&x, norm, &x, NULL)) != MP_OKAY) {
 | 
				
			||||||
 | 
					      goto LBL_Y;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    mp_exch (&x, d);
 | 
					    mp_exch (&x, d);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -20,7 +20,7 @@ static int s_is_power_of_two(mp_digit b, int *p)
 | 
				
			|||||||
   int x;
 | 
					   int x;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   /* fast return if no power of two */
 | 
					   /* fast return if no power of two */
 | 
				
			||||||
   if ((b==0) || (b & (b-1))) {
 | 
					   if ((b == 0) || ((b & (b-1)) != 0)) {
 | 
				
			||||||
      return 0;
 | 
					      return 0;
 | 
				
			||||||
   }
 | 
					   }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -47,7 +47,7 @@ int mp_div_d (mp_int * a, mp_digit b, mp_int * c, mp_digit * d)
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /* quick outs */
 | 
					  /* quick outs */
 | 
				
			||||||
  if (b == 1 || mp_iszero(a) == 1) {
 | 
					  if (b == 1 || mp_iszero(a) == MP_YES) {
 | 
				
			||||||
     if (d != NULL) {
 | 
					     if (d != NULL) {
 | 
				
			||||||
        *d = 0;
 | 
					        *d = 0;
 | 
				
			||||||
     }
 | 
					     }
 | 
				
			||||||
 | 
				
			|||||||
@ -82,7 +82,9 @@ top:
 | 
				
			|||||||
   * Each successive "recursion" makes the input smaller and smaller.
 | 
					   * Each successive "recursion" makes the input smaller and smaller.
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  if (mp_cmp_mag (x, n) != MP_LT) {
 | 
					  if (mp_cmp_mag (x, n) != MP_LT) {
 | 
				
			||||||
    s_mp_sub(x, n, x);
 | 
					    if ((err = s_mp_sub(x, n, x)) != MP_OKAY) {
 | 
				
			||||||
 | 
					      return err;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    goto top;
 | 
					    goto top;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  return MP_OKAY;
 | 
					  return MP_OKAY;
 | 
				
			||||||
 | 
				
			|||||||
@ -34,7 +34,8 @@ int mp_export(void* rop, size_t* countp, int order, size_t size,
 | 
				
			|||||||
		union {
 | 
							union {
 | 
				
			||||||
			unsigned int i;
 | 
								unsigned int i;
 | 
				
			||||||
			char c[4];
 | 
								char c[4];
 | 
				
			||||||
		} lint = {0x01020304};
 | 
							} lint;
 | 
				
			||||||
 | 
							lint.i = 0x01020304;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		endian = (lint.c[0] == 4 ? -1 : 1);
 | 
							endian = (lint.c[0] == 4 ? -1 : 1);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@ -47,7 +48,7 @@ int mp_export(void* rop, size_t* countp, int order, size_t size,
 | 
				
			|||||||
	nail_bytes = nails / 8;
 | 
						nail_bytes = nails / 8;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	bits = mp_count_bits(&t);
 | 
						bits = mp_count_bits(&t);
 | 
				
			||||||
	count = bits / (size * 8 - nails) + (bits % (size * 8 - nails) ? 1 : 0);
 | 
						count = bits / (size * 8 - nails) + ((bits % (size * 8 - nails) != 0) ? 1 : 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for (i = 0; i < count; ++i) {
 | 
						for (i = 0; i < count; ++i) {
 | 
				
			||||||
		for (j = 0; j < size; ++j) {
 | 
							for (j = 0; j < size; ++j) {
 | 
				
			||||||
@ -73,7 +74,7 @@ int mp_export(void* rop, size_t* countp, int order, size_t size,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	mp_clear(&t);
 | 
						mp_clear(&t);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (countp) {
 | 
						if (countp != NULL) {
 | 
				
			||||||
		*countp = count;
 | 
							*countp = count;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -30,10 +30,10 @@ int mp_expt_d_ex (mp_int * a, mp_digit b, mp_int * c, int fast)
 | 
				
			|||||||
  /* set initial result */
 | 
					  /* set initial result */
 | 
				
			||||||
  mp_set (c, 1);
 | 
					  mp_set (c, 1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (fast) {
 | 
					  if (fast != 0) {
 | 
				
			||||||
    while (b > 0) {
 | 
					    while (b > 0) {
 | 
				
			||||||
      /* if the bit is set multiply */
 | 
					      /* if the bit is set multiply */
 | 
				
			||||||
      if (b & 1) {
 | 
					      if ((b & 1) != 0) {
 | 
				
			||||||
        if ((res = mp_mul (c, &g, c)) != MP_OKAY) {
 | 
					        if ((res = mp_mul (c, &g, c)) != MP_OKAY) {
 | 
				
			||||||
          mp_clear (&g);
 | 
					          mp_clear (&g);
 | 
				
			||||||
          return res;
 | 
					          return res;
 | 
				
			||||||
@ -41,10 +41,12 @@ int mp_expt_d_ex (mp_int * a, mp_digit b, mp_int * c, int fast)
 | 
				
			|||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      /* square */
 | 
					      /* square */
 | 
				
			||||||
      if (b > 1 && (res = mp_sqr (&g, &g)) != MP_OKAY) {
 | 
					      if (b > 1) {
 | 
				
			||||||
 | 
					        if ((res = mp_sqr (&g, &g)) != MP_OKAY) {
 | 
				
			||||||
          mp_clear (&g);
 | 
					          mp_clear (&g);
 | 
				
			||||||
          return res;
 | 
					          return res;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      /* shift to next bit */
 | 
					      /* shift to next bit */
 | 
				
			||||||
      b >>= 1;
 | 
					      b >>= 1;
 | 
				
			||||||
 | 
				
			|||||||
@ -89,7 +89,7 @@ int mp_exptmod (mp_int * G, mp_int * X, mp_int * P, mp_int * Y)
 | 
				
			|||||||
    
 | 
					    
 | 
				
			||||||
  /* if the modulus is odd or dr != 0 use the montgomery method */
 | 
					  /* if the modulus is odd or dr != 0 use the montgomery method */
 | 
				
			||||||
#ifdef BN_MP_EXPTMOD_FAST_C
 | 
					#ifdef BN_MP_EXPTMOD_FAST_C
 | 
				
			||||||
  if (mp_isodd (P) == 1 || dr !=  0) {
 | 
					  if (mp_isodd (P) == MP_YES || dr !=  0) {
 | 
				
			||||||
    return mp_exptmod_fast (G, X, P, Y, dr);
 | 
					    return mp_exptmod_fast (G, X, P, Y, dr);
 | 
				
			||||||
  } else {
 | 
					  } else {
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
				
			|||||||
@ -61,9 +61,9 @@ int mp_exteuclid(mp_int *a, mp_int *b, mp_int *U1, mp_int *U2, mp_int *U3)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
   /* make sure U3 >= 0 */
 | 
					   /* make sure U3 >= 0 */
 | 
				
			||||||
   if (u3.sign == MP_NEG) {
 | 
					   if (u3.sign == MP_NEG) {
 | 
				
			||||||
      mp_neg(&u1, &u1);
 | 
					       if ((err = mp_neg(&u1, &u1)) != MP_OKAY)                                   { goto _ERR; }
 | 
				
			||||||
      mp_neg(&u2, &u2);
 | 
					       if ((err = mp_neg(&u2, &u2)) != MP_OKAY)                                   { goto _ERR; }
 | 
				
			||||||
      mp_neg(&u3, &u3);
 | 
					       if ((err = mp_neg(&u3, &u3)) != MP_OKAY)                                   { goto _ERR; }
 | 
				
			||||||
   }
 | 
					   }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   /* copy result out */
 | 
					   /* copy result out */
 | 
				
			||||||
 | 
				
			|||||||
@ -70,7 +70,7 @@ int mp_gcd (mp_int * a, mp_int * b, mp_int * c)
 | 
				
			|||||||
     }
 | 
					     }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  while (mp_iszero(&v) == 0) {
 | 
					  while (mp_iszero(&v) == MP_NO) {
 | 
				
			||||||
     /* make sure v is the largest */
 | 
					     /* make sure v is the largest */
 | 
				
			||||||
     if (mp_cmp_mag(&u, &v) == MP_GT) {
 | 
					     if (mp_cmp_mag(&u, &v) == MP_GT) {
 | 
				
			||||||
        /* swap u and v to make sure v is >= u */
 | 
					        /* swap u and v to make sure v is >= u */
 | 
				
			||||||
 | 
				
			|||||||
@ -31,7 +31,7 @@ unsigned long mp_get_long(mp_int * a)
 | 
				
			|||||||
  /* get most significant digit of result */
 | 
					  /* get most significant digit of result */
 | 
				
			||||||
  res = DIGIT(a,i);
 | 
					  res = DIGIT(a,i);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if ULONG_MAX != 0xfffffffful || DIGIT_BIT < 32
 | 
					#if ULONG_MAX != 0xffffffffuL || DIGIT_BIT < 32
 | 
				
			||||||
  while (--i >= 0) {
 | 
					  while (--i >= 0) {
 | 
				
			||||||
    res = (res << DIGIT_BIT) | DIGIT(a,i);
 | 
					    res = (res << DIGIT_BIT) | DIGIT(a,i);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
				
			|||||||
@ -30,7 +30,8 @@ int mp_import(mp_int* rop, size_t count, int order, size_t size,
 | 
				
			|||||||
		union {
 | 
							union {
 | 
				
			||||||
			unsigned int i;
 | 
								unsigned int i;
 | 
				
			||||||
			char c[4];
 | 
								char c[4];
 | 
				
			||||||
		} lint = {0x01020304};
 | 
							} lint;
 | 
				
			||||||
 | 
							lint.i = 0x01020304;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		endian = (lint.c[0] == 4 ? -1 : 1);
 | 
							endian = (lint.c[0] == 4 ? -1 : 1);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
				
			|||||||
@ -37,7 +37,7 @@ int mp_init_multi(mp_int *mp, ...)
 | 
				
			|||||||
            /* now start cleaning up */            
 | 
					            /* now start cleaning up */            
 | 
				
			||||||
            cur_arg = mp;
 | 
					            cur_arg = mp;
 | 
				
			||||||
            va_start(clean_args, mp);
 | 
					            va_start(clean_args, mp);
 | 
				
			||||||
            while (n--) {
 | 
					            while (n-- != 0) {
 | 
				
			||||||
                mp_clear(cur_arg);
 | 
					                mp_clear(cur_arg);
 | 
				
			||||||
                cur_arg = va_arg(clean_args, mp_int*);
 | 
					                cur_arg = va_arg(clean_args, mp_int*);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
				
			|||||||
@ -19,13 +19,13 @@
 | 
				
			|||||||
int mp_invmod (mp_int * a, mp_int * b, mp_int * c)
 | 
					int mp_invmod (mp_int * a, mp_int * b, mp_int * c)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  /* b cannot be negative */
 | 
					  /* b cannot be negative */
 | 
				
			||||||
  if (b->sign == MP_NEG || mp_iszero(b) == 1) {
 | 
					  if (b->sign == MP_NEG || mp_iszero(b) == MP_YES) {
 | 
				
			||||||
    return MP_VAL;
 | 
					    return MP_VAL;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef BN_FAST_MP_INVMOD_C
 | 
					#ifdef BN_FAST_MP_INVMOD_C
 | 
				
			||||||
  /* if the modulus is odd we can use a faster routine instead */
 | 
					  /* if the modulus is odd we can use a faster routine instead */
 | 
				
			||||||
  if (mp_isodd (b) == 1) {
 | 
					  if (mp_isodd (b) == MP_YES) {
 | 
				
			||||||
    return fast_mp_invmod (a, b, c);
 | 
					    return fast_mp_invmod (a, b, c);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
				
			|||||||
@ -22,7 +22,7 @@ int mp_invmod_slow (mp_int * a, mp_int * b, mp_int * c)
 | 
				
			|||||||
  int     res;
 | 
					  int     res;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /* b cannot be negative */
 | 
					  /* b cannot be negative */
 | 
				
			||||||
  if (b->sign == MP_NEG || mp_iszero(b) == 1) {
 | 
					  if (b->sign == MP_NEG || mp_iszero(b) == MP_YES) {
 | 
				
			||||||
    return MP_VAL;
 | 
					    return MP_VAL;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -41,7 +41,7 @@ int mp_invmod_slow (mp_int * a, mp_int * b, mp_int * c)
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /* 2. [modified] if x,y are both even then return an error! */
 | 
					  /* 2. [modified] if x,y are both even then return an error! */
 | 
				
			||||||
  if (mp_iseven (&x) == 1 && mp_iseven (&y) == 1) {
 | 
					  if (mp_iseven (&x) == MP_YES && mp_iseven (&y) == MP_YES) {
 | 
				
			||||||
    res = MP_VAL;
 | 
					    res = MP_VAL;
 | 
				
			||||||
    goto LBL_ERR;
 | 
					    goto LBL_ERR;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
@ -58,13 +58,13 @@ int mp_invmod_slow (mp_int * a, mp_int * b, mp_int * c)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
top:
 | 
					top:
 | 
				
			||||||
  /* 4.  while u is even do */
 | 
					  /* 4.  while u is even do */
 | 
				
			||||||
  while (mp_iseven (&u) == 1) {
 | 
					  while (mp_iseven (&u) == MP_YES) {
 | 
				
			||||||
    /* 4.1 u = u/2 */
 | 
					    /* 4.1 u = u/2 */
 | 
				
			||||||
    if ((res = mp_div_2 (&u, &u)) != MP_OKAY) {
 | 
					    if ((res = mp_div_2 (&u, &u)) != MP_OKAY) {
 | 
				
			||||||
      goto LBL_ERR;
 | 
					      goto LBL_ERR;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    /* 4.2 if A or B is odd then */
 | 
					    /* 4.2 if A or B is odd then */
 | 
				
			||||||
    if (mp_isodd (&A) == 1 || mp_isodd (&B) == 1) {
 | 
					    if (mp_isodd (&A) == MP_YES || mp_isodd (&B) == MP_YES) {
 | 
				
			||||||
      /* A = (A+y)/2, B = (B-x)/2 */
 | 
					      /* A = (A+y)/2, B = (B-x)/2 */
 | 
				
			||||||
      if ((res = mp_add (&A, &y, &A)) != MP_OKAY) {
 | 
					      if ((res = mp_add (&A, &y, &A)) != MP_OKAY) {
 | 
				
			||||||
         goto LBL_ERR;
 | 
					         goto LBL_ERR;
 | 
				
			||||||
@ -83,13 +83,13 @@ top:
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /* 5.  while v is even do */
 | 
					  /* 5.  while v is even do */
 | 
				
			||||||
  while (mp_iseven (&v) == 1) {
 | 
					  while (mp_iseven (&v) == MP_YES) {
 | 
				
			||||||
    /* 5.1 v = v/2 */
 | 
					    /* 5.1 v = v/2 */
 | 
				
			||||||
    if ((res = mp_div_2 (&v, &v)) != MP_OKAY) {
 | 
					    if ((res = mp_div_2 (&v, &v)) != MP_OKAY) {
 | 
				
			||||||
      goto LBL_ERR;
 | 
					      goto LBL_ERR;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    /* 5.2 if C or D is odd then */
 | 
					    /* 5.2 if C or D is odd then */
 | 
				
			||||||
    if (mp_isodd (&C) == 1 || mp_isodd (&D) == 1) {
 | 
					    if (mp_isodd (&C) == MP_YES || mp_isodd (&D) == MP_YES) {
 | 
				
			||||||
      /* C = (C+y)/2, D = (D-x)/2 */
 | 
					      /* C = (C+y)/2, D = (D-x)/2 */
 | 
				
			||||||
      if ((res = mp_add (&C, &y, &C)) != MP_OKAY) {
 | 
					      if ((res = mp_add (&C, &y, &C)) != MP_OKAY) {
 | 
				
			||||||
         goto LBL_ERR;
 | 
					         goto LBL_ERR;
 | 
				
			||||||
@ -137,7 +137,7 @@ top:
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /* if not zero goto step 4 */
 | 
					  /* if not zero goto step 4 */
 | 
				
			||||||
  if (mp_iszero (&u) == 0)
 | 
					  if (mp_iszero (&u) == MP_NO)
 | 
				
			||||||
    goto top;
 | 
					    goto top;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /* now a = C, b = D, gcd == g*v */
 | 
					  /* now a = C, b = D, gcd == g*v */
 | 
				
			||||||
 | 
				
			|||||||
@ -82,13 +82,13 @@ int mp_is_square(mp_int *arg,int *ret)
 | 
				
			|||||||
   * free "t" so the easiest way is to goto ERR.  We know that res
 | 
					   * free "t" so the easiest way is to goto ERR.  We know that res
 | 
				
			||||||
   * is already equal to MP_OKAY from the mp_mod call 
 | 
					   * is already equal to MP_OKAY from the mp_mod call 
 | 
				
			||||||
   */ 
 | 
					   */ 
 | 
				
			||||||
  if ( (1L<<(r%11)) & 0x5C4L )             goto ERR;
 | 
					  if (((1L<<(r%11)) & 0x5C4L) != 0L)       goto ERR;
 | 
				
			||||||
  if ( (1L<<(r%13)) & 0x9E4L )             goto ERR;
 | 
					  if (((1L<<(r%13)) & 0x9E4L) != 0L)       goto ERR;
 | 
				
			||||||
  if ( (1L<<(r%17)) & 0x5CE8L )            goto ERR;
 | 
					  if (((1L<<(r%17)) & 0x5CE8L) != 0L)      goto ERR;
 | 
				
			||||||
  if ( (1L<<(r%19)) & 0x4F50CL )           goto ERR;
 | 
					  if (((1L<<(r%19)) & 0x4F50CL) != 0L)     goto ERR;
 | 
				
			||||||
  if ( (1L<<(r%23)) & 0x7ACCA0L )          goto ERR;
 | 
					  if (((1L<<(r%23)) & 0x7ACCA0L) != 0L)    goto ERR;
 | 
				
			||||||
  if ( (1L<<(r%29)) & 0xC2EDD0CL )         goto ERR;
 | 
					  if (((1L<<(r%29)) & 0xC2EDD0CL) != 0L)   goto ERR;
 | 
				
			||||||
  if ( (1L<<(r%31)) & 0x6DE2B848L )        goto ERR;
 | 
					  if (((1L<<(r%31)) & 0x6DE2B848L) != 0L)  goto ERR;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /* Final check - is sqr(sqrt(arg)) == arg ? */
 | 
					  /* Final check - is sqr(sqrt(arg)) == arg ? */
 | 
				
			||||||
  if ((res = mp_sqrt(arg,&t)) != MP_OKAY) {
 | 
					  if ((res = mp_sqrt(arg,&t)) != MP_OKAY) {
 | 
				
			||||||
 | 
				
			|||||||
@ -30,7 +30,7 @@ int mp_jacobi (mp_int * a, mp_int * p, int *c)
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /* step 1.  if a == 0, return 0 */
 | 
					  /* step 1.  if a == 0, return 0 */
 | 
				
			||||||
  if (mp_iszero (a) == 1) {
 | 
					  if (mp_iszero (a) == MP_YES) {
 | 
				
			||||||
    *c = 0;
 | 
					    *c = 0;
 | 
				
			||||||
    return MP_OKAY;
 | 
					    return MP_OKAY;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
				
			|||||||
@ -31,7 +31,7 @@ mp_mod (mp_int * a, mp_int * b, mp_int * c)
 | 
				
			|||||||
    return res;
 | 
					    return res;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (mp_iszero(&t) || t.sign == b->sign) {
 | 
					  if (mp_iszero(&t) != MP_NO || t.sign == b->sign) {
 | 
				
			||||||
    res = MP_OKAY;
 | 
					    res = MP_OKAY;
 | 
				
			||||||
    mp_exch (&t, c);
 | 
					    mp_exch (&t, c);
 | 
				
			||||||
  } else {
 | 
					  } else {
 | 
				
			||||||
 | 
				
			|||||||
@ -85,7 +85,7 @@ mp_montgomery_reduce (mp_int * x, mp_int * n, mp_digit rho)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      /* propagate carries upwards as required*/
 | 
					      /* propagate carries upwards as required*/
 | 
				
			||||||
      while (u) {
 | 
					      while (u != 0) {
 | 
				
			||||||
        *tmpx   += u;
 | 
					        *tmpx   += u;
 | 
				
			||||||
        u        = *tmpx >> DIGIT_BIT;
 | 
					        u        = *tmpx >> DIGIT_BIT;
 | 
				
			||||||
        *tmpx++ &= MP_MASK;
 | 
					        *tmpx++ &= MP_MASK;
 | 
				
			||||||
 | 
				
			|||||||
@ -49,12 +49,13 @@ int mp_mul (mp_int * a, mp_int * b, mp_int * c)
 | 
				
			|||||||
      res = fast_s_mp_mul_digs (a, b, c, digs);
 | 
					      res = fast_s_mp_mul_digs (a, b, c, digs);
 | 
				
			||||||
    } else 
 | 
					    } else 
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
#ifdef BN_S_MP_MUL_DIGS_C
 | 
					#ifdef BN_S_MP_MUL_DIGS_C
 | 
				
			||||||
      res = s_mp_mul (a, b, c); /* uses s_mp_mul_digs */
 | 
					      res = s_mp_mul (a, b, c); /* uses s_mp_mul_digs */
 | 
				
			||||||
#else
 | 
					#else
 | 
				
			||||||
      res = MP_VAL;
 | 
					      res = MP_VAL;
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  c->sign = (c->used > 0) ? neg : MP_ZPOS;
 | 
					  c->sign = (c->used > 0) ? neg : MP_ZPOS;
 | 
				
			||||||
  return res;
 | 
					  return res;
 | 
				
			||||||
 | 
				
			|||||||
@ -84,7 +84,7 @@ int mp_prime_next_prime(mp_int *a, int t, int bbs_style)
 | 
				
			|||||||
         if ((err = mp_sub_d(a, (a->dp[0] & 3) + 1, a)) != MP_OKAY) { return err; };
 | 
					         if ((err = mp_sub_d(a, (a->dp[0] & 3) + 1, a)) != MP_OKAY) { return err; };
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
   } else {
 | 
					   } else {
 | 
				
			||||||
      if (mp_iseven(a) == 1) {
 | 
					      if (mp_iseven(a) == MP_YES) {
 | 
				
			||||||
         /* force odd */
 | 
					         /* force odd */
 | 
				
			||||||
         if ((err = mp_sub_d(a, 1, a)) != MP_OKAY) {
 | 
					         if ((err = mp_sub_d(a, 1, a)) != MP_OKAY) {
 | 
				
			||||||
            return err;
 | 
					            return err;
 | 
				
			||||||
 | 
				
			|||||||
@ -41,7 +41,7 @@ int mp_prime_random_ex(mp_int *a, int t, int size, int flags, ltm_prime_callback
 | 
				
			|||||||
   }
 | 
					   }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   /* LTM_PRIME_SAFE implies LTM_PRIME_BBS */
 | 
					   /* LTM_PRIME_SAFE implies LTM_PRIME_BBS */
 | 
				
			||||||
   if (flags & LTM_PRIME_SAFE) {
 | 
					   if ((flags & LTM_PRIME_SAFE) != 0) {
 | 
				
			||||||
      flags |= LTM_PRIME_BBS;
 | 
					      flags |= LTM_PRIME_BBS;
 | 
				
			||||||
   }
 | 
					   }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -60,13 +60,13 @@ int mp_prime_random_ex(mp_int *a, int t, int size, int flags, ltm_prime_callback
 | 
				
			|||||||
   /* calc the maskOR_msb */
 | 
					   /* calc the maskOR_msb */
 | 
				
			||||||
   maskOR_msb        = 0;
 | 
					   maskOR_msb        = 0;
 | 
				
			||||||
   maskOR_msb_offset = ((size & 7) == 1) ? 1 : 0;
 | 
					   maskOR_msb_offset = ((size & 7) == 1) ? 1 : 0;
 | 
				
			||||||
   if (flags & LTM_PRIME_2MSB_ON) {
 | 
					   if ((flags & LTM_PRIME_2MSB_ON) != 0) {
 | 
				
			||||||
      maskOR_msb       |= 0x80 >> ((9 - size) & 7);
 | 
					      maskOR_msb       |= 0x80 >> ((9 - size) & 7);
 | 
				
			||||||
   }  
 | 
					   }  
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   /* get the maskOR_lsb */
 | 
					   /* get the maskOR_lsb */
 | 
				
			||||||
   maskOR_lsb         = 1;
 | 
					   maskOR_lsb         = 1;
 | 
				
			||||||
   if (flags & LTM_PRIME_BBS) {
 | 
					   if ((flags & LTM_PRIME_BBS) != 0) {
 | 
				
			||||||
      maskOR_lsb     |= 3;
 | 
					      maskOR_lsb     |= 3;
 | 
				
			||||||
   }
 | 
					   }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -94,7 +94,7 @@ int mp_prime_random_ex(mp_int *a, int t, int size, int flags, ltm_prime_callback
 | 
				
			|||||||
         continue;
 | 
					         continue;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      if (flags & LTM_PRIME_SAFE) {
 | 
					      if ((flags & LTM_PRIME_SAFE) != 0) {
 | 
				
			||||||
         /* see if (a-1)/2 is prime */
 | 
					         /* see if (a-1)/2 is prime */
 | 
				
			||||||
         if ((err = mp_sub_d(a, 1, a)) != MP_OKAY)                    { goto error; }
 | 
					         if ((err = mp_sub_d(a, 1, a)) != MP_OKAY)                    { goto error; }
 | 
				
			||||||
         if ((err = mp_div_2(a, a)) != MP_OKAY)                       { goto error; }
 | 
					         if ((err = mp_div_2(a, a)) != MP_OKAY)                       { goto error; }
 | 
				
			||||||
@ -104,7 +104,7 @@ int mp_prime_random_ex(mp_int *a, int t, int size, int flags, ltm_prime_callback
 | 
				
			|||||||
      }
 | 
					      }
 | 
				
			||||||
   } while (res == MP_NO);
 | 
					   } while (res == MP_NO);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   if (flags & LTM_PRIME_SAFE) {
 | 
					   if ((flags & LTM_PRIME_SAFE) != 0) {
 | 
				
			||||||
      /* restore a to the original value */
 | 
					      /* restore a to the original value */
 | 
				
			||||||
      if ((err = mp_mul_2(a, a)) != MP_OKAY)                          { goto error; }
 | 
					      if ((err = mp_mul_2(a, a)) != MP_OKAY)                          { goto error; }
 | 
				
			||||||
      if ((err = mp_add_d(a, 1, a)) != MP_OKAY)                       { goto error; }
 | 
					      if ((err = mp_add_d(a, 1, a)) != MP_OKAY)                       { goto error; }
 | 
				
			||||||
 | 
				
			|||||||
@ -43,12 +43,12 @@ int mp_read_radix (mp_int * a, const char *str, int radix)
 | 
				
			|||||||
  mp_zero (a);
 | 
					  mp_zero (a);
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  /* process each digit of the string */
 | 
					  /* process each digit of the string */
 | 
				
			||||||
  while (*str) {
 | 
					  while (*str != '\0') {
 | 
				
			||||||
    /* if the radix <= 36 the conversion is case insensitive
 | 
					    /* if the radix <= 36 the conversion is case insensitive
 | 
				
			||||||
     * this allows numbers like 1AB and 1ab to represent the same  value
 | 
					     * this allows numbers like 1AB and 1ab to represent the same  value
 | 
				
			||||||
     * [e.g. in hex]
 | 
					     * [e.g. in hex]
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    ch = (char) ((radix <= 36) ? toupper ((int)*str) : *str);
 | 
					    ch = (radix <= 36) ? (char)toupper((int)*str) : *str;
 | 
				
			||||||
    for (y = 0; y < 64; y++) {
 | 
					    for (y = 0; y < 64; y++) {
 | 
				
			||||||
      if (ch == mp_s_rmap[y]) {
 | 
					      if (ch == mp_s_rmap[y]) {
 | 
				
			||||||
         break;
 | 
					         break;
 | 
				
			||||||
@ -73,7 +73,7 @@ int mp_read_radix (mp_int * a, const char *str, int radix)
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  /* set the sign only if a != 0 */
 | 
					  /* set the sign only if a != 0 */
 | 
				
			||||||
  if (mp_iszero(a) != 1) {
 | 
					  if (mp_iszero(a) != MP_YES) {
 | 
				
			||||||
     a->sign = neg;
 | 
					     a->sign = neg;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  return MP_OKAY;
 | 
					  return MP_OKAY;
 | 
				
			||||||
 | 
				
			|||||||
@ -45,7 +45,9 @@ top:
 | 
				
			|||||||
   }
 | 
					   }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   if (mp_cmp_mag(a, n) != MP_LT) {
 | 
					   if (mp_cmp_mag(a, n) != MP_LT) {
 | 
				
			||||||
      s_mp_sub(a, n, a);
 | 
					      if ((res = s_mp_sub(a, n, a)) != MP_OKAY) {
 | 
				
			||||||
 | 
					         goto ERR;
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
      goto top;
 | 
					      goto top;
 | 
				
			||||||
   }
 | 
					   }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -46,7 +46,9 @@ top:
 | 
				
			|||||||
   }
 | 
					   }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   if (mp_cmp_mag(a, n) != MP_LT) {
 | 
					   if (mp_cmp_mag(a, n) != MP_LT) {
 | 
				
			||||||
      s_mp_sub(a, n, a);
 | 
					      if ((res = s_mp_sub(a, n, a)) != MP_OKAY) {
 | 
				
			||||||
 | 
					         goto ERR;
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
      goto top;
 | 
					      goto top;
 | 
				
			||||||
   }
 | 
					   }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -21,8 +21,9 @@ int mp_shrink (mp_int * a)
 | 
				
			|||||||
  mp_digit *tmp;
 | 
					  mp_digit *tmp;
 | 
				
			||||||
  int used = 1;
 | 
					  int used = 1;
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  if(a->used > 0)
 | 
					  if(a->used > 0) {
 | 
				
			||||||
    used = a->used;
 | 
					    used = a->used;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  if (a->alloc != used) {
 | 
					  if (a->alloc != used) {
 | 
				
			||||||
    if ((tmp = OPT_CAST(mp_digit) XREALLOC (a->dp, sizeof (mp_digit) * used)) == NULL) {
 | 
					    if ((tmp = OPT_CAST(mp_digit) XREALLOC (a->dp, sizeof (mp_digit) * used)) == NULL) {
 | 
				
			||||||
 | 
				
			|||||||
@ -29,7 +29,7 @@ mp_sqr (mp_int * a, mp_int * b)
 | 
				
			|||||||
  } else 
 | 
					  } else 
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
#ifdef BN_MP_KARATSUBA_SQR_C
 | 
					#ifdef BN_MP_KARATSUBA_SQR_C
 | 
				
			||||||
if (a->used >= KARATSUBA_SQR_CUTOFF) {
 | 
					  if (a->used >= KARATSUBA_SQR_CUTOFF) {
 | 
				
			||||||
    res = mp_karatsuba_sqr (a, b);
 | 
					    res = mp_karatsuba_sqr (a, b);
 | 
				
			||||||
  } else 
 | 
					  } else 
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
@ -42,12 +42,14 @@ if (a->used >= KARATSUBA_SQR_CUTOFF) {
 | 
				
			|||||||
      res = fast_s_mp_sqr (a, b);
 | 
					      res = fast_s_mp_sqr (a, b);
 | 
				
			||||||
    } else
 | 
					    } else
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
#ifdef BN_S_MP_SQR_C
 | 
					#ifdef BN_S_MP_SQR_C
 | 
				
			||||||
      res = s_mp_sqr (a, b);
 | 
					      res = s_mp_sqr (a, b);
 | 
				
			||||||
#else
 | 
					#else
 | 
				
			||||||
      res = MP_VAL;
 | 
					      res = MP_VAL;
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
  b->sign = MP_ZPOS;
 | 
					  b->sign = MP_ZPOS;
 | 
				
			||||||
  return res;
 | 
					  return res;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -23,7 +23,7 @@ int mp_to_signed_bin (mp_int * a, unsigned char *b)
 | 
				
			|||||||
  if ((res = mp_to_unsigned_bin (a, b + 1)) != MP_OKAY) {
 | 
					  if ((res = mp_to_unsigned_bin (a, b + 1)) != MP_OKAY) {
 | 
				
			||||||
    return res;
 | 
					    return res;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  b[0] = (unsigned char) ((a->sign == MP_ZPOS) ? 0 : 1);
 | 
					  b[0] = (a->sign == MP_ZPOS) ? (unsigned char)0 : (unsigned char)1;
 | 
				
			||||||
  return MP_OKAY;
 | 
					  return MP_OKAY;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
				
			|||||||
@ -26,7 +26,7 @@ int mp_to_unsigned_bin (mp_int * a, unsigned char *b)
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  x = 0;
 | 
					  x = 0;
 | 
				
			||||||
  while (mp_iszero (&t) == 0) {
 | 
					  while (mp_iszero (&t) == MP_NO) {
 | 
				
			||||||
#ifndef MP_8BIT
 | 
					#ifndef MP_8BIT
 | 
				
			||||||
      b[x++] = (unsigned char) (t.dp[0] & 255);
 | 
					      b[x++] = (unsigned char) (t.dp[0] & 255);
 | 
				
			||||||
#else
 | 
					#else
 | 
				
			||||||
 | 
				
			|||||||
@ -46,7 +46,9 @@ int mp_toom_mul(mp_int *a, mp_int *b, mp_int *c)
 | 
				
			|||||||
       goto ERR;
 | 
					       goto ERR;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    mp_rshd(&a1, B);
 | 
					    mp_rshd(&a1, B);
 | 
				
			||||||
    mp_mod_2d(&a1, DIGIT_BIT * B, &a1);
 | 
					    if ((res = mp_mod_2d(&a1, DIGIT_BIT * B, &a1)) != MP_OKAY) {
 | 
				
			||||||
 | 
					       goto ERR;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if ((res = mp_copy(a, &a2)) != MP_OKAY) {
 | 
					    if ((res = mp_copy(a, &a2)) != MP_OKAY) {
 | 
				
			||||||
       goto ERR;
 | 
					       goto ERR;
 | 
				
			||||||
@ -62,7 +64,7 @@ int mp_toom_mul(mp_int *a, mp_int *b, mp_int *c)
 | 
				
			|||||||
       goto ERR;
 | 
					       goto ERR;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    mp_rshd(&b1, B);
 | 
					    mp_rshd(&b1, B);
 | 
				
			||||||
    mp_mod_2d(&b1, DIGIT_BIT * B, &b1);
 | 
					    (void)mp_mod_2d(&b1, DIGIT_BIT * B, &b1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if ((res = mp_copy(b, &b2)) != MP_OKAY) {
 | 
					    if ((res = mp_copy(b, &b2)) != MP_OKAY) {
 | 
				
			||||||
       goto ERR;
 | 
					       goto ERR;
 | 
				
			||||||
 | 
				
			|||||||
@ -39,7 +39,9 @@ mp_toom_sqr(mp_int *a, mp_int *b)
 | 
				
			|||||||
       goto ERR;
 | 
					       goto ERR;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    mp_rshd(&a1, B);
 | 
					    mp_rshd(&a1, B);
 | 
				
			||||||
    mp_mod_2d(&a1, DIGIT_BIT * B, &a1);
 | 
					    if ((res = mp_mod_2d(&a1, DIGIT_BIT * B, &a1)) != MP_OKAY) {
 | 
				
			||||||
 | 
					       goto ERR;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if ((res = mp_copy(a, &a2)) != MP_OKAY) {
 | 
					    if ((res = mp_copy(a, &a2)) != MP_OKAY) {
 | 
				
			||||||
       goto ERR;
 | 
					       goto ERR;
 | 
				
			||||||
 | 
				
			|||||||
@ -29,7 +29,7 @@ int mp_toradix (mp_int * a, char *str, int radix)
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /* quick out if its zero */
 | 
					  /* quick out if its zero */
 | 
				
			||||||
  if (mp_iszero(a) == 1) {
 | 
					  if (mp_iszero(a) == MP_YES) {
 | 
				
			||||||
     *str++ = '0';
 | 
					     *str++ = '0';
 | 
				
			||||||
     *str = '\0';
 | 
					     *str = '\0';
 | 
				
			||||||
     return MP_OKAY;
 | 
					     return MP_OKAY;
 | 
				
			||||||
@ -47,7 +47,7 @@ int mp_toradix (mp_int * a, char *str, int radix)
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  digs = 0;
 | 
					  digs = 0;
 | 
				
			||||||
  while (mp_iszero (&t) == 0) {
 | 
					  while (mp_iszero (&t) == MP_NO) {
 | 
				
			||||||
    if ((res = mp_div_d (&t, (mp_digit) radix, &t, &d)) != MP_OKAY) {
 | 
					    if ((res = mp_div_d (&t, (mp_digit) radix, &t, &d)) != MP_OKAY) {
 | 
				
			||||||
      mp_clear (&t);
 | 
					      mp_clear (&t);
 | 
				
			||||||
      return res;
 | 
					      return res;
 | 
				
			||||||
 | 
				
			|||||||
@ -56,7 +56,7 @@ int mp_toradix_n(mp_int * a, char *str, int radix, int maxlen)
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  digs = 0;
 | 
					  digs = 0;
 | 
				
			||||||
  while (mp_iszero (&t) == 0) {
 | 
					  while (mp_iszero (&t) == MP_NO) {
 | 
				
			||||||
    if (--maxlen < 1) {
 | 
					    if (--maxlen < 1) {
 | 
				
			||||||
       /* no more room */
 | 
					       /* no more room */
 | 
				
			||||||
       break;
 | 
					       break;
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										18
									
								
								tommath.h
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								tommath.h
									
									
									
									
									
								
							@ -25,11 +25,11 @@
 | 
				
			|||||||
#include <tommath_class.h>
 | 
					#include <tommath_class.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifndef MIN
 | 
					#ifndef MIN
 | 
				
			||||||
   #define MIN(x,y) ((x)<(y)?(x):(y))
 | 
					   #define MIN(x,y) (((x) < (y)) ? (x) : (y))
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifndef MAX
 | 
					#ifndef MAX
 | 
				
			||||||
   #define MAX(x,y) ((x)>(y)?(x):(y))
 | 
					   #define MAX(x,y) (((x) > (y)) ? (x) : (y))
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef __cplusplus
 | 
					#ifdef __cplusplus
 | 
				
			||||||
@ -200,7 +200,7 @@ extern int KARATSUBA_MUL_CUTOFF,
 | 
				
			|||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* size of comba arrays, should be at least 2 * 2**(BITS_PER_WORD - BITS_PER_DIGIT*2) */
 | 
					/* size of comba arrays, should be at least 2 * 2**(BITS_PER_WORD - BITS_PER_DIGIT*2) */
 | 
				
			||||||
#define MP_WARRAY               (1 << (sizeof(mp_word) * CHAR_BIT - 2 * DIGIT_BIT + 1))
 | 
					#define MP_WARRAY               (1 << (((sizeof(mp_word) * CHAR_BIT) - (2 * DIGIT_BIT)) + 1))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* the infamous mp_int structure */
 | 
					/* the infamous mp_int structure */
 | 
				
			||||||
typedef struct  {
 | 
					typedef struct  {
 | 
				
			||||||
@ -246,9 +246,9 @@ int mp_init_size(mp_int *a, int size);
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
/* ---> Basic Manipulations <--- */
 | 
					/* ---> Basic Manipulations <--- */
 | 
				
			||||||
#define mp_iszero(a) (((a)->used == 0) ? MP_YES : MP_NO)
 | 
					#define mp_iszero(a) (((a)->used == 0) ? MP_YES : MP_NO)
 | 
				
			||||||
#define mp_iseven(a) (((a)->used > 0 && (((a)->dp[0] & 1) == 0)) ? MP_YES : MP_NO)
 | 
					#define mp_iseven(a) ((((a)->used > 0) && (((a)->dp[0] & 1) == 0)) ? MP_YES : MP_NO)
 | 
				
			||||||
#define mp_isodd(a)  (((a)->used > 0 && (((a)->dp[0] & 1) == 1)) ? MP_YES : MP_NO)
 | 
					#define mp_isodd(a)  ((((a)->used > 0) && (((a)->dp[0] & 1) == 1)) ? MP_YES : MP_NO)
 | 
				
			||||||
#define mp_isneg(a)  (((a)->sign) ? MP_YES : MP_NO)
 | 
					#define mp_isneg(a)  (((a)->sign != MP_ZPOS) ? MP_YES : MP_NO)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* set to zero */
 | 
					/* set to zero */
 | 
				
			||||||
void mp_zero(mp_int *a);
 | 
					void mp_zero(mp_int *a);
 | 
				
			||||||
@ -504,7 +504,7 @@ int mp_exptmod(mp_int *a, mp_int *b, mp_int *c, mp_int *d);
 | 
				
			|||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* table of first PRIME_SIZE primes */
 | 
					/* table of first PRIME_SIZE primes */
 | 
				
			||||||
extern const mp_digit ltm_prime_tab[];
 | 
					extern const mp_digit ltm_prime_tab[PRIME_SIZE];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* result=1 if a is divisible by one of the first PRIME_SIZE primes */
 | 
					/* result=1 if a is divisible by one of the first PRIME_SIZE primes */
 | 
				
			||||||
int mp_prime_is_divisible(mp_int *a, int *result);
 | 
					int mp_prime_is_divisible(mp_int *a, int *result);
 | 
				
			||||||
@ -639,14 +639,14 @@ int func_name (mp_int * a, type b)                       \
 | 
				
			|||||||
  mp_zero (a);                                           \
 | 
					  mp_zero (a);                                           \
 | 
				
			||||||
                                                         \
 | 
					                                                         \
 | 
				
			||||||
  /* set four bits at a time */                          \
 | 
					  /* set four bits at a time */                          \
 | 
				
			||||||
  for (x = 0; x < sizeof(type) * 2; x++) {               \
 | 
					  for (x = 0; x < (sizeof(type) * 2); x++) {             \
 | 
				
			||||||
    /* shift the number up four bits */                  \
 | 
					    /* shift the number up four bits */                  \
 | 
				
			||||||
    if ((res = mp_mul_2d (a, 4, a)) != MP_OKAY) {        \
 | 
					    if ((res = mp_mul_2d (a, 4, a)) != MP_OKAY) {        \
 | 
				
			||||||
      return res;                                        \
 | 
					      return res;                                        \
 | 
				
			||||||
    }                                                    \
 | 
					    }                                                    \
 | 
				
			||||||
                                                         \
 | 
					                                                         \
 | 
				
			||||||
    /* OR in the top four bits of the source */          \
 | 
					    /* OR in the top four bits of the source */          \
 | 
				
			||||||
    a->dp[0] |= (b >> ((sizeof(type)) * 8 - 4)) & 15;    \
 | 
					    a->dp[0] |= (b >> ((sizeof(type) * 8) - 4)) & 15;    \
 | 
				
			||||||
                                                         \
 | 
					                                                         \
 | 
				
			||||||
    /* shift the source up to the next four bits */      \
 | 
					    /* shift the source up to the next four bits */      \
 | 
				
			||||||
    b <<= 4;                                             \
 | 
					    b <<= 4;                                             \
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user