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'
This commit is contained in:
Steffen Jaeckel 2014-09-23 22:54:30 +02:00
parent 0213986c7b
commit b0c385afb6
4 changed files with 8 additions and 4 deletions

View File

@ -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;

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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