Move the quasi reduction fixing function to bignum_mod_raw
Rename the function to 'fix_quasi_reduction' to better suite its functionality.
Also changed the name prefix to suite for the new module.
Signed-off-by: Gabor Mezei <gabor.mezei@arm.com>
diff --git a/library/bignum_mod_raw.c b/library/bignum_mod_raw.c
index aa2bd46..b232182 100644
--- a/library/bignum_mod_raw.c
+++ b/library/bignum_mod_raw.c
@@ -128,6 +128,21 @@
N->rep.mont.mm, T);
}
+MBEDTLS_STATIC_TESTABLE
+int mbedtls_mpi_mod_raw_fix_quasi_reduction(mbedtls_mpi_uint *X,
+ const mbedtls_mpi_mod_modulus *N)
+{
+ if (N->limbs == 0) {
+ return MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
+ }
+
+ mbedtls_mpi_uint c = mbedtls_mpi_core_sub(X, X, N->p, N->limbs);
+
+ (void) mbedtls_mpi_core_add_if(X, N->p, N->limbs, (unsigned) c);
+
+ return 0;
+}
+
/* END MERGE SLOT 2 */
/* BEGIN MERGE SLOT 3 */
diff --git a/library/ecp_internal.h b/library/bignum_mod_raw_invasive.h
similarity index 73%
rename from library/ecp_internal.h
rename to library/bignum_mod_raw_invasive.h
index b028225..3d4afed 100644
--- a/library/ecp_internal.h
+++ b/library/bignum_mod_raw_invasive.h
@@ -1,8 +1,8 @@
/**
- * \file ecp_internal.h
+ * \file bignum_mod_raw_invasive.h
*
- * \brief Function declarations for internal functions of elliptic curve
- * point arithmetic.
+ * \brief Function declarations for invasive functions of Low-level
+ * modular bignum.
*/
/**
* Copyright The Mbed TLS Contributors
@@ -21,8 +21,8 @@
* limitations under the License.
*/
-#ifndef MBEDTLS_ECP_INTERNAL_H
-#define MBEDTLS_ECP_INTERNAL_H
+#ifndef MBEDTLS_BIGNUM_MOD_RAW_INVASIVE_H
+#define MBEDTLS_BIGNUM_MOD_RAW_INVASIVE_H
#include "common.h"
#include "mbedtls/bignum.h"
@@ -40,7 +40,8 @@
* \return \c 0 if successful.
* \return #MBEDTLS_ERR_MPI_BAD_INPUT_DATA if \p N is invalid.
*/
-int mbedtls_ecp_quasi_reduction(mbedtls_mpi_uint *X,
- const mbedtls_mpi_mod_modulus *N);
+MBEDTLS_STATIC_TESTABLE
+int mbedtls_mpi_mod_raw_fix_quasi_reduction(mbedtls_mpi_uint *X,
+ const mbedtls_mpi_mod_modulus *N);
-#endif /* MBEDTLS_ECP_INTERNAL_H */
+#endif /* MBEDTLS_BIGNUM_MOD_RAW_INVASIVE_H */
diff --git a/library/ecp.c b/library/ecp.c
index 835bfa3..6f53c1b 100644
--- a/library/ecp.c
+++ b/library/ecp.c
@@ -79,7 +79,6 @@
#include "bn_mul.h"
#include "ecp_invasive.h"
-#include "ecp_internal.h"
#include "bignum_core.h"
#include <string.h>
@@ -1031,20 +1030,6 @@
return ret;
}
-int mbedtls_ecp_quasi_reduction(mbedtls_mpi_uint *X,
- const mbedtls_mpi_mod_modulus *N)
-{
- if (N->limbs == 0) {
- return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
- }
-
- mbedtls_mpi_uint c = mbedtls_mpi_core_sub(X, X, N->p, N->limbs);
-
- (void) mbedtls_mpi_core_add_if(X, N->p, N->limbs, (unsigned) c);
-
- return 0;
-}
-
/*
* Fast mod-p functions expect their argument to be in the 0..p^2 range.
*