From 6c98457ef2cc587213bbbd98031be9aa3f69eaa7 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 9 Jul 2018 20:47:58 +0930 Subject: [PATCH] per-peer seed is a 'struct secret' not a 'struct privkey'. They're both 32 bytes, but it's not a privkey at all. Signed-off-by: Rusty Russell --- channeld/channel.c | 2 +- channeld/channel_wire.csv | 2 +- closingd/closing.c | 2 +- closingd/closing_wire.csv | 2 +- common/derive_basepoints.c | 2 +- common/derive_basepoints.h | 2 +- hsmd/hsm.c | 6 +++--- lightningd/channel.c | 2 +- lightningd/channel.h | 4 ++-- lightningd/opening_control.c | 2 +- onchaind/onchain.c | 2 +- onchaind/onchain_wire.csv | 2 +- onchaind/test/run-grind_feerate.c | 4 ++-- openingd/opening.c | 6 +++--- openingd/opening_wire.csv | 2 +- wallet/test/run-wallet.c | 2 +- 16 files changed, 22 insertions(+), 22 deletions(-) diff --git a/channeld/channel.c b/channeld/channel.c index 902fc35e2..b8f14ece0 100644 --- a/channeld/channel.c +++ b/channeld/channel.c @@ -2398,7 +2398,7 @@ static void init_shared_secrets(struct channel *channel, /* We do this synchronously. */ static void init_channel(struct peer *peer) { - struct privkey seed; + struct secret seed; struct basepoints points[NUM_SIDES]; u64 funding_satoshi; u16 funding_txout; diff --git a/channeld/channel_wire.csv b/channeld/channel_wire.csv index 9c87eab4d..87db09a26 100644 --- a/channeld/channel_wire.csv +++ b/channeld/channel_wire.csv @@ -26,7 +26,7 @@ channel_init,,funder,enum side channel_init,,fee_base,u32 channel_init,,fee_proportional,u32 channel_init,,local_msatoshi,u64 -channel_init,,seed,struct privkey +channel_init,,seed,struct secret channel_init,,local_node_id,struct pubkey channel_init,,remote_node_id,struct pubkey channel_init,,commit_msec,u32 diff --git a/closingd/closing.c b/closingd/closing.c index b819e1af4..48b7d80af 100644 --- a/closingd/closing.c +++ b/closingd/closing.c @@ -424,7 +424,7 @@ int main(int argc, char *argv[]) struct crypto_state cs; const tal_t *ctx = tal(NULL, char); u8 *msg; - struct privkey seed; + struct secret seed; struct pubkey funding_pubkey[NUM_SIDES]; struct bitcoin_txid funding_txid; u16 funding_txout; diff --git a/closingd/closing_wire.csv b/closingd/closing_wire.csv index 964e48d4a..c891f0389 100644 --- a/closingd/closing_wire.csv +++ b/closingd/closing_wire.csv @@ -3,7 +3,7 @@ # Begin! (passes peer fd, gossipd-client fd) closing_init,2001 closing_init,,crypto_state,struct crypto_state -closing_init,,seed,struct privkey +closing_init,,seed,struct secret closing_init,,funding_txid,struct bitcoin_txid closing_init,,funding_txout,u16 closing_init,,funding_satoshi,u64 diff --git a/common/derive_basepoints.c b/common/derive_basepoints.c index 5c675bb5f..e2f833e39 100644 --- a/common/derive_basepoints.c +++ b/common/derive_basepoints.c @@ -3,7 +3,7 @@ #include #include -bool derive_basepoints(const struct privkey *seed, +bool derive_basepoints(const struct secret *seed, struct pubkey *funding_pubkey, struct basepoints *basepoints, struct secrets *secrets, diff --git a/common/derive_basepoints.h b/common/derive_basepoints.h index 2fd38e7f4..b9d975dfa 100644 --- a/common/derive_basepoints.h +++ b/common/derive_basepoints.h @@ -32,7 +32,7 @@ struct secrets { * @secrets: (out) basepoints for channel (if non-NULL) * @shaseed: (out) seed for shachain (if non-NULL) */ -bool derive_basepoints(const struct privkey *seed, +bool derive_basepoints(const struct secret *seed, struct pubkey *funding_pubkey, struct basepoints *basepoints, struct secrets *secrets, diff --git a/hsmd/hsm.c b/hsmd/hsm.c index 2007e97d4..22a4f9bb2 100644 --- a/hsmd/hsm.c +++ b/hsmd/hsm.c @@ -545,7 +545,7 @@ static void pass_client_hsmfd(struct daemon_conn *master, const u8 *msg) } -static void derive_peer_seed(struct privkey *peer_seed, struct privkey *peer_seed_base, +static void derive_peer_seed(struct secret *peer_seed, struct secret *peer_seed_base, const struct pubkey *peer_id, const u64 channel_id) { u8 input[PUBKEY_DER_LEN + sizeof(channel_id)]; @@ -562,10 +562,10 @@ static void derive_peer_seed(struct privkey *peer_seed, struct privkey *peer_see static void hsm_unilateral_close_privkey(struct privkey *dst, struct unilateral_close_info *info) { - struct privkey peer_seed, peer_seed_base; + struct secret peer_seed, peer_seed_base; struct basepoints basepoints; struct secrets secrets; - hsm_peer_secret_base(&peer_seed_base.secret); + hsm_peer_secret_base(&peer_seed_base); derive_peer_seed(&peer_seed, &peer_seed_base, &info->peer_id, info->channel_id); derive_basepoints(&peer_seed, NULL, &basepoints, &secrets, NULL); diff --git a/lightningd/channel.c b/lightningd/channel.c index d20d4036f..6d2f9257c 100644 --- a/lightningd/channel.c +++ b/lightningd/channel.c @@ -114,7 +114,7 @@ void delete_channel(struct channel *channel) * reconnection. We use the DB channel ID to guarantee unique secrets * per channel. */ -void derive_channel_seed(struct lightningd *ld, struct privkey *seed, +void derive_channel_seed(struct lightningd *ld, struct secret *seed, const struct pubkey *peer_id, const u64 dbid) { diff --git a/lightningd/channel.h b/lightningd/channel.h index 57cfc1821..aec4b939d 100644 --- a/lightningd/channel.h +++ b/lightningd/channel.h @@ -79,7 +79,7 @@ struct channel { struct channel_info channel_info; /* Secret seed (FIXME: Move to hsm!) */ - struct privkey seed; + struct secret seed; /* Their scriptpubkey if they sent shutdown. */ u8 *remote_shutdown_scriptpubkey; @@ -203,7 +203,7 @@ static inline bool channel_active(const struct channel *channel) && !channel_on_chain(channel); } -void derive_channel_seed(struct lightningd *ld, struct privkey *seed, +void derive_channel_seed(struct lightningd *ld, struct secret *seed, const struct pubkey *peer_id, const u64 dbid); diff --git a/lightningd/opening_control.c b/lightningd/opening_control.c index 91d80c5cf..4381dac93 100644 --- a/lightningd/opening_control.c +++ b/lightningd/opening_control.c @@ -46,7 +46,7 @@ struct uncommitted_channel { struct funding_channel *fc; /* Secret seed (FIXME: Move to hsm!) */ - struct privkey seed; + struct secret seed; /* Blockheight at creation, scans for funding confirmations * will start here */ diff --git a/onchaind/onchain.c b/onchaind/onchain.c index 52486f105..510890de3 100644 --- a/onchaind/onchain.c +++ b/onchaind/onchain.c @@ -2135,7 +2135,7 @@ int main(int argc, char *argv[]) const tal_t *ctx = tal(NULL, char); u8 *msg; - struct privkey seed; + struct secret seed; struct pubkey remote_payment_basepoint, remote_htlc_basepoint, remote_per_commit_point, old_remote_per_commit_point, remote_revocation_basepoint, remote_delayed_payment_basepoint; diff --git a/onchaind/onchain_wire.csv b/onchaind/onchain_wire.csv index 21a86dd3d..37f80ed79 100644 --- a/onchaind/onchain_wire.csv +++ b/onchaind/onchain_wire.csv @@ -1,7 +1,7 @@ #include # Begin! Here's the onchain tx which spends funding tx, followed by all HTLCs. onchain_init,5001 -onchain_init,,seed,struct privkey +onchain_init,,seed,struct secret onchain_init,,shachain,struct shachain onchain_init,,funding_amount_satoshi,u64 # Remote per commit point for committed tx. diff --git a/onchaind/test/run-grind_feerate.c b/onchaind/test/run-grind_feerate.c index 0fbb8006f..627d9253b 100644 --- a/onchaind/test/run-grind_feerate.c +++ b/onchaind/test/run-grind_feerate.c @@ -19,7 +19,7 @@ u64 commit_number_obscurer(const struct pubkey *opener_payment_basepoint UNNEEDE void daemon_shutdown(void) { fprintf(stderr, "daemon_shutdown called!\n"); abort(); } /* Generated stub for derive_basepoints */ -bool derive_basepoints(const struct privkey *seed UNNEEDED, +bool derive_basepoints(const struct secret *seed UNNEEDED, struct pubkey *funding_pubkey UNNEEDED, struct basepoints *basepoints UNNEEDED, struct secrets *secrets UNNEEDED, @@ -55,7 +55,7 @@ bool fromwire_onchain_depth(const void *p UNNEEDED, struct bitcoin_txid *txid UN bool fromwire_onchain_htlc(const void *p UNNEEDED, struct htlc_stub *htlc UNNEEDED, bool *tell_if_missing UNNEEDED, bool *tell_immediately UNNEEDED) { fprintf(stderr, "fromwire_onchain_htlc called!\n"); abort(); } /* Generated stub for fromwire_onchain_init */ -bool fromwire_onchain_init(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, struct privkey *seed UNNEEDED, struct shachain *shachain UNNEEDED, u64 *funding_amount_satoshi UNNEEDED, struct pubkey *old_remote_per_commitment_point UNNEEDED, struct pubkey *remote_per_commitment_point UNNEEDED, u32 *local_to_self_delay UNNEEDED, u32 *remote_to_self_delay UNNEEDED, u32 *feerate_per_kw UNNEEDED, u64 *local_dust_limit_satoshi UNNEEDED, struct pubkey *remote_revocation_basepoint UNNEEDED, struct bitcoin_txid *our_broadcast_txid UNNEEDED, u8 **local_scriptpubkey UNNEEDED, u8 **remote_scriptpubkey UNNEEDED, struct pubkey *ourwallet_pubkey UNNEEDED, enum side *funder UNNEEDED, struct pubkey *remote_payment_basepoint UNNEEDED, struct pubkey *remote_htlc_basepoint UNNEEDED, struct pubkey *remote_delayed_payment_basepoint UNNEEDED, struct bitcoin_tx **tx UNNEEDED, u32 *tx_blockheight UNNEEDED, u32 *reasonable_depth UNNEEDED, secp256k1_ecdsa_signature **htlc_signature UNNEEDED, u64 *num_htlcs UNNEEDED, u32 *min_possible_feerate UNNEEDED, u32 *max_possible_feerate UNNEEDED) +bool fromwire_onchain_init(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, struct secret *seed UNNEEDED, struct shachain *shachain UNNEEDED, u64 *funding_amount_satoshi UNNEEDED, struct pubkey *old_remote_per_commitment_point UNNEEDED, struct pubkey *remote_per_commitment_point UNNEEDED, u32 *local_to_self_delay UNNEEDED, u32 *remote_to_self_delay UNNEEDED, u32 *feerate_per_kw UNNEEDED, u64 *local_dust_limit_satoshi UNNEEDED, struct pubkey *remote_revocation_basepoint UNNEEDED, struct bitcoin_txid *our_broadcast_txid UNNEEDED, u8 **local_scriptpubkey UNNEEDED, u8 **remote_scriptpubkey UNNEEDED, struct pubkey *ourwallet_pubkey UNNEEDED, enum side *funder UNNEEDED, struct pubkey *remote_payment_basepoint UNNEEDED, struct pubkey *remote_htlc_basepoint UNNEEDED, struct pubkey *remote_delayed_payment_basepoint UNNEEDED, struct bitcoin_tx **tx UNNEEDED, u32 *tx_blockheight UNNEEDED, u32 *reasonable_depth UNNEEDED, secp256k1_ecdsa_signature **htlc_signature UNNEEDED, u64 *num_htlcs UNNEEDED, u32 *min_possible_feerate UNNEEDED, u32 *max_possible_feerate UNNEEDED) { fprintf(stderr, "fromwire_onchain_init called!\n"); abort(); } /* Generated stub for fromwire_onchain_known_preimage */ bool fromwire_onchain_known_preimage(const void *p UNNEEDED, struct preimage *preimage UNNEEDED) diff --git a/openingd/opening.c b/openingd/opening.c index 392376be6..3a5c2a95f 100644 --- a/openingd/opening.c +++ b/openingd/opening.c @@ -813,7 +813,7 @@ int main(int argc, char *argv[]) u8 *msg, *peer_msg; struct state *state = tal(NULL, struct state); - struct privkey seed; + struct secret seed; struct basepoints our_points; struct pubkey our_funding_pubkey; u32 minimum_depth; @@ -849,14 +849,14 @@ int main(int argc, char *argv[]) &state->shaseed)) status_failed(STATUS_FAIL_INTERNAL_ERROR, "Secret derivation failed, secret = %s", - type_to_string(tmpctx, struct privkey, &seed)); + type_to_string(tmpctx, struct secret, &seed)); if (!per_commit_point(&state->shaseed, &state->next_per_commit[LOCAL], 0)) status_failed(STATUS_FAIL_INTERNAL_ERROR, "First per_commitment_point derivation failed," " secret = %s", - type_to_string(tmpctx, struct privkey, &seed)); + type_to_string(tmpctx, struct secret, &seed)); status_trace("First per_commit_point = %s", type_to_string(tmpctx, struct pubkey, diff --git a/openingd/opening_wire.csv b/openingd/opening_wire.csv index a9c16cd0f..7f662b684 100644 --- a/openingd/opening_wire.csv +++ b/openingd/opening_wire.csv @@ -10,7 +10,7 @@ opening_init,,max_to_self_delay,u32 opening_init,,min_effective_htlc_capacity_msat,u64 opening_init,,crypto_state,struct crypto_state # Seed to generate all the keys from -opening_init,,seed,struct privkey +opening_init,,seed,struct secret #include #include diff --git a/wallet/test/run-wallet.c b/wallet/test/run-wallet.c index d46d82a70..b1eac0946 100644 --- a/wallet/test/run-wallet.c +++ b/wallet/test/run-wallet.c @@ -60,7 +60,7 @@ void command_still_pending(struct command *cmd UNNEEDED) void command_success(struct command *cmd UNNEEDED, struct json_result *response UNNEEDED) { fprintf(stderr, "command_success called!\n"); abort(); } /* Generated stub for derive_basepoints */ -bool derive_basepoints(const struct privkey *seed UNNEEDED, +bool derive_basepoints(const struct secret *seed UNNEEDED, struct pubkey *funding_pubkey UNNEEDED, struct basepoints *basepoints UNNEEDED, struct secrets *secrets UNNEEDED,