@@ -300,7 +300,7 @@ typedef struct {
300
300
rsa, dhm, ecdsa, ecdh;
301
301
} todo_list;
302
302
303
- static void test_md ( const todo_list * todo, mbedtls_platform_context* ctx )
303
+ static int test_md ( const todo_list * todo, mbedtls_platform_context* ctx )
304
304
{
305
305
unsigned char tmp[200 ];
306
306
// The call below is used to avoid the "unused parameter" warning.
@@ -338,9 +338,10 @@ static void test_md( const todo_list * todo, mbedtls_platform_context* ctx )
338
338
if ( todo->sha512 )
339
339
TIME_AND_TSC ( " SHA-512" , mbedtls_sha512 ( buf, BUFSIZE, tmp, 0 ) );
340
340
#endif
341
+ return ( 0 );
341
342
}
342
343
343
- static void test_crypt ( const todo_list * todo, mbedtls_platform_context* ctx )
344
+ static int test_crypt ( const todo_list * todo, mbedtls_platform_context* ctx )
344
345
{
345
346
unsigned char tmp[200 ];
346
347
char title[TITLE_LEN];
@@ -569,9 +570,10 @@ static void test_crypt( const todo_list * todo, mbedtls_platform_context* ctx )
569
570
}
570
571
#endif
571
572
573
+ return ( 0 );
572
574
}
573
575
574
- static void test_rng ( const todo_list * todo, mbedtls_platform_context* ctx )
576
+ static int test_rng ( const todo_list * todo, mbedtls_platform_context* ctx )
575
577
{
576
578
unsigned char tmp[200 ];
577
579
// The call below is used to avoid the "unused parameter" warning.
@@ -598,17 +600,17 @@ static void test_rng( const todo_list * todo, mbedtls_platform_context* ctx )
598
600
mbedtls_ctr_drbg_init ( &ctr_drbg );
599
601
600
602
if ( mbedtls_ctr_drbg_seed ( &ctr_drbg, myrand, NULL , NULL , 0 ) != 0 )
601
- mbedtls_exit (1 );
603
+ return (1 );
602
604
TIME_AND_TSC ( " CTR_DRBG (NOPR)" ,
603
605
if ( mbedtls_ctr_drbg_random ( &ctr_drbg, buf, BUFSIZE ) != 0 )
604
- mbedtls_exit (1 ) );
606
+ return (1 ) );
605
607
606
608
if ( mbedtls_ctr_drbg_seed ( &ctr_drbg, myrand, NULL , NULL , 0 ) != 0 )
607
- mbedtls_exit (1 );
609
+ return (1 );
608
610
mbedtls_ctr_drbg_set_prediction_resistance ( &ctr_drbg, MBEDTLS_CTR_DRBG_PR_ON );
609
611
TIME_AND_TSC ( " CTR_DRBG (PR)" ,
610
612
if ( mbedtls_ctr_drbg_random ( &ctr_drbg, buf, BUFSIZE ) != 0 )
611
- mbedtls_exit (1 ) );
613
+ return (1 ) );
612
614
mbedtls_ctr_drbg_free ( &ctr_drbg );
613
615
}
614
616
#endif
@@ -623,50 +625,51 @@ static void test_rng( const todo_list * todo, mbedtls_platform_context* ctx )
623
625
624
626
#if defined(MBEDTLS_SHA1_C)
625
627
if ( ( md_info = mbedtls_md_info_from_type ( MBEDTLS_MD_SHA1 ) ) == NULL )
626
- mbedtls_exit (1 );
628
+ return (1 );
627
629
628
630
if ( mbedtls_hmac_drbg_seed ( &hmac_drbg, md_info, myrand, NULL , NULL , 0 ) != 0 )
629
631
return (1 );
630
632
TIME_AND_TSC ( " HMAC_DRBG SHA-1 (NOPR)" ,
631
633
if ( mbedtls_hmac_drbg_random ( &hmac_drbg, buf, BUFSIZE ) != 0 )
632
- mbedtls_exit (1 ) );
634
+ return (1 ) );
633
635
mbedtls_hmac_drbg_free ( &hmac_drbg );
634
636
635
637
if ( mbedtls_hmac_drbg_seed ( &hmac_drbg, md_info, myrand, NULL , NULL , 0 ) != 0 )
636
- mbedtls_exit (1 );
638
+ return (1 );
637
639
mbedtls_hmac_drbg_set_prediction_resistance ( &hmac_drbg,
638
640
MBEDTLS_HMAC_DRBG_PR_ON );
639
641
TIME_AND_TSC ( " HMAC_DRBG SHA-1 (PR)" ,
640
642
if ( mbedtls_hmac_drbg_random ( &hmac_drbg, buf, BUFSIZE ) != 0 )
641
- mbedtls_exit (1 ) );
643
+ return (1 ) );
642
644
mbedtls_hmac_drbg_free ( &hmac_drbg );
643
645
#endif
644
646
645
647
#if defined(MBEDTLS_SHA256_C)
646
648
if ( ( md_info = mbedtls_md_info_from_type ( MBEDTLS_MD_SHA256 ) ) == NULL )
647
- mbedtls_exit (1 );
649
+ return (1 );
648
650
649
651
if ( mbedtls_hmac_drbg_seed ( &hmac_drbg, md_info, myrand, NULL , NULL , 0 ) != 0 )
650
- mbedtls_exit (1 );
652
+ return (1 );
651
653
TIME_AND_TSC ( " HMAC_DRBG SHA-256 (NOPR)" ,
652
654
if ( mbedtls_hmac_drbg_random ( &hmac_drbg, buf, BUFSIZE ) != 0 )
653
- mbedtls_exit (1 ) );
655
+ return (1 ) );
654
656
mbedtls_hmac_drbg_free ( &hmac_drbg );
655
657
656
658
if ( mbedtls_hmac_drbg_seed ( &hmac_drbg, md_info, myrand, NULL , NULL , 0 ) != 0 )
657
- mbedtls_exit (1 );
659
+ return (1 );
658
660
mbedtls_hmac_drbg_set_prediction_resistance ( &hmac_drbg,
659
661
MBEDTLS_HMAC_DRBG_PR_ON );
660
662
TIME_AND_TSC ( " HMAC_DRBG SHA-256 (PR)" ,
661
663
if ( mbedtls_hmac_drbg_random ( &hmac_drbg, buf, BUFSIZE ) != 0 )
662
- mbedtls_exit (1 ) );
664
+ return (1 ) );
663
665
mbedtls_hmac_drbg_free ( &hmac_drbg );
664
666
#endif
665
667
}
666
668
#endif
669
+ return (0 );
667
670
}
668
671
669
- static void test_pk ( const todo_list * todo, mbedtls_platform_context* ctx )
672
+ static int test_pk ( const todo_list * todo, mbedtls_platform_context* ctx )
670
673
{
671
674
unsigned char tmp[200 ];
672
675
char title[TITLE_LEN];
@@ -729,13 +732,13 @@ static void test_pk( const todo_list * todo, mbedtls_platform_context* ctx )
729
732
if ( mbedtls_mpi_read_string ( &dhm.P , 16 , dhm_P[i] ) != 0 ||
730
733
mbedtls_mpi_read_string ( &dhm.G , 16 , dhm_G[i] ) != 0 )
731
734
{
732
- mbedtls_exit ( 1 );
735
+ return ( 1 );
733
736
}
734
737
735
738
dhm.len = mbedtls_mpi_size ( &dhm.P );
736
739
mbedtls_dhm_make_public ( &dhm, (int ) dhm.len , buf, dhm.len , myrand, NULL );
737
740
if ( mbedtls_mpi_copy ( &dhm.GY , &dhm.GX ) != 0 )
738
- mbedtls_exit ( 1 );
741
+ return ( 1 );
739
742
740
743
mbedtls_snprintf ( title, sizeof ( title ), " DHE-%d" , dhm_sizes[i] );
741
744
TIME_PUBLIC ( title, " handshake" ,
@@ -768,7 +771,7 @@ static void test_pk( const todo_list * todo, mbedtls_platform_context* ctx )
768
771
mbedtls_ecdsa_init ( &ecdsa );
769
772
770
773
if ( mbedtls_ecdsa_genkey ( &ecdsa, curve_info->grp_id , myrand, NULL ) != 0 )
771
- mbedtls_exit ( 1 );
774
+ return ( 1 );
772
775
ecp_clear_precomputed ( &ecdsa.grp );
773
776
774
777
mbedtls_snprintf ( title, sizeof ( title ), " ECDSA-%s" ,
@@ -790,7 +793,7 @@ static void test_pk( const todo_list * todo, mbedtls_platform_context* ctx )
790
793
mbedtls_ecdsa_write_signature ( &ecdsa, MBEDTLS_MD_SHA256, buf, ( curve_info->bit_size + 7 ) / 8 ,
791
794
tmp, &sig_len, myrand, NULL ) != 0 )
792
795
{
793
- mbedtls_exit ( 1 );
796
+ return ( 1 );
794
797
}
795
798
ecp_clear_precomputed ( &ecdsa.grp );
796
799
@@ -826,7 +829,7 @@ static void test_pk( const todo_list * todo, mbedtls_platform_context* ctx )
826
829
myrand, NULL ) != 0 ||
827
830
mbedtls_ecp_copy ( &ecdh.Qp , &ecdh.Q ) != 0 )
828
831
{
829
- mbedtls_exit ( 1 );
832
+ return ( 1 );
830
833
}
831
834
ecp_clear_precomputed ( &ecdh.grp );
832
835
@@ -848,7 +851,7 @@ static void test_pk( const todo_list * todo, mbedtls_platform_context* ctx )
848
851
if ( mbedtls_ecp_group_load ( &ecdh.grp , MBEDTLS_ECP_DP_CURVE25519 ) != 0 ||
849
852
mbedtls_ecdh_gen_public ( &ecdh.grp , &ecdh.d , &ecdh.Qp , myrand, NULL ) != 0 )
850
853
{
851
- mbedtls_exit ( 1 );
854
+ return ( 1 );
852
855
}
853
856
854
857
TIME_PUBLIC ( " ECDHE-Curve25519" , " handshake" ,
@@ -874,7 +877,7 @@ static void test_pk( const todo_list * todo, mbedtls_platform_context* ctx )
874
877
mbedtls_ecdh_make_public ( &ecdh, &olen, buf, sizeof ( buf ),
875
878
myrand, NULL ) != 0 )
876
879
{
877
- mbedtls_exit ( 1 );
880
+ return ( 1 );
878
881
}
879
882
ecp_clear_precomputed ( &ecdh.grp );
880
883
@@ -896,7 +899,7 @@ static void test_pk( const todo_list * todo, mbedtls_platform_context* ctx )
896
899
myrand, NULL ) != 0 ||
897
900
mbedtls_ecdh_gen_public ( &ecdh.grp , &ecdh.d , &ecdh.Q , myrand, NULL ) != 0 )
898
901
{
899
- mbedtls_exit ( 1 );
902
+ return ( 1 );
900
903
}
901
904
902
905
TIME_PUBLIC ( " ECDH-Curve25519" , " handshake" ,
@@ -908,7 +911,7 @@ static void test_pk( const todo_list * todo, mbedtls_platform_context* ctx )
908
911
#endif
909
912
}
910
913
#endif
911
-
914
+ return ( 0 );
912
915
913
916
}
914
917
@@ -993,10 +996,14 @@ static int benchmark( int argc, char *argv[], mbedtls_platform_context* ctx )
993
996
#endif
994
997
memset ( buf, 0xAA , sizeof ( buf ) );
995
998
996
- test_md ( &todo, ctx );
997
- test_crypt ( &todo, ctx );
998
- test_rng ( &todo, ctx );
999
- test_pk ( &todo, ctx );
999
+ if ( test_md ( &todo, ctx ) != 0 )
1000
+ return ( 1 );
1001
+ if ( test_crypt ( &todo, ctx ) != 0 )
1002
+ return ( 1 );
1003
+ if ( test_rng ( &todo, ctx ) != 0 )
1004
+ return ( 1 );
1005
+ if ( test_pk ( &todo, ctx ) != 0 )
1006
+ return ( 1 );
1000
1007
1001
1008
mbedtls_printf (" \r\n DONE\r\n " );
1002
1009
0 commit comments