Expand test to ensure no assumption on output
The functions don't require the caller to preserve the content of the output parameter - let's ensure that they don't assume that.
This commit is contained in:
parent
90f31b71a8
commit
7a28e99fa0
@ -2,6 +2,10 @@
|
||||
#include "mbedtls/ecp.h"
|
||||
|
||||
#define ECP_PF_UNKNOWN -1
|
||||
|
||||
#define ECP_PT_RESET( x ) \
|
||||
mbedtls_ecp_point_free( x ); \
|
||||
mbedtls_ecp_point_init( x );
|
||||
/* END_HEADER */
|
||||
|
||||
/* BEGIN_DEPENDENCIES
|
||||
@ -78,13 +82,14 @@ void ecp_test_vect_restart( int id,
|
||||
*/
|
||||
mbedtls_ecp_restart_ctx ctx;
|
||||
mbedtls_ecp_group grp;
|
||||
mbedtls_ecp_point R;
|
||||
mbedtls_ecp_point R, P;
|
||||
mbedtls_mpi dA, xA, yA, dB, xZ, yZ;
|
||||
int cnt_restarts;
|
||||
int ret;
|
||||
|
||||
mbedtls_ecp_restart_init( &ctx );
|
||||
mbedtls_ecp_group_init( &grp ); mbedtls_ecp_point_init( &R );
|
||||
mbedtls_ecp_group_init( &grp );
|
||||
mbedtls_ecp_point_init( &R ); mbedtls_ecp_point_init( &P );
|
||||
mbedtls_mpi_init( &dA ); mbedtls_mpi_init( &xA ); mbedtls_mpi_init( &yA );
|
||||
mbedtls_mpi_init( &dB ); mbedtls_mpi_init( &xZ ); mbedtls_mpi_init( &yZ );
|
||||
|
||||
@ -103,6 +108,7 @@ void ecp_test_vect_restart( int id,
|
||||
/* Base point case */
|
||||
cnt_restarts = 0;
|
||||
do {
|
||||
ECP_PT_RESET( &R );
|
||||
ret = mbedtls_ecp_mul_restartable( &grp, &R, &dA, &grp.G, NULL, NULL, &ctx );
|
||||
} while( ret == MBEDTLS_ERR_ECP_IN_PROGRESS && ++cnt_restarts );
|
||||
|
||||
@ -114,9 +120,11 @@ void ecp_test_vect_restart( int id,
|
||||
TEST_ASSERT( cnt_restarts <= max_restarts );
|
||||
|
||||
/* Non-base point case */
|
||||
mbedtls_ecp_copy( &P, &R );
|
||||
cnt_restarts = 0;
|
||||
do {
|
||||
ret = mbedtls_ecp_mul_restartable( &grp, &R, &dB, &R, NULL, NULL, &ctx );
|
||||
ECP_PT_RESET( &R );
|
||||
ret = mbedtls_ecp_mul_restartable( &grp, &R, &dB, &P, NULL, NULL, &ctx );
|
||||
} while( ret == MBEDTLS_ERR_ECP_IN_PROGRESS && ++cnt_restarts );
|
||||
|
||||
TEST_ASSERT( ret == 0 );
|
||||
@ -130,13 +138,14 @@ void ecp_test_vect_restart( int id,
|
||||
* This test only makes sense when we actually restart */
|
||||
if( min_restarts > 0 )
|
||||
{
|
||||
ret = mbedtls_ecp_mul_restartable( &grp, &R, &dB, &R, NULL, NULL, &ctx );
|
||||
ret = mbedtls_ecp_mul_restartable( &grp, &R, &dB, &P, NULL, NULL, &ctx );
|
||||
TEST_ASSERT( ret == MBEDTLS_ERR_ECP_IN_PROGRESS );
|
||||
}
|
||||
|
||||
exit:
|
||||
mbedtls_ecp_restart_free( &ctx );
|
||||
mbedtls_ecp_group_free( &grp ); mbedtls_ecp_point_free( &R );
|
||||
mbedtls_ecp_group_free( &grp );
|
||||
mbedtls_ecp_point_free( &R ); mbedtls_ecp_point_free( &P );
|
||||
mbedtls_mpi_free( &dA ); mbedtls_mpi_free( &xA ); mbedtls_mpi_free( &yA );
|
||||
mbedtls_mpi_free( &dB ); mbedtls_mpi_free( &xZ ); mbedtls_mpi_free( &yZ );
|
||||
}
|
||||
@ -183,6 +192,7 @@ void ecp_muladd_restart( int id, char *xR_str, char *yR_str,
|
||||
|
||||
cnt_restarts = 0;
|
||||
do {
|
||||
ECP_PT_RESET( &R );
|
||||
ret = mbedtls_ecp_muladd_restartable( &grp, &R,
|
||||
&u1, &grp.G, &u2, &Q, &ctx );
|
||||
} while( ret == MBEDTLS_ERR_ECP_IN_PROGRESS && ++cnt_restarts );
|
||||
|
Loading…
Reference in New Issue
Block a user