diff --git a/library/ecp.c b/library/ecp.c index 2ff882093..d7a4567ea 100644 --- a/library/ecp.c +++ b/library/ecp.c @@ -1353,6 +1353,14 @@ static int ecp_precompute_comb( const ecp_group *grp, ecp_normalize_many( grp, TT, k ); + /* + * Post-precessing: reclaim some memory by not storing Z (always 1) + */ + for( i = 0; i < ( 1U << (w-1) ); i++ ) + { + mpi_free( &T[i].Z ); + } + cleanup: return( ret ); } @@ -1368,6 +1376,9 @@ static int ecp_select_comb( const ecp_group *grp, ecp_point *R, /* Ignore the "sign" bit */ MPI_CHK( ecp_copy( R, &T[ ( i & 0x7Fu ) >> 1 ] ) ); + /* Restore the Z coordinate */ + MPI_CHK( mpi_lset( &R->Z, 1 ) ); + /* * -R = (R.X, -R.Y, R.Z), and * -R.Y mod P = P - R.Y unless R.Y == 0