Extract MPI_CORE(add) from the prototype
Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
diff --git a/library/bignum_core.c b/library/bignum_core.c
index 0083729..3f4e651 100644
--- a/library/bignum_core.c
+++ b/library/bignum_core.c
@@ -316,8 +316,6 @@
return( 0 );
}
-
-
void mbedtls_mpi_core_shift_r( mbedtls_mpi_uint *X, size_t limbs,
size_t count )
{
@@ -360,7 +358,21 @@
}
}
-
+mbedtls_mpi_uint MPI_CORE(add)( mbedtls_mpi_uint *d,
+ const mbedtls_mpi_uint *l,
+ const mbedtls_mpi_uint *r,
+ size_t n )
+{
+ mbedtls_mpi_uint c = 0, t;
+ for( size_t i = 0; i < n; i++ )
+ {
+ t = c;
+ t += l[i]; c = ( t < l[i] );
+ t += r[i]; c += ( t < r[i] );
+ d[i] = t;
+ }
+ return( c );
+}
mbedtls_mpi_uint mbedtls_mpi_core_add_if( mbedtls_mpi_uint *X,
const mbedtls_mpi_uint *A,
diff --git a/library/bignum_core.h b/library/bignum_core.h
index 56a3bf8..0d7b89f 100644
--- a/library/bignum_core.h
+++ b/library/bignum_core.h
@@ -277,6 +277,29 @@
void mbedtls_mpi_core_shift_r( mbedtls_mpi_uint *X, size_t limbs,
size_t count );
+#define MPI_CORE(func) mbedtls_mpi_core_ ## func ## _minimal
+
+/**
+ * \brief Add two known-size large unsigned integers, returning the carry.
+ *
+ * Calculate l + r where l and r have the same size.
+ * This function operates modulo (2^ciL)^n and returns the carry
+ * (1 if there was a wraparound, and 0 otherwise).
+ *
+ * d may be aliased to l or r.
+ *
+ * \param[out] d The result of the addition.
+ * \param[in] l The left operand.
+ * \param[in] r The right operand.
+ * \param n Number of limbs of \p d, \p l and \p r.
+ *
+ * \return 1 if `l + r >= (2^{ciL})^n`, 0 otherwise.
+ */
+mbedtls_mpi_uint MPI_CORE(add)( mbedtls_mpi_uint *d,
+ const mbedtls_mpi_uint *l,
+ const mbedtls_mpi_uint *r,
+ size_t n );
+
/**
* \brief Conditional addition of two fixed-size large unsigned integers,
* returning the carry.