| 689 | } |
| 690 | |
| 691 | static struct io_plan *act_three_responder2(struct io_conn *conn, |
| 692 | struct handshake *h) |
| 693 | { |
| 694 | u8 der[PUBKEY_CMPR_LEN]; |
| 695 | |
| 696 | SUPERVERBOSE("input: 0x%s", tal_hexstr(tmpctx, &h->act3, ACT_THREE_SIZE)); |
| 697 | |
| 698 | /* BOLT #8: |
| 699 | * |
| 700 | * 2. Parse the read message (`m`) into `v`, `c`, and `t`: |
| 701 | * * where `v` is the _first_ byte of `m`, `c` is the next 49 |
| 702 | * bytes of `m`, and `t` is the last 16 bytes of `m` |
| 703 | */ |
| 704 | |
| 705 | /* BOLT #8: |
| 706 | * |
| 707 | * 3. If `v` is an unrecognized handshake version, then the responder |
| 708 | * MUST abort the connection attempt. |
| 709 | */ |
| 710 | if (h->act3.v != 0) |
| 711 | return handshake_failed(conn, h); |
| 712 | |
| 713 | /* BOLT #8: |
| 714 | * |
| 715 | * 4. `rs = decryptWithAD(temp_k2, 1, h, c)` |
| 716 | * * At this point, the responder has recovered the static public |
| 717 | * key of the initiator. |
| 718 | */ |
| 719 | if (!decrypt(&h->temp_k, 1, &h->h, sizeof(h->h), |
| 720 | h->act3.ciphertext, sizeof(h->act3.ciphertext), |
| 721 | der, sizeof(der))) |
| 722 | return handshake_failed(conn, h); |
| 723 | |
| 724 | SUPERVERBOSE("# rs=0x%s", tal_hexstr(tmpctx, der, sizeof(der))); |
| 725 | |
| 726 | if (secp256k1_ec_pubkey_parse(secp256k1_ctx, &h->their_id.pubkey, |
| 727 | der, sizeof(der)) != 1) |
| 728 | return handshake_failed(conn, h); |
| 729 | |
| 730 | /* BOLT #8: |
| 731 | * |
| 732 | * 5. `h = SHA-256(h || c)` |
| 733 | * |
| 734 | */ |
| 735 | sha_mix_in(&h->h, h->act3.ciphertext, sizeof(h->act3.ciphertext)); |
| 736 | SUPERVERBOSE("# h=0x%s", tal_hexstr(tmpctx, &h->h, sizeof(h->h))); |
| 737 | |
| 738 | /* BOLT #8: |
| 739 | * |
| 740 | * 6. `se = ECDH(e.priv, rs)` |
| 741 | * * where `e` is the responder's original ephemeral key |
| 742 | */ |
| 743 | if (!secp256k1_ecdh(secp256k1_ctx, h->ss->data, &h->their_id.pubkey, |
| 744 | h->e.priv.secret.data, NULL, NULL)) |
| 745 | return handshake_failed(conn, h); |
| 746 | |
| 747 | SUPERVERBOSE("# ss=0x%s", tal_hexstr(tmpctx, h->ss, sizeof(*h->ss))); |
| 748 |
nothing calls this directly
no test coverage detected