Unit-test mpi_core_div2_mod_odd()

This function has specific code to handle carries and it's not clear how
to exercises that code through the modinv function, so well, that's what
unit tests are for.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
diff --git a/library/bignum_core.c b/library/bignum_core.c
index e020da1..3490f7d 100644
--- a/library/bignum_core.c
+++ b/library/bignum_core.c
@@ -18,6 +18,7 @@
 #include "mbedtls/platform.h"
 
 #include "bignum_core.h"
+#include "bignum_core_invasive.h"
 #include "bn_mul.h"
 #include "constant_time_internal.h"
 
@@ -1037,9 +1038,10 @@
  * Divide X by 2 mod N in place, assuming N is odd.
  * The input must be in [0, N) and so will the output.
  */
-static void mpi_core_div2_mod_odd(mbedtls_mpi_uint *X,
-                                  const mbedtls_mpi_uint *N,
-                                  size_t limbs)
+MBEDTLS_STATIC_TESTABLE
+void mbedtls_mpi_core_div2_mod_odd(mbedtls_mpi_uint *X,
+                                   const mbedtls_mpi_uint *N,
+                                   size_t limbs)
 {
     /* If X is odd, add N to make it even before shifting. */
     unsigned odd = (unsigned) X[0] & 1;
@@ -1200,7 +1202,7 @@
             mbedtls_mpi_core_cond_assign(t2, q, N_limbs, u_odd_v_even);
             mbedtls_mpi_core_cond_assign(t2, d, N_limbs, u_odd_v_odd);
 
-            mpi_core_div2_mod_odd(t2, N, N_limbs);
+            mbedtls_mpi_core_div2_mod_odd(t2, N, N_limbs);
 
             /* Update and possibly swap */
             memcpy(r, t1, N_limbs * ciL);
diff --git a/library/bignum_core_invasive.h b/library/bignum_core_invasive.h
index 167099d..a9d447f 100644
--- a/library/bignum_core_invasive.h
+++ b/library/bignum_core_invasive.h
@@ -13,11 +13,26 @@
 
 #include "bignum_core.h"
 
-#if defined(MBEDTLS_TEST_HOOKS) && !defined(MBEDTLS_THREADING_C)
+#if defined(MBEDTLS_TEST_HOOKS)
+
+#if !defined(MBEDTLS_THREADING_C)
 
 extern void (*mbedtls_safe_codepath_hook)(void);
 extern void (*mbedtls_unsafe_codepath_hook)(void);
 
-#endif /* MBEDTLS_TEST_HOOKS && !MBEDTLS_THREADING_C */
+#endif /* !MBEDTLS_THREADING_C */
+
+/** Divide X by 2 mod N in place, assuming N is odd.
+ *
+ * \param[in,out] X     The value to divide by 2 mod \p N.
+ * \param[in]     N     The modulus. Must be odd.
+ * \param[in]     limbs The number of limbs in \p X and \p N.
+ */
+MBEDTLS_STATIC_TESTABLE
+void mbedtls_mpi_core_div2_mod_odd(mbedtls_mpi_uint *X,
+                                   const mbedtls_mpi_uint *N,
+                                   size_t limbs);
+
+#endif /* MBEDTLS_TEST_HOOKS */
 
 #endif /* MBEDTLS_BIGNUM_CORE_INVASIVE_H */