Skip to content

Commit beb3b88

Browse files
Ron EldorRon Eldor
Ron Eldor
authored and
Ron Eldor
committed
Adjust new tests to TEST_ASSERT_RET
Change `TEST_ASSERT` to `TEST_ASSERT_RET` to new `ecdh` tests.
1 parent 4a60058 commit beb3b88

File tree

1 file changed

+52
-52
lines changed

1 file changed

+52
-52
lines changed

tests/suites/test_suite_ecdh.function

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ static int load_public_key( int grp_id, data_t *point,
55
mbedtls_ecp_keypair *ecp )
66
{
77
int ok = 0;
8-
TEST_ASSERT( mbedtls_ecp_group_load( &ecp->grp, grp_id ) == 0 );
9-
TEST_ASSERT( mbedtls_ecp_point_read_binary( &ecp->grp,
10-
&ecp->Q,
11-
point->x,
12-
point->len ) == 0 );
13-
TEST_ASSERT( mbedtls_ecp_check_pubkey( &ecp->grp,
14-
&ecp->Q ) == 0 );
8+
TEST_ASSERT_RET( mbedtls_ecp_group_load( &ecp->grp, grp_id ), 0 );
9+
TEST_ASSERT_RET( mbedtls_ecp_point_read_binary( &ecp->grp,
10+
&ecp->Q,
11+
point->x,
12+
point->len ), 0 );
13+
TEST_ASSERT_RET( mbedtls_ecp_check_pubkey( &ecp->grp,
14+
&ecp->Q ), 0 );
1515
ok = 1;
1616
exit:
1717
return( ok );
@@ -22,14 +22,14 @@ static int load_private_key( int grp_id, data_t *private_key,
2222
rnd_pseudo_info *rnd_info )
2323
{
2424
int ok = 0;
25-
TEST_ASSERT( mbedtls_ecp_read_key( grp_id, ecp,
26-
private_key->x,
27-
private_key->len ) == 0 );
28-
TEST_ASSERT( mbedtls_ecp_check_privkey( &ecp->grp, &ecp->d ) == 0 );
25+
TEST_ASSERT_RET( mbedtls_ecp_read_key( grp_id, ecp,
26+
private_key->x,
27+
private_key->len ), 0 );
28+
TEST_ASSERT_RET( mbedtls_ecp_check_privkey( &ecp->grp, &ecp->d ), 0 );
2929
/* Calculate the public key from the private key. */
30-
TEST_ASSERT( mbedtls_ecp_mul( &ecp->grp, &ecp->Q, &ecp->d,
31-
&ecp->grp.G,
32-
&rnd_pseudo_rand, rnd_info ) == 0 );
30+
TEST_ASSERT_RET( mbedtls_ecp_mul( &ecp->grp, &ecp->Q, &ecp->d,
31+
&ecp->grp.G,
32+
&rnd_pseudo_rand, rnd_info ), 0 );
3333
ok = 1;
3434
exit:
3535
return( ok );
@@ -372,13 +372,13 @@ void ecdh_restart( int id, char *dA_str, char *dB_str, char *z_str,
372372

373373
/* The ECDH context is not guaranteed ot have an mbedtls_ecp_group structure
374374
* in every configuration, therefore we load it separately. */
375-
TEST_ASSERT( mbedtls_ecp_group_load( &grp, id ) == 0 );
375+
TEST_ASSERT_RET( mbedtls_ecp_group_load( &grp, id ), 0 );
376376

377377
/* Otherwise we would have to fix the random buffer,
378378
* as in ecdh_primitive_testvec. */
379379
TEST_ASSERT( grp.nbits % 8 == 0 );
380380

381-
TEST_ASSERT( mbedtls_ecdh_setup( &srv, id ) == 0 );
381+
TEST_ASSERT_RET( mbedtls_ecdh_setup( &srv, id ), 0 );
382382

383383
/* set up restart parameters */
384384
mbedtls_ecp_set_max_ops( max_ops );
@@ -405,7 +405,7 @@ void ecdh_restart( int id, char *dA_str, char *dB_str, char *z_str,
405405

406406
/* client read server params */
407407
vbuf = buf;
408-
TEST_ASSERT( mbedtls_ecdh_read_params( &cli, &vbuf, buf + len ) == 0 );
408+
TEST_ASSERT_RET( mbedtls_ecdh_read_params( &cli, &vbuf, buf + len ), 0 );
409409

410410
/* client writes its key share */
411411
memset( buf, 0x00, sizeof( buf ) );
@@ -422,7 +422,7 @@ void ecdh_restart( int id, char *dA_str, char *dB_str, char *z_str,
422422
TEST_ASSERT( cnt_restart <= max_restart );
423423

424424
/* server reads client key share */
425-
TEST_ASSERT( mbedtls_ecdh_read_public( &srv, buf, len ) == 0 );
425+
TEST_ASSERT_RET( mbedtls_ecdh_read_public( &srv, buf, len ), 0 );
426426

427427
/* server computes shared secret */
428428
memset( buf, 0, sizeof( buf ) );
@@ -479,22 +479,22 @@ void ecdh_exchange_legacy( int id )
479479
mbedtls_ecdh_init( &cli );
480480
memset( &rnd_info, 0x00, sizeof( rnd_pseudo_info ) );
481481

482-
TEST_ASSERT( mbedtls_ecp_group_load( &srv.grp, id ) == 0 );
482+
TEST_ASSERT_RET( mbedtls_ecp_group_load( &srv.grp, id ), 0 );
483483

484484
memset( buf, 0x00, sizeof( buf ) ); vbuf = buf;
485-
TEST_ASSERT( mbedtls_ecdh_make_params( &srv, &len, buf, 1000,
486-
&rnd_pseudo_rand, &rnd_info ) == 0 );
487-
TEST_ASSERT( mbedtls_ecdh_read_params( &cli, &vbuf, buf + len ) == 0 );
485+
TEST_ASSERT_RET( mbedtls_ecdh_make_params( &srv, &len, buf, 1000,
486+
&rnd_pseudo_rand, &rnd_info ), 0 );
487+
TEST_ASSERT_RET( mbedtls_ecdh_read_params( &cli, &vbuf, buf + len ), 0 );
488488

489489
memset( buf, 0x00, sizeof( buf ) );
490-
TEST_ASSERT( mbedtls_ecdh_make_public( &cli, &len, buf, 1000,
491-
&rnd_pseudo_rand, &rnd_info ) == 0 );
492-
TEST_ASSERT( mbedtls_ecdh_read_public( &srv, buf, len ) == 0 );
493-
494-
TEST_ASSERT( mbedtls_ecdh_calc_secret( &srv, &len, buf, 1000,
495-
&rnd_pseudo_rand, &rnd_info ) == 0 );
496-
TEST_ASSERT( mbedtls_ecdh_calc_secret( &cli, &len, buf, 1000, NULL,
497-
NULL ) == 0 );
490+
TEST_ASSERT_RET( mbedtls_ecdh_make_public( &cli, &len, buf, 1000,
491+
&rnd_pseudo_rand, &rnd_info ), 0 );
492+
TEST_ASSERT_RET( mbedtls_ecdh_read_public( &srv, buf, len ), 0 );
493+
494+
TEST_ASSERT_RET( mbedtls_ecdh_calc_secret( &srv, &len, buf, 1000,
495+
&rnd_pseudo_rand, &rnd_info ), 0 );
496+
TEST_ASSERT_RET( mbedtls_ecdh_calc_secret( &cli, &len, buf, 1000, NULL,
497+
NULL ), 0 );
498498
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &srv.z, &cli.z ) == 0 );
499499

500500
exit:
@@ -530,25 +530,25 @@ void ecdh_exchange_calc_secret( int grp_id,
530530
/* Import the keys to the ECDH calculation. */
531531
if( ours_first )
532532
{
533-
TEST_ASSERT( mbedtls_ecdh_get_params(
534-
&ecdh, &our_key, MBEDTLS_ECDH_OURS ) == 0 );
535-
TEST_ASSERT( mbedtls_ecdh_get_params(
536-
&ecdh, &their_key, MBEDTLS_ECDH_THEIRS ) == 0 );
533+
TEST_ASSERT_RET( mbedtls_ecdh_get_params(
534+
&ecdh, &our_key, MBEDTLS_ECDH_OURS ), 0 );
535+
TEST_ASSERT_RET( mbedtls_ecdh_get_params(
536+
&ecdh, &their_key, MBEDTLS_ECDH_THEIRS ), 0 );
537537
}
538538
else
539539
{
540-
TEST_ASSERT( mbedtls_ecdh_get_params(
541-
&ecdh, &their_key, MBEDTLS_ECDH_THEIRS ) == 0 );
542-
TEST_ASSERT( mbedtls_ecdh_get_params(
543-
&ecdh, &our_key, MBEDTLS_ECDH_OURS ) == 0 );
540+
TEST_ASSERT_RET( mbedtls_ecdh_get_params(
541+
&ecdh, &their_key, MBEDTLS_ECDH_THEIRS ), 0 );
542+
TEST_ASSERT_RET( mbedtls_ecdh_get_params(
543+
&ecdh, &our_key, MBEDTLS_ECDH_OURS ), 0 );
544544
}
545545

546546
/* Perform the ECDH calculation. */
547-
TEST_ASSERT( mbedtls_ecdh_calc_secret(
548-
&ecdh,
549-
&shared_secret_length,
550-
shared_secret, sizeof( shared_secret ),
551-
&rnd_pseudo_rand, &rnd_info ) == 0 );
547+
TEST_ASSERT_RET( mbedtls_ecdh_calc_secret(
548+
&ecdh,
549+
&shared_secret_length,
550+
shared_secret, sizeof( shared_secret ),
551+
&rnd_pseudo_rand, &rnd_info ), 0 );
552552
TEST_ASSERT( shared_secret_length == expected->len );
553553
TEST_ASSERT( memcmp( expected->x, shared_secret,
554554
shared_secret_length ) == 0 );
@@ -585,18 +585,18 @@ void ecdh_exchange_get_params_fail( int our_grp_id,
585585

586586
if( ours_first )
587587
{
588-
TEST_ASSERT( mbedtls_ecdh_get_params(
589-
&ecdh, &our_key, MBEDTLS_ECDH_OURS ) == 0 );
590-
TEST_ASSERT( mbedtls_ecdh_get_params(
591-
&ecdh, &their_key, MBEDTLS_ECDH_THEIRS ) ==
592-
expected_ret );
588+
TEST_ASSERT_RET( mbedtls_ecdh_get_params(
589+
&ecdh, &our_key, MBEDTLS_ECDH_OURS ), 0 );
590+
TEST_ASSERT_RET( mbedtls_ecdh_get_params(
591+
&ecdh, &their_key, MBEDTLS_ECDH_THEIRS ),
592+
expected_ret );
593593
}
594594
else
595595
{
596-
TEST_ASSERT( mbedtls_ecdh_get_params(
597-
&ecdh, &their_key, MBEDTLS_ECDH_THEIRS ) == 0 );
598-
TEST_ASSERT( mbedtls_ecdh_get_params(
599-
&ecdh, &our_key, MBEDTLS_ECDH_OURS ) ==
596+
TEST_ASSERT_RET( mbedtls_ecdh_get_params(
597+
&ecdh, &their_key, MBEDTLS_ECDH_THEIRS ), 0 );
598+
TEST_ASSERT_RET( mbedtls_ecdh_get_params(
599+
&ecdh, &our_key, MBEDTLS_ECDH_OURS ),
600600
expected_ret );
601601
}
602602

0 commit comments

Comments
 (0)