Fix for MPI divide on MSVC

Resolves multiple platform issues when building bignum.c with Microsoft
Visual Studio.
This commit is contained in:
Simon Butcher 2016-01-03 00:24:34 +00:00
parent 28b35c02f7
commit 6189175900
2 changed files with 8 additions and 6 deletions

View file

@ -122,6 +122,7 @@
#define MBEDTLS_HAVE_INT64 #define MBEDTLS_HAVE_INT64
typedef int64_t mbedtls_mpi_sint; typedef int64_t mbedtls_mpi_sint;
typedef uint64_t mbedtls_mpi_uint; typedef uint64_t mbedtls_mpi_uint;
/* mbedtls_t_udbl defined as 128-bit unsigned int */
typedef unsigned int mbedtls_t_udbl __attribute__((mode(TI))); typedef unsigned int mbedtls_t_udbl __attribute__((mode(TI)));
#define MBEDTLS_HAVE_UDBL #define MBEDTLS_HAVE_UDBL
#else #else

View file

@ -1221,10 +1221,11 @@ static mbedtls_mpi_uint mbedtls_int_div_int( mbedtls_mpi_uint u1,
#if defined(MBEDTLS_HAVE_UDBL) #if defined(MBEDTLS_HAVE_UDBL)
mbedtls_t_udbl dividend, quotient; mbedtls_t_udbl dividend, quotient;
#else #else
const mbedtls_mpi_uint radix = 1 << biH; const mbedtls_mpi_uint radix = (mbedtls_mpi_uint) 1 << biH;
const mbedtls_mpi_uint uint_halfword_mask = ( (mbedtls_mpi_uint) 1 << biH ) - 1;
mbedtls_mpi_uint d0, d1, q0, q1, rAX, r0, quotient; mbedtls_mpi_uint d0, d1, q0, q1, rAX, r0, quotient;
mbedtls_mpi_uint u0_msw, u0_lsw; mbedtls_mpi_uint u0_msw, u0_lsw;
int s; size_t s;
#endif #endif
/* /*
@ -1245,7 +1246,7 @@ static mbedtls_mpi_uint mbedtls_int_div_int( mbedtls_mpi_uint u1,
quotient = ( (mbedtls_t_udbl) 1 << biL ) - 1; quotient = ( (mbedtls_t_udbl) 1 << biL ) - 1;
if( r != NULL ) if( r != NULL )
*r = dividend - (quotient * d); *r = (mbedtls_mpi_uint)( dividend - (quotient * d ) );
return (mbedtls_mpi_uint) quotient; return (mbedtls_mpi_uint) quotient;
#else #else
@ -1262,14 +1263,14 @@ static mbedtls_mpi_uint mbedtls_int_div_int( mbedtls_mpi_uint u1,
d = d << s; d = d << s;
u1 = u1 << s; u1 = u1 << s;
u1 |= ( u0 >> ( 32 - s ) ) & ( -s >> 31 ); u1 |= ( u0 >> ( biL - s ) ) & ( -(mbedtls_mpi_sint)s >> ( biL - 1 ) );
u0 = u0 << s; u0 = u0 << s;
d1 = d >> biH; d1 = d >> biH;
d0 = d & 0xffff; d0 = d & uint_halfword_mask;
u0_msw = u0 >> biH; u0_msw = u0 >> biH;
u0_lsw = u0 & 0xffff; u0_lsw = u0 & uint_halfword_mask;
/* /*
* Find the first quotient and remainder * Find the first quotient and remainder