mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-23 08:35:43 +01:00
Avoid running useless code in tests
With max_ops set to 0 or a very large value, we would always be doing an extra full operation for no testing value.
This commit is contained in:
parent
fd87e354f6
commit
46ba7f3a92
@ -254,10 +254,14 @@ void ecdsa_read_restart( int id, char *k_str, char *h_str, char *s_str,
|
|||||||
TEST_ASSERT( ret == MBEDTLS_ERR_ECP_VERIFY_FAILED );
|
TEST_ASSERT( ret == MBEDTLS_ERR_ECP_VERIFY_FAILED );
|
||||||
sig[sig_len - 1]--;
|
sig[sig_len - 1]--;
|
||||||
|
|
||||||
/* do we leak memory when aborting? */
|
/* Do we leak memory when aborting an operation?
|
||||||
|
* This test only makes sense when we actually restart */
|
||||||
|
if( min_restart > 0 )
|
||||||
|
{
|
||||||
ret = mbedtls_ecdsa_read_signature_restartable( &ctx,
|
ret = mbedtls_ecdsa_read_signature_restartable( &ctx,
|
||||||
hash, hash_len, sig, sig_len, &rs_ctx );
|
hash, hash_len, sig, sig_len, &rs_ctx );
|
||||||
TEST_ASSERT( ret == 0 || ret == MBEDTLS_ERR_ECP_IN_PROGRESS );
|
TEST_ASSERT( ret == MBEDTLS_ERR_ECP_IN_PROGRESS );
|
||||||
|
}
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
mbedtls_ecdsa_free( &ctx );
|
mbedtls_ecdsa_free( &ctx );
|
||||||
@ -311,10 +315,14 @@ void ecdsa_write_restart( int id, char *d_str, int md_alg,
|
|||||||
TEST_ASSERT( cnt_restart >= min_restart );
|
TEST_ASSERT( cnt_restart >= min_restart );
|
||||||
TEST_ASSERT( cnt_restart <= max_restart );
|
TEST_ASSERT( cnt_restart <= max_restart );
|
||||||
|
|
||||||
/* do we leak memory when aborting? */
|
/* Do we leak memory when aborting an operation?
|
||||||
|
* This test only makes sense when we actually restart */
|
||||||
|
if( min_restart > 0 )
|
||||||
|
{
|
||||||
ret = mbedtls_ecdsa_write_signature_restartable( &ctx,
|
ret = mbedtls_ecdsa_write_signature_restartable( &ctx,
|
||||||
md_alg, hash, hlen, sig, &slen, NULL, NULL, &rs_ctx );
|
md_alg, hash, hlen, sig, &slen, NULL, NULL, &rs_ctx );
|
||||||
TEST_ASSERT( ret == 0 || ret == MBEDTLS_ERR_ECP_IN_PROGRESS );
|
TEST_ASSERT( ret == MBEDTLS_ERR_ECP_IN_PROGRESS );
|
||||||
|
}
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
mbedtls_ecdsa_restart_free( &rs_ctx );
|
mbedtls_ecdsa_restart_free( &rs_ctx );
|
||||||
|
@ -103,13 +103,9 @@ void ecp_test_vect_restart( int id,
|
|||||||
cnt_restarts = 0;
|
cnt_restarts = 0;
|
||||||
do {
|
do {
|
||||||
ret = mbedtls_ecp_mul_restartable( &grp, &R, &dA, &grp.G, NULL, NULL, &ctx );
|
ret = mbedtls_ecp_mul_restartable( &grp, &R, &dA, &grp.G, NULL, NULL, &ctx );
|
||||||
TEST_ASSERT( ret == 0 || ret == MBEDTLS_ERR_ECP_IN_PROGRESS );
|
} while( ret == MBEDTLS_ERR_ECP_IN_PROGRESS && ++cnt_restarts );
|
||||||
|
|
||||||
if( ret == MBEDTLS_ERR_ECP_IN_PROGRESS )
|
|
||||||
cnt_restarts++;
|
|
||||||
}
|
|
||||||
while( ret != 0 );
|
|
||||||
|
|
||||||
|
TEST_ASSERT( ret == 0 );
|
||||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &R.X, &xA ) == 0 );
|
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &R.X, &xA ) == 0 );
|
||||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &R.Y, &yA ) == 0 );
|
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &R.Y, &yA ) == 0 );
|
||||||
|
|
||||||
@ -120,22 +116,22 @@ void ecp_test_vect_restart( int id,
|
|||||||
cnt_restarts = 0;
|
cnt_restarts = 0;
|
||||||
do {
|
do {
|
||||||
ret = mbedtls_ecp_mul_restartable( &grp, &R, &dB, &R, NULL, NULL, &ctx );
|
ret = mbedtls_ecp_mul_restartable( &grp, &R, &dB, &R, NULL, NULL, &ctx );
|
||||||
TEST_ASSERT( ret == 0 || ret == MBEDTLS_ERR_ECP_IN_PROGRESS );
|
} while( ret == MBEDTLS_ERR_ECP_IN_PROGRESS && ++cnt_restarts );
|
||||||
|
|
||||||
if( ret == MBEDTLS_ERR_ECP_IN_PROGRESS )
|
|
||||||
cnt_restarts++;
|
|
||||||
}
|
|
||||||
while( ret != 0 );
|
|
||||||
|
|
||||||
|
TEST_ASSERT( ret == 0 );
|
||||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &R.X, &xZ ) == 0 );
|
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &R.X, &xZ ) == 0 );
|
||||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &R.Y, &yZ ) == 0 );
|
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &R.Y, &yZ ) == 0 );
|
||||||
|
|
||||||
TEST_ASSERT( cnt_restarts >= min_restarts );
|
TEST_ASSERT( cnt_restarts >= min_restarts );
|
||||||
TEST_ASSERT( cnt_restarts <= max_restarts );
|
TEST_ASSERT( cnt_restarts <= max_restarts );
|
||||||
|
|
||||||
/* Do we leak memory when not finishing an operation? */
|
/* Do we leak memory when aborting an operation?
|
||||||
|
* 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, &R, NULL, NULL, &ctx );
|
||||||
TEST_ASSERT( ret == 0 || ret == MBEDTLS_ERR_ECP_IN_PROGRESS );
|
TEST_ASSERT( ret == MBEDTLS_ERR_ECP_IN_PROGRESS );
|
||||||
|
}
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
mbedtls_ecp_restart_free( &ctx );
|
mbedtls_ecp_restart_free( &ctx );
|
||||||
@ -188,23 +184,23 @@ void ecp_muladd_restart( int id, char *xR_str, char *yR_str,
|
|||||||
do {
|
do {
|
||||||
ret = mbedtls_ecp_muladd_restartable( &grp, &R,
|
ret = mbedtls_ecp_muladd_restartable( &grp, &R,
|
||||||
&u1, &grp.G, &u2, &Q, &ctx );
|
&u1, &grp.G, &u2, &Q, &ctx );
|
||||||
TEST_ASSERT( ret == 0 || ret == MBEDTLS_ERR_ECP_IN_PROGRESS );
|
} while( ret == MBEDTLS_ERR_ECP_IN_PROGRESS && ++cnt_restarts );
|
||||||
|
|
||||||
if( ret == MBEDTLS_ERR_ECP_IN_PROGRESS )
|
|
||||||
cnt_restarts++;
|
|
||||||
}
|
|
||||||
while( ret != 0 );
|
|
||||||
|
|
||||||
|
TEST_ASSERT( ret == 0 );
|
||||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &R.X, &xR ) == 0 );
|
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &R.X, &xR ) == 0 );
|
||||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &R.Y, &yR ) == 0 );
|
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &R.Y, &yR ) == 0 );
|
||||||
|
|
||||||
TEST_ASSERT( cnt_restarts >= min_restarts );
|
TEST_ASSERT( cnt_restarts >= min_restarts );
|
||||||
TEST_ASSERT( cnt_restarts <= max_restarts );
|
TEST_ASSERT( cnt_restarts <= max_restarts );
|
||||||
|
|
||||||
/* Do we leak memory when aborting? */
|
/* Do we leak memory when aborting an operation?
|
||||||
|
* This test only makes sense when we actually restart */
|
||||||
|
if( min_restarts > 0 )
|
||||||
|
{
|
||||||
ret = mbedtls_ecp_muladd_restartable( &grp, &R,
|
ret = mbedtls_ecp_muladd_restartable( &grp, &R,
|
||||||
&u1, &grp.G, &u2, &Q, &ctx );
|
&u1, &grp.G, &u2, &Q, &ctx );
|
||||||
TEST_ASSERT( ret == 0 || ret == MBEDTLS_ERR_ECP_IN_PROGRESS );
|
TEST_ASSERT( ret == MBEDTLS_ERR_ECP_IN_PROGRESS );
|
||||||
|
}
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
mbedtls_ecp_restart_free( &ctx );
|
mbedtls_ecp_restart_free( &ctx );
|
||||||
|
@ -347,16 +347,20 @@ void pk_sign_verify_restart( int pk_type, int grp_id, char *d_str,
|
|||||||
TEST_ASSERT( ret != 0 );
|
TEST_ASSERT( ret != 0 );
|
||||||
sig[0]--;
|
sig[0]--;
|
||||||
|
|
||||||
/* Do we leak memory when aborting? try verify then sign */
|
/* Do we leak memory when aborting? try verify then sign
|
||||||
|
* This test only makes sense when we actually restart */
|
||||||
|
if( min_restart > 0 )
|
||||||
|
{
|
||||||
ret = mbedtls_pk_verify_restartable( &pub, md_alg,
|
ret = mbedtls_pk_verify_restartable( &pub, md_alg,
|
||||||
hash, hlen, sig, slen, &rs_ctx );
|
hash, hlen, sig, slen, &rs_ctx );
|
||||||
TEST_ASSERT( ret == 0 || ret == MBEDTLS_ERR_ECP_IN_PROGRESS );
|
TEST_ASSERT( ret == MBEDTLS_ERR_ECP_IN_PROGRESS );
|
||||||
mbedtls_pk_restart_free( &rs_ctx );
|
mbedtls_pk_restart_free( &rs_ctx );
|
||||||
|
|
||||||
slen = sizeof( sig );
|
slen = sizeof( sig );
|
||||||
ret = mbedtls_pk_sign_restartable( &prv, md_alg, hash, hlen,
|
ret = mbedtls_pk_sign_restartable( &prv, md_alg, hash, hlen,
|
||||||
sig, &slen, NULL, NULL, &rs_ctx );
|
sig, &slen, NULL, NULL, &rs_ctx );
|
||||||
TEST_ASSERT( ret == 0 || ret == MBEDTLS_ERR_ECP_IN_PROGRESS );
|
TEST_ASSERT( ret == MBEDTLS_ERR_ECP_IN_PROGRESS );
|
||||||
|
}
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
mbedtls_pk_restart_free( &rs_ctx );
|
mbedtls_pk_restart_free( &rs_ctx );
|
||||||
|
Loading…
Reference in New Issue
Block a user