Skip to content

Commit be7ee4d

Browse files
authored
Merge pull request #238 from fperrad/20190508_macros
new macros
2 parents 17719ea + 7d4e836 commit be7ee4d

12 files changed

+20
-21
lines changed

bn_mp_get_long.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ unsigned long mp_get_long(const mp_int *a)
1414
}
1515

1616
/* get number of digits of the lsb we have to read */
17-
i = MP_MIN(a->used, (((CHAR_BIT * (int)sizeof(unsigned long)) + MP_DIGIT_BIT - 1) / MP_DIGIT_BIT)) - 1;
17+
i = MP_MIN(a->used, (((int)MP_SIZEOF_BITS(unsigned long) + MP_DIGIT_BIT - 1) / MP_DIGIT_BIT)) - 1;
1818

1919
/* get most significant digit of result */
2020
res = (unsigned long)a->dp[i];

bn_mp_get_long_long.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ unsigned long long mp_get_long_long(const mp_int *a)
1414
}
1515

1616
/* get number of digits of the lsb we have to read */
17-
i = MP_MIN(a->used, (((CHAR_BIT * (int)sizeof(unsigned long long)) + MP_DIGIT_BIT - 1) / MP_DIGIT_BIT)) - 1;
17+
i = MP_MIN(a->used, (((int)MP_SIZEOF_BITS(unsigned long long) + MP_DIGIT_BIT - 1) / MP_DIGIT_BIT)) - 1;
1818

1919
/* get most significant digit of result */
2020
res = (unsigned long long)a->dp[i];

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 << ((CHAR_BIT * sizeof(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 << ((CHAR_BIT * sizeof(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_prime_is_prime.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,11 +287,11 @@ int mp_prime_is_prime(const mp_int *a, int t, int *result)
287287
* One 8-bit digit is too small, so concatenate two if the size of
288288
* unsigned int allows for it.
289289
*/
290-
if (((sizeof(unsigned int) * CHAR_BIT)/2) >= (sizeof(mp_digit) * CHAR_BIT)) {
290+
if ((MP_SIZEOF_BITS(unsigned int)/2) >= MP_SIZEOF_BITS(mp_digit)) {
291291
if ((err = mp_rand(&b, 1)) != MP_OKAY) {
292292
goto LBL_B;
293293
}
294-
fips_rand <<= CHAR_BIT * sizeof(mp_digit);
294+
fips_rand <<= MP_SIZEOF_BITS(mp_digit);
295295
fips_rand |= (unsigned int) b.dp[0];
296296
fips_rand &= mask;
297297
}

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 << (((CHAR_BIT * sizeof(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_mp_sub_d.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ int mp_sub_d(const mp_int *a, mp_digit b, mp_int *c)
5555

5656
/* subtract first digit */
5757
*tmpc = *tmpa++ - b;
58-
mu = *tmpc >> ((CHAR_BIT * sizeof(mp_digit)) - 1u);
58+
mu = *tmpc >> (MP_SIZEOF_BITS(mp_digit) - 1u);
5959
*tmpc++ &= MP_MASK;
6060

6161
/* handle rest of the digits */
6262
for (ix = 1; ix < a->used; ix++) {
6363
*tmpc = *tmpa++ - mu;
64-
mu = *tmpc >> ((CHAR_BIT * sizeof(mp_digit)) - 1u);
64+
mu = *tmpc >> (MP_SIZEOF_BITS(mp_digit) - 1u);
6565
*tmpc++ &= MP_MASK;
6666
}
6767
}

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 << ((CHAR_BIT * sizeof(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 << ((CHAR_BIT * sizeof(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 << ((CHAR_BIT * sizeof(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

0 commit comments

Comments
 (0)