fix x32 compilation change mp_digit/mp_word to unsigned long long introduce new internal type mp_min_u32 that is minimum 32 bit wide x32 target is 64 bit arch but has 32 bit wide 'unsigned long'
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 63 64 65
diff --git a/bn_mp_get_int.c b/bn_mp_get_int.c
index 27e3351..c4673fb 100644
--- a/bn_mp_get_int.c
+++ b/bn_mp_get_int.c
@@ -19,7 +19,7 @@
unsigned long mp_get_int(mp_int * a)
{
int i;
- unsigned long res;
+ mp_min_u32 res;
if (a->used == 0) {
return 0;
diff --git a/bn_mp_montgomery_setup.c b/bn_mp_montgomery_setup.c
index cc99d9b..17a2a3c 100644
--- a/bn_mp_montgomery_setup.c
+++ b/bn_mp_montgomery_setup.c
@@ -48,7 +48,7 @@ mp_montgomery_setup (mp_int * n, mp_digit * rho)
#endif
/* rho = -1/m mod b */
- *rho = (unsigned long)(((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;
}
diff --git a/bn_mp_reduce.c b/bn_mp_reduce.c
index 737bc58..e7f25ce 100644
--- a/bn_mp_reduce.c
+++ b/bn_mp_reduce.c
@@ -33,7 +33,7 @@ int mp_reduce (mp_int * x, mp_int * m, mp_int * mu)
mp_rshd (&q, um - 1);
/* according to HAC this optimization is ok */
- if (((unsigned long) um) > (((mp_digit)1) << (DIGIT_BIT - 1))) {
+ if (((mp_digit) um) > (((mp_digit)1) << (DIGIT_BIT - 1))) {
if ((res = mp_mul (&q, mu, &q)) != MP_OKAY) {
goto CLEANUP;
}
diff --git a/tommath.h b/tommath.h
index 9fd62f3..496ce1c 100644
--- a/tommath.h
+++ b/tommath.h
@@ -73,7 +73,7 @@ extern "C" {
typedef signed long long long64;
#endif
- typedef unsigned long mp_digit;
+ typedef unsigned long long mp_digit;
typedef unsigned long mp_word __attribute__ ((mode(TI)));
#define DIGIT_BIT 60
@@ -125,8 +125,12 @@ extern "C" {
/* otherwise the bits per digit is calculated automatically from the size of a mp_digit */
#ifndef DIGIT_BIT
#define DIGIT_BIT ((int)((CHAR_BIT * sizeof(mp_digit) - 1))) /* bits per digit */
+ typedef unsigned long mp_min_u32;
+#else
+ typedef mp_digit mp_min_u32;
#endif
+
#define MP_DIGIT_BIT DIGIT_BIT
#define MP_MASK ((((mp_digit)1)<<((mp_digit)DIGIT_BIT))-((mp_digit)1))
#define MP_DIGIT_MAX MP_MASK