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

Function hsmd_init

hsmd/libhsmd.c:1651–1800  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1649}
1650
1651u8 *hsmd_init(struct secret hsm_secret,
1652 struct bip32_key_version bip32_key_version)
1653{
1654 u8 bip32_seed[BIP32_ENTROPY_LEN_256];
1655 struct pubkey key;
1656 struct point32 bolt12;
1657 u32 salt = 0;
1658 struct ext_key master_extkey, child_extkey;
1659 struct node_id node_id;
1660 struct secret onion_reply_secret;
1661
1662 /*~ Don't swap this. */
1663 sodium_mlock(secretstuff.hsm_secret.data,
1664 sizeof(secretstuff.hsm_secret.data));
1665 memcpy(secretstuff.hsm_secret.data, hsm_secret.data, sizeof(hsm_secret.data));
1666
1667 assert(bip32_key_version.bip32_pubkey_version == BIP32_VER_MAIN_PUBLIC
1668 || bip32_key_version.bip32_pubkey_version == BIP32_VER_TEST_PUBLIC);
1669
1670 assert(bip32_key_version.bip32_privkey_version == BIP32_VER_MAIN_PRIVATE
1671 || bip32_key_version.bip32_privkey_version == BIP32_VER_TEST_PRIVATE);
1672
1673 /* Fill in the BIP32 tree for bitcoin addresses. */
1674 /* In libwally-core, the version BIP32_VER_TEST_PRIVATE is for testnet/regtest,
1675 * and BIP32_VER_MAIN_PRIVATE is for mainnet. For litecoin, we also set it like
1676 * bitcoin else.*/
1677 do {
1678 hkdf_sha256(bip32_seed, sizeof(bip32_seed),
1679 &salt, sizeof(salt),
1680 &secretstuff.hsm_secret,
1681 sizeof(secretstuff.hsm_secret),
1682 "bip32 seed", strlen("bip32 seed"));
1683 salt++;
1684 } while (bip32_key_from_seed(bip32_seed, sizeof(bip32_seed),
1685 bip32_key_version.bip32_privkey_version,
1686 0, &master_extkey) != WALLY_OK);
1687
1688#if DEVELOPER
1689 /* In DEVELOPER mode, we can override with --dev-force-bip32-seed */
1690 if (dev_force_bip32_seed) {
1691 if (bip32_key_from_seed(dev_force_bip32_seed->data,
1692 sizeof(dev_force_bip32_seed->data),
1693 bip32_key_version.bip32_privkey_version,
1694 0, &master_extkey) != WALLY_OK)
1695 hsmd_status_failed(STATUS_FAIL_INTERNAL_ERROR,
1696 "Can't derive bip32 master key");
1697 }
1698#endif /* DEVELOPER */
1699
1700 /* BIP 32:
1701 *
1702 * The default wallet layout
1703 *
1704 * An HDW is organized as several 'accounts'. Accounts are numbered,
1705 * the default account ("") being number 0. Clients are not required
1706 * to support more than one account - if not, they only use the
1707 * default account.
1708 *

Callers 1

init_hsmFunction · 0.85

Calls 4

hkdf_sha256Function · 0.85
node_keyFunction · 0.85
node_id_from_pubkeyFunction · 0.85
hsmd_status_failedFunction · 0.70

Tested by

no test coverage detected