Files
palladum-lightning/common/randbytes.h
Rusty Russell 2086699b70 common: add randbytes() wrapper to override cryptographic entropy: $CLN_DEV_ENTROPY_SEED
Only in developer mode, ofc.

Notes:
1. We have to move the initialization before the lightningd main trace_start,
   since that uses pseudorand().
2. To make the results stable, we need to use per-caller values to randbytes().
   Otherwise external timing changes the call order.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-11-13 21:21:29 +10:30

21 lines
617 B
C

#ifndef LIGHTNING_COMMON_RANDBYTES_H
#define LIGHTNING_COMMON_RANDBYTES_H
#include "config.h"
#include <ccan/short_types/short_types.h>
#include <stdbool.h>
#include <stddef.h>
/* Usually the libsodium routine randombytes_buf, but dev options can make this deterministic */
#define randbytes(bytes, num_bytes) \
do { \
static u64 offset; \
randbytes_((bytes), (num_bytes), &offset); \
} while(0)
void randbytes_(void *bytes, size_t num_bytes, u64 *offset);
void dev_override_randbytes(const char *argv0, long int seed);
bool randbytes_overridden(void);
#endif /* LIGHTNING_COMMON_RANDBYTES_H */