Make a public version of mpi_montg_init() in bignum_new.c and add unit tests
The unit tests were created by capturing runs of the existing function during
execution of existing unit tests.
Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
diff --git a/tests/suites/test_suite_mpi.function b/tests/suites/test_suite_mpi.function
index 20cc344..26d1553 100644
--- a/tests/suites/test_suite_mpi.function
+++ b/tests/suites/test_suite_mpi.function
@@ -1991,6 +1991,41 @@
}
/* END_CASE */
+/* BEGIN_CASE */
+void mbedtls_mpi_montg_init( char * input_N, char * input_mm )
+{
+ mbedtls_mpi N, mm;
+
+ mbedtls_mpi_init( &N );
+ mbedtls_mpi_init( &mm );
+
+ TEST_EQUAL( mbedtls_test_read_mpi( &N, input_N ), 0 );
+ TEST_EQUAL( mbedtls_test_read_mpi( &mm, input_mm ), 0 );
+
+ /* The MPI encoding of mm should be 1 limb (sizeof(mbedtls_mpi_uint) == 8) or
+ * 2 limbs (sizeof(mbedtls_mpi_uint) == 4).
+ *
+ * The data file contains the expected result for sizeof(mbedtls_mpi_uint) == 8;
+ * for sizeof(mbedtls_mpi_uint) == 4 it's just the LSW of this.
+ */
+ TEST_ASSERT( mm.n == 1 || mm.n == 2);
+
+ /* All of the inputs are +ve (or zero) */
+ TEST_EQUAL( N.s, 1 );
+ TEST_EQUAL( mm.s, 1 );
+
+ /* mbedtls_mpi_montg_init() only returns a result, no error possible */
+ mbedtls_mpi_uint result = mbedtls_mpi_montg_init( N.p[0] );
+
+ /* Check we got the correct result */
+ TEST_EQUAL( result, mm.p[0] );
+
+exit:
+ mbedtls_mpi_free( &N );
+ mbedtls_mpi_free( &mm );
+}
+/* END_CASE */
+
/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */
void mpi_selftest( )
{