| 410 | } |
| 411 | |
| 412 | static struct handshake *new_handshake(const tal_t *ctx, |
| 413 | const struct pubkey *responder_id) |
| 414 | { |
| 415 | struct handshake *handshake = tal(ctx, struct handshake); |
| 416 | |
| 417 | /* BOLT #8: |
| 418 | * |
| 419 | * Before the start of Act One, both sides initialize their |
| 420 | * per-sessions state as follows: |
| 421 | * |
| 422 | * 1. `h = SHA-256(protocolName)` |
| 423 | * * where `protocolName = "Noise_XK_secp256k1_ChaChaPoly_SHA256"` |
| 424 | * encoded as an ASCII string |
| 425 | */ |
| 426 | sha256(&handshake->h, "Noise_XK_secp256k1_ChaChaPoly_SHA256", |
| 427 | strlen("Noise_XK_secp256k1_ChaChaPoly_SHA256")); |
| 428 | |
| 429 | /* BOLT #8: |
| 430 | * |
| 431 | * 2. `ck = h` |
| 432 | */ |
| 433 | CROSS_TYPE_ASSIGNMENT(&handshake->ck, &handshake->h); |
| 434 | SUPERVERBOSE("# ck=%s", |
| 435 | tal_hexstr(tmpctx, &handshake->ck, sizeof(handshake->ck))); |
| 436 | |
| 437 | /* BOLT #8: |
| 438 | * |
| 439 | * 3. `h = SHA-256(h || prologue)` |
| 440 | * * where `prologue` is the ASCII string: `lightning` |
| 441 | */ |
| 442 | sha_mix_in(&handshake->h, "lightning", strlen("lightning")); |
| 443 | |
| 444 | /* BOLT #8: |
| 445 | * |
| 446 | * As a concluding step, both sides mix the responder's public key |
| 447 | * into the handshake digest: |
| 448 | * |
| 449 | * * The initiating node mixes in the responding node's static public |
| 450 | * key serialized in Bitcoin's compressed format: |
| 451 | * * `h = SHA-256(h || rs.pub.serializeCompressed())` |
| 452 | * |
| 453 | * * The responding node mixes in their local static public key |
| 454 | * serialized in Bitcoin's compressed format: |
| 455 | * * `h = SHA-256(h || ls.pub.serializeCompressed())` |
| 456 | */ |
| 457 | sha_mix_in_key(&handshake->h, responder_id); |
| 458 | SUPERVERBOSE("# h=%s", |
| 459 | tal_hexstr(tmpctx, &handshake->h, sizeof(handshake->h))); |
| 460 | |
| 461 | return handshake; |
| 462 | } |
| 463 | |
| 464 | static struct io_plan *act_three_initiator(struct io_conn *conn, |
| 465 | struct handshake *h) |
no test coverage detected