| 443 | } |
| 444 | |
| 445 | static struct io_plan *act_three_initiator(struct io_conn *conn, |
| 446 | struct handshake *h) |
| 447 | { |
| 448 | u8 spub[PUBKEY_CMPR_LEN]; |
| 449 | size_t len = sizeof(spub); |
| 450 | |
| 451 | SUPERVERBOSE("Initiator: Act 3"); |
| 452 | |
| 453 | /* BOLT #8: |
| 454 | * 1. `c = encryptWithAD(temp_k2, 1, h, s.pub.serializeCompressed())` |
| 455 | * * where `s` is the static public key of the initiator |
| 456 | */ |
| 457 | secp256k1_ec_pubkey_serialize(secp256k1_ctx, spub, &len, |
| 458 | &h->my_id.pubkey, |
| 459 | SECP256K1_EC_COMPRESSED); |
| 460 | encrypt_ad(&h->temp_k, 1, &h->h, sizeof(h->h), spub, sizeof(spub), |
| 461 | h->act3.ciphertext, sizeof(h->act3.ciphertext)); |
| 462 | SUPERVERBOSE("# c=0x%s", |
| 463 | tal_hexstr(tmpctx, |
| 464 | h->act3.ciphertext, sizeof(h->act3.ciphertext))); |
| 465 | |
| 466 | /* BOLT #8: |
| 467 | * 2. `h = SHA-256(h || c)` |
| 468 | */ |
| 469 | sha_mix_in(&h->h, h->act3.ciphertext, sizeof(h->act3.ciphertext)); |
| 470 | SUPERVERBOSE("# h=0x%s", tal_hexstr(tmpctx, &h->h, sizeof(h->h))); |
| 471 | |
| 472 | /* BOLT #8: |
| 473 | * |
| 474 | * 3. `se = ECDH(s.priv, re)` |
| 475 | * * where `re` is the ephemeral public key of the responder |
| 476 | */ |
| 477 | h->ss = tal(h, struct secret); |
| 478 | ecdh(&h->re, h->ss); |
| 479 | SUPERVERBOSE("# ss=0x%s", tal_hexstr(tmpctx, h->ss, sizeof(*h->ss))); |
| 480 | |
| 481 | /* BOLT #8: |
| 482 | * |
| 483 | * 4. `ck, temp_k3 = HKDF(ck, se)` |
| 484 | * * The final intermediate shared secret is mixed into the running chaining key. |
| 485 | */ |
| 486 | hkdf_two_keys(&h->ck, &h->temp_k, &h->ck, h->ss, sizeof(*h->ss)); |
| 487 | SUPERVERBOSE("# ck,temp_k3=0x%s,0x%s", |
| 488 | tal_hexstr(tmpctx, &h->ck, sizeof(h->ck)), |
| 489 | tal_hexstr(tmpctx, &h->temp_k, sizeof(h->temp_k))); |
| 490 | |
| 491 | /* BOLT #8: |
| 492 | * |
| 493 | * 5. `t = encryptWithAD(temp_k3, 0, h, zero)` |
| 494 | * * where `zero` is a zero-length plaintext |
| 495 | * |
| 496 | */ |
| 497 | encrypt_ad(&h->temp_k, 0, &h->h, sizeof(h->h), NULL, 0, |
| 498 | h->act3.tag, sizeof(h->act3.tag)); |
| 499 | SUPERVERBOSE("# t=0x%s", |
| 500 | tal_hexstr(tmpctx, h->act3.tag, sizeof(h->act3.tag))); |
| 501 | |
| 502 | /* BOLT #8: |
no test coverage detected