mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-25 22:55:47 +01:00
ECDH: Fix error checks in benchmark.c
This commit is contained in:
parent
853218d93f
commit
cade42238c
24
programs/test/benchmark.c
Normal file → Executable file
24
programs/test/benchmark.c
Normal file → Executable file
@ -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 );
|
||||
|
Loading…
Reference in New Issue
Block a user