Stop checking for argument change
This was intended to detect aborted operations, but now that case is handled
by the caller freeing the restart context.
Also, as the internal sub-context is managed by the callee, no need for the
caller to free/reset the restart context between successful calls.
diff --git a/include/mbedtls/ecp.h b/include/mbedtls/ecp.h
index 59d9d3d..d9e62f0 100644
--- a/include/mbedtls/ecp.h
+++ b/include/mbedtls/ecp.h
@@ -263,9 +263,10 @@
*
* If more operations are needed to complete a computation,
* MBEDTLS_ERR_ECP_IN_PROGRESS will be returned by the
- * function performing the computation. That function will
- * then need to be called again with the same arguments until
- * it returns 0 or an other error code.
+ * function performing the computation. It is then the
+ * caller's responsibility to either call again with the same
+ * arguments until it returns 0 or an error code; or to free
+ * the restart context if the operation is to be aborted.
*
* This only affects functions that accept a pointer to a
* \c mbedtls_ecp_restart_ctx as an argument, and only works
@@ -615,14 +616,11 @@
* \param P Point to multiply
* \param f_rng RNG function (see notes)
* \param p_rng RNG parameter
- * \param rs_ctx Restart context - must be non-NULL to enable early-return
+ * \param rs_ctx Restart context
*
* \return See \c mbedtls_ecp_mul(), or
* MBEDTLS_ERR_ECP_IN_PROGRESS if maximum number of
- * operations was reached (see \c mbedtls_ecp_set_max_ops()),
- * indicating the function should be called again with the
- * exact same arguments.
- *
+ * operations was reached: see \c mbedtls_ecp_set_max_ops().
*/
int mbedtls_ecp_mul_restartable( mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
const mbedtls_mpi *m, const mbedtls_ecp_point *P,
diff --git a/library/ecp.c b/library/ecp.c
index 21ce22f..fcc3ae0 100644
--- a/library/ecp.c
+++ b/library/ecp.c
@@ -105,8 +105,6 @@
*/
struct mbedtls_ecp_restart_mul {
unsigned ops_done; /* number of operations done this time */
- mbedtls_mpi m; /* saved argument: scalar */
- mbedtls_ecp_point P; /* saved argument: point */
mbedtls_ecp_point R; /* current intermediate result */
size_t i; /* current index in various loops, 0 outside */
mbedtls_ecp_point *T; /* table for precomputed points */
@@ -139,8 +137,6 @@
if( ctx == NULL )
return;
- mbedtls_mpi_free( &ctx->m );
- mbedtls_ecp_point_free( &ctx->P );
mbedtls_ecp_point_free( &ctx->R );
if( ctx->T != NULL ) {
@@ -1763,17 +1759,6 @@
#endif
#if defined(MBEDTLS_ECP_EARLY_RETURN)
- /* check for restart with new arguments */
- if( rs_ctx != NULL && rs_ctx->rsm != NULL && rs_ctx->rsm != NULL &&
- ( mbedtls_mpi_cmp_mpi( m, &rs_ctx->rsm->m ) != 0 ||
- mbedtls_mpi_cmp_mpi( &P->X, &rs_ctx->rsm->P.X ) != 0 ||
- mbedtls_mpi_cmp_mpi( &P->Y, &rs_ctx->rsm->P.Y ) != 0 ) )
- {
- ecp_restart_mul_free( rs_ctx->rsm );
- mbedtls_free( rs_ctx->rsm );
- rs_ctx->rsm = NULL;
- }
-
/* set up restart context if needed */
if( ecp_max_ops != 0 && rs_ctx != NULL && rs_ctx->rsm == NULL )
{
@@ -1782,9 +1767,6 @@
return( MBEDTLS_ERR_ECP_ALLOC_FAILED );
ecp_restart_mul_init( rs_ctx->rsm );
-
- MBEDTLS_MPI_CHK( mbedtls_mpi_copy( &rs_ctx->rsm->m, m ) );
- MBEDTLS_MPI_CHK( mbedtls_ecp_copy( &rs_ctx->rsm->P, P ) );
}
/* reset ops count for this call */
diff --git a/tests/suites/test_suite_ecp.function b/tests/suites/test_suite_ecp.function
index 195146c..23905ce 100644
--- a/tests/suites/test_suite_ecp.function
+++ b/tests/suites/test_suite_ecp.function
@@ -116,9 +116,6 @@
TEST_ASSERT( cnt_restarts >= min_restarts );
TEST_ASSERT( cnt_restarts <= max_restarts );
- /* Prepare context for new operation */
- mbedtls_ecp_restart_free( &ctx );
-
/* Non-base point case */
cnt_restarts = 0;
do {