diff --git a/library/ecp.c b/library/ecp.c index 47c7da2a25..7bcf25626f 100644 --- a/library/ecp.c +++ b/library/ecp.c @@ -1334,6 +1334,7 @@ static int ecp_precompute_comb( const mbedtls_ecp_group *grp, int ret; unsigned char i; size_t j; + const unsigned char T_len = 1U << ( w - 1 ); mbedtls_ecp_point *cur, *TT[COMB_MAX_PRE - 1]; #if defined(MBEDTLS_ECP_EARLY_RETURN) @@ -1351,7 +1352,7 @@ static int ecp_precompute_comb( const mbedtls_ecp_group *grp, */ MBEDTLS_MPI_CHK( mbedtls_ecp_copy( &T[0], P ) ); - for( i = 1; i < ( 1U << ( w - 1 ) ); i <<= 1 ) + for( i = 1; i < T_len; i <<= 1 ) { cur = T + i; MBEDTLS_MPI_CHK( mbedtls_ecp_copy( cur, T + ( i >> 1 ) ) ); @@ -1364,7 +1365,7 @@ static int ecp_precompute_comb( const mbedtls_ecp_group *grp, * use an auxiliary array of pointers to elements in T. */ j = 0; - for( i = 1; i < ( 1U << ( w - 1 ) ); i <<= 1 ) + for( i = 1; i < T_len; i <<= 1 ) TT[j++] = T + i; MBEDTLS_MPI_CHK( ecp_normalize_jac_many( grp, TT, j ) ); @@ -1373,7 +1374,7 @@ static int ecp_precompute_comb( const mbedtls_ecp_group *grp, * Compute the remaining ones using the minimal number of additions * Be careful to update T[2^l] only after using it! */ - for( i = 1; i < ( 1U << ( w - 1 ) ); i <<= 1 ) + for( i = 1; i < T_len; i <<= 1 ) { j = i; while( j-- ) @@ -1383,9 +1384,9 @@ static int ecp_precompute_comb( const mbedtls_ecp_group *grp, /* * Normalize final elements in T. Even though there are no holes now, * we still need the auxiliary array for homogeneity with last time. - * Also skip T[0] which is already normalised, being a copy of P. + * Also, skip T[0] which is already normalised, being a copy of P. */ - for( j = 0; j + 1 < ( 1U << ( w - 1 ) ); j++ ) + for( j = 0; j + 1 < T_len; j++ ) TT[j] = T + j + 1; MBEDTLS_MPI_CHK( ecp_normalize_jac_many( grp, TT, j ) );