Start moving to new design/API

Following discussion in the team, it was deemed preferable for the restart
context to be explicitly managed by the caller.

This commits in the first in a series moving in that directly: it starts by
only changing the public API, while still internally using the old design.
Future commits in that series will change to the new design internally.

The test function was simplified as it no longer makes sense to test for some
memory management errors since that responsibility shifted to the caller.
This commit is contained in:
Manuel Pégourié-Gonnard 2017-04-19 10:11:56 +02:00
parent 45fd0164dd
commit b739a712d1
3 changed files with 93 additions and 27 deletions

View file

@ -152,6 +152,27 @@ static void ecp_restart_mul_free( mbedtls_ecp_restart_mul_ctx *ctx )
memset( ctx, 0, sizeof( mbedtls_ecp_restart_mul_ctx ) );
}
/*
* Initialize a restart context
*/
void mbedtls_ecp_restart_init( mbedtls_ecp_restart_ctx *ctx )
{
memset( ctx, 0, sizeof( *ctx ) );
}
/*
* Free the components of a restart context
*/
void mbedtls_ecp_restart_free( mbedtls_ecp_restart_ctx *ctx )
{
if( ctx == NULL )
return;
ecp_restart_mul_free( ctx->rsm );
mbedtls_free( ctx->rsm );
ctx->rsm = NULL;
}
/*
* Operation counts
*/
@ -2111,6 +2132,20 @@ cleanup:
return( ret );
}
#if defined(MBEDTLS_ECP_EARLY_RETURN)
/*
* Restartable multiplication R = m * P
*/
int mbedtls_ecp_mul_restartable( mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
const mbedtls_mpi *m, const mbedtls_ecp_point *P,
int (*f_rng)(void *, unsigned char *, size_t), void *p_rng,
mbedtls_ecp_restart_ctx *rs_ctx )
{
(void) rs_ctx; /* cheating for now */
return( mbedtls_ecp_mul( grp, R, m, P, f_rng, p_rng ) );
}
#endif
#if defined(ECP_SHORTWEIERSTRASS)
/*
* Check that an affine point is valid as a public key,