refactor with new private macro MP_MAXFAST

This commit is contained in:
Francois Perrad 2019-05-08 19:43:21 +02:00
parent 556219aa5b
commit 7d4e8363e0
7 changed files with 7 additions and 10 deletions

View File

@ -18,8 +18,7 @@ int mp_montgomery_reduce(mp_int *x, const mp_int *n, mp_digit rho)
digs = (n->used * 2) + 1;
if ((digs < (int)MP_WARRAY) &&
(x->used <= (int)MP_WARRAY) &&
(n->used <
(int)(1u << (MP_SIZEOF_BITS(mp_word) - (2u * (size_t)MP_DIGIT_BIT))))) {
(n->used < MP_MAXFAST)) {
return s_mp_montgomery_reduce_fast(x, n, rho);
}

View File

@ -66,8 +66,7 @@ GO_ON:
#ifdef BN_S_MP_MUL_DIGS_FAST_C
if ((digs < (int)MP_WARRAY) &&
(MP_MIN(a->used, b->used) <=
(int)(1u << (MP_SIZEOF_BITS(mp_word) - (2u * (size_t)MP_DIGIT_BIT))))) {
(MP_MIN(a->used, b->used) <= MP_MAXFAST)) {
res = s_mp_mul_digs_fast(a, b, c, digs);
} else
#endif

View File

@ -24,8 +24,7 @@ int mp_sqr(const mp_int *a, mp_int *b)
#ifdef BN_S_MP_SQR_FAST_C
/* can we use the fast comba multiplier? */
if ((((a->used * 2) + 1) < (int)MP_WARRAY) &&
(a->used <
(int)(1u << ((MP_SIZEOF_BITS(mp_word) - (2u * (size_t)MP_DIGIT_BIT)) - 1u)))) {
(a->used < (MP_MAXFAST / 2))) {
res = s_mp_sqr_fast(a, b);
} else
#endif

View File

@ -85,7 +85,7 @@ int s_mp_exptmod_fast(const mp_int *G, const mp_int *X, const mp_int *P, mp_int
/* automatically pick the comba one if available (saves quite a few calls/ifs) */
#ifdef BN_S_MP_MONTGOMERY_REDUCE_FAST_C
if ((((P->used * 2) + 1) < (int)MP_WARRAY) &&
(P->used < (1 << (MP_SIZEOF_BITS(mp_word) - (2 * MP_DIGIT_BIT))))) {
(P->used < MP_MAXFAST)) {
redux = s_mp_montgomery_reduce_fast;
} else
#endif

View File

@ -17,8 +17,7 @@ int s_mp_mul_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs)
/* can we use the fast multiplier? */
if ((digs < (int)MP_WARRAY) &&
(MP_MIN(a->used, b->used) <
(int)(1u << (MP_SIZEOF_BITS(mp_word) - (2u * (size_t)MP_DIGIT_BIT))))) {
(MP_MIN(a->used, b->used) < MP_MAXFAST)) {
return s_mp_mul_digs_fast(a, b, c, digs);
}

View File

@ -17,7 +17,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? */
#ifdef BN_S_MP_MUL_HIGH_DIGS_FAST_C
if (((a->used + b->used + 1) < (int)MP_WARRAY)
&& (MP_MIN(a->used, b->used) < (int)(1u << (MP_SIZEOF_BITS(mp_word) - (2u * (size_t)MP_DIGIT_BIT))))) {
&& (MP_MIN(a->used, b->used) < MP_MAXFAST)) {
return s_mp_mul_high_digs_fast(a, b, c, digs);
}
#endif

View File

@ -67,6 +67,7 @@ extern void MP_FREE(void *mem, size_t size);
#define MP_IS_ODD(a) (((a)->used > 0) && (((a)->dp[0] & 1u) == 1u))
#define MP_SIZEOF_BITS(type) (CHAR_BIT * sizeof(type))
#define MP_MAXFAST (int)(1u << (MP_SIZEOF_BITS(mp_word) - (2u * (size_t)MP_DIGIT_BIT)))
/* random number source */
extern int (*s_rand_source)(void *, size_t);