1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-07-28 00:21:48 +03:00

static initialize comb table

MBEDTLS_ECP_FIXED_POINT_OPTIM aims to speed up ecc multiplication performance.

We compute the comb table in runtime now. It is a costly operation.

This patch add a pre-computed table to initialize well-known curves. It speed up ECDSA signature verify process in runtime by using more ROM size.

Signed-off-by: kXuan <kxuanobj@gmail.com>
This commit is contained in:
kXuan
2021-04-08 14:32:06 +08:00
parent 6d84e917bb
commit ba9cb76e9f
4 changed files with 4035 additions and 27 deletions

View File

@ -728,6 +728,18 @@ void mbedtls_ecp_point_free( mbedtls_ecp_point *pt )
mbedtls_mpi_free( &( pt->Z ) );
}
/*
* Check that the comb table (grp->T) is static initialized.
*/
static int ecp_group_is_static_comb_table( const mbedtls_ecp_group *grp ) {
#if MBEDTLS_ECP_FIXED_POINT_OPTIM == 1
return grp->T != NULL && grp->T_size == 0;
#else
(void) grp;
return 0;
#endif
}
/*
* Unallocate (the components of) a group
*/
@ -747,7 +759,7 @@ void mbedtls_ecp_group_free( mbedtls_ecp_group *grp )
mbedtls_mpi_free( &grp->N );
}
if( grp->T != NULL )
if( !ecp_group_is_static_comb_table(grp) && grp->T != NULL )
{
for( i = 0; i < grp->T_size; i++ )
mbedtls_ecp_point_free( &grp->T[i] );
@ -2245,11 +2257,16 @@ static unsigned char ecp_pick_window_size( const mbedtls_ecp_group *grp,
w++;
/*
* Make sure w is within bounds.
* If static comb table may not be used (!p_eq_g) or static comb table does
* not exists, make sure w is within bounds.
* (The last test is useful only for very small curves in the test suite.)
*
* The user reduces MBEDTLS_ECP_WINDOW_SIZE does not changes the size of
* static comb table, because the size of static comb table is fixed when
* it is generated.
*/
#if( MBEDTLS_ECP_WINDOW_SIZE < 6 )
if( w > MBEDTLS_ECP_WINDOW_SIZE )
if( (!p_eq_g || !ecp_group_is_static_comb_table(grp)) && w > MBEDTLS_ECP_WINDOW_SIZE )
w = MBEDTLS_ECP_WINDOW_SIZE;
#endif
if( w >= grp->nbits )