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

Function act_two_initiator2

connectd/handshake.c:533–608  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

531}
532
533static struct io_plan *act_two_initiator2(struct io_conn *conn,
534 struct handshake *h)
535{
536 SUPERVERBOSE("input: 0x%s", tal_hexstr(tmpctx, &h->act2, ACT_TWO_SIZE));
537
538 /* BOLT #8:
539 *
540 * 3. If `v` is an unrecognized handshake version, then the responder
541 * MUST abort the connection attempt.
542 */
543 if (h->act2.v != 0)
544 return handshake_failed(conn, h);
545
546 /* BOLT #8:
547 *
548 * * The raw bytes of the remote party's ephemeral public key
549 * (`re`) are to be deserialized into a point on the curve using
550 * affine coordinates as encoded by the key's serialized
551 * composed format.
552 */
553 if (secp256k1_ec_pubkey_parse(secp256k1_ctx, &h->re.pubkey,
554 h->act2.pubkey, sizeof(h->act2.pubkey)) != 1)
555 return handshake_failed(conn, h);
556
557 SUPERVERBOSE("# re=0x%s", fmt_pubkey(tmpctx, &h->re));
558
559 /* BOLT #8:
560 *
561 * 4. `h = SHA-256(h || re.serializeCompressed())`
562 */
563 sha_mix_in_key(&h->h, &h->re);
564 SUPERVERBOSE("# h=0x%s", tal_hexstr(tmpctx, &h->h, sizeof(h->h)));
565
566 /* BOLT #8:
567 *
568 * 5. `es = ECDH(s.priv, re)`
569 */
570 if (!secp256k1_ecdh(secp256k1_ctx, h->ss->data, &h->re.pubkey,
571 h->e.priv.secret.data, NULL, NULL))
572 return handshake_failed(conn, h);
573
574 SUPERVERBOSE("# ss=0x%s", tal_hexstr(tmpctx, h->ss, sizeof(*h->ss)));
575
576 /* BOLT #8:
577 *
578 * 6. `ck, temp_k2 = HKDF(ck, ee)`
579 * * A new temporary encryption key is generated, which is
580 * used to generate the authenticating MAC.
581 */
582 hkdf_two_keys(&h->ck, &h->temp_k, &h->ck, h->ss, sizeof(*h->ss));
583 SUPERVERBOSE("# ck,temp_k2=0x%s,0x%s",
584 tal_hexstr(tmpctx, &h->ck, sizeof(h->ck)),
585 tal_hexstr(tmpctx, &h->temp_k, sizeof(h->temp_k)));
586
587 /* BOLT #8:
588 *
589 * 7. `p = decryptWithAD(temp_k2, 0, h, c)`
590 * * If the MAC check in this operation fails, then the initiator

Callers

nothing calls this directly

Calls 7

tal_hexstrFunction · 0.85
fmt_pubkeyFunction · 0.85
sha_mix_in_keyFunction · 0.85
decryptFunction · 0.85
sha_mix_inFunction · 0.85
act_three_initiatorFunction · 0.85
hkdf_two_keysFunction · 0.70

Tested by

no test coverage detected