mirror of
https://git.suyu.dev/suyu/mbedtls.git
synced 2025-12-23 15:55:10 +01:00
tests: Get rid of mbedtls_test_unhexify() in unit test code
In test functions calling mbedtls_test_unhexify(), change the type of the associated parameters from `char*` to `data_t`. That way the `unhexify` operation is done by the test framework and not by the unit test code. Use for the new parameters of type data_t the name of the local variable that used to store the `unhexify` version of the `char*` parameter. Signed-off-by: Ronald Cron <ronald.cron@arm.com>
This commit is contained in:
parent
1d5ef2919b
commit
14a5645cbf
12 changed files with 239 additions and 498 deletions
|
|
@ -433,33 +433,26 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_ECP_RESTARTABLE */
|
||||
void ecdsa_read_restart( int id, char *k_str, char *h_str, char *s_str,
|
||||
void ecdsa_read_restart( int id, data_t *pk, data_t *hash, data_t *sig,
|
||||
int max_ops, int min_restart, int max_restart )
|
||||
{
|
||||
mbedtls_ecdsa_context ctx;
|
||||
mbedtls_ecdsa_restart_ctx rs_ctx;
|
||||
unsigned char hash[64];
|
||||
unsigned char sig[200];
|
||||
unsigned char pk[65];
|
||||
size_t sig_len, hash_len, pk_len;
|
||||
int ret, cnt_restart;
|
||||
|
||||
mbedtls_ecdsa_init( &ctx );
|
||||
mbedtls_ecdsa_restart_init( &rs_ctx );
|
||||
|
||||
hash_len = mbedtls_test_unhexify(hash, h_str);
|
||||
sig_len = mbedtls_test_unhexify(sig, s_str);
|
||||
pk_len = mbedtls_test_unhexify(pk, k_str);
|
||||
|
||||
TEST_ASSERT( mbedtls_ecp_group_load( &ctx.grp, id ) == 0 );
|
||||
TEST_ASSERT( mbedtls_ecp_point_read_binary( &ctx.grp, &ctx.Q, pk, pk_len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_ecp_point_read_binary( &ctx.grp, &ctx.Q,
|
||||
pk->x, pk->len ) == 0 );
|
||||
|
||||
mbedtls_ecp_set_max_ops( max_ops );
|
||||
|
||||
cnt_restart = 0;
|
||||
do {
|
||||
ret = mbedtls_ecdsa_read_signature_restartable( &ctx,
|
||||
hash, hash_len, sig, sig_len, &rs_ctx );
|
||||
hash->x, hash->len, sig->x, sig->len, &rs_ctx );
|
||||
} while( ret == MBEDTLS_ERR_ECP_IN_PROGRESS && ++cnt_restart );
|
||||
|
||||
TEST_ASSERT( ret == 0 );
|
||||
|
|
@ -467,29 +460,31 @@ void ecdsa_read_restart( int id, char *k_str, char *h_str, char *s_str,
|
|||
TEST_ASSERT( cnt_restart <= max_restart );
|
||||
|
||||
/* try modifying r */
|
||||
sig[10]++;
|
||||
|
||||
TEST_ASSERT( sig->len > 10 );
|
||||
sig->x[10]++;
|
||||
do {
|
||||
ret = mbedtls_ecdsa_read_signature_restartable( &ctx,
|
||||
hash, hash_len, sig, sig_len, &rs_ctx );
|
||||
hash->x, hash->len, sig->x, sig->len, &rs_ctx );
|
||||
} while( ret == MBEDTLS_ERR_ECP_IN_PROGRESS );
|
||||
TEST_ASSERT( ret == MBEDTLS_ERR_ECP_VERIFY_FAILED );
|
||||
sig[10]--;
|
||||
sig->x[10]--;
|
||||
|
||||
/* try modifying s */
|
||||
sig[sig_len - 1]++;
|
||||
sig->x[sig->len - 1]++;
|
||||
do {
|
||||
ret = mbedtls_ecdsa_read_signature_restartable( &ctx,
|
||||
hash, hash_len, sig, sig_len, &rs_ctx );
|
||||
hash->x, hash->len, sig->x, sig->len, &rs_ctx );
|
||||
} while( ret == MBEDTLS_ERR_ECP_IN_PROGRESS );
|
||||
TEST_ASSERT( ret == MBEDTLS_ERR_ECP_VERIFY_FAILED );
|
||||
sig[sig_len - 1]--;
|
||||
sig->x[sig->len - 1]--;
|
||||
|
||||
/* 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,
|
||||
hash, hash_len, sig, sig_len, &rs_ctx );
|
||||
hash->x, hash->len, sig->x, sig->len, &rs_ctx );
|
||||
TEST_ASSERT( ret == MBEDTLS_ERR_ECP_IN_PROGRESS );
|
||||
}
|
||||
|
||||
|
|
@ -501,7 +496,7 @@ exit:
|
|||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_ECP_RESTARTABLE:MBEDTLS_ECDSA_DETERMINISTIC */
|
||||
void ecdsa_write_restart( int id, char *d_str, int md_alg,
|
||||
char *msg, char *sig_str,
|
||||
char *msg, data_t *sig_check,
|
||||
int max_ops, int min_restart, int max_restart )
|
||||
{
|
||||
int ret, cnt_restart;
|
||||
|
|
@ -509,19 +504,16 @@ void ecdsa_write_restart( int id, char *d_str, int md_alg,
|
|||
mbedtls_ecdsa_context ctx;
|
||||
unsigned char hash[MBEDTLS_MD_MAX_SIZE];
|
||||
unsigned char sig[MBEDTLS_ECDSA_MAX_LEN];
|
||||
unsigned char sig_check[MBEDTLS_ECDSA_MAX_LEN];
|
||||
size_t hlen, slen, slen_check;
|
||||
size_t hlen, slen;
|
||||
const mbedtls_md_info_t *md_info;
|
||||
|
||||
mbedtls_ecdsa_restart_init( &rs_ctx );
|
||||
mbedtls_ecdsa_init( &ctx );
|
||||
memset( hash, 0, sizeof( hash ) );
|
||||
memset( sig, 0, sizeof( sig ) );
|
||||
memset( sig_check, 0, sizeof( sig_check ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_ecp_group_load( &ctx.grp, id ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &ctx.d, 16, d_str ) == 0 );
|
||||
slen_check = mbedtls_test_unhexify( sig_check, sig_str );
|
||||
|
||||
md_info = mbedtls_md_info_from_type( md_alg );
|
||||
TEST_ASSERT( md_info != NULL );
|
||||
|
|
@ -541,8 +533,8 @@ void ecdsa_write_restart( int id, char *d_str, int md_alg,
|
|||
} while( ret == MBEDTLS_ERR_ECP_IN_PROGRESS && ++cnt_restart );
|
||||
|
||||
TEST_ASSERT( ret == 0 );
|
||||
TEST_ASSERT( slen == slen_check );
|
||||
TEST_ASSERT( memcmp( sig, sig_check, slen ) == 0 );
|
||||
TEST_ASSERT( slen == sig_check->len );
|
||||
TEST_ASSERT( memcmp( sig, sig_check->x, slen ) == 0 );
|
||||
|
||||
TEST_ASSERT( cnt_restart >= min_restart );
|
||||
TEST_ASSERT( cnt_restart <= max_restart );
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue