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

Function handle_ecdh

hsmd/libhsmd.c:762–783  ·  view source on GitHub ↗

~ The client has asked us to extract the shared secret from an EC Diffie * Hellman token. This doesn't leak any information, but requires the private * key, so the hsmd performs it. It's used to set up an encryption key for the * connection handshaking (BOLT #8) and for the onion wrapping (BOLT #4). */

Source from the content-addressed store, hash-verified

760 * key, so the hsmd performs it. It's used to set up an encryption key for the
761 * connection handshaking (BOLT #8) and for the onion wrapping (BOLT #4). */
762static u8 *handle_ecdh(struct hsmd_client *c, const u8 *msg_in)
763{
764 struct privkey privkey;
765 struct pubkey point;
766 struct secret ss;
767
768 if (!fromwire_hsmd_ecdh_req(msg_in, &point))
769 return hsmd_status_malformed_request(c, msg_in);
770
771 /*~ We simply use the secp256k1_ecdh function: if privkey.secret.data is invalid,
772 * we kill them for bad randomness (~1 in 2^127 if privkey.secret.data is random) */
773 node_key(&privkey, NULL);
774 if (secp256k1_ecdh(secp256k1_ctx, ss.data, &point.pubkey,
775 privkey.secret.data, NULL, NULL) != 1) {
776 return hsmd_status_bad_request_fmt(c, msg_in,
777 "secp256k1_ecdh fail");
778 }
779
780 /*~ In the normal case, we return the shared secret, and then read
781 * the next msg. */
782 return towire_hsmd_ecdh_resp(NULL, &ss);
783}
784
785/*~ This is used when the remote peer claims to have knowledge of future
786 * commitment states (option_data_loss_protect in the spec) which means we've

Callers 1

Calls 3

node_keyFunction · 0.85

Tested by

no test coverage detected