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/library/bignum.c b/library/bignum.c
index 931d34d..98bea73 100644
--- a/library/bignum.c
+++ b/library/bignum.c
@@ -1550,16 +1550,7 @@
*/
static void mpi_montg_init( mbedtls_mpi_uint *mm, const mbedtls_mpi *N )
{
- mbedtls_mpi_uint x, m0 = N->p[0];
- unsigned int i;
-
- x = m0;
- x += ( ( m0 + 2 ) & 4 ) << 1;
-
- for( i = biL; i >= 8; i /= 2 )
- x *= ( 2 - ( m0 * x ) );
-
- *mm = ~x + 1;
+ *mm = mbedtls_mpi_montg_init( N->p[0] );
}
/** Montgomery multiplication: A = A * B * R^-1 mod N (HAC 14.36)