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

Function node_key

hsmd/libhsmd.c:247–282  ·  view source on GitHub ↗

~ This returns the secret and/or public key for this node. */

Source from the content-addressed store, hash-verified

245
246/*~ This returns the secret and/or public key for this node. */
247static void node_key(struct privkey *node_privkey, struct pubkey *node_id)
248{
249 u32 salt = 0;
250 struct privkey unused_s;
251 struct pubkey unused_k;
252
253 /* If caller specifies NULL, they don't want the results. */
254 if (node_privkey == NULL)
255 node_privkey = &unused_s;
256 if (node_id == NULL)
257 node_id = &unused_k;
258
259 /*~ So, there is apparently a 1 in 2^127 chance that a random value is
260 * not a valid private key, so this never actually loops. */
261 do {
262 /*~ ccan/crypto/hkdf_sha256 implements RFC5869 "Hardened Key
263 * Derivation Functions". That means that if a derived key
264 * leaks somehow, the other keys are not compromised. */
265 hkdf_sha256(node_privkey, sizeof(*node_privkey),
266 &salt, sizeof(salt),
267 secretstuff.bip32_seed,
268 32, /* Use first 32 bytes for node key derivation */
269 "nodeid", 6);
270 salt++;
271 } while (!secp256k1_ec_pubkey_create(secp256k1_ctx, &node_id->pubkey,
272 node_privkey->secret.data));
273
274 /* In --developer mode, we can override with --dev-force-privkey */
275 if (dev_force_privkey) {
276 *node_privkey = *dev_force_privkey;
277 if (!secp256k1_ec_pubkey_create(secp256k1_ctx, &node_id->pubkey,
278 node_privkey->secret.data))
279 hsmd_status_failed(STATUS_FAIL_INTERNAL_ERROR,
280 "Failed to derive pubkey for dev_force_privkey");
281 }
282}
283
284/*~ This returns the secret key for this node. */
285static void node_schnorrkey(secp256k1_keypair *node_keypair)

Callers 10

node_schnorrkeyFunction · 0.70
handle_sign_messageFunction · 0.70
handle_sign_bolt12_2Function · 0.70
handle_sign_invoiceFunction · 0.70
handle_ecdhFunction · 0.70
hsmd_initFunction · 0.70

Calls 2

hkdf_sha256Function · 0.85
hsmd_status_failedFunction · 0.70

Tested by

no test coverage detected