| 19 | |
| 20 | #define RUNS (16 * 10000) |
| 21 | static struct timerel const_time_test(struct secret *s1, |
| 22 | struct secret *s2, |
| 23 | size_t off) |
| 24 | { |
| 25 | struct timeabs start, end; |
| 26 | int result = 0; |
| 27 | |
| 28 | memset(s1, 0, RUNS * sizeof(*s1)); |
| 29 | memset(s2, 0, RUNS * sizeof(*s2)); |
| 30 | |
| 31 | for (size_t i = 0; i < RUNS; i++) |
| 32 | s2[i].data[off] = i; |
| 33 | |
| 34 | start = time_now(); |
| 35 | for (size_t i = 0; i < RUNS; i++) |
| 36 | result += secret_eq_consttime(&s1[i], &s2[i]); |
| 37 | end = time_now(); |
| 38 | |
| 39 | if (result != RUNS / 256) |
| 40 | errx(1, "Expected %u successes at offset %zu, not %u!", |
| 41 | RUNS / 256, off, result); |
| 42 | |
| 43 | return time_between(end, start); |
| 44 | } |
| 45 | |
| 46 | static inline bool secret_eq_nonconst(const struct secret *a, |
| 47 | const struct secret *b) |
nothing calls this directly
no test coverage detected