Commit b0c385afb6a2e6416a355c6259d76ed51c284710

Steffen Jaeckel 2014-09-23T22:54:30

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'

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