|
|
@@ -67,7 +67,9 @@ static inline size_t bits_to_words(size_t bits)
|
|
|
/* Return the number of words actually used to represent an mpi
|
|
|
number.
|
|
|
*/
|
|
|
-#if defined(MBEDTLS_MPI_EXP_MOD_ALT)
|
|
|
+int __wrap_mbedtls_mpi_exp_mod( mbedtls_mpi *Z, const mbedtls_mpi *X, const mbedtls_mpi *Y, const mbedtls_mpi *M, mbedtls_mpi *_Rinv );
|
|
|
+extern int __real_mbedtls_mpi_exp_mod( mbedtls_mpi *Z, const mbedtls_mpi *X, const mbedtls_mpi *Y, const mbedtls_mpi *M, mbedtls_mpi *_Rinv );
|
|
|
+
|
|
|
static size_t mpi_words(const mbedtls_mpi *mpi)
|
|
|
{
|
|
|
for (size_t i = mpi->n; i > 0; i--) {
|
|
|
@@ -78,7 +80,6 @@ static size_t mpi_words(const mbedtls_mpi *mpi)
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-#endif //MBEDTLS_MPI_EXP_MOD_ALT
|
|
|
|
|
|
/**
|
|
|
*
|
|
|
@@ -181,8 +182,6 @@ cleanup:
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
-#if defined(MBEDTLS_MPI_EXP_MOD_ALT)
|
|
|
-
|
|
|
#ifdef ESP_MPI_USE_MONT_EXP
|
|
|
/*
|
|
|
* Return the most significant one-bit.
|
|
|
@@ -273,7 +272,7 @@ cleanup2:
|
|
|
* (See RSA Accelerator section in Technical Reference for more about Mprime, Rinv)
|
|
|
*
|
|
|
*/
|
|
|
-int mbedtls_mpi_exp_mod( mbedtls_mpi *Z, const mbedtls_mpi *X, const mbedtls_mpi *Y, const mbedtls_mpi *M, mbedtls_mpi *_Rinv )
|
|
|
+int __wrap_mbedtls_mpi_exp_mod( mbedtls_mpi *Z, const mbedtls_mpi *X, const mbedtls_mpi *Y, const mbedtls_mpi *M, mbedtls_mpi *_Rinv )
|
|
|
{
|
|
|
int ret = 0;
|
|
|
size_t x_words = mpi_words(X);
|
|
|
@@ -303,7 +302,11 @@ int mbedtls_mpi_exp_mod( mbedtls_mpi *Z, const mbedtls_mpi *X, const mbedtls_mpi
|
|
|
}
|
|
|
|
|
|
if (num_words * 32 > SOC_RSA_MAX_BIT_LEN) {
|
|
|
+#ifdef CONFIG_MBEDTLS_LARGE_KEY_SOFTWARE_MPI
|
|
|
+ return __real_mbedtls_mpi_exp_mod(Z, X, Y, M, _Rinv);
|
|
|
+#else
|
|
|
return MBEDTLS_ERR_MPI_NOT_ACCEPTABLE;
|
|
|
+#endif
|
|
|
}
|
|
|
|
|
|
/* Determine RR pointer, either _RR for cached value
|
|
|
@@ -352,10 +355,6 @@ cleanup:
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
-#endif /* MBEDTLS_MPI_EXP_MOD_ALT */
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
#if defined(MBEDTLS_MPI_MUL_MPI_ALT) /* MBEDTLS_MPI_MUL_MPI_ALT */
|
|
|
|
|
|
static int mpi_mult_mpi_failover_mod_mult( mbedtls_mpi *Z, const mbedtls_mpi *X, const mbedtls_mpi *Y, size_t z_words);
|