@@ -8,6 +8,29 @@ used within the protocol to establish an encrypted and authenticated connection
88with peers, and also to authenticate any information advertised on behalf
99of a node.
1010
11+ # Table of Contents
12+
13+ * [ Cryptographic Messaging Overview] ( #cryptographic-messaging-overview )
14+ * [ Authenticated Key Agreement Handshake] ( #authenticated-key-agreement-handshake )
15+ * [ Handshake Versioning] ( #handshake-versioning )
16+ * [ Noise Protocol Instantiation] ( #noise-protocol-instantiation )
17+ * [ Authenticated Key Exchange Handshake Specification] ( #authenticated-key-exchange-handshake-specification )
18+ * [ Handshake State] ( #handshake-state )
19+ * [ Handshake State Initialization] ( #handshake-state-initialization )
20+ * [ Handshake Exchange] ( #handshake-exchange )
21+ * [ Lightning Message Specification] ( #lightning-message-specification )
22+ * [ Encrypting Messages] ( #encrypting-messages )
23+ * [ Decrypting Messages] ( #decrypting-messages )
24+ * [ Lightning Message Key Rotation] ( #lightning-message-key-rotation )
25+ * [ Security Considerations] ( #security-considerations )
26+ * [ Appendix A: Transport Test Vectors] ( #appendix-a-transport-test-vectors )
27+ * [ Initiator Tests] ( #initiator-tests )
28+ * [ Responder Tests] ( #responder-tests )
29+ * [ Message Encryption Tests] ( #message-encryption-tests )
30+ * [ Acknowledgments] ( #acknowledgments )
31+ * [ References] ( #references )
32+ * [ Authors] ( #authors )
33+
1134## Cryptographic Messaging Overview
1235
1336Prior to sending any Lightning messages, nodes must first initiate the
@@ -27,20 +50,19 @@ The transcript between two nodes is separated into two distinct segments:
2750
2851### Authenticated Key Agreement Handshake
2952
30- The handshake chosen for the authenticated key exchange is ` Noise_XK ` . Prior
31- to the handshake , the initiator must know the identity public key of
53+ The handshake chosen for the authenticated key exchange is ` Noise_XK ` . As a
54+ pre-message , the initiator must know the identity public key of
3255the responder. This provides a degree of identity hiding for the
3356responder, as its public key is _ never_ transmitted during the handshake. Instead,
3457authentication is achieved implicitly via a series of Elliptic-Curve
3558Diffie-Hellman (ECDH) operations followed by a MAC check.
3659
3760The authenticated key agreement (` Noise_XK ` ) is performed in three distinct
38- steps. During each "act" of the handshake: some (possibly encrypted) keying
61+ steps. During each "act" of the handshake the following occurs : some (possibly encrypted) keying
3962material is sent to the other party; an ECDH is performed based on exactly
4063which act is being executed, with the result mixed into the current set of
4164encryption keys (` ck ` the chaining key and ` k ` the encryption key); and
42- an AEAD payload with a zero-length cipher text is sent. As this payload is
43- length zero, only a MAC is sent across. The mixing of ECDH outputs into
65+ an AEAD payload with a zero-length cipher text is sent. As this payload has no length, only a MAC is sent across. The mixing of ECDH outputs into
4466a hash digest forms an incremental TripleDH handshake.
4567
4668Using the language of the Noise Protocol, ` e ` and ` s ` (both public keys)
@@ -120,7 +142,7 @@ Throughout the handshake process, each side maintains these variables:
120142 * ` e ` : A party's ** ephemeral keypair** . For each session a node MUST generate a
121143 new ephemeral key with strong cryptographic randomness.
122144
123- * ` s ` : A party's ** static public key** (` ls ` for local, ` rs ` for remote).
145+ * ` s ` : A party's ** static public key** (` ls ` for local, ` rs ` for remote)
124146
125147The following functions will also be referenced:
126148
@@ -223,7 +245,7 @@ and 16 bytes for the `poly1305` tag.
223245** Receiver Actions:**
224246
225247 * Read _ exactly_ 50 bytes from the network buffer.
226- * Parse out the read message (` m ` ) into ` v = m[0] ` , ` re = m[1:33] ` and ` c = m[34:] ` .
248+ * Parse out the read message (` m ` ) into ` v = m[0] ` , ` re = m[1:33] ` , and ` c = m[34:] ` .
227249 * where ` m[0] ` is the _ first_ byte of ` m ` , ` m[1:33] ` is the next 33
228250 bytes of ` m ` , and ` m[34:] ` is the last 16 bytes of ` m `
229251 * The raw bytes of the remote party's ephemeral public key (` e ` ) are to be
@@ -285,7 +307,7 @@ for the `poly1305` tag.
285307
286308** Receiver Actions:**
287309
288- * Read _ exactly_ 50- bytes from the network buffer.
310+ * Read _ exactly_ 50 bytes from the network buffer.
289311 * Parse out the read message (` m ` ) into ` v = m[0] ` , ` re = m[1:33] ` , and ` c = m[34:] ` .
290312 * where ` m[0] ` is the _ first_ byte of ` m ` , ` m[1:33] ` is the next 33
291313 bytes of ` m ` , and ` m[34:] ` is the last 16 bytes of ` m `
@@ -351,7 +373,7 @@ construction, and 16 bytes for a final authenticating tag.
351373
352374** Receiver Actions:**
353375
354- * Read _ exactly_ 66- bytes from the network buffer.
376+ * Read _ exactly_ 66 bytes from the network buffer.
355377 * Parse out the read message (` m ` ) into ` v = m[0] ` , ` c = m[1:49] ` and ` t = m[50:] `
356378 * If ` v ` is an unrecognized handshake version, then the responder MUST
357379 abort the connection attempt.
@@ -372,7 +394,7 @@ construction, and 16 bytes for a final authenticating tag.
372394 and ` sk ` is the key to be used by the responder to encrypt messages to
373395 the initiator
374396 * The final encryption keys to be used for sending and
375- receiving messages for the duration of the session are generated
397+ receiving messages for the duration of the session are generated.
376398 * ` rn = 0, sn = 0 `
377399 * The sending and receiving nonces are initialized to zero.
378400
@@ -424,7 +446,7 @@ In order to encrypt a Lightning message (`m`), given a sending key (`sk`) and a
424446 * let ` l = len(m) `
425447 * where ` len ` obtains the length in bytes of the Lightning message
426448 * Serialize ` l ` into 2 bytes encoded as a big-endian integer.
427- * Encrypt ` l ` using ` ChaChaPoly-1305 ` , ` sn ` , and ` sk ` , to obtain ` lc `
449+ * Encrypt ` l ` ( using ` ChaChaPoly-1305 ` , ` sn ` , and ` sk ` ) , to obtain ` lc `
428450 (18 bytes)
429451 * The nonce ` sn ` is encoded as a 96-bit little-endian number. As the
430452 decoded nonce is 64 bits, the 96-bit nonce is encoded as: 32 bits
@@ -444,21 +466,21 @@ done:
444466
445467 * Read _ exactly_ 18 bytes from the network buffer.
446468 * Let the encrypted length prefix be known as ` lc `
447- * Decrypt ` lc ` using ` ChaCha20-Poly1305 ` , ` rn ` , and ` rk ` , to obtain the size of
469+ * Decrypt ` lc ` ( using ` ChaCha20-Poly1305 ` , ` rn ` , and ` rk ` ) , to obtain the size of
448470 the encrypted packet ` l ` .
449471 * A zero-length byte slice is to be passed as the AD (associated data).
450472 * The nonce ` rn ` MUST be incremented after this step.
451473 * Read _ exactly_ ` l+16 ` bytes from the network buffer, let the bytes be known as
452474 ` c ` .
453- * Decrypt ` c ` using ` ChaCha20-Poly1305 ` , ` rn ` , and ` rk ` , to obtain decrypted
475+ * Decrypt ` c ` ( using ` ChaCha20-Poly1305 ` , ` rn ` , and ` rk ` ) , to obtain decrypted
454476 plaintext packet ` p ` .
455477 * The nonce ` rn ` MUST be incremented after this step.
456478
457479
458480## Lightning Message Key Rotation
459481
460482Changing keys regularly and forgetting previous keys is useful to
461- prevent the decryption of old messages in the case of later key leakage (i.e.
483+ prevent the decryption of old messages, in the case of later key leakage (i.e.
462484backwards secrecy).
463485
464486Key rotation is performed for _ each_ key (` sk ` and ` rk ` ) _ individually_ . A key
0 commit comments