| 511 | } |
| 512 | |
| 513 | static struct io_plan *act_two_initiator2(struct io_conn *conn, |
| 514 | struct handshake *h) |
| 515 | { |
| 516 | SUPERVERBOSE("input: 0x%s", tal_hexstr(tmpctx, &h->act2, ACT_TWO_SIZE)); |
| 517 | |
| 518 | /* BOLT #8: |
| 519 | * |
| 520 | * 3. If `v` is an unrecognized handshake version, then the responder |
| 521 | * MUST abort the connection attempt. |
| 522 | */ |
| 523 | if (h->act2.v != 0) |
| 524 | return handshake_failed(conn, h); |
| 525 | |
| 526 | /* BOLT #8: |
| 527 | * |
| 528 | * * The raw bytes of the remote party's ephemeral public key |
| 529 | * (`re`) are to be deserialized into a point on the curve using |
| 530 | * affine coordinates as encoded by the key's serialized |
| 531 | * composed format. |
| 532 | */ |
| 533 | if (secp256k1_ec_pubkey_parse(secp256k1_ctx, &h->re.pubkey, |
| 534 | h->act2.pubkey, sizeof(h->act2.pubkey)) != 1) |
| 535 | return handshake_failed(conn, h); |
| 536 | |
| 537 | SUPERVERBOSE("# re=0x%s", type_to_string(tmpctx, struct pubkey, &h->re)); |
| 538 | |
| 539 | /* BOLT #8: |
| 540 | * |
| 541 | * 4. `h = SHA-256(h || re.serializeCompressed())` |
| 542 | */ |
| 543 | sha_mix_in_key(&h->h, &h->re); |
| 544 | SUPERVERBOSE("# h=0x%s", tal_hexstr(tmpctx, &h->h, sizeof(h->h))); |
| 545 | |
| 546 | /* BOLT #8: |
| 547 | * |
| 548 | * 5. `es = ECDH(s.priv, re)` |
| 549 | */ |
| 550 | if (!secp256k1_ecdh(secp256k1_ctx, h->ss->data, &h->re.pubkey, |
| 551 | h->e.priv.secret.data, NULL, NULL)) |
| 552 | return handshake_failed(conn, h); |
| 553 | |
| 554 | SUPERVERBOSE("# ss=0x%s", tal_hexstr(tmpctx, h->ss, sizeof(*h->ss))); |
| 555 | |
| 556 | /* BOLT #8: |
| 557 | * |
| 558 | * 6. `ck, temp_k2 = HKDF(ck, ee)` |
| 559 | * * A new temporary encryption key is generated, which is |
| 560 | * used to generate the authenticating MAC. |
| 561 | */ |
| 562 | hkdf_two_keys(&h->ck, &h->temp_k, &h->ck, h->ss, sizeof(*h->ss)); |
| 563 | SUPERVERBOSE("# ck,temp_k2=0x%s,0x%s", |
| 564 | tal_hexstr(tmpctx, &h->ck, sizeof(h->ck)), |
| 565 | tal_hexstr(tmpctx, &h->temp_k, sizeof(h->temp_k))); |
| 566 | |
| 567 | /* BOLT #8: |
| 568 | * |
| 569 | * 7. `p = decryptWithAD(temp_k2, 0, h, c)` |
| 570 | * * If the MAC check in this operation fails, then the initiator |
nothing calls this directly
no test coverage detected