MCPcopy Create free account
hub / github.com/ElementsProject/lightning / new_handshake

Function new_handshake

connectd/handshake.c:392–443  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

390}
391
392static struct handshake *new_handshake(const tal_t *ctx,
393 const struct pubkey *responder_id)
394{
395 struct handshake *handshake = tal(ctx, struct handshake);
396
397 /* BOLT #8:
398 *
399 * Before the start of Act One, both sides initialize their
400 * per-sessions state as follows:
401 *
402 * 1. `h = SHA-256(protocolName)`
403 * * where `protocolName = "Noise_XK_secp256k1_ChaChaPoly_SHA256"`
404 * encoded as an ASCII string
405 */
406 sha256(&handshake->h, "Noise_XK_secp256k1_ChaChaPoly_SHA256",
407 strlen("Noise_XK_secp256k1_ChaChaPoly_SHA256"));
408
409 /* BOLT #8:
410 *
411 * 2. `ck = h`
412 */
413 BUILD_ASSERT(sizeof(handshake->h) == sizeof(handshake->ck));
414 memcpy(&handshake->ck, &handshake->h, sizeof(handshake->ck));
415 SUPERVERBOSE("# ck=%s",
416 tal_hexstr(tmpctx, &handshake->ck, sizeof(handshake->ck)));
417
418 /* BOLT #8:
419 *
420 * 3. `h = SHA-256(h || prologue)`
421 * * where `prologue` is the ASCII string: `lightning`
422 */
423 sha_mix_in(&handshake->h, "lightning", strlen("lightning"));
424
425 /* BOLT #8:
426 *
427 * As a concluding step, both sides mix the responder's public key
428 * into the handshake digest:
429 *
430 * * The initiating node mixes in the responding node's static public
431 * key serialized in Bitcoin's compressed format:
432 * * `h = SHA-256(h || rs.pub.serializeCompressed())`
433 *
434 * * The responding node mixes in their local static public key
435 * serialized in Bitcoin's compressed format:
436 * * `h = SHA-256(h || ls.pub.serializeCompressed())`
437 */
438 sha_mix_in_key(&handshake->h, responder_id);
439 SUPERVERBOSE("# h=%s",
440 tal_hexstr(tmpctx, &handshake->h, sizeof(handshake->h)));
441
442 return handshake;
443}
444
445static struct io_plan *act_three_initiator(struct io_conn *conn,
446 struct handshake *h)

Callers 2

responder_handshake_Function · 0.85
initiator_handshake_Function · 0.85

Calls 4

tal_hexstrFunction · 0.85
sha_mix_inFunction · 0.85
sha_mix_in_keyFunction · 0.85
sha256Class · 0.70

Tested by

no test coverage detected