From a63bc94a2dc8ce4fa623e4ba8b1f45bdba268b03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Thu, 14 May 2015 18:22:47 +0200 Subject: [PATCH] Remove timing_m_sleep() -> net_usleep() --- ChangeLog | 2 ++ include/mbedtls/compat-1.3.h | 1 - include/mbedtls/config.h | 2 +- include/mbedtls/timing.h | 7 ---- library/timing.c | 64 +++++----------------------------- programs/ssl/ssl_client2.c | 2 +- programs/ssl/ssl_fork_server.c | 2 +- 7 files changed, 14 insertions(+), 66 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9df31f986..a1b5e8af5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -73,6 +73,8 @@ Removals mbedtls_ecp_muladd(). * Removed individual mdX_hmac and shaX_hmac functions (use generic md_hmac functions from md.h) + * Removed mbedtls_timing_msleep(). Use mbedtls_timing_usleep() or a custom + waiting function. * Removed the PBKDF2 module (use PKCS5). * Removed POLARSSL_ERROR_STRERROR_BC (use mbedtls_strerror()). * Removed compat-1.2.h (helper for migrating from 1.2 to 1.3). diff --git a/include/mbedtls/compat-1.3.h b/include/mbedtls/compat-1.3.h index 9276eaee4..d19e04a84 100644 --- a/include/mbedtls/compat-1.3.h +++ b/include/mbedtls/compat-1.3.h @@ -2049,7 +2049,6 @@ #define hmac_drbg_write_seed_file mbedtls_hmac_drbg_write_seed_file #define hr_time mbedtls_timing_hr_time #define key_exchange_type_t mbedtls_key_exchange_type_t -#define m_sleep mbedtls_timing_m_sleep #define md mbedtls_md #define md2 mbedtls_md2 #define md2_context mbedtls_md2_context diff --git a/include/mbedtls/config.h b/include/mbedtls/config.h index 34d0bc2f6..e6b0cd5cd 100644 --- a/include/mbedtls/config.h +++ b/include/mbedtls/config.h @@ -183,7 +183,7 @@ * \def MBEDTLS_TIMING_ALT * * Uncomment to provide your own alternate implementation for mbedtls_timing_hardclock(), - * mbedtls_timing_get_timer(), mbedtls_set_alarm() and mbedtls_timing_m_sleep(). + * mbedtls_timing_get_timer(), mbedtls_set_alarm(), mbedtls_set/get_delay() * * Only works if you have MBEDTLS_TIMING_C enabled. * diff --git a/include/mbedtls/timing.h b/include/mbedtls/timing.h index efcc5dc3d..6598c1a99 100644 --- a/include/mbedtls/timing.h +++ b/include/mbedtls/timing.h @@ -84,13 +84,6 @@ unsigned long mbedtls_timing_get_timer( struct mbedtls_timing_hr_time *val, int */ void mbedtls_set_alarm( int seconds ); -/** - * \brief Sleep for a certain amount of time - * - * \param milliseconds delay in milliseconds - */ -void mbedtls_timing_m_sleep( int milliseconds ); - /** * \brief Set a pair of delays to watch * (See \c mbedtls_timing_get_delay().) diff --git a/library/timing.c b/library/timing.c index 8ce975336..e83b74e75 100644 --- a/library/timing.c +++ b/library/timing.c @@ -273,11 +273,6 @@ void mbedtls_set_alarm( int seconds ) CloseHandle( CreateThread( NULL, 0, TimerProc, NULL, 0, &ThreadId ) ); } -void mbedtls_timing_m_sleep( int milliseconds ) -{ - Sleep( milliseconds ); -} - #else /* _WIN32 && !EFIX64 && !EFI32 */ unsigned long mbedtls_timing_get_timer( struct mbedtls_timing_hr_time *val, int reset ) @@ -301,14 +296,6 @@ unsigned long mbedtls_timing_get_timer( struct mbedtls_timing_hr_time *val, int return( delta ); } -#if defined(INTEGRITY) -void mbedtls_timing_m_sleep( int milliseconds ) -{ - usleep( milliseconds * 1000 ); -} - -#else /* INTEGRITY */ - static void sighandler( int signum ) { mbedtls_timing_alarmed = 1; @@ -322,17 +309,6 @@ void mbedtls_set_alarm( int seconds ) alarm( seconds ); } -void mbedtls_timing_m_sleep( int milliseconds ) -{ - struct timeval tv; - - tv.tv_sec = milliseconds / 1000; - tv.tv_usec = ( milliseconds % 1000 ) * 1000; - - select( 0, NULL, NULL, NULL, &tv ); -} -#endif /* INTEGRITY */ - #endif /* _WIN32 && !EFIX64 && !EFI32 */ /* @@ -425,31 +401,9 @@ int mbedtls_timing_self_test( int verbose ) if( verbose != 0 ) mbedtls_printf( " TIMING tests note: will take some time!\n" ); - if( verbose != 0 ) - mbedtls_printf( " TIMING test #1 (m_sleep / get_timer): " ); - - for( secs = 1; secs <= 3; secs++ ) - { - (void) mbedtls_timing_get_timer( &hires, 1 ); - - mbedtls_timing_m_sleep( (int)( 500 * secs ) ); - - millisecs = mbedtls_timing_get_timer( &hires, 0 ); - - if( millisecs < 450 * secs || millisecs > 550 * secs ) - { - if( verbose != 0 ) - mbedtls_printf( "failed\n" ); - - return( 1 ); - } - } if( verbose != 0 ) - mbedtls_printf( "passed\n" ); - - if( verbose != 0 ) - mbedtls_printf( " TIMING test #2 (set_alarm / get_timer): " ); + mbedtls_printf( " TIMING test #1 (set_alarm / get_timer): " ); for( secs = 1; secs <= 3; secs++ ) { @@ -474,7 +428,7 @@ int mbedtls_timing_self_test( int verbose ) mbedtls_printf( "passed\n" ); if( verbose != 0 ) - mbedtls_printf( " TIMING test #3 (hardclock / get_timer): " ); + mbedtls_printf( " TIMING test #2 (hardclock / get_timer): " ); /* * Allow one failure for possible counter wrapping. @@ -519,7 +473,7 @@ hard_test: mbedtls_printf( "passed\n" ); if( verbose != 0 ) - mbedtls_printf( " TIMING test #4 (m_sleep / delay ): " ); + mbedtls_printf( " TIMING test #3 (set/get_delay ): " ); for( a = 100; a <= 200; a += 100 ) { @@ -527,26 +481,26 @@ hard_test: { mbedtls_timing_set_delay( &ctx, a, a + b ); - mbedtls_timing_m_sleep( (int)( a - a / 10 ) ); + busy_msleep( a - a / 10 ); if( mbedtls_timing_get_delay( &ctx ) != 0 ) FAIL; - mbedtls_timing_m_sleep( (int)( a / 5 ) ); + busy_msleep( a / 5 ); if( mbedtls_timing_get_delay( &ctx ) != 1 ) FAIL; - mbedtls_timing_m_sleep( (int)( b - a / 5 ) ); + busy_msleep( b - a / 5 ); if( mbedtls_timing_get_delay( &ctx ) != 1 ) FAIL; - mbedtls_timing_m_sleep( (int)( b / 5 ) ); + busy_msleep( b / 5 ); if( mbedtls_timing_get_delay( &ctx ) != 2 ) FAIL; } } mbedtls_timing_set_delay( &ctx, 0, 0 ); - mbedtls_timing_m_sleep( 200 ); + busy_msleep( 200 ); if( mbedtls_timing_get_delay( &ctx ) != -1 ) FAIL; @@ -555,7 +509,7 @@ hard_test: #if defined(MBEDTLS_NET_C) && defined(MBEDTLS_HAVE_TIME) if( verbose != 0 ) - mbedtls_printf( " TIMING test #5 (net_usleep/ get_timer): " ); + mbedtls_printf( " TIMING test #4 (net_usleep/ get_timer): " ); for( secs = 1; secs <= 3; secs++ ) { diff --git a/programs/ssl/ssl_client2.c b/programs/ssl/ssl_client2.c index 1b4d654df..b14026361 100644 --- a/programs/ssl/ssl_client2.c +++ b/programs/ssl/ssl_client2.c @@ -1494,7 +1494,7 @@ reconnect: #if defined(MBEDTLS_TIMING_C) if( opt.reco_delay > 0 ) - mbedtls_timing_m_sleep( 1000 * opt.reco_delay ); + mbedtls_net_usleep( 1000000 * opt.reco_delay ); #endif mbedtls_printf( " . Reconnecting with saved session..." ); diff --git a/programs/ssl/ssl_fork_server.c b/programs/ssl/ssl_fork_server.c index 1df814b1d..06c479e7b 100644 --- a/programs/ssl/ssl_fork_server.c +++ b/programs/ssl/ssl_fork_server.c @@ -373,7 +373,7 @@ int main( void ) len = ret; mbedtls_printf( " %d bytes written\n\n%s\n", len, (char *) buf ); - mbedtls_timing_m_sleep( 1000 ); + mbedtls_net_usleep( 1000000 ); } mbedtls_ssl_close_notify( &ssl );