From a77911e5c1e791854af8fb9e0b26319ac2b9e3be Mon Sep 17 00:00:00 2001 From: Janos Follath Date: Sat, 8 Oct 2022 09:48:20 +0100 Subject: [PATCH] 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 --- library/bignum_core.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/library/bignum_core.c b/library/bignum_core.c index 2337ae521..79d5a720e 100644 --- a/library/bignum_core.c +++ b/library/bignum_core.c @@ -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 */