Fix RSA perf regression
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
diff --git a/library/bignum_core.c b/library/bignum_core.c
index b41d046..5e19590 100644
--- a/library/bignum_core.c
+++ b/library/bignum_core.c
@@ -211,8 +211,14 @@
return;
}
- mbedtls_ct_memcpy_if(assign, (unsigned char *) X, (unsigned char *) A, NULL,
- limbs * sizeof(mbedtls_mpi_uint));
+ /* This function is very performance-sensitive for RSA. For this reason
+ * we have the loop below, instead of calling mbedtls_ct_memcpy_if
+ * (this is more optimal since here we don't have to handle the case where
+ * we copy awkwardly sized data).
+ */
+ for (size_t i = 0; i < limbs; i++) {
+ X[i] = mbedtls_ct_mpi_uint_if(assign, A[i], X[i]);
+ }
}
void mbedtls_mpi_core_cond_swap(mbedtls_mpi_uint *X,