Skip to content

Commit b4495b7

Browse files
committed
BOLTs: update which renames blinding terminology.
No code changes, just catching up with the BOLT changes which rework our blinded path terminology (for the better!). Another patch will sweep the rest of our internal names, this tries only to make things compile and fix up the BOLT quotes. 1. Inside payload: current_blinding_point -> current_path_key 2. Inside update_add_htlc TLV: blinding_point -> blinded_path 3. Inside blinded_path: blinding -> first_path_key 4. Inside onion_message: blinding -> path_key. 5. Inside encrypted_data_tlv: next_blinding_override -> next_path_key_override Signed-off-by: Rusty Russell <[email protected]>
1 parent a8b68c9 commit b4495b7

39 files changed

+336
-349
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ CCANDIR := ccan
2626

2727
# Where we keep the BOLT RFCs
2828
BOLTDIR := ../bolts/
29-
DEFAULT_BOLTVERSION := 6a51861d93ad617438fe24195768e2742d7708ac
29+
DEFAULT_BOLTVERSION := 6c0f0d878f52ee189be9649b06a0dd86e52a517a
3030
# Can be overridden on cmdline.
3131
BOLTVERSION := $(DEFAULT_BOLTVERSION)
3232

channeld/channeld.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ static void handle_peer_add_htlc(struct peer *peer, const u8 *msg)
622622
}
623623
add_err = channel_add_htlc(peer->channel, REMOTE, id, amount,
624624
cltv_expiry, &payment_hash,
625-
onion_routing_packet, tlvs->blinding_point, &htlc, NULL,
625+
onion_routing_packet, tlvs->blinded_path, &htlc, NULL,
626626
/* We don't immediately fail incoming htlcs,
627627
* instead we wait and fail them after
628628
* they've been committed */
@@ -4412,8 +4412,8 @@ static void resend_commitment(struct peer *peer, struct changed_htlc *last)
44124412
struct tlv_update_add_htlc_tlvs *tlvs;
44134413
if (h->blinding) {
44144414
tlvs = tlv_update_add_htlc_tlvs_new(tmpctx);
4415-
tlvs->blinding_point = tal_dup(tlvs, struct pubkey,
4416-
h->blinding);
4415+
tlvs->blinded_path = tal_dup(tlvs, struct pubkey,
4416+
h->blinding);
44174417
} else
44184418
tlvs = NULL;
44194419
msg = towire_update_add_htlc(NULL, &peer->channel_id,
@@ -5360,7 +5360,7 @@ static void handle_offer_htlc(struct peer *peer, const u8 *inmsg)
53605360

53615361
if (blinding) {
53625362
tlvs = tlv_update_add_htlc_tlvs_new(tmpctx);
5363-
tlvs->blinding_point = tal_dup(tlvs, struct pubkey, blinding);
5363+
tlvs->blinded_path = tal_dup(tlvs, struct pubkey, blinding);
53645364
} else
53655365
tlvs = NULL;
53665366

common/blindedpath.c

Lines changed: 43 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
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

5454
static 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

111111
u8 *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

159159
u8 *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

199198
struct 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
}

common/blindedpath.h

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,33 +17,33 @@ struct tlv_encrypted_data_tlv_payment_relay;
1717
/**
1818
* encrypt_tlv_encrypted_data - Encrypt a tlv_encrypted_data_tlv.
1919
* @ctx: tal context
20-
* @blinding: e(i), the blinding secret
20+
* @path_privkey: e(i), the path key
2121
* @node: the pubkey of the node to encrypt for
2222
* @tlv: the message to encrypt.
23-
* @next_blinding: (out) e(i+1), the next blinding secret (optional)
23+
* @next_path_privkey: (out) e(i+1), the next blinding secret (optional)
2424
* @node_alias: (out) the blinded pubkey of the node to tell the recipient.
2525
*
2626
* You create a blinding secret using randombytes_buf(), then call this
2727
* iteratively for each node in the path.
2828
*/
2929
u8 *encrypt_tlv_encrypted_data(const tal_t *ctx,
30-
const struct privkey *blinding,
30+
const struct privkey *path_privkey,
3131
const struct pubkey *node,
3232
const struct tlv_encrypted_data_tlv *tlv,
33-
struct privkey *next_blinding,
33+
struct privkey *next_path_privkey,
3434
struct pubkey *node_alias)
3535
NON_NULL_ARGS(2, 3, 4, 6);
3636

3737
/**
3838
* unblind_onion - tweak onion epheremeral key so we can decode it with ours.
39-
* @blinding: E(i), the blinding pubkey the previous peer gave us.
39+
* @path_key: E(i), the blinding pubkey the previous peer gave us.
4040
* @ecdh: the ecdh routine (usually ecdh from common/ecdh_hsmd).
4141
* @onion_key: (in, out) the onionpacket->ephemeralkey to tweak.
4242
* @ss: (out) the shared secret we gained from blinding pubkey.
4343
*
4444
* The shared secret is needed to decrypt the enctlv we expect to find, too.
4545
*/
46-
bool unblind_onion(const struct pubkey *blinding,
46+
bool unblind_onion(const struct pubkey *path_key,
4747
void (*ecdh)(const struct pubkey *point, struct secret *ss),
4848
struct pubkey *onion_key,
4949
struct secret *ss)
@@ -64,30 +64,27 @@ bool blindedpath_get_alias(const struct secret *ss,
6464
/**
6565
* decrypt_encrypted_data - Decrypt an encmsg to form an tlv_encrypted_data_tlv.
6666
* @ctx: the context to allocate off.
67-
* @blinding: E(i), the blinding pubkey the previous peer gave us.
6867
* @ss: the blinding secret from unblind_onion().
6968
* @enctlv: the enctlv from the onion (tal, may be NULL).
7069
*
7170
* Returns NULL if decryption failed or encmsg was malformed.
7271
*/
7372
struct tlv_encrypted_data_tlv *decrypt_encrypted_data(const tal_t *ctx,
74-
const struct pubkey *blinding,
7573
const struct secret *ss,
7674
const u8 *enctlv)
7775
NON_NULL_ARGS(2, 3);
7876

7977
/* Low-level accessor */
8078
u8 *decrypt_encmsg_raw(const tal_t *ctx,
81-
const struct pubkey *blinding,
8279
const struct secret *ss,
8380
const u8 *enctlv);
8481

8582
/**
86-
* blindedpath_next_blinding - Calculate or extract next blinding pubkey
83+
* blindedpath_next_path_key - Calculate or extract next blinding pubkey
8784
*/
88-
void blindedpath_next_blinding(const struct tlv_encrypted_data_tlv *enc,
89-
const struct pubkey *blinding,
85+
void blindedpath_next_path_key(const struct tlv_encrypted_data_tlv *enc,
86+
const struct pubkey *path_key,
9087
const struct secret *ss,
91-
struct pubkey *next_blinding);
88+
struct pubkey *next_path_key);
9289

9390
#endif /* LIGHTNING_COMMON_BLINDEDPATH_H */

common/blindedpay.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ u8 **blinded_onion_hops(const tal_t *ctx,
2323
* - MUST include the `encrypted_recipient_data` provided by the
2424
* recipient
2525
* - For the first node in the blinded route:
26-
* - MUST include the `blinding_point` provided by the
27-
* recipient in `current_blinding_point`
26+
* - MUST include the `path_key` provided by the
27+
* recipient in `current_path_key`
2828
* - If it is the final node:
2929
* - MUST include `amt_to_forward`, `outgoing_cltv_value` and `total_amount_msat`.
3030
*...
@@ -35,7 +35,7 @@ u8 **blinded_onion_hops(const tal_t *ctx,
3535
final ? &total_amount : NULL,
3636
final ? &final_cltv : NULL,
3737
path->path[i]->encrypted_recipient_data,
38-
first ? &path->blinding : NULL);
38+
first ? &path->first_path_key : NULL);
3939
}
4040
return onions;
4141
}

common/blinding.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ void blinding_hash_e_and_ss(const struct pubkey *e,
1919
}
2020

2121
/* E(i+1) = H(E(i) || ss(i)) * E(i) */
22-
bool blinding_next_pubkey(const struct pubkey *pk,
23-
const struct sha256 *h,
24-
struct pubkey *next)
22+
bool blinding_next_path_key(const struct pubkey *pk,
23+
const struct sha256 *h,
24+
struct pubkey *next)
2525
{
2626

2727
*next = *pk;
@@ -30,9 +30,9 @@ bool blinding_next_pubkey(const struct pubkey *pk,
3030
}
3131

3232
/* e(i+1) = H(E(i) || ss(i)) * e(i) */
33-
bool blinding_next_privkey(const struct privkey *e,
34-
const struct sha256 *h,
35-
struct privkey *next)
33+
bool blinding_next_path_privkey(const struct privkey *e,
34+
const struct sha256 *h,
35+
struct privkey *next)
3636
{
3737
*next = *e;
3838
return secp256k1_ec_seckey_tweak_mul(secp256k1_ctx, next->secret.data,

common/blinding.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ void blinding_hash_e_and_ss(const struct pubkey *e,
1313
struct sha256 *sha);
1414

1515
/* E(i+1) = H(E(i) || ss(i)) * E(i) */
16-
bool blinding_next_pubkey(const struct pubkey *pk,
17-
const struct sha256 *h,
18-
struct pubkey *next);
16+
bool blinding_next_path_key(const struct pubkey *pk,
17+
const struct sha256 *h,
18+
struct pubkey *next);
1919

2020
/* e(i+1) = H(E(i) || ss(i)) * e(i) */
21-
bool blinding_next_privkey(const struct privkey *e,
22-
const struct sha256 *h,
23-
struct privkey *next);
21+
bool blinding_next_path_privkey(const struct privkey *e,
22+
const struct sha256 *h,
23+
struct privkey *next);
2424

2525
#endif /* LIGHTNING_COMMON_BLINDING_H */

0 commit comments

Comments
 (0)