refactor cast
This commit is contained in:
		
							parent
							
								
									bdbed00079
								
							
						
					
					
						commit
						f1d6c88759
					
				| @ -27,10 +27,10 @@ static const struct { | |||||||
| /* return a char * string for a given code */ | /* return a char * string for a given code */ | ||||||
| const char *mp_error_to_string(int code) | const char *mp_error_to_string(int code) | ||||||
| { | { | ||||||
|    int x; |    size_t x; | ||||||
| 
 | 
 | ||||||
|    /* scan the lookup table for the given message */ |    /* scan the lookup table for the given message */ | ||||||
|    for (x = 0; x < (int)(sizeof(msgs) / sizeof(msgs[0])); x++) { |    for (x = 0; x < (sizeof(msgs) / sizeof(msgs[0])); x++) { | ||||||
|       if (msgs[x].code == code) { |       if (msgs[x].code == code) { | ||||||
|          return msgs[x].msg; |          return msgs[x].msg; | ||||||
|       } |       } | ||||||
|  | |||||||
| @ -28,7 +28,7 @@ int fast_mp_montgomery_reduce(mp_int *x, const mp_int *n, mp_digit rho) | |||||||
|    int     ix, res, olduse; |    int     ix, res, olduse; | ||||||
|    mp_word W[MP_WARRAY]; |    mp_word W[MP_WARRAY]; | ||||||
| 
 | 
 | ||||||
|    if (x->used > MP_WARRAY) { |    if (x->used > (int)MP_WARRAY) { | ||||||
|       return MP_VAL; |       return MP_VAL; | ||||||
|    } |    } | ||||||
| 
 | 
 | ||||||
| @ -77,7 +77,7 @@ int fast_mp_montgomery_reduce(mp_int *x, const mp_int *n, mp_digit rho) | |||||||
|        * that W[ix-1] have  the carry cleared (see after the inner loop) |        * that W[ix-1] have  the carry cleared (see after the inner loop) | ||||||
|        */ |        */ | ||||||
|       mp_digit mu; |       mp_digit mu; | ||||||
|       mu = (mp_digit)(((W[ix] & MP_MASK) * rho) & MP_MASK); |       mu = ((W[ix] & MP_MASK) * rho) & MP_MASK; | ||||||
| 
 | 
 | ||||||
|       /* a = a + mu * m * b**i
 |       /* a = a + mu * m * b**i
 | ||||||
|        * |        * | ||||||
| @ -106,12 +106,12 @@ int fast_mp_montgomery_reduce(mp_int *x, const mp_int *n, mp_digit rho) | |||||||
| 
 | 
 | ||||||
|          /* inner loop */ |          /* inner loop */ | ||||||
|          for (iy = 0; iy < n->used; iy++) { |          for (iy = 0; iy < n->used; iy++) { | ||||||
|             *_W++ += ((mp_word)mu) * ((mp_word)*tmpn++); |             *_W++ += (mp_word)mu * (mp_word)*tmpn++; | ||||||
|          } |          } | ||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
|       /* now fix carry for next digit, W[ix+1] */ |       /* now fix carry for next digit, W[ix+1] */ | ||||||
|       W[ix + 1] += W[ix] >> ((mp_word) DIGIT_BIT); |       W[ix + 1] += W[ix] >> (mp_word)DIGIT_BIT; | ||||||
|    } |    } | ||||||
| 
 | 
 | ||||||
|    /* now we have to propagate the carries and
 |    /* now we have to propagate the carries and
 | ||||||
| @ -131,7 +131,7 @@ int fast_mp_montgomery_reduce(mp_int *x, const mp_int *n, mp_digit rho) | |||||||
|       _W = W + ++ix; |       _W = W + ++ix; | ||||||
| 
 | 
 | ||||||
|       for (; ix <= ((n->used * 2) + 1); ix++) { |       for (; ix <= ((n->used * 2) + 1); ix++) { | ||||||
|          *_W++ += *_W1++ >> ((mp_word) DIGIT_BIT); |          *_W++ += *_W1++ >> (mp_word)DIGIT_BIT; | ||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
|       /* copy out, A = A/b**n
 |       /* copy out, A = A/b**n
 | ||||||
| @ -148,7 +148,7 @@ int fast_mp_montgomery_reduce(mp_int *x, const mp_int *n, mp_digit rho) | |||||||
|       _W = W + n->used; |       _W = W + n->used; | ||||||
| 
 | 
 | ||||||
|       for (ix = 0; ix < (n->used + 1); ix++) { |       for (ix = 0; ix < (n->used + 1); ix++) { | ||||||
|          *tmpx++ = (mp_digit)(*_W++ & ((mp_word) MP_MASK)); |          *tmpx++ = *_W++ & (mp_word)MP_MASK; | ||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
|       /* zero oldused digits, if the input a was larger than
 |       /* zero oldused digits, if the input a was larger than
 | ||||||
|  | |||||||
| @ -69,15 +69,15 @@ int fast_s_mp_mul_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs) | |||||||
| 
 | 
 | ||||||
|       /* execute loop */ |       /* execute loop */ | ||||||
|       for (iz = 0; iz < iy; ++iz) { |       for (iz = 0; iz < iy; ++iz) { | ||||||
|          _W += ((mp_word)*tmpx++)*((mp_word)*tmpy--); |          _W += (mp_word)*tmpx++ * (mp_word)*tmpy--; | ||||||
| 
 | 
 | ||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
|       /* store term */ |       /* store term */ | ||||||
|       W[ix] = ((mp_digit)_W) & MP_MASK; |       W[ix] = (mp_digit)_W & MP_MASK; | ||||||
| 
 | 
 | ||||||
|       /* make next carry */ |       /* make next carry */ | ||||||
|       _W = _W >> ((mp_word)DIGIT_BIT); |       _W = _W >> (mp_word)DIGIT_BIT; | ||||||
|    } |    } | ||||||
| 
 | 
 | ||||||
|    /* setup dest */ |    /* setup dest */ | ||||||
|  | |||||||
| @ -60,14 +60,14 @@ int fast_s_mp_mul_high_digs(const mp_int *a, const mp_int *b, mp_int *c, int dig | |||||||
| 
 | 
 | ||||||
|       /* execute loop */ |       /* execute loop */ | ||||||
|       for (iz = 0; iz < iy; iz++) { |       for (iz = 0; iz < iy; iz++) { | ||||||
|          _W += ((mp_word)*tmpx++)*((mp_word)*tmpy--); |          _W += (mp_word)*tmpx++ * (mp_word)*tmpy--; | ||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
|       /* store term */ |       /* store term */ | ||||||
|       W[ix] = ((mp_digit)_W) & MP_MASK; |       W[ix] = (mp_digit)_W & MP_MASK; | ||||||
| 
 | 
 | ||||||
|       /* make next carry */ |       /* make next carry */ | ||||||
|       _W = _W >> ((mp_word)DIGIT_BIT); |       _W = _W >> (mp_word)DIGIT_BIT; | ||||||
|    } |    } | ||||||
| 
 | 
 | ||||||
|    /* setup dest */ |    /* setup dest */ | ||||||
|  | |||||||
| @ -70,7 +70,7 @@ int fast_s_mp_sqr(const mp_int *a, mp_int *b) | |||||||
| 
 | 
 | ||||||
|       /* execute loop */ |       /* execute loop */ | ||||||
|       for (iz = 0; iz < iy; iz++) { |       for (iz = 0; iz < iy; iz++) { | ||||||
|          _W += ((mp_word)*tmpx++)*((mp_word)*tmpy--); |          _W += (mp_word)*tmpx++ * (mp_word)*tmpy--; | ||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
|       /* double the inner product and add carry */ |       /* double the inner product and add carry */ | ||||||
| @ -78,14 +78,14 @@ int fast_s_mp_sqr(const mp_int *a, mp_int *b) | |||||||
| 
 | 
 | ||||||
|       /* even columns have the square term in them */ |       /* even columns have the square term in them */ | ||||||
|       if (((unsigned)ix & 1u) == 0u) { |       if (((unsigned)ix & 1u) == 0u) { | ||||||
|          _W += ((mp_word)a->dp[ix>>1])*((mp_word)a->dp[ix>>1]); |          _W += (mp_word)a->dp[ix>>1] * (mp_word)a->dp[ix>>1]; | ||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
|       /* store it */ |       /* store it */ | ||||||
|       W[ix] = (mp_digit)(_W & MP_MASK); |       W[ix] = _W & MP_MASK; | ||||||
| 
 | 
 | ||||||
|       /* make next carry */ |       /* make next carry */ | ||||||
|       W1 = _W >> ((mp_word)DIGIT_BIT); |       W1 = _W >> (mp_word)DIGIT_BIT; | ||||||
|    } |    } | ||||||
| 
 | 
 | ||||||
|    /* setup dest */ |    /* setup dest */ | ||||||
|  | |||||||
| @ -36,7 +36,7 @@ int mp_2expt(mp_int *a, int b) | |||||||
|    a->used = (b / DIGIT_BIT) + 1; |    a->used = (b / DIGIT_BIT) + 1; | ||||||
| 
 | 
 | ||||||
|    /* put the single bit in its place */ |    /* put the single bit in its place */ | ||||||
|    a->dp[b / DIGIT_BIT] = ((mp_digit)1) << (b % DIGIT_BIT); |    a->dp[b / DIGIT_BIT] = (mp_digit)1 << (mp_digit)(b % DIGIT_BIT); | ||||||
| 
 | 
 | ||||||
|    return MP_OKAY; |    return MP_OKAY; | ||||||
| } | } | ||||||
|  | |||||||
| @ -31,9 +31,9 @@ int mp_count_bits(const mp_int *a) | |||||||
| 
 | 
 | ||||||
|    /* take the last digit and count the bits in it */ |    /* take the last digit and count the bits in it */ | ||||||
|    q = a->dp[a->used - 1]; |    q = a->dp[a->used - 1]; | ||||||
|    while (q > ((mp_digit) 0)) { |    while (q > (mp_digit)0) { | ||||||
|       ++r; |       ++r; | ||||||
|       q >>= ((mp_digit) 1); |       q >>= (mp_digit)1; | ||||||
|    } |    } | ||||||
|    return r; |    return r; | ||||||
| } | } | ||||||
|  | |||||||
							
								
								
									
										20
									
								
								bn_mp_div.c
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								bn_mp_div.c
									
									
									
									
									
								
							| @ -150,8 +150,8 @@ int mp_div(const mp_int *a, const mp_int *b, mp_int *c, mp_int *d) | |||||||
| 
 | 
 | ||||||
|    /* normalize both x and y, ensure that y >= b/2, [b == 2**DIGIT_BIT] */ |    /* normalize both x and y, ensure that y >= b/2, [b == 2**DIGIT_BIT] */ | ||||||
|    norm = mp_count_bits(&y) % DIGIT_BIT; |    norm = mp_count_bits(&y) % DIGIT_BIT; | ||||||
|    if (norm < (int)(DIGIT_BIT-1)) { |    if (norm < (DIGIT_BIT - 1)) { | ||||||
|       norm = (DIGIT_BIT-1) - norm; |       norm = (DIGIT_BIT - 1) - norm; | ||||||
|       if ((res = mp_mul_2d(&x, norm, &x)) != MP_OKAY) { |       if ((res = mp_mul_2d(&x, norm, &x)) != MP_OKAY) { | ||||||
|          goto LBL_Y; |          goto LBL_Y; | ||||||
|       } |       } | ||||||
| @ -190,16 +190,16 @@ int mp_div(const mp_int *a, const mp_int *b, mp_int *c, mp_int *d) | |||||||
|       /* step 3.1 if xi == yt then set q{i-t-1} to b-1,
 |       /* step 3.1 if xi == yt then set q{i-t-1} to b-1,
 | ||||||
|        * otherwise set q{i-t-1} to (xi*b + x{i-1})/yt */ |        * otherwise set q{i-t-1} to (xi*b + x{i-1})/yt */ | ||||||
|       if (x.dp[i] == y.dp[t]) { |       if (x.dp[i] == y.dp[t]) { | ||||||
|          q.dp[(i - t) - 1] = ((((mp_digit)1) << DIGIT_BIT) - 1); |          q.dp[(i - t) - 1] = ((mp_digit)1 << (mp_digit)DIGIT_BIT) - (mp_digit)1; | ||||||
|       } else { |       } else { | ||||||
|          mp_word tmp; |          mp_word tmp; | ||||||
|          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); | ||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
|       /* while (q{i-t-1} * (yt * b + y{t-1})) >
 |       /* while (q{i-t-1} * (yt * b + y{t-1})) >
 | ||||||
| @ -207,9 +207,9 @@ int mp_div(const mp_int *a, const mp_int *b, mp_int *c, mp_int *d) | |||||||
| 
 | 
 | ||||||
|          do q{i-t-1} -= 1; |          do q{i-t-1} -= 1; | ||||||
|       */ |       */ | ||||||
|       q.dp[(i - t) - 1] = (q.dp[(i - t) - 1] + 1uL) & MP_MASK; |       q.dp[(i - t) - 1] = (q.dp[(i - t) - 1] + 1uL) & (mp_digit)MP_MASK; | ||||||
|       do { |       do { | ||||||
|          q.dp[(i - t) - 1] = (q.dp[(i - t) - 1] - 1uL) & MP_MASK; |          q.dp[(i - t) - 1] = (q.dp[(i - t) - 1] - 1uL) & (mp_digit)MP_MASK; | ||||||
| 
 | 
 | ||||||
|          /* find left hand */ |          /* find left hand */ | ||||||
|          mp_zero(&t1); |          mp_zero(&t1); | ||||||
|  | |||||||
| @ -44,7 +44,7 @@ int mp_div_2d(const mp_int *a, int b, mp_int *c, mp_int *d) | |||||||
|    } |    } | ||||||
| 
 | 
 | ||||||
|    /* shift by as many digits in the bit count */ |    /* shift by as many digits in the bit count */ | ||||||
|    if (b >= (int)DIGIT_BIT) { |    if (b >= DIGIT_BIT) { | ||||||
|       mp_rshd(c, b / DIGIT_BIT); |       mp_rshd(c, b / DIGIT_BIT); | ||||||
|    } |    } | ||||||
| 
 | 
 | ||||||
| @ -57,7 +57,7 @@ int mp_div_2d(const mp_int *a, int b, mp_int *c, mp_int *d) | |||||||
|       mask = (1uL << D) - 1uL; |       mask = (1uL << D) - 1uL; | ||||||
| 
 | 
 | ||||||
|       /* shift for lsb */ |       /* shift for lsb */ | ||||||
|       shift = DIGIT_BIT - D; |       shift = (mp_digit)DIGIT_BIT - D; | ||||||
| 
 | 
 | ||||||
|       /* alias */ |       /* alias */ | ||||||
|       tmpc = c->dp + (c->used - 1); |       tmpc = c->dp + (c->used - 1); | ||||||
|  | |||||||
| @ -24,7 +24,7 @@ int mp_div_3(const mp_int *a, mp_int *c, mp_digit *d) | |||||||
|    int      res, ix; |    int      res, ix; | ||||||
| 
 | 
 | ||||||
|    /* b = 2**DIGIT_BIT / 3 */ |    /* b = 2**DIGIT_BIT / 3 */ | ||||||
|    b = (((mp_word)1) << ((mp_word)DIGIT_BIT)) / ((mp_word)3); |    b = ((mp_word)1 << (mp_word)DIGIT_BIT) / (mp_word)3; | ||||||
| 
 | 
 | ||||||
|    if ((res = mp_init_size(&q, a->used)) != MP_OKAY) { |    if ((res = mp_init_size(&q, a->used)) != MP_OKAY) { | ||||||
|       return res; |       return res; | ||||||
| @ -34,11 +34,11 @@ int mp_div_3(const mp_int *a, mp_int *c, mp_digit *d) | |||||||
|    q.sign = a->sign; |    q.sign = a->sign; | ||||||
|    w = 0; |    w = 0; | ||||||
|    for (ix = a->used - 1; ix >= 0; ix--) { |    for (ix = a->used - 1; ix >= 0; ix--) { | ||||||
|       w = (w << ((mp_word)DIGIT_BIT)) | ((mp_word)a->dp[ix]); |       w = (w << (mp_word)DIGIT_BIT) | (mp_word)a->dp[ix]; | ||||||
| 
 | 
 | ||||||
|       if (w >= 3u) { |       if (w >= 3u) { | ||||||
|          /* multiply w by [1/3] */ |          /* multiply w by [1/3] */ | ||||||
|          t = (w * ((mp_word)b)) >> ((mp_word)DIGIT_BIT); |          t = (w * (mp_word)b) >> (mp_word)DIGIT_BIT; | ||||||
| 
 | 
 | ||||||
|          /* now subtract 3 * [w/3] from w, to get the remainder */ |          /* now subtract 3 * [w/3] from w, to get the remainder */ | ||||||
|          w -= t+t+t; |          w -= t+t+t; | ||||||
|  | |||||||
| @ -25,7 +25,7 @@ static int s_is_power_of_two(mp_digit b, int *p) | |||||||
|    } |    } | ||||||
| 
 | 
 | ||||||
|    for (x = 0; x < DIGIT_BIT; x++) { |    for (x = 0; x < DIGIT_BIT; x++) { | ||||||
|       if (b == (1uL<<x)) { |       if (b == (1uL<<(mp_digit)x)) { | ||||||
|          *p = x; |          *p = x; | ||||||
|          return 1; |          return 1; | ||||||
|       } |       } | ||||||
| @ -60,7 +60,7 @@ int mp_div_d(const mp_int *a, mp_digit b, mp_int *c, mp_digit *d) | |||||||
|    /* power of two ? */ |    /* power of two ? */ | ||||||
|    if (s_is_power_of_two(b, &ix) == 1) { |    if (s_is_power_of_two(b, &ix) == 1) { | ||||||
|       if (d != NULL) { |       if (d != NULL) { | ||||||
|          *d = a->dp[0] & ((1uL<<ix) - 1uL); |          *d = a->dp[0] & ((1uL<<(mp_digit)ix) - 1uL); | ||||||
|       } |       } | ||||||
|       if (c != NULL) { |       if (c != NULL) { | ||||||
|          return mp_div_2d(a, ix, c, NULL); |          return mp_div_2d(a, ix, c, NULL); | ||||||
| @ -84,15 +84,15 @@ int mp_div_d(const mp_int *a, mp_digit b, mp_int *c, mp_digit *d) | |||||||
|    q.sign = a->sign; |    q.sign = a->sign; | ||||||
|    w = 0; |    w = 0; | ||||||
|    for (ix = a->used - 1; ix >= 0; ix--) { |    for (ix = a->used - 1; ix >= 0; ix--) { | ||||||
|       w = (w << ((mp_word)DIGIT_BIT)) | ((mp_word)a->dp[ix]); |       w = (w << (mp_word)DIGIT_BIT) | (mp_word)a->dp[ix]; | ||||||
| 
 | 
 | ||||||
|       if (w >= b) { |       if (w >= b) { | ||||||
|          t = (mp_digit)(w / b); |          t = (mp_digit)(w / b); | ||||||
|          w -= ((mp_word)t) * ((mp_word)b); |          w -= (mp_word)t * (mp_word)b; | ||||||
|       } else { |       } else { | ||||||
|          t = 0; |          t = 0; | ||||||
|       } |       } | ||||||
|       q.dp[ix] = (mp_digit)t; |       q.dp[ix] = t; | ||||||
|    } |    } | ||||||
| 
 | 
 | ||||||
|    if (d != NULL) { |    if (d != NULL) { | ||||||
|  | |||||||
| @ -61,7 +61,7 @@ top: | |||||||
| 
 | 
 | ||||||
|    /* compute (x mod B**m) + k * [x/B**m] inline and inplace */ |    /* compute (x mod B**m) + k * [x/B**m] inline and inplace */ | ||||||
|    for (i = 0; i < m; i++) { |    for (i = 0; i < m; i++) { | ||||||
|       r         = (((mp_word)*tmpx2++) * (mp_word)k) + *tmpx1 + mu; |       r         = ((mp_word)*tmpx2++ * (mp_word)k) + *tmpx1 + mu; | ||||||
|       *tmpx1++  = (mp_digit)(r & MP_MASK); |       *tmpx1++  = (mp_digit)(r & MP_MASK); | ||||||
|       mu        = (mp_digit)(r >> ((mp_word)DIGIT_BIT)); |       mu        = (mp_digit)(r >> ((mp_word)DIGIT_BIT)); | ||||||
|    } |    } | ||||||
|  | |||||||
| @ -21,7 +21,7 @@ void mp_dr_setup(const mp_int *a, mp_digit *d) | |||||||
|    /* the casts are required if DIGIT_BIT is one less than
 |    /* the casts are required if DIGIT_BIT is one less than
 | ||||||
|     * the number of bits in a mp_digit [e.g. DIGIT_BIT==31] |     * the number of bits in a mp_digit [e.g. DIGIT_BIT==31] | ||||||
|     */ |     */ | ||||||
|    *d = (mp_digit)((((mp_word)1) << ((mp_word)DIGIT_BIT)) - ((mp_word)a->dp[0])); |    *d = (mp_digit)(((mp_word)1 << (mp_word)DIGIT_BIT) - (mp_word)a->dp[0]); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #endif | #endif | ||||||
|  | |||||||
| @ -48,7 +48,7 @@ int mp_export(void *rop, size_t *countp, int order, size_t size, | |||||||
|    } |    } | ||||||
|    nail_bytes = nails / 8u; |    nail_bytes = nails / 8u; | ||||||
| 
 | 
 | ||||||
|    bits = mp_count_bits(&t); |    bits = (size_t)mp_count_bits(&t); | ||||||
|    count = (bits / ((size * 8u) - nails)) + (((bits % ((size * 8u) - nails)) != 0u) ? 1u : 0u); |    count = (bits / ((size * 8u) - nails)) + (((bits % ((size * 8u) - nails)) != 0u) ? 1u : 0u); | ||||||
| 
 | 
 | ||||||
|    for (i = 0; i < count; ++i) { |    for (i = 0; i < count; ++i) { | ||||||
|  | |||||||
| @ -52,7 +52,7 @@ int mp_expt_d_ex(const mp_int *a, mp_digit b, mp_int *c, int fast) | |||||||
|          b >>= 1; |          b >>= 1; | ||||||
|       } |       } | ||||||
|    } else { |    } else { | ||||||
|       for (x = 0; x < DIGIT_BIT; x++) { |       for (x = 0; x < (unsigned)DIGIT_BIT; x++) { | ||||||
|          /* square */ |          /* square */ | ||||||
|          if ((res = mp_sqr(c, c)) != MP_OKAY) { |          if ((res = mp_sqr(c, c)) != MP_OKAY) { | ||||||
|             mp_clear(&g); |             mp_clear(&g); | ||||||
| @ -60,7 +60,7 @@ int mp_expt_d_ex(const mp_int *a, mp_digit b, mp_int *c, int fast) | |||||||
|          } |          } | ||||||
| 
 | 
 | ||||||
|          /* if the bit is set multiply */ |          /* if the bit is set multiply */ | ||||||
|          if ((b & (mp_digit)(1uL << (DIGIT_BIT - 1))) != 0u) { |          if ((b & (1uL << (DIGIT_BIT - 1))) != 0u) { | ||||||
|             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; | ||||||
|  | |||||||
| @ -96,7 +96,7 @@ int mp_exptmod_fast(const mp_int *G, const mp_int *X, const mp_int *P, mp_int *Y | |||||||
| 
 | 
 | ||||||
|       /* automatically pick the comba one if available (saves quite a few calls/ifs) */ |       /* automatically pick the comba one if available (saves quite a few calls/ifs) */ | ||||||
| #ifdef BN_FAST_MP_MONTGOMERY_REDUCE_C | #ifdef BN_FAST_MP_MONTGOMERY_REDUCE_C | ||||||
|       if ((((P->used * 2) + 1) < MP_WARRAY) && |       if ((((P->used * 2) + 1) < (int)MP_WARRAY) && | ||||||
|           (P->used < (1 << ((CHAR_BIT * sizeof(mp_word)) - (2 * DIGIT_BIT))))) { |           (P->used < (1 << ((CHAR_BIT * sizeof(mp_word)) - (2 * DIGIT_BIT))))) { | ||||||
|          redux = fast_mp_montgomery_reduce; |          redux = fast_mp_montgomery_reduce; | ||||||
|       } else |       } else | ||||||
|  | |||||||
| @ -27,7 +27,7 @@ int mp_fread(mp_int *a, int radix, FILE *stream) | |||||||
| 
 | 
 | ||||||
|    /* if first digit is - then set negative */ |    /* if first digit is - then set negative */ | ||||||
|    ch = fgetc(stream); |    ch = fgetc(stream); | ||||||
|    if (ch == '-') { |    if (ch == (int)'-') { | ||||||
|       neg = MP_NEG; |       neg = MP_NEG; | ||||||
|       ch = fgetc(stream); |       ch = fgetc(stream); | ||||||
|    } else { |    } else { | ||||||
| @ -35,22 +35,22 @@ int mp_fread(mp_int *a, int radix, FILE *stream) | |||||||
|    } |    } | ||||||
| 
 | 
 | ||||||
|    for (;;) { |    for (;;) { | ||||||
|       pos = ch - '('; |       pos = (unsigned)(ch - (int)'('); | ||||||
|       if (mp_s_rmap_reverse_sz < pos) { |       if (mp_s_rmap_reverse_sz < pos) { | ||||||
|          break; |          break; | ||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
|       y = mp_s_rmap_reverse[pos]; |       y = (int)mp_s_rmap_reverse[pos]; | ||||||
| 
 | 
 | ||||||
|       if (y == 0xff || y >= radix) { |       if (y == 0xff || y >= radix) { | ||||||
|          break; |          break; | ||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
|       /* shift up and add */ |       /* shift up and add */ | ||||||
|       if ((err = mp_mul_d(a, radix, a)) != MP_OKAY) { |       if ((err = mp_mul_d(a, (mp_digit)radix, a)) != MP_OKAY) { | ||||||
|          return err; |          return err; | ||||||
|       } |       } | ||||||
|       if ((err = mp_add_d(a, y, a)) != MP_OKAY) { |       if ((err = mp_add_d(a, (mp_digit)y, a)) != MP_OKAY) { | ||||||
|          return err; |          return err; | ||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -25,7 +25,7 @@ int mp_fwrite(const mp_int *a, int radix, FILE *stream) | |||||||
|       return err; |       return err; | ||||||
|    } |    } | ||||||
| 
 | 
 | ||||||
|    buf = OPT_CAST(char) XMALLOC(len); |    buf = OPT_CAST(char) XMALLOC((size_t)len); | ||||||
|    if (buf == NULL) { |    if (buf == NULL) { | ||||||
|       return MP_MEM; |       return MP_MEM; | ||||||
|    } |    } | ||||||
| @ -36,7 +36,7 @@ int mp_fwrite(const mp_int *a, int radix, FILE *stream) | |||||||
|    } |    } | ||||||
| 
 | 
 | ||||||
|    for (x = 0; x < len; x++) { |    for (x = 0; x < len; x++) { | ||||||
|       if (fputc(buf[x], stream) == EOF) { |       if (fputc((int)buf[x], stream) == EOF) { | ||||||
|          XFREE(buf); |          XFREE(buf); | ||||||
|          return MP_VAL; |          return MP_VAL; | ||||||
|       } |       } | ||||||
|  | |||||||
| @ -26,7 +26,7 @@ unsigned long mp_get_int(const mp_int *a) | |||||||
|    } |    } | ||||||
| 
 | 
 | ||||||
|    /* get number of digits of the lsb we have to read */ |    /* get number of digits of the lsb we have to read */ | ||||||
|    i = MIN(a->used, (int)(((sizeof(unsigned long) * CHAR_BIT) + DIGIT_BIT - 1) / DIGIT_BIT)) - 1; |    i = MIN(a->used, ((((int)sizeof(unsigned long) * CHAR_BIT) + DIGIT_BIT - 1) / DIGIT_BIT)) - 1; | ||||||
| 
 | 
 | ||||||
|    /* get most significant digit of result */ |    /* get most significant digit of result */ | ||||||
|    res = DIGIT(a, i); |    res = DIGIT(a, i); | ||||||
|  | |||||||
| @ -26,7 +26,7 @@ unsigned long mp_get_long(const mp_int *a) | |||||||
|    } |    } | ||||||
| 
 | 
 | ||||||
|    /* get number of digits of the lsb we have to read */ |    /* get number of digits of the lsb we have to read */ | ||||||
|    i = MIN(a->used, (int)(((sizeof(unsigned long) * CHAR_BIT) + DIGIT_BIT - 1) / DIGIT_BIT)) - 1; |    i = MIN(a->used, ((((int)sizeof(unsigned long) * CHAR_BIT) + DIGIT_BIT - 1) / DIGIT_BIT)) - 1; | ||||||
| 
 | 
 | ||||||
|    /* get most significant digit of result */ |    /* get most significant digit of result */ | ||||||
|    res = DIGIT(a, i); |    res = DIGIT(a, i); | ||||||
|  | |||||||
| @ -26,7 +26,7 @@ unsigned long long mp_get_long_long(const mp_int *a) | |||||||
|    } |    } | ||||||
| 
 | 
 | ||||||
|    /* get number of digits of the lsb we have to read */ |    /* get number of digits of the lsb we have to read */ | ||||||
|    i = MIN(a->used, (int)(((sizeof(unsigned long long) * CHAR_BIT) + DIGIT_BIT - 1) / DIGIT_BIT)) - 1; |    i = MIN(a->used, ((((int)sizeof(unsigned long long) * CHAR_BIT) + DIGIT_BIT - 1) / DIGIT_BIT)) - 1; | ||||||
| 
 | 
 | ||||||
|    /* get most significant digit of result */ |    /* get most significant digit of result */ | ||||||
|    res = DIGIT(a, i); |    res = DIGIT(a, i); | ||||||
|  | |||||||
| @ -32,7 +32,7 @@ int mp_grow(mp_int *a, int size) | |||||||
|        * in case the operation failed we don't want |        * in case the operation failed we don't want | ||||||
|        * to overwrite the dp member of a. |        * to overwrite the dp member of a. | ||||||
|        */ |        */ | ||||||
|       tmp = OPT_CAST(mp_digit) XREALLOC(a->dp, sizeof(mp_digit) * size); |       tmp = OPT_CAST(mp_digit) XREALLOC(a->dp, sizeof(mp_digit) * (size_t)size); | ||||||
|       if (tmp == NULL) { |       if (tmp == NULL) { | ||||||
|          /* reallocation failed but "a" is still valid [can be freed] */ |          /* reallocation failed but "a" is still valid [can be freed] */ | ||||||
|          return MP_MEM; |          return MP_MEM; | ||||||
|  | |||||||
| @ -54,7 +54,7 @@ int mp_import(mp_int *rop, size_t count, int order, size_t size, | |||||||
|             return result; |             return result; | ||||||
|          } |          } | ||||||
| 
 | 
 | ||||||
|          rop->dp[0] |= (j == 0u) ? (byte & odd_nail_mask) : byte; |          rop->dp[0] |= (j == 0u) ? (mp_digit)(byte & odd_nail_mask) : (mp_digit)byte; | ||||||
|          rop->used  += 1; |          rop->used  += 1; | ||||||
|       } |       } | ||||||
|    } |    } | ||||||
|  | |||||||
| @ -21,7 +21,7 @@ int mp_init(mp_int *a) | |||||||
|    int i; |    int i; | ||||||
| 
 | 
 | ||||||
|    /* allocate memory required and clear it */ |    /* allocate memory required and clear it */ | ||||||
|    a->dp = OPT_CAST(mp_digit) XMALLOC(sizeof(mp_digit) * MP_PREC); |    a->dp = OPT_CAST(mp_digit) XMALLOC(sizeof(mp_digit) * (size_t)MP_PREC); | ||||||
|    if (a->dp == NULL) { |    if (a->dp == NULL) { | ||||||
|       return MP_MEM; |       return MP_MEM; | ||||||
|    } |    } | ||||||
|  | |||||||
| @ -24,7 +24,7 @@ int mp_init_size(mp_int *a, int size) | |||||||
|    size += (MP_PREC * 2) - (size % MP_PREC); |    size += (MP_PREC * 2) - (size % MP_PREC); | ||||||
| 
 | 
 | ||||||
|    /* alloc mem */ |    /* alloc mem */ | ||||||
|    a->dp = OPT_CAST(mp_digit) XMALLOC(sizeof(mp_digit) * size); |    a->dp = OPT_CAST(mp_digit) XMALLOC(sizeof(mp_digit) * (size_t)size); | ||||||
|    if (a->dp == NULL) { |    if (a->dp == NULL) { | ||||||
|       return MP_MEM; |       return MP_MEM; | ||||||
|    } |    } | ||||||
|  | |||||||
| @ -58,7 +58,7 @@ int mp_is_square(const mp_int *arg, int *ret) | |||||||
|    } |    } | ||||||
| 
 | 
 | ||||||
|    /* First check mod 128 (suppose that DIGIT_BIT is at least 7) */ |    /* First check mod 128 (suppose that DIGIT_BIT is at least 7) */ | ||||||
|    if (rem_128[127u & DIGIT(arg, 0)] == 1) { |    if (rem_128[127u & DIGIT(arg, 0)] == (char)1) { | ||||||
|       return MP_OKAY; |       return MP_OKAY; | ||||||
|    } |    } | ||||||
| 
 | 
 | ||||||
| @ -66,7 +66,7 @@ int mp_is_square(const mp_int *arg, int *ret) | |||||||
|    if ((res = mp_mod_d(arg, 105uL, &c)) != MP_OKAY) { |    if ((res = mp_mod_d(arg, 105uL, &c)) != MP_OKAY) { | ||||||
|       return res; |       return res; | ||||||
|    } |    } | ||||||
|    if (rem_105[c] == 1) { |    if (rem_105[c] == (char)1) { | ||||||
|       return MP_OKAY; |       return MP_OKAY; | ||||||
|    } |    } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -27,7 +27,7 @@ int mp_mod_2d(const mp_int *a, int b, mp_int *c) | |||||||
|    } |    } | ||||||
| 
 | 
 | ||||||
|    /* if the modulus is larger than the value than return */ |    /* if the modulus is larger than the value than return */ | ||||||
|    if (b >= (int)(a->used * DIGIT_BIT)) { |    if (b >= (a->used * DIGIT_BIT)) { | ||||||
|       res = mp_copy(a, c); |       res = mp_copy(a, c); | ||||||
|       return res; |       return res; | ||||||
|    } |    } | ||||||
| @ -43,7 +43,7 @@ int mp_mod_2d(const mp_int *a, int b, mp_int *c) | |||||||
|    } |    } | ||||||
|    /* clear the digit that is not completely outside/inside the modulus */ |    /* clear the digit that is not completely outside/inside the modulus */ | ||||||
|    c->dp[b / DIGIT_BIT] &= |    c->dp[b / DIGIT_BIT] &= | ||||||
|       (mp_digit)((1uL << (((mp_digit) b) % DIGIT_BIT)) - 1uL); |       (1uL << (mp_digit)(b % DIGIT_BIT)) - 1uL; | ||||||
|    mp_clamp(c); |    mp_clamp(c); | ||||||
|    return MP_OKAY; |    return MP_OKAY; | ||||||
| } | } | ||||||
|  | |||||||
| @ -28,8 +28,8 @@ int mp_montgomery_reduce(mp_int *x, const mp_int *n, mp_digit rho) | |||||||
|     * are fixed up in the inner loop. |     * are fixed up in the inner loop. | ||||||
|     */ |     */ | ||||||
|    digs = (n->used * 2) + 1; |    digs = (n->used * 2) + 1; | ||||||
|    if ((digs < MP_WARRAY) && |    if ((digs < (int)MP_WARRAY) && | ||||||
|        (x->used <= MP_WARRAY) && |        (x->used <= (int)MP_WARRAY) && | ||||||
|        (n->used < |        (n->used < | ||||||
|         (int)(1u << (((size_t)CHAR_BIT * sizeof(mp_word)) - (2u * (size_t)DIGIT_BIT))))) { |         (int)(1u << (((size_t)CHAR_BIT * sizeof(mp_word)) - (2u * (size_t)DIGIT_BIT))))) { | ||||||
|       return fast_mp_montgomery_reduce(x, n, rho); |       return fast_mp_montgomery_reduce(x, n, rho); | ||||||
| @ -73,13 +73,13 @@ int mp_montgomery_reduce(mp_int *x, const mp_int *n, mp_digit rho) | |||||||
|          for (iy = 0; iy < n->used; iy++) { |          for (iy = 0; iy < n->used; iy++) { | ||||||
|             /* compute product and sum */ |             /* compute product and sum */ | ||||||
|             r       = ((mp_word)mu * (mp_word)*tmpn++) + |             r       = ((mp_word)mu * (mp_word)*tmpn++) + | ||||||
|                       (mp_word) u + (mp_word) *tmpx; |                       (mp_word)u + (mp_word)*tmpx; | ||||||
| 
 | 
 | ||||||
|             /* get carry */ |             /* get carry */ | ||||||
|             u       = (mp_digit)(r >> ((mp_word) DIGIT_BIT)); |             u       = (mp_digit)(r >> (mp_word)DIGIT_BIT); | ||||||
| 
 | 
 | ||||||
|             /* fix digit */ |             /* fix digit */ | ||||||
|             *tmpx++ = (mp_digit)(r & ((mp_word) MP_MASK)); |             *tmpx++ = (mp_digit)(r & (mp_word)MP_MASK); | ||||||
|          } |          } | ||||||
|          /* At this point the ix'th digit of x should be zero */ |          /* At this point the ix'th digit of x should be zero */ | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -47,7 +47,7 @@ int mp_montgomery_setup(const mp_int *n, mp_digit *rho) | |||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
|    /* rho = -1/m mod b */ |    /* rho = -1/m mod b */ | ||||||
|    *rho = (mp_digit)(((mp_word)1 << ((mp_word) DIGIT_BIT)) - x) & MP_MASK; |    *rho = (mp_digit)(((mp_word)1 << (mp_word)DIGIT_BIT) - x) & MP_MASK; | ||||||
| 
 | 
 | ||||||
|    return MP_OKAY; |    return MP_OKAY; | ||||||
| } | } | ||||||
|  | |||||||
| @ -43,7 +43,7 @@ int mp_mul(const mp_int *a, const mp_int *b, mp_int *c) | |||||||
|          int     digs = a->used + b->used + 1; |          int     digs = a->used + b->used + 1; | ||||||
| 
 | 
 | ||||||
| #ifdef BN_FAST_S_MP_MUL_DIGS_C | #ifdef BN_FAST_S_MP_MUL_DIGS_C | ||||||
|          if ((digs < MP_WARRAY) && |          if ((digs < (int)MP_WARRAY) && | ||||||
|              (MIN(a->used, b->used) <= |              (MIN(a->used, b->used) <= | ||||||
|               (int)(1u << (((size_t)CHAR_BIT * sizeof(mp_word)) - (2u * (size_t)DIGIT_BIT))))) { |               (int)(1u << (((size_t)CHAR_BIT * sizeof(mp_word)) - (2u * (size_t)DIGIT_BIT))))) { | ||||||
|             res = fast_s_mp_mul_digs(a, b, c, digs); |             res = fast_s_mp_mul_digs(a, b, c, digs); | ||||||
|  | |||||||
| @ -46,7 +46,7 @@ int mp_mul_2(const mp_int *a, mp_int *b) | |||||||
|          /* get what will be the *next* carry bit from the
 |          /* get what will be the *next* carry bit from the
 | ||||||
|           * MSB of the current digit |           * MSB of the current digit | ||||||
|           */ |           */ | ||||||
|          rr = *tmpa >> ((mp_digit)(DIGIT_BIT - 1)); |          rr = *tmpa >> (mp_digit)(DIGIT_BIT - 1); | ||||||
| 
 | 
 | ||||||
|          /* now shift up this digit, add in the carry [from the previous] */ |          /* now shift up this digit, add in the carry [from the previous] */ | ||||||
|          *tmpb++ = ((*tmpa++ << 1uL) | r) & MP_MASK; |          *tmpb++ = ((*tmpa++ << 1uL) | r) & MP_MASK; | ||||||
|  | |||||||
| @ -28,14 +28,14 @@ int mp_mul_2d(const mp_int *a, int b, mp_int *c) | |||||||
|       } |       } | ||||||
|    } |    } | ||||||
| 
 | 
 | ||||||
|    if (c->alloc < (int)(c->used + (b / DIGIT_BIT) + 1)) { |    if (c->alloc < (c->used + (b / DIGIT_BIT) + 1)) { | ||||||
|       if ((res = mp_grow(c, c->used + (b / DIGIT_BIT) + 1)) != MP_OKAY) { |       if ((res = mp_grow(c, c->used + (b / DIGIT_BIT) + 1)) != MP_OKAY) { | ||||||
|          return res; |          return res; | ||||||
|       } |       } | ||||||
|    } |    } | ||||||
| 
 | 
 | ||||||
|    /* shift by as many digits in the bit count */ |    /* shift by as many digits in the bit count */ | ||||||
|    if (b >= (int)DIGIT_BIT) { |    if (b >= DIGIT_BIT) { | ||||||
|       if ((res = mp_lshd(c, b / DIGIT_BIT)) != MP_OKAY) { |       if ((res = mp_lshd(c, b / DIGIT_BIT)) != MP_OKAY) { | ||||||
|          return res; |          return res; | ||||||
|       } |       } | ||||||
| @ -51,7 +51,7 @@ int mp_mul_2d(const mp_int *a, int b, mp_int *c) | |||||||
|       mask = (1uL << d) - 1uL; |       mask = (1uL << d) - 1uL; | ||||||
| 
 | 
 | ||||||
|       /* shift for msbs */ |       /* shift for msbs */ | ||||||
|       shift = DIGIT_BIT - d; |       shift = (mp_digit)DIGIT_BIT - d; | ||||||
| 
 | 
 | ||||||
|       /* alias */ |       /* alias */ | ||||||
|       tmpc = c->dp; |       tmpc = c->dp; | ||||||
|  | |||||||
| @ -50,10 +50,10 @@ int mp_mul_d(const mp_int *a, mp_digit b, mp_int *c) | |||||||
|       r       = (mp_word)u + ((mp_word)*tmpa++ * (mp_word)b); |       r       = (mp_word)u + ((mp_word)*tmpa++ * (mp_word)b); | ||||||
| 
 | 
 | ||||||
|       /* mask off higher bits to get a single digit */ |       /* mask off higher bits to get a single digit */ | ||||||
|       *tmpc++ = (mp_digit)(r & ((mp_word)MP_MASK)); |       *tmpc++ = (mp_digit)(r & (mp_word)MP_MASK); | ||||||
| 
 | 
 | ||||||
|       /* send carry into next iteration */ |       /* send carry into next iteration */ | ||||||
|       u       = (mp_digit)(r >> ((mp_word)DIGIT_BIT)); |       u       = (mp_digit)(r >> (mp_word)DIGIT_BIT); | ||||||
|    } |    } | ||||||
| 
 | 
 | ||||||
|    /* store final carry [if any] and increment ix offset  */ |    /* store final carry [if any] and increment ix offset  */ | ||||||
|  | |||||||
| @ -49,7 +49,7 @@ int mp_prime_random_ex(mp_int *a, int t, int size, int flags, ltm_prime_callback | |||||||
|    bsize = (size>>3) + ((size&7)?1:0); |    bsize = (size>>3) + ((size&7)?1:0); | ||||||
| 
 | 
 | ||||||
|    /* we need a buffer of bsize bytes */ |    /* we need a buffer of bsize bytes */ | ||||||
|    tmp = OPT_CAST(unsigned char) XMALLOC(bsize); |    tmp = OPT_CAST(unsigned char) XMALLOC((size_t)bsize); | ||||||
|    if (tmp == NULL) { |    if (tmp == NULL) { | ||||||
|       return MP_MEM; |       return MP_MEM; | ||||||
|    } |    } | ||||||
|  | |||||||
| @ -50,11 +50,11 @@ int mp_read_radix(mp_int *a, const char *str, int radix) | |||||||
|        * [e.g. in hex] |        * [e.g. in hex] | ||||||
|        */ |        */ | ||||||
|       ch = (radix <= 36) ? (char)toupper((int)*str) : *str; |       ch = (radix <= 36) ? (char)toupper((int)*str) : *str; | ||||||
|       pos = ch - '('; |       pos = (unsigned)(ch - '('); | ||||||
|       if (mp_s_rmap_reverse_sz < pos) { |       if (mp_s_rmap_reverse_sz < pos) { | ||||||
|          break; |          break; | ||||||
|       } |       } | ||||||
|       y = mp_s_rmap_reverse[pos]; |       y = (int)mp_s_rmap_reverse[pos]; | ||||||
| 
 | 
 | ||||||
|       /* if the char was found in the map
 |       /* if the char was found in the map
 | ||||||
|        * and is less than the given radix add it |        * and is less than the given radix add it | ||||||
|  | |||||||
| @ -26,7 +26,7 @@ int mp_read_signed_bin(mp_int *a, const unsigned char *b, int c) | |||||||
|    } |    } | ||||||
| 
 | 
 | ||||||
|    /* first byte is 0 for positive, non-zero for negative */ |    /* first byte is 0 for positive, non-zero for negative */ | ||||||
|    if (b[0] == 0) { |    if (b[0] == (unsigned char)0) { | ||||||
|       a->sign = MP_ZPOS; |       a->sign = MP_ZPOS; | ||||||
|    } else { |    } else { | ||||||
|       a->sign = MP_NEG; |       a->sign = MP_NEG; | ||||||
|  | |||||||
| @ -33,7 +33,7 @@ int mp_reduce(mp_int *x, const mp_int *m, const mp_int *mu) | |||||||
|    mp_rshd(&q, um - 1); |    mp_rshd(&q, um - 1); | ||||||
| 
 | 
 | ||||||
|    /* according to HAC this optimization is ok */ |    /* according to HAC this optimization is ok */ | ||||||
|    if (((mp_digit) um) > (1uL << (DIGIT_BIT - 1))) { |    if ((mp_digit)um > (1uL << (DIGIT_BIT - 1))) { | ||||||
|       if ((res = mp_mul(&q, mu, &q)) != MP_OKAY) { |       if ((res = mp_mul(&q, mu, &q)) != MP_OKAY) { | ||||||
|          goto CLEANUP; |          goto CLEANUP; | ||||||
|       } |       } | ||||||
|  | |||||||
| @ -30,7 +30,7 @@ int mp_set_int(mp_int *a, unsigned long b) | |||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
|       /* OR in the top four bits of the source */ |       /* OR in the top four bits of the source */ | ||||||
|       a->dp[0] |= (b >> 28) & 15uL; |       a->dp[0] |= (mp_digit)(b >> 28) & 15uL; | ||||||
| 
 | 
 | ||||||
|       /* shift the source up to the next four bits */ |       /* shift the source up to the next four bits */ | ||||||
|       b <<= 4; |       b <<= 4; | ||||||
|  | |||||||
| @ -26,7 +26,7 @@ int mp_shrink(mp_int *a) | |||||||
|    } |    } | ||||||
| 
 | 
 | ||||||
|    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) * (size_t)used)) == NULL) { | ||||||
|          return MP_MEM; |          return MP_MEM; | ||||||
|       } |       } | ||||||
|       a->dp    = tmp; |       a->dp    = tmp; | ||||||
|  | |||||||
| @ -35,7 +35,7 @@ int mp_sqr(const mp_int *a, mp_int *b) | |||||||
|       { |       { | ||||||
| #ifdef BN_FAST_S_MP_SQR_C | #ifdef BN_FAST_S_MP_SQR_C | ||||||
|          /* can we use the fast comba multiplier? */ |          /* can we use the fast comba multiplier? */ | ||||||
|          if ((((a->used * 2) + 1) < MP_WARRAY) && |          if ((((a->used * 2) + 1) < (int)MP_WARRAY) && | ||||||
|              (a->used < |              (a->used < | ||||||
|               (int)(1u << (((sizeof(mp_word) * (size_t)CHAR_BIT) - (2u * (size_t)DIGIT_BIT)) - 1u)))) { |               (int)(1u << (((sizeof(mp_word) * (size_t)CHAR_BIT) - (2u * (size_t)DIGIT_BIT)) - 1u)))) { | ||||||
|             res = fast_s_mp_sqr(a, b); |             res = fast_s_mp_sqr(a, b); | ||||||
|  | |||||||
| @ -21,7 +21,7 @@ int mp_to_signed_bin_n(const mp_int *a, unsigned char *b, unsigned long *outlen) | |||||||
|    if (*outlen < (unsigned long)mp_signed_bin_size(a)) { |    if (*outlen < (unsigned long)mp_signed_bin_size(a)) { | ||||||
|       return MP_VAL; |       return MP_VAL; | ||||||
|    } |    } | ||||||
|    *outlen = mp_signed_bin_size(a); |    *outlen = (unsigned long)mp_signed_bin_size(a); | ||||||
|    return mp_to_signed_bin(a, b); |    return mp_to_signed_bin(a, b); | ||||||
| } | } | ||||||
| #endif | #endif | ||||||
|  | |||||||
| @ -21,7 +21,7 @@ int mp_to_unsigned_bin_n(const mp_int *a, unsigned char *b, unsigned long *outle | |||||||
|    if (*outlen < (unsigned long)mp_unsigned_bin_size(a)) { |    if (*outlen < (unsigned long)mp_unsigned_bin_size(a)) { | ||||||
|       return MP_VAL; |       return MP_VAL; | ||||||
|    } |    } | ||||||
|    *outlen = mp_unsigned_bin_size(a); |    *outlen = (unsigned long)mp_unsigned_bin_size(a); | ||||||
|    return mp_to_unsigned_bin(a, b); |    return mp_to_unsigned_bin(a, b); | ||||||
| } | } | ||||||
| #endif | #endif | ||||||
|  | |||||||
| @ -67,7 +67,7 @@ int s_mp_add(const mp_int *a, const mp_int *b, mp_int *c) | |||||||
|          *tmpc = *tmpa++ + *tmpb++ + u; |          *tmpc = *tmpa++ + *tmpb++ + u; | ||||||
| 
 | 
 | ||||||
|          /* U = carry bit of T[i] */ |          /* U = carry bit of T[i] */ | ||||||
|          u = *tmpc >> ((mp_digit)DIGIT_BIT); |          u = *tmpc >> (mp_digit)DIGIT_BIT; | ||||||
| 
 | 
 | ||||||
|          /* take away carry bit from T[i] */ |          /* take away carry bit from T[i] */ | ||||||
|          *tmpc++ &= MP_MASK; |          *tmpc++ &= MP_MASK; | ||||||
| @ -82,7 +82,7 @@ int s_mp_add(const mp_int *a, const mp_int *b, mp_int *c) | |||||||
|             *tmpc = x->dp[i] + u; |             *tmpc = x->dp[i] + u; | ||||||
| 
 | 
 | ||||||
|             /* U = carry bit of T[i] */ |             /* U = carry bit of T[i] */ | ||||||
|             u = *tmpc >> ((mp_digit)DIGIT_BIT); |             u = *tmpc >> (mp_digit)DIGIT_BIT; | ||||||
| 
 | 
 | ||||||
|             /* take away carry bit from T[i] */ |             /* take away carry bit from T[i] */ | ||||||
|             *tmpc++ &= MP_MASK; |             *tmpc++ &= MP_MASK; | ||||||
|  | |||||||
| @ -28,7 +28,7 @@ int s_mp_mul_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs) | |||||||
|    mp_digit tmpx, *tmpt, *tmpy; |    mp_digit tmpx, *tmpt, *tmpy; | ||||||
| 
 | 
 | ||||||
|    /* can we use the fast multiplier? */ |    /* can we use the fast multiplier? */ | ||||||
|    if (((digs) < MP_WARRAY) && |    if ((digs < (int)MP_WARRAY) && | ||||||
|        (MIN(a->used, b->used) < |        (MIN(a->used, b->used) < | ||||||
|         (int)(1u << (((size_t)CHAR_BIT * sizeof(mp_word)) - (2u * (size_t)DIGIT_BIT))))) { |         (int)(1u << (((size_t)CHAR_BIT * sizeof(mp_word)) - (2u * (size_t)DIGIT_BIT))))) { | ||||||
|       return fast_s_mp_mul_digs(a, b, c, digs); |       return fast_s_mp_mul_digs(a, b, c, digs); | ||||||
| @ -66,10 +66,10 @@ int s_mp_mul_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs) | |||||||
|                    (mp_word)u; |                    (mp_word)u; | ||||||
| 
 | 
 | ||||||
|          /* the new column is the lower part of the result */ |          /* the new column is the lower part of the result */ | ||||||
|          *tmpt++ = (mp_digit)(r & ((mp_word) MP_MASK)); |          *tmpt++ = (mp_digit)(r & (mp_word)MP_MASK); | ||||||
| 
 | 
 | ||||||
|          /* get the carry word from the result */ |          /* get the carry word from the result */ | ||||||
|          u       = (mp_digit)(r >> ((mp_word) DIGIT_BIT)); |          u       = (mp_digit)(r >> (mp_word)DIGIT_BIT); | ||||||
|       } |       } | ||||||
|       /* set carry if it is placed below digs */ |       /* set carry if it is placed below digs */ | ||||||
|       if ((ix + iy) < digs) { |       if ((ix + iy) < digs) { | ||||||
|  | |||||||
| @ -28,7 +28,7 @@ int s_mp_mul_high_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs) | |||||||
| 
 | 
 | ||||||
|    /* can we use the fast multiplier? */ |    /* can we use the fast multiplier? */ | ||||||
| #ifdef BN_FAST_S_MP_MUL_HIGH_DIGS_C | #ifdef BN_FAST_S_MP_MUL_HIGH_DIGS_C | ||||||
|    if (((a->used + b->used + 1) < MP_WARRAY) |    if (((a->used + b->used + 1) < (int)MP_WARRAY) | ||||||
|        && (MIN(a->used, b->used) < (int)(1u << (((size_t)CHAR_BIT * sizeof(mp_word)) - (2u * (size_t)DIGIT_BIT))))) { |        && (MIN(a->used, b->used) < (int)(1u << (((size_t)CHAR_BIT * sizeof(mp_word)) - (2u * (size_t)DIGIT_BIT))))) { | ||||||
|       return fast_s_mp_mul_high_digs(a, b, c, digs); |       return fast_s_mp_mul_high_digs(a, b, c, digs); | ||||||
|    } |    } | ||||||
| @ -61,10 +61,10 @@ int s_mp_mul_high_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs) | |||||||
|                    (mp_word)u; |                    (mp_word)u; | ||||||
| 
 | 
 | ||||||
|          /* get the lower part */ |          /* get the lower part */ | ||||||
|          *tmpt++ = (mp_digit)(r & ((mp_word) MP_MASK)); |          *tmpt++ = (mp_digit)(r & (mp_word)MP_MASK); | ||||||
| 
 | 
 | ||||||
|          /* carry the carry */ |          /* carry the carry */ | ||||||
|          u       = (mp_digit)(r >> ((mp_word) DIGIT_BIT)); |          u       = (mp_digit)(r >> (mp_word)DIGIT_BIT); | ||||||
|       } |       } | ||||||
|       *tmpt = u; |       *tmpt = u; | ||||||
|    } |    } | ||||||
|  | |||||||
| @ -38,10 +38,10 @@ int s_mp_sqr(const mp_int *a, mp_int *b) | |||||||
|           ((mp_word)a->dp[ix] * (mp_word)a->dp[ix]); |           ((mp_word)a->dp[ix] * (mp_word)a->dp[ix]); | ||||||
| 
 | 
 | ||||||
|       /* store lower part in result */ |       /* store lower part in result */ | ||||||
|       t.dp[ix+ix] = (mp_digit)(r & ((mp_word)MP_MASK)); |       t.dp[ix+ix] = (mp_digit)(r & (mp_word)MP_MASK); | ||||||
| 
 | 
 | ||||||
|       /* get the carry */ |       /* get the carry */ | ||||||
|       u           = (mp_digit)(r >> ((mp_word)DIGIT_BIT)); |       u           = (mp_digit)(r >> (mp_word)DIGIT_BIT); | ||||||
| 
 | 
 | ||||||
|       /* left hand side of A[ix] * A[iy] */ |       /* left hand side of A[ix] * A[iy] */ | ||||||
|       tmpx        = a->dp[ix]; |       tmpx        = a->dp[ix]; | ||||||
| @ -51,24 +51,24 @@ int s_mp_sqr(const mp_int *a, mp_int *b) | |||||||
| 
 | 
 | ||||||
|       for (iy = ix + 1; iy < pa; iy++) { |       for (iy = ix + 1; iy < pa; iy++) { | ||||||
|          /* first calculate the product */ |          /* first calculate the product */ | ||||||
|          r       = ((mp_word)tmpx) * ((mp_word)a->dp[iy]); |          r       = (mp_word)tmpx * (mp_word)a->dp[iy]; | ||||||
| 
 | 
 | ||||||
|          /* now calculate the double precision result, note we use
 |          /* now calculate the double precision result, note we use
 | ||||||
|           * addition instead of *2 since it's easier to optimize |           * addition instead of *2 since it's easier to optimize | ||||||
|           */ |           */ | ||||||
|          r       = ((mp_word) *tmpt) + r + r + ((mp_word) u); |          r       = (mp_word)*tmpt + r + r + (mp_word)u; | ||||||
| 
 | 
 | ||||||
|          /* store lower part */ |          /* store lower part */ | ||||||
|          *tmpt++ = (mp_digit)(r & ((mp_word) MP_MASK)); |          *tmpt++ = (mp_digit)(r & (mp_word)MP_MASK); | ||||||
| 
 | 
 | ||||||
|          /* get carry */ |          /* get carry */ | ||||||
|          u       = (mp_digit)(r >> ((mp_word) DIGIT_BIT)); |          u       = (mp_digit)(r >> (mp_word)DIGIT_BIT); | ||||||
|       } |       } | ||||||
|       /* propagate upwards */ |       /* propagate upwards */ | ||||||
|       while (u != 0uL) { |       while (u != 0uL) { | ||||||
|          r       = ((mp_word) *tmpt) + ((mp_word) u); |          r       = (mp_word)*tmpt + (mp_word)u; | ||||||
|          *tmpt++ = (mp_digit)(r & ((mp_word) MP_MASK)); |          *tmpt++ = (mp_digit)(r & (mp_word)MP_MASK); | ||||||
|          u       = (mp_digit)(r >> ((mp_word) DIGIT_BIT)); |          u       = (mp_digit)(r >> (mp_word)DIGIT_BIT); | ||||||
|       } |       } | ||||||
|    } |    } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -53,7 +53,7 @@ int s_mp_sub(const mp_int *a, const mp_int *b, mp_int *c) | |||||||
|           * if a carry does occur it will propagate all the way to the |           * if a carry does occur it will propagate all the way to the | ||||||
|           * MSB.  As a result a single shift is enough to get the carry |           * MSB.  As a result a single shift is enough to get the carry | ||||||
|           */ |           */ | ||||||
|          u = *tmpc >> ((mp_digit)((CHAR_BIT * sizeof(mp_digit)) - 1u)); |          u = *tmpc >> (((size_t)CHAR_BIT * sizeof(mp_digit)) - 1u); | ||||||
| 
 | 
 | ||||||
|          /* Clear carry from T[i] */ |          /* Clear carry from T[i] */ | ||||||
|          *tmpc++ &= MP_MASK; |          *tmpc++ &= MP_MASK; | ||||||
| @ -65,7 +65,7 @@ int s_mp_sub(const mp_int *a, const mp_int *b, mp_int *c) | |||||||
|          *tmpc = *tmpa++ - u; |          *tmpc = *tmpa++ - u; | ||||||
| 
 | 
 | ||||||
|          /* U = carry bit of T[i] */ |          /* U = carry bit of T[i] */ | ||||||
|          u = *tmpc >> ((mp_digit)((CHAR_BIT * sizeof(mp_digit)) - 1u)); |          u = *tmpc >> (((size_t)CHAR_BIT * sizeof(mp_digit)) - 1u); | ||||||
| 
 | 
 | ||||||
|          /* Clear carry from T[i] */ |          /* Clear carry from T[i] */ | ||||||
|          *tmpc++ &= MP_MASK; |          *tmpc++ &= MP_MASK; | ||||||
|  | |||||||
| @ -101,7 +101,7 @@ int func_name (mp_int * a, type b)                       \ | |||||||
|     }                                                    \ |     }                                                    \ | ||||||
|                                                          \ |                                                          \ | ||||||
|     /* OR in the top four bits of the source */          \ |     /* OR in the top four bits of the source */          \ | ||||||
|     a->dp[0] |= (b >> ((sizeof(type) * 8u) - 4u)) & 15uL;\ |     a->dp[0] |= (mp_digit)(b >> ((sizeof(type) * 8u) - 4u)) & 15uL;\ | ||||||
|                                                          \ |                                                          \ | ||||||
|     /* 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