use MP_SIZEOF_BITS
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
diff --git a/demo/test.c b/demo/test.c
index 748be4b..41e0394 100644
--- a/demo/test.c
+++ b/demo/test.c
@@ -726,7 +726,7 @@ static int test_mp_get_ul(void)
return EXIT_FAILURE;
}
- for (i = 0; i < ((int)(sizeof(unsigned long)*CHAR_BIT) - 1); ++i) {
+ for (i = 0; i < ((int)MP_SIZEOF_BITS(unsigned long) - 1); ++i) {
t = (1UL << (i+1)) - 1;
if (!t)
t = ~0UL;
@@ -759,7 +759,7 @@ static int test_mp_get_u64(void)
return EXIT_FAILURE;
}
- for (i = 0; i < ((int)(sizeof(unsigned long long)*CHAR_BIT) - 1); ++i) {
+ for (i = 0; i < (int)(MP_SIZEOF_BITS(unsigned long long) - 1); ++i) {
r = (1ULL << (i+1)) - 1;
if (!r)
r = ~0ULL;
diff --git a/tommath_private.h b/tommath_private.h
index b08fbd7..f37b541 100644
--- a/tommath_private.h
+++ b/tommath_private.h
@@ -169,7 +169,7 @@ typedef private_mp_word mp_word;
#endif
/* Minimum number of available digits in mp_int, MP_PREC >= MP_MIN_PREC */
-#define MP_MIN_PREC ((((CHAR_BIT * (int)sizeof(long long)) + MP_DIGIT_BIT) - 1) / MP_DIGIT_BIT)
+#define MP_MIN_PREC ((((int)MP_SIZEOF_BITS(long long) + MP_DIGIT_BIT) - 1) / MP_DIGIT_BIT)
MP_STATIC_ASSERT(prec_geq_min_prec, MP_PREC >= MP_MIN_PREC)
@@ -238,8 +238,8 @@ MP_DEPRECATED(s_mp_reverse) void bn_reverse(unsigned char *s, int len);
int i = 0; \
while (b != 0u) { \
a->dp[i++] = ((mp_digit)b & MP_MASK); \
- if ((sizeof(type) * CHAR_BIT) <= MP_DIGIT_BIT) { break; } \
- b >>= (((sizeof(type) * CHAR_BIT) <= MP_DIGIT_BIT) ? 0 : MP_DIGIT_BIT); \
+ if (MP_SIZEOF_BITS(type) <= MP_DIGIT_BIT) { break; } \
+ b >>= ((MP_SIZEOF_BITS(type) <= MP_DIGIT_BIT) ? 0 : MP_DIGIT_BIT); \
} \
a->used = i; \
a->sign = MP_ZPOS; \
@@ -267,12 +267,12 @@ MP_DEPRECATED(s_mp_reverse) void bn_reverse(unsigned char *s, int len);
#define MP_GET_MAG(type, name) \
type name(const mp_int* a) \
{ \
- unsigned i = MP_MIN((unsigned)a->used, (unsigned)(((sizeof(type) * CHAR_BIT) + MP_DIGIT_BIT - 1) / MP_DIGIT_BIT)); \
+ unsigned i = MP_MIN((unsigned)a->used, (unsigned)((MP_SIZEOF_BITS(type) + MP_DIGIT_BIT - 1) / MP_DIGIT_BIT)); \
type res = 0u; \
while (i --> 0u) { \
- res <<= (((sizeof(type) * CHAR_BIT) <= MP_DIGIT_BIT) ? 0 : MP_DIGIT_BIT); \
+ res <<= ((MP_SIZEOF_BITS(type) <= MP_DIGIT_BIT) ? 0 : MP_DIGIT_BIT); \
res |= (type)a->dp[i]; \
- if ((sizeof(type) * CHAR_BIT) <= MP_DIGIT_BIT) { break; } \
+ if (MP_SIZEOF_BITS(type) <= MP_DIGIT_BIT) { break; } \
} \
return res; \
}