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

Function act_two_responder

connectd/handshake.c:785–865  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

783}
784
785static struct io_plan *act_two_responder(struct io_conn *conn,
786 struct handshake *h)
787{
788 size_t len;
789
790 SUPERVERBOSE("Responder: Act 2");
791
792 /* BOLT #8:
793 *
794 * **Sender Actions:**
795 *
796 * 1. `e = generateKey()`
797 */
798 h->e = generate_key();
799 SUPERVERBOSE("# e.pub=0x%s e.priv=0x%s",
800 type_to_string(tmpctx, struct pubkey, &h->e.pub),
801 tal_hexstr(tmpctx, &h->e.priv, sizeof(h->e.priv)));
802
803 /* BOLT #8:
804 *
805 * 2. `h = SHA-256(h || e.pub.serializeCompressed())`
806 * * The newly generated ephemeral key is accumulated into the
807 * running handshake digest.
808 */
809 sha_mix_in_key(&h->h, &h->e.pub);
810 SUPERVERBOSE("# h=0x%s", tal_hexstr(tmpctx, &h->h, sizeof(h->h)));
811
812 /* BOLT #8:
813 *
814 * 3. `ee = ECDH(e.priv, re)`
815 * * where `re` is the ephemeral key of the initiator, which was received
816 * during Act One
817 */
818 if (!secp256k1_ecdh(secp256k1_ctx, h->ss->data, &h->re.pubkey,
819 h->e.priv.secret.data, NULL, NULL))
820 return handshake_failed(conn, h);
821 SUPERVERBOSE("# ss=0x%s", tal_hexstr(tmpctx, h->ss, sizeof(*h->ss)));
822
823 /* BOLT #8:
824 *
825 * 4. `ck, temp_k2 = HKDF(ck, ee)`
826 * * A new temporary encryption key is generated, which is
827 * used to generate the authenticating MAC.
828 */
829 hkdf_two_keys(&h->ck, &h->temp_k, &h->ck, h->ss, sizeof(*h->ss));
830 SUPERVERBOSE("# ck,temp_k2=0x%s,0x%s",
831 tal_hexstr(tmpctx, &h->ck, sizeof(h->ck)),
832 tal_hexstr(tmpctx, &h->temp_k, sizeof(h->temp_k)));
833
834 /* BOLT #8:
835 *
836 * 5. `c = encryptWithAD(temp_k2, 0, h, zero)`
837 * * where `zero` is a zero-length plaintext
838 */
839 encrypt_ad(&h->temp_k, 0, &h->h, sizeof(h->h), NULL, 0,
840 h->act2.tag, sizeof(h->act2.tag));
841 SUPERVERBOSE("# c=0x%s", tal_hexstr(tmpctx, h->act2.tag, sizeof(h->act2.tag)));
842

Callers 1

act_one_responder2Function · 0.85

Calls 8

tal_hexstrFunction · 0.85
sha_mix_in_keyFunction · 0.85
encrypt_adFunction · 0.85
sha_mix_inFunction · 0.85
check_act_twoFunction · 0.85
generate_keyFunction · 0.70
hkdf_two_keysFunction · 0.70
type_to_stringClass · 0.50

Tested by

no test coverage detected