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

Function get_channel_seed

tools/hsmtool.c:112–145  ·  view source on GitHub ↗

Taken from hsmd. */

Source from the content-addressed store, hash-verified

110
111/* Taken from hsmd. */
112static void get_channel_seed(struct secret *channel_seed, struct node_id *peer_id,
113 u64 dbid, struct secret *hsm_secret)
114{
115 struct secret channel_base;
116 u8 input[sizeof(peer_id->k) + sizeof(dbid)];
117 /*~ Again, "per-peer" should be "per-channel", but Hysterical Raisins */
118 const char *info = "per-peer seed";
119
120 /*~ We use the DER encoding of the pubkey, because it's platform
121 * independent. Since the dbid is unique, however, it's completely
122 * unnecessary, but again, existing users can't be broken. */
123 /* FIXME: lnd has a nicer BIP32 method for deriving secrets which we
124 * should migrate to. */
125 hkdf_sha256(&channel_base, sizeof(struct secret), NULL, 0,
126 hsm_secret, sizeof(*hsm_secret),
127 /*~ Initially, we didn't support multiple channels per
128 * peer at all: a channel had to be completely forgotten
129 * before another could exist. That was slightly relaxed,
130 * but the phrase "peer seed" is wired into the seed
131 * generation here, so we need to keep it that way for
132 * existing clients, rather than using "channel seed". */
133 "peer seed", strlen("peer seed"));
134 memcpy(input, peer_id->k, sizeof(peer_id->k));
135 BUILD_ASSERT(sizeof(peer_id->k) == PUBKEY_CMPR_LEN);
136 /*~ For all that talk about platform-independence, note that this
137 * field is endian-dependent! But let's face it, little-endian won.
138 * In related news, we don't support EBCDIC or middle-endian. */
139 memcpy(input + PUBKEY_CMPR_LEN, &dbid, sizeof(dbid));
140
141 hkdf_sha256(channel_seed, sizeof(*channel_seed),
142 input, sizeof(input),
143 &channel_base, sizeof(channel_base),
144 info, strlen(info));
145}
146
147/* We detect an encrypted hsm_secret as a hsm_secret which is 73-bytes long. */
148static bool hsm_secret_is_encrypted(const char *hsm_secret_path)

Callers 2

dump_commitments_infosFunction · 0.70
guess_to_remoteFunction · 0.70

Calls 1

hkdf_sha256Function · 0.85

Tested by

no test coverage detected