diff --git a/Makefile b/Makefile index 54a3bbeab..07f1a193f 100644 --- a/Makefile +++ b/Makefile @@ -603,7 +603,7 @@ check-tmpctx: @if git grep -n 'tal_free[(]tmpctx)' | grep -Ev '^ccan/|/test/|^common/setup.c:|^common/utils.c:'; then echo "Don't free tmpctx!">&2; exit 1; fi check-discouraged-functions: - @if git grep -E "[^a-z_/](fgets|fputs|gets|scanf|sprintf)\(" -- "*.c" "*.h" ":(exclude)ccan/" ":(exclude)contrib/"; then exit 1; fi + @if git grep -nE "[^a-z_/](fgets|fputs|gets|scanf|sprintf|randombytes_buf)\(" -- "*.c" "*.h" ":(exclude)ccan/" ":(exclude)contrib/" | grep -Fv '/* discouraged:'; then exit 1; fi check-bad-sprintf: @if git grep -n "%[*]\.s"; then exit 1; fi diff --git a/bitcoin/script.c b/bitcoin/script.c index 1c703dbbf..2422f612b 100644 --- a/bitcoin/script.c +++ b/bitcoin/script.c @@ -6,8 +6,8 @@ #include #include #include +#include #include -#include #include /* To push 0-75 bytes onto stack. */ diff --git a/bitcoin/short_channel_id.c b/bitcoin/short_channel_id.c index cc1de68c4..98fe4748b 100644 --- a/bitcoin/short_channel_id.c +++ b/bitcoin/short_channel_id.c @@ -1,7 +1,7 @@ #include "config.h" #include #include -#include +#include #include #include @@ -104,6 +104,6 @@ struct short_channel_id fromwire_short_channel_id(const u8 **cursor, size_t *max struct short_channel_id random_scid(void) { struct short_channel_id scid; - randombytes_buf(&scid, sizeof(scid)); + randbytes(&scid, sizeof(scid)); return scid; } diff --git a/channeld/test/Makefile b/channeld/test/Makefile index 0bb50c47a..f683ec31b 100644 --- a/channeld/test/Makefile +++ b/channeld/test/Makefile @@ -27,6 +27,7 @@ channeld/test/run-full_channel: \ common/msg_queue.o \ common/permute_tx.o \ common/pseudorand.o \ + common/randbytes.o \ common/setup.o \ common/utils.o diff --git a/channeld/test/run-full_channel.c b/channeld/test/run-full_channel.c index a852d1927..1bb406a78 100644 --- a/channeld/test/run-full_channel.c +++ b/channeld/test/run-full_channel.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include diff --git a/common/blindedpath.h b/common/blindedpath.h index 7a5238f15..96a55edce 100644 --- a/common/blindedpath.h +++ b/common/blindedpath.h @@ -22,7 +22,7 @@ struct tlv_encrypted_data_tlv_payment_relay; * @next_path_privkey: (out) e(i+1), the next blinding secret (optional) * @node_alias: (out) the blinded pubkey of the node to tell the recipient. * - * You create a blinding secret using randombytes_buf(), then call this + * You create a blinding secret using randbytes(), then call this * iteratively for each node in the path. */ u8 *encrypt_tlv_encrypted_data(const tal_t *ctx, diff --git a/common/onion_message.c b/common/onion_message.c index 34faf004c..25e83dfb3 100644 --- a/common/onion_message.c +++ b/common/onion_message.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -66,7 +67,7 @@ struct blinded_path *blinded_path_from_encdata_tlvs(const tal_t *ctx, assert(nhops > 0); assert(tal_count(ids) > 0); - randombytes_buf(&first_blinding, sizeof(first_blinding)); + randbytes(&first_blinding, sizeof(first_blinding)); if (!pubkey_from_privkey(&first_blinding, &path->first_path_key)) abort(); sciddir_or_pubkey_from_pubkey(&path->first_node_id, &ids[0]); diff --git a/common/pseudorand.c b/common/pseudorand.c index b29aeee06..7f3efafe5 100644 --- a/common/pseudorand.c +++ b/common/pseudorand.c @@ -4,7 +4,7 @@ #include #include #include -#include +#include static struct isaac64_ctx isaac64; static struct siphash_seed siphashseed; @@ -16,7 +16,7 @@ static void init_if_needed(void) unsigned char seedbuf[16]; struct sha256 sha; - randombytes_buf(seedbuf, sizeof(seedbuf)); + randbytes(seedbuf, sizeof(seedbuf)); memcpy(&siphashseed, seedbuf, sizeof(siphashseed)); /* In case isaac is reversible, don't leak seed. */ diff --git a/common/sphinx.c b/common/sphinx.c index dd405a05f..6ac128d9a 100644 --- a/common/sphinx.c +++ b/common/sphinx.c @@ -5,13 +5,13 @@ #include #include #include +#include #include #include #include #include -#include #define BLINDING_FACTOR_SIZE 32 @@ -566,7 +566,7 @@ struct onionpacket *create_onionpacket( if (sp->session_key == NULL) { sp->session_key = tal(sp, struct secret); - randombytes_buf(sp->session_key, sizeof(struct secret)); + randbytes(sp->session_key, sizeof(struct secret)); } params = generate_hop_params(ctx, sp->session_key->data, sp); diff --git a/common/test/Makefile b/common/test/Makefile index 8ae6a4136..e13bfb3fd 100644 --- a/common/test/Makefile +++ b/common/test/Makefile @@ -5,6 +5,7 @@ COMMON_TEST_PROGRAMS := $(COMMON_TEST_OBJS:.o=) COMMON_TEST_COMMON_OBJS := \ common/autodata.o \ + common/randbytes.o \ common/setup.o \ common/utils.o @@ -119,6 +120,7 @@ common/test/run-trace: \ common/amount.o \ common/memleak.o \ common/pseudorand.o \ + common/randbytes.o \ common/trace.o \ wire/fromwire.o \ wire/towire.o diff --git a/common/test/run-amount.c b/common/test/run-amount.c index 0e9f295dc..f76484ef3 100644 --- a/common/test/run-amount.c +++ b/common/test/run-amount.c @@ -1,5 +1,6 @@ #include "config.h" #include "../amount.c" +#include #include #include diff --git a/common/test/run-base64.c b/common/test/run-base64.c index c36c08bb3..e71371c98 100644 --- a/common/test/run-base64.c +++ b/common/test/run-base64.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include diff --git a/common/test/run-bigsize.c b/common/test/run-bigsize.c index 8ff40e549..1e167fd7c 100644 --- a/common/test/run-bigsize.c +++ b/common/test/run-bigsize.c @@ -4,6 +4,7 @@ #include #include #include +#include #include static const char *reason; diff --git a/common/test/run-blindedpath_enctlv.c b/common/test/run-blindedpath_enctlv.c index c9408cba2..d2552ad4e 100644 --- a/common/test/run-blindedpath_enctlv.c +++ b/common/test/run-blindedpath_enctlv.c @@ -3,6 +3,7 @@ #include "../blinding.c" #include "../hmac.c" #include +#include #include #include diff --git a/common/test/run-bolt11.c b/common/test/run-bolt11.c index e4fbbd797..bd8c2c662 100644 --- a/common/test/run-bolt11.c +++ b/common/test/run-bolt11.c @@ -6,11 +6,12 @@ #include "../features.c" #include "../node_id.c" #include "../hash_u5.c" -#include "../memleak.c" #include "../wire/fromwire.c" #include "../wire/towire.c" #include +#include #include +#include /* AUTOGENERATED MOCKS START */ /* AUTOGENERATED MOCKS END */ diff --git a/common/test/run-bolt12-encode-test.c b/common/test/run-bolt12-encode-test.c index e7de25fdd..5ca641f93 100644 --- a/common/test/run-bolt12-encode-test.c +++ b/common/test/run-bolt12-encode-test.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include diff --git a/common/test/run-bolt12-format-string-test.c b/common/test/run-bolt12-format-string-test.c index e120af65f..f2a5e1124 100644 --- a/common/test/run-bolt12-format-string-test.c +++ b/common/test/run-bolt12-format-string-test.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include diff --git a/common/test/run-bolt12-offer-decode.c b/common/test/run-bolt12-offer-decode.c index 6febbb363..329a13970 100644 --- a/common/test/run-bolt12-offer-decode.c +++ b/common/test/run-bolt12-offer-decode.c @@ -14,6 +14,7 @@ #include #include #include +#include #include /* AUTOGENERATED MOCKS START */ diff --git a/common/test/run-bolt12_decode.c b/common/test/run-bolt12_decode.c index 9e5333b33..e4473ada7 100644 --- a/common/test/run-bolt12_decode.c +++ b/common/test/run-bolt12_decode.c @@ -8,6 +8,7 @@ #include #include #include +#include #include /* AUTOGENERATED MOCKS START */ diff --git a/common/test/run-bolt12_merkle-json.c b/common/test/run-bolt12_merkle-json.c index 3c7d5a047..fefac76cc 100644 --- a/common/test/run-bolt12_merkle-json.c +++ b/common/test/run-bolt12_merkle-json.c @@ -12,6 +12,7 @@ #include #include #include +#include #include /* AUTOGENERATED MOCKS START */ diff --git a/common/test/run-bolt12_merkle.c b/common/test/run-bolt12_merkle.c index 43265ef4d..4d2f0bc6d 100644 --- a/common/test/run-bolt12_merkle.c +++ b/common/test/run-bolt12_merkle.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include diff --git a/common/test/run-bolt12_period.c b/common/test/run-bolt12_period.c index e4daf72f5..6b92f9cb6 100644 --- a/common/test/run-bolt12_period.c +++ b/common/test/run-bolt12_period.c @@ -5,6 +5,7 @@ #include #include #include +#include #include /* AUTOGENERATED MOCKS START */ diff --git a/common/test/run-channel_type.c b/common/test/run-channel_type.c index 46edef12b..2cac84ac8 100644 --- a/common/test/run-channel_type.c +++ b/common/test/run-channel_type.c @@ -2,6 +2,7 @@ #include "../channel_type.c" #include "../features.c" #include +#include #include #include #include diff --git a/common/test/run-codex32.c b/common/test/run-codex32.c index 3b32582f9..276bd0277 100644 --- a/common/test/run-codex32.c +++ b/common/test/run-codex32.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include diff --git a/common/test/run-coin_mvt.c b/common/test/run-coin_mvt.c index e7512c089..99651ccbb 100644 --- a/common/test/run-coin_mvt.c +++ b/common/test/run-coin_mvt.c @@ -1,6 +1,7 @@ #include "config.h" #include "../coin_mvt.c" #include +#include #include #include diff --git a/common/test/run-cryptomsg.c b/common/test/run-cryptomsg.c index 9b7619d95..0284f9da1 100644 --- a/common/test/run-cryptomsg.c +++ b/common/test/run-cryptomsg.c @@ -1,5 +1,6 @@ #include "config.h" #include +#include #include #include #include diff --git a/common/test/run-deprecation.c b/common/test/run-deprecation.c index fe1a4cd05..fa1378c86 100644 --- a/common/test/run-deprecation.c +++ b/common/test/run-deprecation.c @@ -6,6 +6,7 @@ static const char *test_next_version; #include "../deprecation.c" #include +#include #include #include #include diff --git a/common/test/run-derive_basepoints.c b/common/test/run-derive_basepoints.c index 861a65d63..cb896ad77 100644 --- a/common/test/run-derive_basepoints.c +++ b/common/test/run-derive_basepoints.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include diff --git a/common/test/run-features.c b/common/test/run-features.c index 9d2d37d47..efbea7f9f 100644 --- a/common/test/run-features.c +++ b/common/test/run-features.c @@ -3,6 +3,7 @@ #include "../memleak.c" #include #include +#include #include /* AUTOGENERATED MOCKS START */ diff --git a/common/test/run-gossmap-fp16.c b/common/test/run-gossmap-fp16.c index 274eccf3a..539b129b5 100644 --- a/common/test/run-gossmap-fp16.c +++ b/common/test/run-gossmap-fp16.c @@ -1,5 +1,6 @@ #include "config.h" #include "../fp16.c" +#include #include #include #include diff --git a/common/test/run-htable.c b/common/test/run-htable.c index 267ad8c03..75164ce20 100644 --- a/common/test/run-htable.c +++ b/common/test/run-htable.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include diff --git a/common/test/run-ip_port_parsing.c b/common/test/run-ip_port_parsing.c index 026a06f8f..c7c5ba226 100644 --- a/common/test/run-ip_port_parsing.c +++ b/common/test/run-ip_port_parsing.c @@ -4,6 +4,7 @@ #include #include +#include #include /* AUTOGENERATED MOCKS START */ diff --git a/common/test/run-json.c b/common/test/run-json.c index 529d96c62..3f1069ee4 100644 --- a/common/test/run-json.c +++ b/common/test/run-json.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include diff --git a/common/test/run-json_filter.c b/common/test/run-json_filter.c index 54138cbe6..d682b8213 100644 --- a/common/test/run-json_filter.c +++ b/common/test/run-json_filter.c @@ -6,6 +6,7 @@ #include "../json_stream.c" #include #include +#include #include #include diff --git a/common/test/run-json_remove.c b/common/test/run-json_remove.c index f1c16a28c..8a15653eb 100644 --- a/common/test/run-json_remove.c +++ b/common/test/run-json_remove.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include diff --git a/common/test/run-json_scan.c b/common/test/run-json_scan.c index ab3e487ca..877bce6be 100644 --- a/common/test/run-json_scan.c +++ b/common/test/run-json_scan.c @@ -2,6 +2,7 @@ #include "../json_parse.c" #include "../json_parse_simple.c" #include +#include #include #include #include diff --git a/common/test/run-json_stream-filter.c b/common/test/run-json_stream-filter.c index 1e484b475..6f6fe060f 100644 --- a/common/test/run-json_stream-filter.c +++ b/common/test/run-json_stream-filter.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include diff --git a/common/test/run-jsonrpc_io.c b/common/test/run-jsonrpc_io.c index 4d5e604bb..d0f75ff2f 100644 --- a/common/test/run-jsonrpc_io.c +++ b/common/test/run-jsonrpc_io.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include diff --git a/common/test/run-key_derive.c b/common/test/run-key_derive.c index f30fcdfb2..6b158f744 100644 --- a/common/test/run-key_derive.c +++ b/common/test/run-key_derive.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include diff --git a/common/test/run-lease_rates.c b/common/test/run-lease_rates.c index 31da81c7d..f995eb88c 100644 --- a/common/test/run-lease_rates.c +++ b/common/test/run-lease_rates.c @@ -1,6 +1,7 @@ #include "config.h" #include "../amount.c" #include "../lease_rates.c" +#include #include #include diff --git a/common/test/run-marginal_feerate.c b/common/test/run-marginal_feerate.c index e0514cfdd..097852cea 100644 --- a/common/test/run-marginal_feerate.c +++ b/common/test/run-marginal_feerate.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include "../fee_states.c" diff --git a/common/test/run-param.c b/common/test/run-param.c index 749f6a494..1778942a6 100644 --- a/common/test/run-param.c +++ b/common/test/run-param.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include diff --git a/common/test/run-psbt_diff.c b/common/test/run-psbt_diff.c index 6d3556977..235163fe0 100644 --- a/common/test/run-psbt_diff.c +++ b/common/test/run-psbt_diff.c @@ -1,4 +1,5 @@ #include "config.h" +#include #include #include #include "../amount.c" diff --git a/common/test/run-route-infloop.c b/common/test/run-route-infloop.c index 7556fd2f9..b52921e1d 100644 --- a/common/test/run-route-infloop.c +++ b/common/test/run-route-infloop.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include diff --git a/common/test/run-route-specific.c b/common/test/run-route-specific.c index 759b614fd..6e73f459d 100644 --- a/common/test/run-route-specific.c +++ b/common/test/run-route-specific.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include diff --git a/common/test/run-route.c b/common/test/run-route.c index d9fb4d3b2..53c735918 100644 --- a/common/test/run-route.c +++ b/common/test/run-route.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include diff --git a/common/test/run-route_blinding_test.c b/common/test/run-route_blinding_test.c index 049e2a585..26b52e605 100644 --- a/common/test/run-route_blinding_test.c +++ b/common/test/run-route_blinding_test.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include diff --git a/common/test/run-shutdown_scriptpubkey.c b/common/test/run-shutdown_scriptpubkey.c index db543a9d8..c98610d28 100644 --- a/common/test/run-shutdown_scriptpubkey.c +++ b/common/test/run-shutdown_scriptpubkey.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include diff --git a/common/test/run-splice_script.c b/common/test/run-splice_script.c index c3bd63fcb..082f46cea 100644 --- a/common/test/run-splice_script.c +++ b/common/test/run-splice_script.c @@ -6,6 +6,7 @@ #include "../json_stream.c" #include "../json_parse_simple.c" #include +#include #include #include #include diff --git a/common/test/run-tlv_span.c b/common/test/run-tlv_span.c index 4055ec9bc..eb3ede4b6 100644 --- a/common/test/run-tlv_span.c +++ b/common/test/run-tlv_span.c @@ -2,6 +2,7 @@ #include "../bolt12.c" #include "../bigsize.c" #include "../../wire/fromwire.c" +#include #include #include diff --git a/common/test/run-tlv_unknown.c b/common/test/run-tlv_unknown.c index fdecc4699..071b10432 100644 --- a/common/test/run-tlv_unknown.c +++ b/common/test/run-tlv_unknown.c @@ -5,6 +5,7 @@ #include "../../wire/towire.c" #include "../bigsize.c" #include "../bolt12.c" +#include #include #include diff --git a/common/test/run-version.c b/common/test/run-version.c index 0e04b4cb0..3b46f56e2 100644 --- a/common/test/run-version.c +++ b/common/test/run-version.c @@ -1,9 +1,13 @@ #include "config.h" #include "../version.c" +#include #include #include #include +/* AUTOGENERATED MOCKS START */ +/* AUTOGENERATED MOCKS END */ + int main(int argc, char *argv[]) { common_setup(argv[0]); diff --git a/common/test/run-wireaddr.c b/common/test/run-wireaddr.c index faa48e3c7..f5dd2ff92 100644 --- a/common/test/run-wireaddr.c +++ b/common/test/run-wireaddr.c @@ -1,6 +1,7 @@ #include "config.h" #include #include +#include #include #include diff --git a/connectd/connectd.c b/connectd/connectd.c index 761b6dd23..1b19b3930 100644 --- a/connectd/connectd.c +++ b/connectd/connectd.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -1560,7 +1561,7 @@ setup_listeners(const tal_t *ctx, if (sodium_mlock(&random, sizeof(random)) != 0) status_failed(STATUS_FAIL_INTERNAL_ERROR, "Could not lock the random prf key memory."); - randombytes_buf((void * const)&random, 32); + randbytes((void * const)&random, 32); /* generate static tor node address, take first 32 bytes from secret of node_id plus 32 random bytes from sodiom */ struct sha256 sha; struct secret ss; @@ -1585,7 +1586,7 @@ setup_listeners(const tal_t *ctx, localaddr, 0); /* get rid of blob data on our side of tor and add jitter */ - randombytes_buf((void * const)proposed_wireaddr[i].u.torservice.blob, TOR_V3_BLOBLEN); + randbytes((void * const)proposed_wireaddr[i].u.torservice.blob, TOR_V3_BLOBLEN); if (!(proposed_listen_announce[i] & ADDR_ANNOUNCE)) { continue; diff --git a/connectd/handshake.c b/connectd/handshake.c index 09e44bfa9..3382b50d5 100644 --- a/connectd/handshake.c +++ b/connectd/handshake.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -15,7 +16,6 @@ #include #include #include -#include #ifndef SUPERVERBOSE #define SUPERVERBOSE(...) @@ -199,7 +199,7 @@ static struct keypair generate_key(void) struct keypair k; do { - randombytes_buf(k.priv.secret.data, sizeof(k.priv.secret.data)); + randbytes(k.priv.secret.data, sizeof(k.priv.secret.data)); } while (!secp256k1_ec_pubkey_create(secp256k1_ctx, &k.pub.pubkey, k.priv.secret.data)); return k; diff --git a/connectd/test/run-initiator-success.c b/connectd/test/run-initiator-success.c index 6a652ca5c..fd59a040b 100644 --- a/connectd/test/run-initiator-success.c +++ b/connectd/test/run-initiator-success.c @@ -17,10 +17,10 @@ /* AUTOGENERATED MOCKS END */ /* No randomness please, we want to replicate test vectors. */ -#include +#include -static void seed_randomness(u8 *secret, size_t len); -#define randombytes_buf(secret, len) seed_randomness((secret), (len)) +static void seed_randomness(u8 *secret, size_t len, u64 *offset); +#define randbytes_(secret, len, offset) seed_randomness((secret), (len), (offset)) struct handshake; static struct io_plan *test_write(struct io_conn *conn, @@ -91,7 +91,7 @@ const void *trc; static struct pubkey rs_pub, ls_pub, e_pub; static struct privkey ls_priv, e_priv; -static void seed_randomness(u8 *secret, size_t len) +static void seed_randomness(u8 *secret, size_t len, u64 *offset) { assert(len == sizeof(e_priv)); memcpy(secret, &e_priv, len); diff --git a/connectd/test/run-responder-success.c b/connectd/test/run-responder-success.c index c4c2e7339..9e93f802b 100644 --- a/connectd/test/run-responder-success.c +++ b/connectd/test/run-responder-success.c @@ -17,10 +17,10 @@ /* AUTOGENERATED MOCKS END */ /* No randomness please, we want to replicate test vectors. */ -#include +#include -static void seed_randomness(u8 *secret, size_t len); -#define randombytes_buf(secret, len) seed_randomness((secret), (len)) +static void seed_randomness(u8 *secret, size_t len, u64 *offset); +#define randbytes_(secret, len, offset) seed_randomness((secret), (len), (offset)) struct handshake; static struct io_plan *test_write(struct io_conn *conn, @@ -90,7 +90,7 @@ extern secp256k1_context *secp256k1_ctx; static struct pubkey ls_pub, e_pub; static struct privkey ls_priv, e_priv; -static void seed_randomness(u8 *secret, size_t len) +static void seed_randomness(u8 *secret, size_t len, u64 *offset) { assert(len == sizeof(e_priv)); memcpy(secret, &e_priv, len); diff --git a/hsmd/hsmd.c b/hsmd/hsmd.c index 708fa84b3..8391164f9 100644 --- a/hsmd/hsmd.c +++ b/hsmd/hsmd.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -310,7 +311,7 @@ static void create_hsm(int fd, const char *passphrase) /* Initialize wally tal context for libwally operations */ /* Generate random entropy for new mnemonic */ - randombytes_buf(entropy, sizeof(entropy)); + randbytes(entropy, sizeof(entropy)); /* Generate mnemonic from entropy */ tal_wally_start(); diff --git a/lightningd/channel.c b/lightningd/channel.c index 798c7ad7a..5e7545553 100644 --- a/lightningd/channel.c +++ b/lightningd/channel.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include diff --git a/lightningd/invoice.c b/lightningd/invoice.c index 49933a932..c609508be 100644 --- a/lightningd/invoice.c +++ b/lightningd/invoice.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -20,7 +21,6 @@ #include #include #include -#include #include #include @@ -1180,8 +1180,8 @@ static struct command_result *json_invoice(struct command *cmd, info->payment_preimage = *preimage; else /* Generate random secret preimage. */ - randombytes_buf(&info->payment_preimage, - sizeof(info->payment_preimage)); + randbytes(&info->payment_preimage, + sizeof(info->payment_preimage)); /* Generate preimage hash. */ sha256(&rhash, &info->payment_preimage, sizeof(info->payment_preimage)); /* Generate payment secret. */ @@ -1620,7 +1620,7 @@ static void add_stub_blindedpath(const tal_t *ctx, path = tal(NULL, struct blinded_path); sciddir_or_pubkey_from_pubkey(&path->first_node_id, &ld->our_pubkey); - randombytes_buf(&path_key, sizeof(path_key)); + randbytes(&path_key, sizeof(path_key)); if (!pubkey_from_privkey(&path_key, &path->first_path_key)) abort(); path->path = tal_arr(path, struct blinded_path_hop *, 1); diff --git a/onchaind/test/run-grind_feerate-bug.c b/onchaind/test/run-grind_feerate-bug.c index ba71992cc..4e64c268b 100644 --- a/onchaind/test/run-grind_feerate-bug.c +++ b/onchaind/test/run-grind_feerate-bug.c @@ -4,6 +4,7 @@ */ #include "config.h" #include +#include #include #include @@ -171,6 +172,9 @@ void *notleak_(void *ptr UNNEEDED, bool plus_children UNNEEDED) /* Generated stub for peer_billboard */ void peer_billboard(bool perm UNNEEDED, const char *fmt UNNEEDED, ...) { fprintf(stderr, "peer_billboard called!\n"); abort(); } +/* Generated stub for randbytes_ */ +void randbytes_(void *bytes UNNEEDED, size_t num_bytes UNNEEDED, u64 *offset UNNEEDED) +{ fprintf(stderr, "randbytes_ called!\n"); abort(); } /* Generated stub for shachain_get_secret */ bool shachain_get_secret(const struct shachain *shachain UNNEEDED, u64 commit_num UNNEEDED, diff --git a/plugins/fetchinvoice.c b/plugins/fetchinvoice.c index a18b82e18..64414b9ec 100644 --- a/plugins/fetchinvoice.c +++ b/plugins/fetchinvoice.c @@ -11,11 +11,11 @@ #include #include #include +#include #include #include #include #include -#include static LIST_HEAD(sent_list); @@ -452,7 +452,7 @@ static struct blinded_path *make_reply_path(const tal_t *ctx, assert(tal_count(path) > 0); - randombytes_buf(reply_secret, sizeof(struct secret)); + randbytes(reply_secret, sizeof(struct secret)); if (sent->dev_reply_path) { ids = sent->dev_reply_path; @@ -1080,8 +1080,8 @@ struct command_result *json_fetchinvoice(struct command *cmd, * bytes. */ invreq->invreq_metadata = tal_arr(invreq, u8, 16); - randombytes_buf(invreq->invreq_metadata, - tal_bytelen(invreq->invreq_metadata)); + randbytes(invreq->invreq_metadata, + tal_bytelen(invreq->invreq_metadata)); } } @@ -1589,7 +1589,7 @@ struct command_result *json_sendinvoice(struct command *cmd, * - MUST set `invoice_payment_hash` to the SHA256 hash of the * `payment_preimage` that will be given in return for payment. */ - randombytes_buf(&sent->inv_preimage, sizeof(sent->inv_preimage)); + randbytes(&sent->inv_preimage, sizeof(sent->inv_preimage)); sent->inv->invoice_payment_hash = tal(sent->inv, struct sha256); sha256(sent->inv->invoice_payment_hash, &sent->inv_preimage, sizeof(sent->inv_preimage)); diff --git a/plugins/keysend.c b/plugins/keysend.c index 58c66cbc9..2e1ba2974 100644 --- a/plugins/keysend.c +++ b/plugins/keysend.c @@ -7,10 +7,10 @@ #include #include #include +#include #include #include #include -#include #define PREIMAGE_TLV_TYPE 5482373484 #define KEYSEND_FEATUREBIT 55 @@ -49,7 +49,7 @@ static struct keysend_data *keysend_init(struct payment *p) * and populate the preimage field in the keysend_data and the * payment_hash in the payment. */ d = tal(p, struct keysend_data); - randombytes_buf(&d->preimage, sizeof(d->preimage)); + randbytes(&d->preimage, sizeof(d->preimage)); ccan_sha256(&payment_hash, &d->preimage, sizeof(d->preimage)); p->payment_hash = tal_dup(p, struct sha256, &payment_hash); d->extra_tlvs = NULL; diff --git a/plugins/offers_invreq_hook.c b/plugins/offers_invreq_hook.c index 153def675..16dd717e1 100644 --- a/plugins/offers_invreq_hook.c +++ b/plugins/offers_invreq_hook.c @@ -11,10 +11,10 @@ #include #include #include +#include #include #include #include -#include /* We need to keep the reply path around so we can reply with invoice */ struct invreq { @@ -1006,7 +1006,7 @@ static struct command_result *listoffers_done(struct command *cmd, * - MUST set `invoice_payment_hash` to the SHA256 hash of the * `payment_preimage` that will be given in return for payment. */ - randombytes_buf(&ir->preimage, sizeof(ir->preimage)); + randbytes(&ir->preimage, sizeof(ir->preimage)); ir->inv->invoice_payment_hash = tal(ir->inv, struct sha256); sha256(ir->inv->invoice_payment_hash, &ir->preimage, sizeof(ir->preimage)); diff --git a/plugins/offers_offer.c b/plugins/offers_offer.c index 34b6844d4..53c88f05a 100644 --- a/plugins/offers_offer.c +++ b/plugins/offers_offer.c @@ -9,9 +9,9 @@ #include #include #include +#include #include #include -#include static bool msat_or_any(const char *buffer, const jsmntok_t *tok, @@ -706,8 +706,8 @@ struct command_result *json_invoicerequest(struct command *cmd, * - MUST set `invreq_metadata` to an unpredictable series of bytes. */ invreq->invreq_metadata = tal_arr(invreq, u8, 16); - randombytes_buf(invreq->invreq_metadata, - tal_bytelen(invreq->invreq_metadata)); + randbytes(invreq->invreq_metadata, + tal_bytelen(invreq->invreq_metadata)); /* BOLT #12: * - otherwise (not responding to an offer): diff --git a/plugins/renepay/test/run-bottleneck.c b/plugins/renepay/test/run-bottleneck.c index 6e8bda762..ec1e934f2 100644 --- a/plugins/renepay/test/run-bottleneck.c +++ b/plugins/renepay/test/run-bottleneck.c @@ -14,9 +14,9 @@ #include #include #include +#include #include #include -#include /* AUTOGENERATED MOCKS START */ /* AUTOGENERATED MOCKS END */ @@ -231,7 +231,7 @@ int main(int argc, char *argv[]) pinfo.base_prob_success = 1.0; pinfo.use_shadow = false; - randombytes_buf(&preimage, sizeof(preimage)); + randbytes(&preimage, sizeof(preimage)); sha256(&pinfo.payment_hash, &preimage, sizeof(preimage)); // char hex_preimage[600], hex_sha256[600]; diff --git a/tests/fuzz/connectd_handshake.h b/tests/fuzz/connectd_handshake.h index 139ee25d4..8145bd630 100644 --- a/tests/fuzz/connectd_handshake.h +++ b/tests/fuzz/connectd_handshake.h @@ -1,6 +1,6 @@ /* This header contains globals and helper functions used by all the * fuzz-connectd-handshake-act* fuzz targets. It also takes care of intercepting - * io_read(), io_write(), and randombytes_buf(), so that the actual fuzz targets + * io_read(), io_write(), and randbytes(), so that the actual fuzz targets * only need to implement the test_read() and test_write() interceptors and the * run() function. */ @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -19,9 +20,9 @@ /* No randomness please, we want to replicate test vectors. */ #include - +#undef randbytes static void seeded_randombytes_buf(u8 *secret, size_t len); -#define randombytes_buf(secret, len) seeded_randombytes_buf((secret), (len)) +#define randbytes(secret, len) seeded_randombytes_buf((secret), (len)) struct handshake; diff --git a/wire/test/run-peer-wire.c b/wire/test/run-peer-wire.c index f8b17c32e..a220af8fc 100644 --- a/wire/test/run-peer-wire.c +++ b/wire/test/run-peer-wire.c @@ -13,6 +13,7 @@ #include #include +#include #include #include #include @@ -21,6 +22,9 @@ extern secp256k1_context *secp256k1_ctx; /* AUTOGENERATED MOCKS START */ +/* Generated stub for randbytes_ */ +void randbytes_(void *bytes UNNEEDED, size_t num_bytes UNNEEDED, u64 *offset UNNEEDED) +{ fprintf(stderr, "randbytes_ called!\n"); abort(); } /* AUTOGENERATED MOCKS END */ /* memsetting pubkeys doesn't work */ diff --git a/wire/test/run-tlvstream.c b/wire/test/run-tlvstream.c index 2cb0c8ceb..3782191da 100644 --- a/wire/test/run-tlvstream.c +++ b/wire/test/run-tlvstream.c @@ -11,6 +11,7 @@ static const char *reason; #include #include #include +#include #include #include @@ -29,6 +30,9 @@ int chainparams_get_ln_port(const struct chainparams *params UNNEEDED) bool fromwire_channel_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct channel_id *channel_id UNNEEDED) { fprintf(stderr, "fromwire_channel_id called!\n"); abort(); } +/* Generated stub for randbytes_ */ +void randbytes_(void *bytes UNNEEDED, size_t num_bytes UNNEEDED, u64 *offset UNNEEDED) +{ fprintf(stderr, "randbytes_ called!\n"); abort(); } /* Generated stub for towire_channel_id */ void towire_channel_id(u8 **pptr UNNEEDED, const struct channel_id *channel_id UNNEEDED) { fprintf(stderr, "towire_channel_id called!\n"); abort(); }