1414#endif
1515
1616/* Blinds node_id and calculates next blinding factor. */
17- static bool blind_node (const struct privkey * blinding ,
17+ static bool blind_node (const struct privkey * path_privkey ,
1818 const struct secret * ss ,
1919 const struct pubkey * node ,
2020 struct pubkey * node_alias ,
21- struct privkey * next_blinding )
21+ struct privkey * next_path_privkey )
2222{
23- struct pubkey blinding_pubkey ;
23+ struct pubkey path_pubkey ;
2424 struct sha256 h ;
2525
2626 if (!blindedpath_get_alias (ss , node , node_alias ))
@@ -30,32 +30,32 @@ static bool blind_node(const struct privkey *blinding,
3030
3131 /* BOLT #4:
3232 * - $`E_{i+1} = SHA256(E_i || ss_i) * E_i`$
33- * (NB: $`N_i`$ MUST NOT learn $`e_i`$)
33+ * (`path_key`. NB: $`N_i`$ MUST NOT learn $`e_i`$)
3434 */
35- if (!pubkey_from_privkey (blinding , & blinding_pubkey ))
35+ if (!pubkey_from_privkey (path_privkey , & path_pubkey ))
3636 return false;
3737 SUPERVERBOSE ("\t\"E\": \"%s\",\n" ,
38- fmt_pubkey (tmpctx , & blinding_pubkey ));
38+ fmt_pubkey (tmpctx , & path_pubkey ));
3939
4040 /* BOLT #4:
4141 * - $`e_{i+1} = SHA256(E_i || ss_i) * e_i`$
42- * (blinding ephemeral private key, only known by $`N_r`$)
42+ * (ephemeral private path key, only known by $`N_r`$)
4343 */
44- blinding_hash_e_and_ss (& blinding_pubkey , ss , & h );
44+ blinding_hash_e_and_ss (& path_pubkey , ss , & h );
4545 SUPERVERBOSE ("\t\"H(E || ss)\": \"%s\",\n" ,
4646 fmt_sha256 (tmpctx , & h ));
47- blinding_next_privkey ( blinding , & h , next_blinding );
47+ blinding_next_path_privkey ( path_privkey , & h , next_path_privkey );
4848 SUPERVERBOSE ("\t\"next_e\": \"%s\",\n" ,
49- fmt_privkey (tmpctx , next_blinding ));
49+ fmt_privkey (tmpctx , next_path_privkey ));
5050
5151 return true;
5252}
5353
5454static u8 * enctlv_from_encmsg_raw (const tal_t * ctx ,
55- const struct privkey * blinding ,
55+ const struct privkey * path_privkey ,
5656 const struct pubkey * node ,
5757 const u8 * raw_encmsg TAKES ,
58- struct privkey * next_blinding ,
58+ struct privkey * next_path_privkey ,
5959 struct pubkey * node_alias )
6060{
6161 struct secret ss , rho ;
@@ -65,33 +65,33 @@ static u8 *enctlv_from_encmsg_raw(const tal_t *ctx,
6565 static const unsigned char npub [crypto_aead_chacha20poly1305_ietf_NPUBBYTES ];
6666
6767 /* BOLT #4:
68- * - $`ss_i = SHA256(e_i * N_i) = SHA256(k_i * E_i)$`
68+ * - $`ss_i = SHA256(e_i * N_i) = SHA256(k_i * E_i)`$
6969 * (ECDH shared secret known only by $`N_r`$ and $`N_i`$)
7070 */
7171 if (secp256k1_ecdh (secp256k1_ctx , ss .data ,
72- & node -> pubkey , blinding -> secret .data ,
72+ & node -> pubkey , path_privkey -> secret .data ,
7373 NULL , NULL ) != 1 )
7474 return NULL ;
7575 SUPERVERBOSE ("\t\"ss\": \"%s\",\n" ,
7676 fmt_secret (tmpctx , & ss ));
7777
78- /* This calculates the node's alias, and next blinding */
79- if (!blind_node (blinding , & ss , node , node_alias , next_blinding ))
78+ /* This calculates the node's alias, and next path_key */
79+ if (!blind_node (path_privkey , & ss , node , node_alias , next_path_privkey ))
8080 return NULL ;
8181
8282 ret = tal_dup_talarr (ctx , u8 , raw_encmsg );
8383
8484 /* BOLT #4:
8585 * - $`rho_i = HMAC256(\text{"rho"}, ss_i)`$
86- * (key used to encrypt the payload for $`N_i`$ by $`N_r`$)
86+ * (key used to encrypt `encrypted_recipient_data` for $`N_i`$ by $`N_r`$)
8787 */
8888 subkey_from_hmac ("rho" , & ss , & rho );
8989 SUPERVERBOSE ("\t\"rho\": \"%s\",\n" ,
9090 fmt_secret (tmpctx , & rho ));
9191
9292 /* BOLT #4:
9393 * - MUST encrypt each `encrypted_data_tlv[i]` with ChaCha20-Poly1305 using
94- * the corresponding `rho_i` key and an all-zero nonce to produce
94+ * the corresponding $ `rho_i`$ key and an all-zero nonce to produce
9595 * `encrypted_recipient_data[i]`
9696 */
9797 /* Encrypt in place */
@@ -109,24 +109,24 @@ static u8 *enctlv_from_encmsg_raw(const tal_t *ctx,
109109}
110110
111111u8 * encrypt_tlv_encrypted_data (const tal_t * ctx ,
112- const struct privkey * blinding ,
112+ const struct privkey * path_privkey ,
113113 const struct pubkey * node ,
114- const struct tlv_encrypted_data_tlv * encmsg ,
115- struct privkey * next_blinding ,
114+ const struct tlv_encrypted_data_tlv * tlv ,
115+ struct privkey * next_path_privkey ,
116116 struct pubkey * node_alias )
117117{
118118 struct privkey unused ;
119- u8 * encmsg_raw = tal_arr (NULL , u8 , 0 );
120- towire_tlv_encrypted_data_tlv (& encmsg_raw , encmsg );
119+ u8 * tlv_wire = tal_arr (NULL , u8 , 0 );
120+ towire_tlv_encrypted_data_tlv (& tlv_wire , tlv );
121121
122- /* last hop doesn't care about next_blinding */
123- if (!next_blinding )
124- next_blinding = & unused ;
125- return enctlv_from_encmsg_raw (ctx , blinding , node , take (encmsg_raw ),
126- next_blinding , node_alias );
122+ /* last hop doesn't care about next path_key */
123+ if (!next_path_privkey )
124+ next_path_privkey = & unused ;
125+ return enctlv_from_encmsg_raw (ctx , path_privkey , node , take (tlv_wire ),
126+ next_path_privkey , node_alias );
127127}
128128
129- bool unblind_onion (const struct pubkey * blinding ,
129+ bool unblind_onion (const struct pubkey * path_key ,
130130 void (* ecdh )(const struct pubkey * point , struct secret * ss ),
131131 struct pubkey * onion_key ,
132132 struct secret * ss )
@@ -140,7 +140,7 @@ bool unblind_onion(const struct pubkey *blinding,
140140 * - $`ss_i = SHA256(k_i * E_i)`$ (standard ECDH)
141141 * - $`b_i = HMAC256(\text{"blinded\_node\_id"}, ss_i) * k_i`$
142142 */
143- ecdh (blinding , ss );
143+ ecdh (path_key , ss );
144144 subkey_from_hmac ("blinded_node_id" , ss , & hmac );
145145
146146 /* We instead tweak the *ephemeral* key from the onion and use
@@ -149,15 +149,14 @@ bool unblind_onion(const struct pubkey *blinding,
149149 /* BOLT #4:
150150 * - MUST use $`b_i`$ instead of its private key $`k_i`$ to decrypt the onion. Note
151151 * that the node may instead tweak the onion ephemeral key with
152- * $`HMAC256(\text{"blinded\_node\_id}" , ss_i)`$ which achieves the same result.
152+ * $`HMAC256(\text{"blinded\_node\_id"} , ss_i)`$ which achieves the same result.
153153 */
154154 return secp256k1_ec_pubkey_tweak_mul (secp256k1_ctx ,
155155 & onion_key -> pubkey ,
156156 hmac .data ) == 1 ;
157157}
158158
159159u8 * decrypt_encmsg_raw (const tal_t * ctx ,
160- const struct pubkey * blinding ,
161160 const struct secret * ss ,
162161 const u8 * enctlv )
163162{
@@ -197,17 +196,16 @@ u8 *decrypt_encmsg_raw(const tal_t *ctx,
197196}
198197
199198struct tlv_encrypted_data_tlv * decrypt_encrypted_data (const tal_t * ctx ,
200- const struct pubkey * blinding ,
201199 const struct secret * ss ,
202200 const u8 * enctlv )
203201{
204- const u8 * cursor = decrypt_encmsg_raw (tmpctx , blinding , ss , enctlv );
202+ const u8 * cursor = decrypt_encmsg_raw (tmpctx , ss , enctlv );
205203 size_t maxlen = tal_bytelen (cursor );
206204
207205 /* BOLT #4:
208206 *
209207 * - MUST return an error if `encrypted_recipient_data` does not decrypt
210- * using the blinding point as described in
208+ * using the `path_key` as described in
211209 * [Route Blinding](#route-blinding).
212210 */
213211 /* Note: our parser consider nothing is a valid TLV, but decrypt_encmsg_raw
@@ -237,27 +235,27 @@ bool blindedpath_get_alias(const struct secret *ss,
237235 node_id_blinding .data ) == 1 ;
238236}
239237
240- void blindedpath_next_blinding (const struct tlv_encrypted_data_tlv * enc ,
241- const struct pubkey * blinding ,
238+ void blindedpath_next_path_key (const struct tlv_encrypted_data_tlv * enc ,
239+ const struct pubkey * path_key ,
242240 const struct secret * ss ,
243- struct pubkey * next_blinding )
241+ struct pubkey * next_path_key )
244242{
245243 /* BOLT #4:
246244 * - $`E_{i+1} = SHA256(E_i || ss_i) * E_i`$
247245 * ...
248- * - If `encrypted_data` contains a `next_blinding_override `:
249- * - MUST use it as the next blinding point instead of $`E_{i+1}`$
246+ * - If `encrypted_data` contains a `next_path_key_override `:
247+ * - MUST use it as the next `path_key` instead of $`E_{i+1}`$
250248 * - Otherwise:
251- * - MUST use $`E_{i+1}`$ as the next blinding point
249+ * - MUST use $`E_{i+1}`$ as the next `path_key`
252250 */
253- if (enc -> next_blinding_override )
254- * next_blinding = * enc -> next_blinding_override ;
251+ if (enc -> next_path_key_override )
252+ * next_path_key = * enc -> next_path_key_override ;
255253 else {
256254 /* BOLT #4:
257255 * $`E_{i+1} = SHA256(E_i || ss_i) * E_i`$
258256 */
259257 struct sha256 h ;
260- blinding_hash_e_and_ss (blinding , ss , & h );
261- blinding_next_pubkey ( blinding , & h , next_blinding );
258+ blinding_hash_e_and_ss (path_key , ss , & h );
259+ blinding_next_path_key ( path_key , & h , next_path_key );
262260 }
263261}
0 commit comments