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

Function act_two_responder

connectd/handshake.c:805–885  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

803}
804
805static struct io_plan *act_two_responder(struct io_conn *conn,
806 struct handshake *h)
807{
808 size_t len;
809
810 SUPERVERBOSE("Responder: Act 2");
811
812 /* BOLT #8:
813 *
814 * **Sender Actions:**
815 *
816 * 1. `e = generateKey()`
817 */
818 h->e = generate_key();
819 SUPERVERBOSE("# e.pub=0x%s e.priv=0x%s",
820 fmt_pubkey(tmpctx, &h->e.pub),
821 tal_hexstr(tmpctx, &h->e.priv, sizeof(h->e.priv)));
822
823 /* BOLT #8:
824 *
825 * 2. `h = SHA-256(h || e.pub.serializeCompressed())`
826 * * The newly generated ephemeral key is accumulated into the
827 * running handshake digest.
828 */
829 sha_mix_in_key(&h->h, &h->e.pub);
830 SUPERVERBOSE("# h=0x%s", tal_hexstr(tmpctx, &h->h, sizeof(h->h)));
831
832 /* BOLT #8:
833 *
834 * 3. `ee = ECDH(e.priv, re)`
835 * * where `re` is the ephemeral key of the initiator, which was received
836 * during Act One
837 */
838 if (!secp256k1_ecdh(secp256k1_ctx, h->ss->data, &h->re.pubkey,
839 h->e.priv.secret.data, NULL, NULL))
840 return handshake_failed(conn, h);
841 SUPERVERBOSE("# ss=0x%s", tal_hexstr(tmpctx, h->ss, sizeof(*h->ss)));
842
843 /* BOLT #8:
844 *
845 * 4. `ck, temp_k2 = HKDF(ck, ee)`
846 * * A new temporary encryption key is generated, which is
847 * used to generate the authenticating MAC.
848 */
849 hkdf_two_keys(&h->ck, &h->temp_k, &h->ck, h->ss, sizeof(*h->ss));
850 SUPERVERBOSE("# ck,temp_k2=0x%s,0x%s",
851 tal_hexstr(tmpctx, &h->ck, sizeof(h->ck)),
852 tal_hexstr(tmpctx, &h->temp_k, sizeof(h->temp_k)));
853
854 /* BOLT #8:
855 *
856 * 5. `c = encryptWithAD(temp_k2, 0, h, zero)`
857 * * where `zero` is a zero-length plaintext
858 */
859 encrypt_ad(&h->temp_k, 0, &h->h, sizeof(h->h), NULL, 0,
860 h->act2.tag, sizeof(h->act2.tag));
861 SUPERVERBOSE("# c=0x%s", tal_hexstr(tmpctx, h->act2.tag, sizeof(h->act2.tag)));
862

Callers 1

act_one_responder2Function · 0.85

Calls 8

fmt_pubkeyFunction · 0.85
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

Tested by

no test coverage detected