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

Function derive_simple_privkey

common/key_derive.c:73–103  ·  view source on GitHub ↗

BOLT #3: * * The corresponding private keys can be similarly derived, if the basepoint * secrets are known (i.e. the private keys corresponding to `localpubkey`, * `local_htlcpubkey`, and `local_delayedpubkey` only): * * privkey = basepoint_secret + SHA256(per_commitment_point || basepoint) */

Source from the content-addressed store, hash-verified

71 * privkey = basepoint_secret + SHA256(per_commitment_point || basepoint)
72 */
73bool derive_simple_privkey(const struct secret *base_secret,
74 const struct pubkey *basepoint,
75 const struct pubkey *per_commitment_point,
76 struct privkey *key)
77{
78 struct sha256 sha;
79 unsigned char der_keys[PUBKEY_CMPR_LEN * 2];
80
81 pubkey_to_der(der_keys, per_commitment_point);
82 pubkey_to_der(der_keys + PUBKEY_CMPR_LEN, basepoint);
83 sha256(&sha, der_keys, sizeof(der_keys));
84#ifdef SUPERVERBOSE
85 printf("# SHA256(per_commitment_point || basepoint)\n");
86 printf("# => SHA256(0x%s || 0x%s)\n",
87 tal_hexstr(tmpctx, der_keys, PUBKEY_CMPR_LEN),
88 tal_hexstr(tmpctx, der_keys + PUBKEY_CMPR_LEN, PUBKEY_CMPR_LEN));
89 printf("# = 0x%s\n", tal_hexstr(tmpctx, &sha, sizeof(sha)));
90#endif
91
92 key->secret = *base_secret;
93 if (secp256k1_ec_seckey_tweak_add(secp256k1_ctx, key->secret.data,
94 sha.u.u8) != 1)
95 return false;
96#ifdef SUPERVERBOSE
97 printf("# + basepoint_secret (0x%s)\n",
98 tal_hexstr(tmpctx, base_secret, sizeof(*base_secret)));
99 printf("# = 0x%s\n",
100 tal_hexstr(tmpctx, key, sizeof(*key)));
101#endif
102 return true;
103}
104
105/* BOLT #3:
106 *

Callers 9

derive_to_remoteFunction · 0.85
do_sign_local_htlc_txFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85

Calls 3

pubkey_to_derFunction · 0.85
tal_hexstrFunction · 0.85
sha256Class · 0.70

Tested by 2

mainFunction · 0.68
mainFunction · 0.68