binum_mod: Added `mbedtls_mpi_mod_optred_modulus_setup()`.
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
diff --git a/library/bignum_mod.c b/library/bignum_mod.c
index acf45e9..9b0f6ec 100644
--- a/library/bignum_mod.c
+++ b/library/bignum_mod.c
@@ -171,6 +171,19 @@
return ret;
}
+int mbedtls_mpi_mod_optred_modulus_setup(mbedtls_mpi_mod_modulus *N,
+ const mbedtls_mpi_uint *p,
+ size_t p_limbs,
+ mbedtls_mpi_opt_red_struct *ored)
+{
+ N->p = p;
+ N->limbs = p_limbs;
+ N->bits = mbedtls_mpi_core_bitlen(p, p_limbs);
+ N->int_rep = MBEDTLS_MPI_MOD_REP_OPT_RED;
+ N->rep.ored =ored ;
+ return 0;
+}
+
int mbedtls_mpi_mod_mul(mbedtls_mpi_mod_residue *X,
const mbedtls_mpi_mod_residue *A,
const mbedtls_mpi_mod_residue *B,
diff --git a/library/bignum_mod.h b/library/bignum_mod.h
index db177ed..6c283b3 100644
--- a/library/bignum_mod.h
+++ b/library/bignum_mod.h
@@ -208,6 +208,23 @@
size_t p_limbs,
mbedtls_mpi_mod_rep_selector int_rep);
+/** Setup an optimised-reduction compatible modulus structure.
+ *
+ * \param[out] N The address of the modulus structure to populate.
+ * \param[in] p The address of the limb array storing the value of \p N.
+ * The memory pointed to by \p p will be used by \p N and must
+ * not be modified in any way until after
+ * mbedtls_mpi_mod_modulus_free() is called.
+ * \param p_limbs The number of limbs of \p p.
+ * \param ored The optimized reduction structure to use. \p p.
+ *
+ * \return \c 0 if successful.
+ */
+int mbedtls_mpi_mod_optred_modulus_setup(mbedtls_mpi_mod_modulus *N,
+ const mbedtls_mpi_uint *p,
+ size_t p_limbs,
+ mbedtls_mpi_opt_red_struct *ored);
+
/** Free elements of a modulus structure.
*
* This function frees any memory allocated by mbedtls_mpi_mod_modulus_setup().