From ae55707b2859ca1abf2d349213670283aeec59f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Mon, 20 Mar 2017 12:21:24 +0100 Subject: [PATCH] Turn double loop into single loop In preparation for making the loop restartable --- library/ecp.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/library/ecp.c b/library/ecp.c index 2d473d9b4..5ee97c895 100644 --- a/library/ecp.c +++ b/library/ecp.c @@ -1359,12 +1359,15 @@ static int ecp_precompute_comb( const mbedtls_ecp_group *grp, MBEDTLS_MPI_CHK( mbedtls_ecp_copy( &T[0], P ) ); - for( i = 1; i < T_len; i <<= 1 ) + for( j = 0; j < d * ( w - 1 ); j++ ) { + i = 1U << ( j / d ); cur = T + i; - MBEDTLS_MPI_CHK( mbedtls_ecp_copy( cur, T + ( i >> 1 ) ) ); - for( j = 0; j < d; j++ ) - MBEDTLS_MPI_CHK( ecp_double_jac( grp, cur, cur ) ); + + if( j % d == 0 ) + MBEDTLS_MPI_CHK( mbedtls_ecp_copy( cur, T + ( i >> 1 ) ) ); + + MBEDTLS_MPI_CHK( ecp_double_jac( grp, cur, cur ) ); } #if defined(MBEDTLS_ECP_EARLY_RETURN)