Skip to content

Commit

Permalink
Blinded paths: rename encrypted_tlvs_ss to *_rho for precision
Browse files Browse the repository at this point in the history
The previous name can be confused for the shared secret that the rho is derived
from.
  • Loading branch information
valentinewallace committed Aug 5, 2023
1 parent dd65361 commit 4b7b7e8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
12 changes: 6 additions & 6 deletions lightning/src/blinded_path/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ pub(super) fn blinded_hops<T: secp256k1::Signing + secp256k1::Verification>(
) -> Result<Vec<BlindedHop>, secp256k1::Error> {
let mut blinded_hops = Vec::with_capacity(unblinded_path.len());

let mut prev_ss_and_blinded_node_id = None;
let mut prev_rho_and_blinded_node_id = None;
utils::construct_keys_callback(secp_ctx, unblinded_path.iter(), None, session_priv,
|blinded_node_id, _, _, encrypted_payload_ss, unblinded_pk, _| {
if let Some((prev_ss, prev_blinded_node_id)) = prev_ss_and_blinded_node_id {
|blinded_node_id, _, _, encrypted_payload_rho, unblinded_pk, _| {
if let Some((prev_ss, prev_blinded_node_id)) = prev_rho_and_blinded_node_id {
if let Some(pk) = unblinded_pk {
let payload = ForwardTlvs {
next_node_id: pk,
Expand All @@ -76,14 +76,14 @@ pub(super) fn blinded_hops<T: secp256k1::Signing + secp256k1::Verification>(
});
} else { debug_assert!(false); }
}
prev_ss_and_blinded_node_id = Some((encrypted_payload_ss, blinded_node_id));
prev_rho_and_blinded_node_id = Some((encrypted_payload_rho, blinded_node_id));
})?;

if let Some((final_ss, final_blinded_node_id)) = prev_ss_and_blinded_node_id {
if let Some((final_rho, final_blinded_node_id)) = prev_rho_and_blinded_node_id {
let final_payload = ReceiveTlvs { path_id: None };
blinded_hops.push(BlindedHop {
blinded_node_id: final_blinded_node_id,
encrypted_payload: utils::encrypt_payload(final_payload, final_ss),
encrypted_payload: utils::encrypt_payload(final_payload, final_rho),
});
} else { debug_assert!(false) }

Expand Down
4 changes: 2 additions & 2 deletions lightning/src/blinded_path/payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,10 @@ pub(super) fn blinded_hops<T: secp256k1::Signing + secp256k1::Verification>(
let mut curr_hop_idx = 0;
utils::construct_keys_callback(
secp_ctx, unblinded_path.iter().map(|(pk, _)| pk), None, session_priv,
|blinded_node_id, _, _, encrypted_payload_ss, _, _| {
|blinded_node_id, _, _, encrypted_payload_rho, _, _| {
blinded_hops.push(BlindedHop {
blinded_node_id,
encrypted_payload: utils::encrypt_payload(&unblinded_path[curr_hop_idx].1, encrypted_payload_ss),
encrypted_payload: utils::encrypt_payload(&unblinded_path[curr_hop_idx].1, encrypted_payload_rho),
});
curr_hop_idx += 1;
})?;
Expand Down
4 changes: 2 additions & 2 deletions lightning/src/blinded_path/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ where
}

/// Encrypt TLV payload to be used as a [`crate::blinded_path::BlindedHop::encrypted_payload`].
pub(super) fn encrypt_payload<P: Writeable>(payload: P, encrypted_tlvs_ss: [u8; 32]) -> Vec<u8> {
pub(super) fn encrypt_payload<P: Writeable>(payload: P, encrypted_tlvs_rho: [u8; 32]) -> Vec<u8> {
let mut writer = VecWriter(Vec::new());
let write_adapter = ChaChaPolyWriteAdapter::new(encrypted_tlvs_ss, &payload);
let write_adapter = ChaChaPolyWriteAdapter::new(encrypted_tlvs_rho, &payload);
write_adapter.write(&mut writer).expect("In-memory writes cannot fail");
writer.0
}
Expand Down

0 comments on commit 4b7b7e8

Please sign in to comment.