Fix for MPI divide on MSVC
Resolves multiple platform issues when building bignum.c with Microsoft
Visual Studio.
diff --git a/library/bignum.c b/library/bignum.c
index 21069d8..0e587f1 100644
--- a/library/bignum.c
+++ b/library/bignum.c
@@ -1221,10 +1221,11 @@
#if defined(MBEDTLS_HAVE_UDBL)
mbedtls_t_udbl dividend, quotient;
#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 u0_msw, u0_lsw;
- int s;
+ size_t s;
#endif
/*
@@ -1245,7 +1246,7 @@
quotient = ( (mbedtls_t_udbl) 1 << biL ) - 1;
if( r != NULL )
- *r = dividend - (quotient * d);
+ *r = (mbedtls_mpi_uint)( dividend - (quotient * d ) );
return (mbedtls_mpi_uint) quotient;
#else
@@ -1262,14 +1263,14 @@
d = d << s;
u1 = u1 << s;
- u1 |= ( u0 >> ( 32 - s ) ) & ( -s >> 31 );
+ u1 |= ( u0 >> ( biL - s ) ) & ( -(mbedtls_mpi_sint)s >> ( biL - 1 ) );
u0 = u0 << s;
d1 = d >> biH;
- d0 = d & 0xffff;
+ d0 = d & uint_halfword_mask;
u0_msw = u0 >> biH;
- u0_lsw = u0 & 0xffff;
+ u0_lsw = u0 & uint_halfword_mask;
/*
* Find the first quotient and remainder