| 353 | handshake_failed_((conn), (h), __func__, __LINE__) |
| 354 | |
| 355 | static struct io_plan *handshake_succeeded(struct io_conn *conn, |
| 356 | struct handshake *h) |
| 357 | { |
| 358 | struct crypto_state cs; |
| 359 | struct io_plan *(*cb)(struct io_conn *conn, |
| 360 | const struct pubkey *their_id, |
| 361 | const struct wireaddr_internal *addr, |
| 362 | struct crypto_state *cs, |
| 363 | struct oneshot *timeout, |
| 364 | enum is_websocket is_websocket, |
| 365 | struct timemono starttime, |
| 366 | void *cbarg); |
| 367 | void *cbarg; |
| 368 | struct pubkey their_id; |
| 369 | struct wireaddr_internal addr; |
| 370 | struct oneshot *timeout; |
| 371 | enum is_websocket is_websocket; |
| 372 | struct timemono starttime; |
| 373 | |
| 374 | /* BOLT #8: |
| 375 | * |
| 376 | * 9. `rk, sk = HKDF(ck, zero)` |
| 377 | * * where `zero` is a zero-length plaintext, `rk` is the key to |
| 378 | * be used by the responder to decrypt the messages sent by the |
| 379 | * initiator, and `sk` is the key to be used by the responder |
| 380 | * to encrypt messages to the initiator |
| 381 | * |
| 382 | * * The final encryption keys, to be used for sending and |
| 383 | * receiving messages for the duration of the session, are |
| 384 | * generated. |
| 385 | */ |
| 386 | if (h->side == RESPONDER) |
| 387 | hkdf_two_keys(&cs.rk, &cs.sk, &h->ck, NULL, 0); |
| 388 | else |
| 389 | hkdf_two_keys(&cs.sk, &cs.rk, &h->ck, NULL, 0); |
| 390 | |
| 391 | cs.rn = cs.sn = 0; |
| 392 | /* BOLT #8: |
| 393 | * |
| 394 | * 11. `rck = sck = ck` |
| 395 | * * The sending and receiving chaining keys are initialized the same. |
| 396 | */ |
| 397 | |
| 398 | cs.r_ck = cs.s_ck = h->ck; |
| 399 | |
| 400 | cb = h->cb; |
| 401 | cbarg = h->cbarg; |
| 402 | their_id = h->their_id; |
| 403 | addr = h->addr; |
| 404 | timeout = h->timeout; |
| 405 | is_websocket = h->is_websocket; |
| 406 | starttime = h->starttime; |
| 407 | |
| 408 | tal_free(h); |
| 409 | return cb(conn, &their_id, &addr, &cs, timeout, is_websocket, starttime, cbarg); |
| 410 | } |
| 411 | |
| 412 | static struct handshake *new_handshake(const tal_t *ctx, |
no test coverage detected