MCPcopy Create free account
hub / github.com/ElementsProject/lightning / const_time_test

Function const_time_test

bitcoin/test/run-secret_eq_consttime.c:21–44  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19
20#define RUNS (16 * 10000)
21static 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
46static inline bool secret_eq_nonconst(const struct secret *a,
47 const struct secret *b)

Callers

nothing calls this directly

Calls 4

time_nowFunction · 0.85
secret_eq_consttimeFunction · 0.85
errxFunction · 0.85
time_betweenFunction · 0.85

Tested by

no test coverage detected