Allow (NULL, 0) as a representation of 0
- We don't check for NULL pointers this deep in the library
- Accessing a NULL pointer when the limb number is 0 as a mistake is the
very similar to any other out of bounds access
- We could potentially mandate at least 1 limb representation for 0 but
we either would need to enforce it or the implementation would be less
robust.
- Allowing zero limb representation - (NULL, 0) in particular - for zero
is present in the legacy interface, if we disallow it, the
compatibility code will need to deal with this (more code size and
opportunities for mistakes)
In summary, interpreting (NULL, 0) as the number zero in the core
interface is the least of the two evils.
Signed-off-by: Janos Follath <janos.follath@arm.com>
diff --git a/tests/suites/test_suite_mpi.function b/tests/suites/test_suite_mpi.function
index 34710c4..b0d947c 100644
--- a/tests/suites/test_suite_mpi.function
+++ b/tests/suites/test_suite_mpi.function
@@ -198,6 +198,37 @@
/* END_CASE */
/* BEGIN_CASE */
+void mbedtls_mpi_core_io_null()
+{
+ mbedtls_mpi_uint X = 0;
+ int ret;
+
+ ret = mbedtls_mpi_core_read_be( &X, 1, NULL, 0 );
+ TEST_ASSERT( ret == 0 );
+ ret = mbedtls_mpi_core_write_be( &X, 1, NULL, 0 );
+ TEST_ASSERT( ret == 0 );
+
+ ret = mbedtls_mpi_core_read_be( NULL, 0, NULL, 0 );
+ TEST_ASSERT( ret == 0 );
+ ret = mbedtls_mpi_core_write_be( NULL, 0, NULL, 0 );
+ TEST_ASSERT( ret == 0 );
+
+ ret = mbedtls_mpi_core_read_le( &X, 1, NULL, 0 );
+ TEST_ASSERT( ret == 0 );
+ ret = mbedtls_mpi_core_write_le( &X, 1, NULL, 0 );
+ TEST_ASSERT( ret == 0 );
+
+ ret = mbedtls_mpi_core_read_le( NULL, 0, NULL, 0 );
+ TEST_ASSERT( ret == 0 );
+ ret = mbedtls_mpi_core_write_le( NULL, 0, NULL, 0 );
+ TEST_ASSERT( ret == 0 );
+
+exit:
+ ;
+}
+/* END_CASE */
+
+/* BEGIN_CASE */
void mbedtls_mpi_core_io_be( data_t *input, int nb_int, int nx_64_int, int iret,
int oret )
{