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

Function act_three_initiator

connectd/handshake.c:464–531  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

462}
463
464static struct io_plan *act_three_initiator(struct io_conn *conn,
465 struct handshake *h)
466{
467 u8 spub[PUBKEY_CMPR_LEN];
468 size_t len = sizeof(spub);
469
470 SUPERVERBOSE("Initiator: Act 3");
471
472 /* BOLT #8:
473 * 1. `c = encryptWithAD(temp_k2, 1, h, s.pub.serializeCompressed())`
474 * * where `s` is the static public key of the initiator
475 */
476 secp256k1_ec_pubkey_serialize(secp256k1_ctx, spub, &len,
477 &h->my_id.pubkey,
478 SECP256K1_EC_COMPRESSED);
479 encrypt_ad(&h->temp_k, 1, &h->h, sizeof(h->h), spub, sizeof(spub),
480 h->act3.ciphertext, sizeof(h->act3.ciphertext));
481 SUPERVERBOSE("# c=0x%s",
482 tal_hexstr(tmpctx,
483 h->act3.ciphertext, sizeof(h->act3.ciphertext)));
484
485 /* BOLT #8:
486 * 2. `h = SHA-256(h || c)`
487 */
488 sha_mix_in(&h->h, h->act3.ciphertext, sizeof(h->act3.ciphertext));
489 SUPERVERBOSE("# h=0x%s", tal_hexstr(tmpctx, &h->h, sizeof(h->h)));
490
491 /* BOLT #8:
492 *
493 * 3. `se = ECDH(s.priv, re)`
494 * * where `re` is the ephemeral public key of the responder
495 */
496 tal_free(h->ss);
497 h->ss = tal(h, struct secret);
498 ecdh(&h->re, h->ss);
499 SUPERVERBOSE("# ss=0x%s", tal_hexstr(tmpctx, h->ss, sizeof(*h->ss)));
500
501 /* BOLT #8:
502 *
503 * 4. `ck, temp_k3 = HKDF(ck, se)`
504 * * The final intermediate shared secret is mixed into the running chaining key.
505 */
506 hkdf_two_keys(&h->ck, &h->temp_k, &h->ck, h->ss, sizeof(*h->ss));
507 SUPERVERBOSE("# ck,temp_k3=0x%s,0x%s",
508 tal_hexstr(tmpctx, &h->ck, sizeof(h->ck)),
509 tal_hexstr(tmpctx, &h->temp_k, sizeof(h->temp_k)));
510
511 /* BOLT #8:
512 *
513 * 5. `t = encryptWithAD(temp_k3, 0, h, zero)`
514 * * where `zero` is a zero-length plaintext
515 *
516 */
517 encrypt_ad(&h->temp_k, 0, &h->h, sizeof(h->h), NULL, 0,
518 h->act3.tag, sizeof(h->act3.tag));
519 SUPERVERBOSE("# t=0x%s",
520 tal_hexstr(tmpctx, h->act3.tag, sizeof(h->act3.tag)));
521

Callers 1

act_two_initiator2Function · 0.85

Calls 6

encrypt_adFunction · 0.85
tal_hexstrFunction · 0.85
sha_mix_inFunction · 0.85
tal_freeFunction · 0.85
hkdf_two_keysFunction · 0.70
ecdhFunction · 0.50

Tested by

no test coverage detected