diff --git a/library/bignum.c b/library/bignum.c index 9776d29de..acf620f9a 100644 --- a/library/bignum.c +++ b/library/bignum.c @@ -712,7 +712,7 @@ cleanup: int mbedtls_mpi_write_binary_le( const mbedtls_mpi *X, unsigned char *buf, size_t buflen ) { - return( mbedtls_mpi_core_write_le( X->p, X->n, buf, buflen) ); + return( mbedtls_mpi_core_write_le( X->p, X->n, buf, buflen ) ); } /* diff --git a/library/bignum_core.c b/library/bignum_core.c index d3d74fff9..41be49616 100644 --- a/library/bignum_core.c +++ b/library/bignum_core.c @@ -174,7 +174,10 @@ int mbedtls_mpi_core_read_le( mbedtls_mpi_uint *X, memset( X, 0, X_limbs * ciL ); for( size_t i = 0; i < input_length; i++ ) - X[i / ciL] |= ((mbedtls_mpi_uint) input[i]) << ((i % ciL) << 3); + { + size_t offset = ( ( i % ciL ) << 3 ); + X[i / ciL] |= ( (mbedtls_mpi_uint) input[i] ) << offset; + } } return( 0 ); diff --git a/library/bignum_core.h b/library/bignum_core.h index 1557d10b3..221bb1afe 100644 --- a/library/bignum_core.h +++ b/library/bignum_core.h @@ -141,9 +141,9 @@ int mbedtls_mpi_core_write_be( const mbedtls_mpi_uint *A, unsigned char *output, size_t output_length ); -#define ciL (sizeof(mbedtls_mpi_uint)) /* chars in limb */ -#define biL (ciL << 3) /* bits in limb */ -#define biH (ciL << 2) /* half limb size */ +#define ciL ( sizeof(mbedtls_mpi_uint) ) /* chars in limb */ +#define biL ( ciL << 3 ) /* bits in limb */ +#define biH ( ciL << 2 ) /* half limb size */ /* * Convert between bits/chars and number of limbs @@ -153,6 +153,6 @@ int mbedtls_mpi_core_write_be( const mbedtls_mpi_uint *A, #define CHARS_TO_LIMBS(i) ( (i) / ciL + ( (i) % ciL != 0 ) ) /* Get a specific byte, without range checks. */ #define GET_BYTE( X, i ) \ - ( ( ( X )[( i ) / ciL] >> ( ( ( i ) % ciL ) * 8 ) ) & 0xff ) + ( ( (X)[(i) / ciL] >> ( ( (i) % ciL ) * 8 ) ) & 0xff ) #endif /* MBEDTLS_BIGNUM_CORE_H */