From d41d59e9006c01fa8783ccfea168bf9e6e0820dd Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Tue, 25 May 2021 09:19:45 +0200 Subject: [PATCH] Timing: support ALT implementations in self-test Don't assume that the context has a timer field if MBEDTLS_TIMING_ALT is defined. Signed-off-by: Gilles Peskine --- library/timing.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/library/timing.c b/library/timing.c index eb4146132..664fde082 100644 --- a/library/timing.c +++ b/library/timing.c @@ -387,6 +387,21 @@ static void busy_msleep( unsigned long msec ) (void) j; } +static void print_timers( struct mbedtls_timing_hr_time *hires, + mbedtls_timing_delay_context *ctx ) +{ +#if defined(MBEDTLS_TIMING_ALT) + mbedtls_printf( " elapsed(hires)=%lu elapsed(ctx)=?? status(ctx)=%d\n", + mbedtls_timing_get_timer( hires, 0 ), + mbedtls_timing_get_delay( ctx ) ); +#else + mbedtls_printf( " elapsed(hires)=%lu elapsed(ctx)=%lu status(ctx)=%d\n", + mbedtls_timing_get_timer( hires, 0 ), + mbedtls_timing_get_timer( &ctx->timer, 0 ), + mbedtls_timing_get_delay( ctx ) ); +#endif +} + #define FAIL do \ { \ if( verbose != 0 ) \ @@ -395,10 +410,7 @@ static void busy_msleep( unsigned long msec ) mbedtls_printf( " cycles=%lu ratio=%lu millisecs=%lu secs=%lu hardfail=%d a=%lu b=%lu\n", \ cycles, ratio, millisecs, secs, hardfail, \ (unsigned long) a, (unsigned long) b ); \ - mbedtls_printf( " elapsed(hires)=%lu elapsed(ctx)=%lu status(ctx)=%d\n", \ - mbedtls_timing_get_timer( &hires, 0 ), \ - mbedtls_timing_get_timer( &ctx.timer, 0 ), \ - mbedtls_timing_get_delay( &ctx ) ); \ + print_timers( &hires, &ctx ); \ } \ return( 1 ); \ } while( 0 )