@ -3,12 +3,13 @@
# include <ccan/err/err.h>
# include <ccan/err/err.h>
# include <ccan/time/time.h>
# include <ccan/time/time.h>
# include <stdio.h>
# include <stdio.h>
# include <unistd.h>
/* AUTOGENERATED MOCKS START */
/* AUTOGENERATED MOCKS START */
/* AUTOGENERATED MOCKS END */
/* AUTOGENERATED MOCKS END */
static bool verbose = false ;
static bool verbose = false ;
# define RUNS (25 6 * 10000)
# define RUNS (1 6 * 10000)
static struct timerel const_time_test ( struct secret * s1 ,
static struct timerel const_time_test ( struct secret * s1 ,
struct secret * s2 ,
struct secret * s2 ,
size_t off )
size_t off )
@ -73,10 +74,13 @@ static bool secret_time_test(struct timerel (*test)(struct secret *s1,
{
{
struct secret * s1 , * s2 ;
struct secret * s1 , * s2 ;
struct timerel firstbyte_time , lastbyte_time , diff ;
struct timerel firstbyte_time , lastbyte_time , diff ;
/* Give up rest of our timeslice: useful if under load! */
struct timespec ts = { 0 , 100000000 } ;
s1 = calloc ( RUNS , sizeof ( * s1 ) ) ;
s1 = calloc ( RUNS , sizeof ( * s1 ) ) ;
s2 = calloc ( RUNS , sizeof ( * s2 ) ) ;
s2 = calloc ( RUNS , sizeof ( * s2 ) ) ;
nanosleep ( & ts , NULL ) ;
firstbyte_time = test ( s1 , s2 , 0 ) ;
firstbyte_time = test ( s1 , s2 , 0 ) ;
lastbyte_time = test ( s1 , s2 , sizeof ( s1 - > data ) - 1 ) ;
lastbyte_time = test ( s1 , s2 , sizeof ( s1 - > data ) - 1 ) ;
@ -113,13 +117,14 @@ int main(void)
if ( v & & atoi ( v ) = = 1 )
if ( v & & atoi ( v ) = = 1 )
exit ( 0 ) ;
exit ( 0 ) ;
/* I've never seen this fail more than 5 times */
/* I've never seen this fail more than 80% of the time, even
* when loaded */
success = 0 ;
success = 0 ;
for ( i = 0 ; i < 10 ; i + + )
for ( i = 0 ; i < 100 ; i + + )
success + = secret_time_test ( const_time_test , true ) ;
success + = secret_time_test ( const_time_test , true ) ;
printf ( " => Within 5%% %u/%u times \n " , success , i ) ;
printf ( " => Within 5%% %u/%u times \n " , success , i ) ;
if ( success < i / 2 )
if ( success < i / 5 )
errx ( 1 , " Only const time %u/%u? " , success , i ) ;
errx ( 1 , " Only const time %u/%u? " , success , i ) ;
/* This fails without -O2 or above, at least here (x86 Ubuntu gcc 7.3) */
/* This fails without -O2 or above, at least here (x86 Ubuntu gcc 7.3) */