Skip to content

Commit 18606a0

Browse files
committed
Expand utility of secondary shared secrets
When encrypting errors, we currently have the ability to use two shared secrets for Phantom Node payments. Trampoline also requires the re-encryption of encrypted errors, first using the Trampoline shared secret, and then using the outer one. Given these two cryptographically equivalent use cases, we're renaming the phantom_shared_secret parameter to secondary_shared_secret, and explaining the now two contexts in which it will be applicable.
1 parent d219c89 commit 18606a0

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

lightning/src/ln/onion_utils.rs

+13-7
Original file line numberDiff line numberDiff line change
@@ -1329,19 +1329,25 @@ impl HTLCFailReason {
13291329
Self(HTLCFailReasonRepr::LightningError { err: msg.reason.clone() })
13301330
}
13311331

1332+
/// Encrypted a failure packet using a shared secret.
1333+
///
1334+
/// For phantom nodes or inner Trampoline onions, a secondary_shared_secret can be passed, which
1335+
/// will be used to encrypt the failure packet before applying the outer encryption step using
1336+
/// incoming_packet_shared_secret.
13321337
pub(super) fn get_encrypted_failure_packet(
1333-
&self, incoming_packet_shared_secret: &[u8; 32], phantom_shared_secret: &Option<[u8; 32]>,
1338+
&self, incoming_packet_shared_secret: &[u8; 32], secondary_shared_secret: &Option<[u8; 32]>,
13341339
) -> msgs::OnionErrorPacket {
13351340
match self.0 {
13361341
HTLCFailReasonRepr::Reason { ref failure_code, ref data } => {
1337-
if let Some(phantom_ss) = phantom_shared_secret {
1338-
let phantom_packet =
1339-
build_failure_packet(phantom_ss, *failure_code, &data[..]).encode();
1340-
let encrypted_phantom_packet =
1341-
encrypt_failure_packet(phantom_ss, &phantom_packet);
1342+
if let Some(secondary_shared_secret) = secondary_shared_secret {
1343+
let inner_packet =
1344+
build_failure_packet(secondary_shared_secret, *failure_code, &data[..])
1345+
.encode();
1346+
let encrypted_inner_packet =
1347+
encrypt_failure_packet(secondary_shared_secret, &inner_packet);
13421348
encrypt_failure_packet(
13431349
incoming_packet_shared_secret,
1344-
&encrypted_phantom_packet.data[..],
1350+
&encrypted_inner_packet.data[..],
13451351
)
13461352
} else {
13471353
let packet = build_failure_packet(

0 commit comments

Comments
 (0)