Add tests for big endian core I/O
The test case where there were extra limbs in the MPI failed and this
commit contains the corresponding fix as well. (We used to use the
minimum required limbs instead of the actual limbs present.)
Signed-off-by: Janos Follath <janos.follath@arm.com>
diff --git a/library/bignum_new.c b/library/bignum_new.c
index 1c5cb8c..b01f742 100644
--- a/library/bignum_new.c
+++ b/library/bignum_new.c
@@ -347,8 +347,8 @@
size_t buflen )
{
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
- size_t const limbs = CHARS_TO_LIMBS( buflen );
- size_t const overhead = ( limbs * ciL ) - buflen;
+ size_t const limbs = CHARS_TO_LIMBS( buflen );
+ size_t overhead;
unsigned char *Xp;
MPI_VALIDATE_RET( X != NULL );
@@ -357,6 +357,8 @@
/* Ensure that target MPI has at least the necessary number of limbs */
MBEDTLS_MPI_CHK( mpi_core_clear( X, nx, limbs ) );
+ overhead = ( nx * ciL ) - buflen;
+
/* Avoid calling `memcpy` with NULL source or destination argument,
* even if buflen is 0. */
if( buflen != 0 )