| 20 | } |
| 21 | |
| 22 | void 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) */ |
no test coverage detected