| 29 | } |
| 30 | |
| 31 | static void get_channel_seed(const struct secret *hsm_secret, |
| 32 | const struct node_id *peer_id, u64 dbid, |
| 33 | struct secret *channel_seed) |
| 34 | { |
| 35 | struct secret channel_base; |
| 36 | u8 input[sizeof(peer_id->k) + sizeof(dbid)]; |
| 37 | /*~ Again, "per-peer" should be "per-channel", but Hysterical Raisins */ |
| 38 | const char *info = "per-peer seed"; |
| 39 | |
| 40 | /*~ We use the DER encoding of the pubkey, because it's platform |
| 41 | * independent. Since the dbid is unique, however, it's completely |
| 42 | * unnecessary, but again, existing users can't be broken. */ |
| 43 | /* FIXME: lnd has a nicer BIP32 method for deriving secrets which we |
| 44 | * should migrate to. */ |
| 45 | hsm_channel_secret_base(&channel_base, hsm_secret); |
| 46 | memcpy(input, peer_id->k, sizeof(peer_id->k)); |
| 47 | BUILD_ASSERT(sizeof(peer_id->k) == PUBKEY_CMPR_LEN); |
| 48 | /*~ For all that talk about platform-independence, note that this |
| 49 | * field is endian-dependent! But let's face it, little-endian won. |
| 50 | * In related news, we don't support EBCDIC or middle-endian. */ |
| 51 | memcpy(input + PUBKEY_CMPR_LEN, &dbid, sizeof(dbid)); |
| 52 | |
| 53 | hkdf_sha256(channel_seed, sizeof(*channel_seed), |
| 54 | input, sizeof(input), |
| 55 | &channel_base, sizeof(channel_base), |
| 56 | info, strlen(info)); |
| 57 | } |
| 58 | |
| 59 | struct keys { |
| 60 | struct privkey f, r, h, p, d; |
no test coverage detected