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

Function derive_simple_key

common/key_derive.c:27–57  ·  view source on GitHub ↗

BOLT #3: * * ### `localpubkey`, `local_htlcpubkey`, `remote_htlcpubkey`, `local_delayedpubkey`, and `remote_delayedpubkey` Derivation * * These pubkeys are simply generated by addition from their base points: * * pubkey = basepoint + SHA256(per_commitment_point || basepoint) * G * * The `localpubkey` uses the local node's `payment_basepoint`; * The `remotepubkey` uses the remote node's `p

Source from the content-addressed store, hash-verified

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

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

tal_hexstrFunction · 0.85
sha256Class · 0.70
type_to_stringClass · 0.70
pubkey_to_derFunction · 0.50

Tested by 2

mainFunction · 0.68
mainFunction · 0.68