@@ -8,6 +8,29 @@ used within the protocol to establish an encrypted and authenticated connection
8
8
with peers, and also to authenticate any information advertised on behalf
9
9
of a node.
10
10
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
+
11
34
## Cryptographic Messaging Overview
12
35
13
36
Prior 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:
27
50
28
51
### Authenticated Key Agreement Handshake
29
52
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
32
55
the responder. This provides a degree of identity hiding for the
33
56
responder, as its public key is _ never_ transmitted during the handshake. Instead,
34
57
authentication is achieved implicitly via a series of Elliptic-Curve
35
58
Diffie-Hellman (ECDH) operations followed by a MAC check.
36
59
37
60
The 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
39
62
material is sent to the other party; an ECDH is performed based on exactly
40
63
which act is being executed, with the result mixed into the current set of
41
64
encryption 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
44
66
a hash digest forms an incremental TripleDH handshake.
45
67
46
68
Using 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:
120
142
* ` e ` : A party's ** ephemeral keypair** . For each session a node MUST generate a
121
143
new ephemeral key with strong cryptographic randomness.
122
144
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)
124
146
125
147
The following functions will also be referenced:
126
148
@@ -223,7 +245,7 @@ and 16 bytes for the `poly1305` tag.
223
245
** Receiver Actions:**
224
246
225
247
* 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:] ` .
227
249
* where ` m[0] ` is the _ first_ byte of ` m ` , ` m[1:33] ` is the next 33
228
250
bytes of ` m ` , and ` m[34:] ` is the last 16 bytes of ` m `
229
251
* The raw bytes of the remote party's ephemeral public key (` e ` ) are to be
@@ -285,7 +307,7 @@ for the `poly1305` tag.
285
307
286
308
** Receiver Actions:**
287
309
288
- * Read _ exactly_ 50- bytes from the network buffer.
310
+ * Read _ exactly_ 50 bytes from the network buffer.
289
311
* Parse out the read message (` m ` ) into ` v = m[0] ` , ` re = m[1:33] ` , and ` c = m[34:] ` .
290
312
* where ` m[0] ` is the _ first_ byte of ` m ` , ` m[1:33] ` is the next 33
291
313
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.
351
373
352
374
** Receiver Actions:**
353
375
354
- * Read _ exactly_ 66- bytes from the network buffer.
376
+ * Read _ exactly_ 66 bytes from the network buffer.
355
377
* Parse out the read message (` m ` ) into ` v = m[0] ` , ` c = m[1:49] ` and ` t = m[50:] `
356
378
* If ` v ` is an unrecognized handshake version, then the responder MUST
357
379
abort the connection attempt.
@@ -372,7 +394,7 @@ construction, and 16 bytes for a final authenticating tag.
372
394
and ` sk ` is the key to be used by the responder to encrypt messages to
373
395
the initiator
374
396
* 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.
376
398
* ` rn = 0, sn = 0 `
377
399
* The sending and receiving nonces are initialized to zero.
378
400
@@ -424,7 +446,7 @@ In order to encrypt a Lightning message (`m`), given a sending key (`sk`) and a
424
446
* let ` l = len(m) `
425
447
* where ` len ` obtains the length in bytes of the Lightning message
426
448
* 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 `
428
450
(18 bytes)
429
451
* The nonce ` sn ` is encoded as a 96-bit little-endian number. As the
430
452
decoded nonce is 64 bits, the 96-bit nonce is encoded as: 32 bits
@@ -444,21 +466,21 @@ done:
444
466
445
467
* Read _ exactly_ 18 bytes from the network buffer.
446
468
* 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
448
470
the encrypted packet ` l ` .
449
471
* A zero-length byte slice is to be passed as the AD (associated data).
450
472
* The nonce ` rn ` MUST be incremented after this step.
451
473
* Read _ exactly_ ` l+16 ` bytes from the network buffer, let the bytes be known as
452
474
` 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
454
476
plaintext packet ` p ` .
455
477
* The nonce ` rn ` MUST be incremented after this step.
456
478
457
479
458
480
## Lightning Message Key Rotation
459
481
460
482
Changing 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.
462
484
backwards secrecy).
463
485
464
486
Key rotation is performed for _ each_ key (` sk ` and ` rk ` ) _ individually_ . A key
0 commit comments