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

Function randbytes_

common/randbytes.c:22–48  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

20}
21
22void randbytes_(void *bytes, size_t num_bytes, u64 *offset)
23{
24 static u64 offset_init;
25 be64 pattern;
26
27 used = true;
28 if (!randbytes_overridden()) {
29 randombytes_buf(bytes, num_bytes); /* discouraged: use randbytes() */
30 return;
31 }
32
33 /* First time, start callers at different offsets */
34 if (*offset == 0) {
35 *offset = offset_init;
36 offset_init += 1000;
37 }
38
39 /* Somewhat recognizable pattern */
40 pattern = cpu_to_be64(dev_seed + (*offset)++);
41 for (size_t i = 0; i < num_bytes; i += sizeof(pattern)) {
42 size_t copy = num_bytes - i;
43 if (copy > sizeof(pattern))
44 copy = sizeof(pattern);
45
46 memcpy((u8 *)bytes + i, &pattern, copy);
47 }
48}
49
50/* We want different seeds for each plugin (hence argv0), and for each
51 * lightmingd instance, (hence seed from environment) */

Callers 3

pseudorand_Function · 0.70
pseudorand_u64_Function · 0.70
pseudorand_double_Function · 0.70

Calls 2

cpu_to_be64Function · 0.85
randbytes_overriddenFunction · 0.70

Tested by

no test coverage detected