mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
esp_bignum: move check for supported MPI bits at start of API
This can allow hardware MPI API to return as soon as it identifies that it can handle require bitlength operation.
This commit is contained in:
parent
1cae1fc18e
commit
7a8c8f8576
@ -277,19 +277,23 @@ cleanup2:
|
||||
static int esp_mpi_exp_mod( mbedtls_mpi *Z, const mbedtls_mpi *X, const mbedtls_mpi *Y, const mbedtls_mpi *M, mbedtls_mpi *_Rinv )
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
mbedtls_mpi Rinv_new; /* used if _Rinv == NULL */
|
||||
mbedtls_mpi *Rinv; /* points to _Rinv (if not NULL) othwerwise &RR_new */
|
||||
mbedtls_mpi_uint Mprime;
|
||||
|
||||
size_t x_words = mpi_words(X);
|
||||
size_t y_words = mpi_words(Y);
|
||||
size_t m_words = mpi_words(M);
|
||||
|
||||
|
||||
/* "all numbers must be the same length", so choose longest number
|
||||
as cardinal length of operation...
|
||||
*/
|
||||
size_t num_words = esp_mpi_hardware_words(MAX(m_words, MAX(x_words, y_words)));
|
||||
|
||||
mbedtls_mpi Rinv_new; /* used if _Rinv == NULL */
|
||||
mbedtls_mpi *Rinv; /* points to _Rinv (if not NULL) othwerwise &RR_new */
|
||||
mbedtls_mpi_uint Mprime;
|
||||
if (num_words * 32 > SOC_RSA_MAX_BIT_LEN) {
|
||||
return MBEDTLS_ERR_MPI_NOT_ACCEPTABLE;
|
||||
}
|
||||
|
||||
if (mbedtls_mpi_cmp_int(M, 0) <= 0 || (M->p[0] & 1) == 0) {
|
||||
return MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
|
||||
@ -303,10 +307,6 @@ static int esp_mpi_exp_mod( mbedtls_mpi *Z, const mbedtls_mpi *X, const mbedtls_
|
||||
return mbedtls_mpi_lset(Z, 1);
|
||||
}
|
||||
|
||||
if (num_words * 32 > SOC_RSA_MAX_BIT_LEN) {
|
||||
return MBEDTLS_ERR_MPI_NOT_ACCEPTABLE;
|
||||
}
|
||||
|
||||
/* Determine RR pointer, either _RR for cached value
|
||||
or local RR_new */
|
||||
if (_Rinv == NULL) {
|
||||
|
Loading…
Reference in New Issue
Block a user