mirror of
https://github.com/lnbook/lnbook
synced 2024-11-04 18:00:26 +00:00
routing: simplify ECDH mentions
I think it's better to formally define ECDH in an earlier section in order to do justice to the concept. We may be able to lift some text from Mastering Bitcoin, as IIRC it covers stealth addresses in brief.
This commit is contained in:
parent
b89c7cfa8b
commit
639c22e59d
@ -459,31 +459,22 @@ If this wasn't the case, and the onion packet shrank as it was being processed,
|
||||
Since David is the final recipient of the payment, we only have 65 bytes worth of data to fill with actual content.
|
||||
The remaining bytes are filled with random bytes to pad out the packet in an unpredictable manner.
|
||||
|
||||
After Alice has set all the data she needs to encrypt the onion payload.
|
||||
For this she derives a shared secret between Davids public node key and the private secret that she generated for David.
|
||||
This process is also well known as an Elliptic Curve Diffie Hellmann key exchange and a standard technique in cryptography and Bitcoin.
|
||||
Taking a step back, before Alice is able to prepare the remainder of the packet, we needs to generate an ephemeral key (a key only used once).
|
||||
This ephemeral key is then used to generate a series of additional keys, which are themselves used for encryption, authentication, and also as input to a CSPRNG to deterministically generate the set of random filler bytes.
|
||||
In the spirit of onion encryption, Alice will begin encrypting the payload from the last hop, adding a new layer of encryption with each new hop.
|
||||
During processing, each node will authenticate the contents of the payload, then process the packet (decryption it and shifting around some bytes) to prepare it for processing by the next node in the route.
|
||||
As we want each node to use a new shared secret to authenticate and encrypt its portion of the packet, the Sphinx onion packet format uses a _re-randomization_ scheme to allow Alice to generate a single ephemeral Diffie-Hellman key for the entire route.
|
||||
Rather than occupying space in the routing payload for N public keys, with this little trick, we're able to only include a single public key, which is used for ECDH at each step, and randomized in a deterministic manner for the next hop.
|
||||
|
||||
[[routing-onion-3]]
|
||||
.`per_hop` payload of Glorias onion and the encrypted
|
||||
image:images/routing-onion-3.png[]
|
||||
|
||||
You can see that Alice put the encrypted payload inside the full Onion Package which contains a the public keys from the secret key that she used to derive the shared secret.
|
||||
Full onion package also has a version byte in the beginning and an HMAC for the entire Onion.
|
||||
When David receives the Onion package he will extract the public key from the unencrypted part of the onion package.
|
||||
The property of the Elliptic Curve Diffie Hellmann key exchange is that if he multiplies this public key with his private node key he will get the same shared secret as a result as Alice did.
|
||||
However others cannot derive the same shared secret as they neither know Alice's nor David's private key.
|
||||
|
||||
[NOTE]
|
||||
====
|
||||
Let `(d,D)` be the secret and Public key of David and let G be the generator point of the elliptic curve so that `D = d*G`.
|
||||
Similarly let `(ek_d, EPK_D)` the ephemeral keys that Alice has generated for David such that the Public ephemeral Key `EPK_D = ek_d*G`.
|
||||
Alice computed the shared secret as ss_`d = ek_d*D`.
|
||||
Using the definition of public keys this is the same as `ek_d*(d*G)=(ek_d*d)*G`.
|
||||
Since multiplication with the generator point is a group homomorphism we can apply the law of associativity.
|
||||
And because the secrets are just numbers modulo some prime we can change the order of the multiplication resulting in `ss_d = (d*ek_d)*G`.
|
||||
With the same argument as before we apply the law of associativity and apply the definition of public keys resulting in `(d*ek_d)*G = d*(ek_d*G) = d*EPK_D`.
|
||||
We just saw why `ek_d*D = d*EPK_D = ss_d` and why Alice and Davide will be able to derive the same shared secret if Alice puts the ephemeral public key inside the onion.
|
||||
====
|
||||
You can see that Alice put the encrypted payload inside the full Onion Package which contains the public keys from the secret key that she used to derive the shared secret.
|
||||
The full onion packet also has a version byte in the beginning (for future extensibility) and an HMAC for the entire Onion.
|
||||
When David receives the Onion packet he will extract the public key from the unencrypted part of the onion package.
|
||||
David then uses ECDH to derive the shared secret using that ephemeral public key which he'll use to process the packet in full.
|
||||
The properties of ECDH make is such that only Alice and David are able to derive the corresponding shared secret.
|
||||
|
||||
After the encrypted Onion for David is created Alice will create the next outer layer by creating the onion for Wei.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user