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

Function derive_simple_key

common/key_derive.c:33–63  ·  view source on GitHub ↗

The old BOLT defined what happened prior to option_static_remotekey, * which we still support for existing channels: * * If `option_static_remotekey` or `option_anchors` is negotiated, the * `remotepubkey` is simply the remote node's `payment_basepoint`, otherwise * it is calculated as above using the remote node's `payment_basepoint`. */

Source from the content-addressed store, hash-verified

31 * it is calculated as above using the remote node's `payment_basepoint`.
32 */
33bool derive_simple_key(const struct pubkey *basepoint,
34 const struct pubkey *per_commitment_point,
35 struct pubkey *key)
36{
37 struct sha256 sha;
38 unsigned char der_keys[PUBKEY_CMPR_LEN * 2];
39
40 pubkey_to_der(der_keys, per_commitment_point);
41 pubkey_to_der(der_keys + PUBKEY_CMPR_LEN, basepoint);
42 sha256(&sha, der_keys, sizeof(der_keys));
43#ifdef SUPERVERBOSE
44 printf("# SHA256(per_commitment_point || basepoint)\n");
45 printf("# => SHA256(0x%s || 0x%s)\n",
46 tal_hexstr(tmpctx, der_keys, PUBKEY_CMPR_LEN),
47 tal_hexstr(tmpctx, der_keys + PUBKEY_CMPR_LEN, PUBKEY_CMPR_LEN));
48 printf("# = 0x%s\n",
49 tal_hexstr(tmpctx, &sha, sizeof(sha)));
50#endif
51
52 *key = *basepoint;
53 if (secp256k1_ec_pubkey_tweak_add(secp256k1_ctx,
54 &key->pubkey, sha.u.u8) != 1)
55 return false;
56#ifdef SUPERVERBOSE
57 printf("# + basepoint (0x%s)\n",
58 fmt_pubkey(tmpctx, basepoint));
59 printf("# = 0x%s\n",
60 fmt_pubkey(tmpctx, key));
61#endif
62 return true;
63}
64
65/* BOLT #3:
66 *

Callers 7

calc_commitsigsFunction · 0.85
handle_peer_commit_sigFunction · 0.85
mainFunction · 0.85
derive_keysetFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85

Calls 4

pubkey_to_derFunction · 0.85
tal_hexstrFunction · 0.85
fmt_pubkeyFunction · 0.85
sha256Class · 0.70

Tested by 2

mainFunction · 0.68
mainFunction · 0.68