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>
This commit is contained in:
Janos Follath 2022-10-08 09:48:20 +01:00
parent 0f0d1e88a2
commit a77911e5c1

View File

@ -583,10 +583,10 @@ cleanup:
/* 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 @@ int mbedtls_mpi_core_exp_mod( mbedtls_mpi_uint *X,
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 */