Skip to content

Commit 7d4e836

Browse files
committed
refactor with new private macro MP_MAXFAST
1 parent 556219a commit 7d4e836

File tree

7 files changed

+7
-10
lines changed

7 files changed

+7
-10
lines changed

bn_mp_montgomery_reduce.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ int mp_montgomery_reduce(mp_int *x, const mp_int *n, mp_digit rho)
1818
digs = (n->used * 2) + 1;
1919
if ((digs < (int)MP_WARRAY) &&
2020
(x->used <= (int)MP_WARRAY) &&
21-
(n->used <
22-
(int)(1u << (MP_SIZEOF_BITS(mp_word) - (2u * (size_t)MP_DIGIT_BIT))))) {
21+
(n->used < MP_MAXFAST)) {
2322
return s_mp_montgomery_reduce_fast(x, n, rho);
2423
}
2524

bn_mp_mul.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ int mp_mul(const mp_int *a, const mp_int *b, mp_int *c)
6666

6767
#ifdef BN_S_MP_MUL_DIGS_FAST_C
6868
if ((digs < (int)MP_WARRAY) &&
69-
(MP_MIN(a->used, b->used) <=
70-
(int)(1u << (MP_SIZEOF_BITS(mp_word) - (2u * (size_t)MP_DIGIT_BIT))))) {
69+
(MP_MIN(a->used, b->used) <= MP_MAXFAST)) {
7170
res = s_mp_mul_digs_fast(a, b, c, digs);
7271
} else
7372
#endif

bn_mp_sqr.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ int mp_sqr(const mp_int *a, mp_int *b)
2424
#ifdef BN_S_MP_SQR_FAST_C
2525
/* can we use the fast comba multiplier? */
2626
if ((((a->used * 2) + 1) < (int)MP_WARRAY) &&
27-
(a->used <
28-
(int)(1u << ((MP_SIZEOF_BITS(mp_word) - (2u * (size_t)MP_DIGIT_BIT)) - 1u)))) {
27+
(a->used < (MP_MAXFAST / 2))) {
2928
res = s_mp_sqr_fast(a, b);
3029
} else
3130
#endif

bn_s_mp_exptmod_fast.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ int s_mp_exptmod_fast(const mp_int *G, const mp_int *X, const mp_int *P, mp_int
8585
/* automatically pick the comba one if available (saves quite a few calls/ifs) */
8686
#ifdef BN_S_MP_MONTGOMERY_REDUCE_FAST_C
8787
if ((((P->used * 2) + 1) < (int)MP_WARRAY) &&
88-
(P->used < (1 << (MP_SIZEOF_BITS(mp_word) - (2 * MP_DIGIT_BIT))))) {
88+
(P->used < MP_MAXFAST)) {
8989
redux = s_mp_montgomery_reduce_fast;
9090
} else
9191
#endif

bn_s_mp_mul_digs.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ int s_mp_mul_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs)
1717

1818
/* can we use the fast multiplier? */
1919
if ((digs < (int)MP_WARRAY) &&
20-
(MP_MIN(a->used, b->used) <
21-
(int)(1u << (MP_SIZEOF_BITS(mp_word) - (2u * (size_t)MP_DIGIT_BIT))))) {
20+
(MP_MIN(a->used, b->used) < MP_MAXFAST)) {
2221
return s_mp_mul_digs_fast(a, b, c, digs);
2322
}
2423

bn_s_mp_mul_high_digs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ int s_mp_mul_high_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs)
1717
/* can we use the fast multiplier? */
1818
#ifdef BN_S_MP_MUL_HIGH_DIGS_FAST_C
1919
if (((a->used + b->used + 1) < (int)MP_WARRAY)
20-
&& (MP_MIN(a->used, b->used) < (int)(1u << (MP_SIZEOF_BITS(mp_word) - (2u * (size_t)MP_DIGIT_BIT))))) {
20+
&& (MP_MIN(a->used, b->used) < MP_MAXFAST)) {
2121
return s_mp_mul_high_digs_fast(a, b, c, digs);
2222
}
2323
#endif

tommath_private.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ extern void MP_FREE(void *mem, size_t size);
6767
#define MP_IS_ODD(a) (((a)->used > 0) && (((a)->dp[0] & 1u) == 1u))
6868

6969
#define MP_SIZEOF_BITS(type) (CHAR_BIT * sizeof(type))
70+
#define MP_MAXFAST (int)(1u << (MP_SIZEOF_BITS(mp_word) - (2u * (size_t)MP_DIGIT_BIT)))
7071

7172
/* random number source */
7273
extern int (*s_rand_source)(void *, size_t);

0 commit comments

Comments
 (0)