From 3c449621ceaed42fcfe708d3907afff9f1cd6dbe Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Fri, 14 Dec 2018 11:54:59 +0000 Subject: [PATCH] ECDH: Fix error checks in benchmark.c --- programs/test/benchmark.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) mode change 100644 => 100755 programs/test/benchmark.c diff --git a/programs/test/benchmark.c b/programs/test/benchmark.c old mode 100644 new mode 100755 index a808a84b6..0d4837f60 --- a/programs/test/benchmark.c +++ b/programs/test/benchmark.c @@ -225,6 +225,14 @@ static int myrand( void *rng_state, unsigned char *output, size_t len ) return( 0 ); } +#if defined(MBEDTLS_ECDH_C) +static void check( int r ) +{ + if( r != 0 ) + mbedtls_exit( 1 ); +} +#endif + /* * Clear some memory that was used to prepare the context */ @@ -1003,8 +1011,8 @@ int main( int argc, char *argv[] ) { mbedtls_ecdh_init( &ecdh_srv ); mbedtls_ecdh_init( &ecdh_cli ); - mbedtls_ecdh_setup( &ecdh_srv, curve_info->grp_id ); - mbedtls_ecdh_setup( &ecdh_cli, curve_info->grp_id ); + check( mbedtls_ecdh_setup( &ecdh_srv, curve_info->grp_id ) ); + check( mbedtls_ecdh_setup( &ecdh_cli, curve_info->grp_id ) ); #if defined(MBEDTLS_ECDH_LEGACY_CONTEXT) if (mbedtls_ecp_group_load(&ecdh_srv.grp, curve_info->grp_id) != 0 || @@ -1023,15 +1031,15 @@ int main( int argc, char *argv[] ) mbedtls_snprintf( title, sizeof( title ), "ECDHE-%s", curve_info->name ); TIME_PUBLIC( title, "full handshake", const unsigned char * p_srv = buf_srv; - ret |= mbedtls_ecdh_make_params( &ecdh_srv, &olen, buf_srv, sizeof( buf_srv ), myrand, NULL ); + check( mbedtls_ecdh_make_params( &ecdh_srv, &olen, buf_srv, sizeof( buf_srv ), myrand, NULL ) ); - ret |= mbedtls_ecdh_read_params( &ecdh_cli, &p_srv, p_srv + olen ); - ret |= mbedtls_ecdh_make_public( &ecdh_cli, &olen, buf_cli, sizeof( buf_cli ), myrand, NULL ); + check( mbedtls_ecdh_read_params( &ecdh_cli, &p_srv, p_srv + olen ) ); + check( mbedtls_ecdh_make_public( &ecdh_cli, &olen, buf_cli, sizeof( buf_cli ), myrand, NULL ) ); - ret |= mbedtls_ecdh_read_public( &ecdh_srv, buf_cli, olen ); - ret |= mbedtls_ecdh_calc_secret( &ecdh_srv, &olen, buf_srv, sizeof( buf_srv ), myrand, NULL ); + check( mbedtls_ecdh_read_public( &ecdh_srv, buf_cli, olen ) ); + check( mbedtls_ecdh_calc_secret( &ecdh_srv, &olen, buf_srv, sizeof( buf_srv ), myrand, NULL ) ); - ret |= mbedtls_ecdh_calc_secret( &ecdh_cli, &olen, buf_cli, sizeof( buf_cli ), myrand, NULL ); + check( mbedtls_ecdh_calc_secret( &ecdh_cli, &olen, buf_cli, sizeof( buf_cli ), myrand, NULL ) ); ); mbedtls_ecdh_free( &ecdh_srv );