core_exp_mod: improve window selection
We are looking at the exponent at limb granularity and therefore
exponent bits can't go below 32.
The `mpi_` prefix is also removed as it is better not to have prefix at
all than to have just a partial. (Full prefix would be overly long and
would hurt readability.)
Signed-off-by: Janos Follath <janos.follath@arm.com>
diff --git a/library/bignum_core.c b/library/bignum_core.c
index 2337ae5..79d5a72 100644
--- a/library/bignum_core.c
+++ b/library/bignum_core.c
@@ -583,10 +583,10 @@
/* BEGIN MERGE SLOT 1 */
-static size_t mpi_exp_mod_get_window_size( size_t Ebits )
+static size_t exp_mod_get_window_size( size_t Ebits )
{
size_t wsize = ( Ebits > 671 ) ? 6 : ( Ebits > 239 ) ? 5 :
- ( Ebits > 79 ) ? 4 : ( Ebits > 23 ) ? 3 : 1;
+ ( Ebits > 79 ) ? 4 : 1;
#if( MBEDTLS_MPI_WINDOW_SIZE < 6 )
if( wsize > MBEDTLS_MPI_WINDOW_SIZE )
@@ -618,7 +618,7 @@
mm = mbedtls_mpi_core_montmul_init( N ); /* Compute Montgomery constant */
E += E_len; /* Skip to end of exponent buffer */
- wsize = mpi_exp_mod_get_window_size( E_len * biL );
+ wsize = exp_mod_get_window_size( E_len * biL );
welem = ( (size_t) 1 ) << wsize;
/* Allocate memory pool and set pointers to parts of it */