@ -6,6 +6,7 @@
/* AUTOGENERATED MOCKS START */
/* AUTOGENERATED MOCKS END */
static bool verbose = false ;
# define RUNS (256 * 10000)
static struct timerel const_time_test ( struct secret * s1 ,
@ -82,9 +83,10 @@ static bool secret_time_test(struct timerel (*test)(struct secret *s1,
free ( s1 ) ;
free ( s2 ) ;
printf ( " First byte %u psec vs last byte %u psec \n " ,
( int ) time_to_nsec ( time_divide ( firstbyte_time , RUNS / 1000 ) ) ,
( int ) time_to_nsec ( time_divide ( lastbyte_time , RUNS / 1000 ) ) ) ;
if ( verbose )
printf ( " First byte %u psec vs last byte %u psec \n " ,
( int ) time_to_nsec ( time_divide ( firstbyte_time , RUNS / 1000 ) ) ,
( int ) time_to_nsec ( time_divide ( lastbyte_time , RUNS / 1000 ) ) ) ;
/* If they differ by more than 5%, get upset. */
if ( time_less ( firstbyte_time , lastbyte_time ) )
@ -120,17 +122,17 @@ int main(void)
if ( success < i / 2 )
errx ( 1 , " Only const time %u/%u? " , success , i ) ;
/* This, should show measurable differences at least 1/2 the time. */
success = 0 ;
for ( i = 0 ; i < 10 ; i + + )
success + = secret_time_test ( nonconst_time_test , false ) ;
printf ( " => More than 5%% slower %u/%u times \n " , success , i ) ;
/* This fails without -O2 or above, at least here (x86 Ubuntu gcc 7.3) */
# ifdef __OPTIMIZE__
if ( success < i / 2 )
errx ( 1 , " memcmp seemed const time %u/%u? " , success , i ) ;
# endif
if ( strstr ( COPTFLAGS , " -O2 " ) | | strstr ( COPTFLAGS , " -O3 " ) ) {
/* Should show measurable differences at least 1/2 the time. */
success = 0 ;
for ( i = 0 ; i < 10 ; i + + )
success + = secret_time_test ( nonconst_time_test , false ) ;
printf ( " => More than 5%% slower %u/%u times \n " , success , i ) ;
if ( success < i / 2 )
errx ( 1 , " memcmp seemed const time %u/%u? " , success , i ) ;
}
return 0 ;
}