diff --git a/bitcoin/test/run-secret_eq_consttime.c b/bitcoin/test/run-secret_eq_consttime.c index 7dd7df0b1..cb6fdb92b 100644 --- a/bitcoin/test/run-secret_eq_consttime.c +++ b/bitcoin/test/run-secret_eq_consttime.c @@ -3,12 +3,13 @@ #include #include #include +#include /* AUTOGENERATED MOCKS START */ /* AUTOGENERATED MOCKS END */ static bool verbose = false; -#define RUNS (256 * 10000) +#define RUNS (16 * 10000) static struct timerel const_time_test(struct secret *s1, struct secret *s2, size_t off) @@ -73,10 +74,13 @@ static bool secret_time_test(struct timerel (*test)(struct secret *s1, { struct secret *s1, *s2; 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)); s2 = calloc(RUNS, sizeof(*s2)); + nanosleep(&ts, NULL); firstbyte_time = test(s1, s2, 0); lastbyte_time = test(s1, s2, sizeof(s1->data)-1); @@ -113,13 +117,14 @@ int main(void) if (v && atoi(v) == 1) 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; - for (i = 0; i < 10; i++) + for (i = 0; i < 100; i++) success += secret_time_test(const_time_test, true); 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); /* This fails without -O2 or above, at least here (x86 Ubuntu gcc 7.3) */