Skip to content

Commit 9fd40cd

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 164c166 commit 9fd40cd

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
@@ -1355,19 +1355,25 @@ impl HTLCFailReason {
13551355
Self(HTLCFailReasonRepr::LightningError { err: msg.reason.clone() })
13561356
}
13571357

1358+
/// Encrypted a failure packet using a shared secret.
1359+
///
1360+
/// For phantom nodes or inner Trampoline onions, a secondary_shared_secret can be passed, which
1361+
/// will be used to encrypt the failure packet before applying the outer encryption step using
1362+
/// incoming_packet_shared_secret.
13581363
pub(super) fn get_encrypted_failure_packet(
1359-
&self, incoming_packet_shared_secret: &[u8; 32], phantom_shared_secret: &Option<[u8; 32]>,
1364+
&self, incoming_packet_shared_secret: &[u8; 32], secondary_shared_secret: &Option<[u8; 32]>,
13601365
) -> msgs::OnionErrorPacket {
13611366
match self.0 {
13621367
HTLCFailReasonRepr::Reason { ref failure_code, ref data } => {
1363-
if let Some(phantom_ss) = phantom_shared_secret {
1364-
let phantom_packet =
1365-
build_failure_packet(phantom_ss, *failure_code, &data[..]).encode();
1366-
let encrypted_phantom_packet =
1367-
encrypt_failure_packet(phantom_ss, &phantom_packet);
1368+
if let Some(secondary_shared_secret) = secondary_shared_secret {
1369+
let inner_packet =
1370+
build_failure_packet(secondary_shared_secret, *failure_code, &data[..])
1371+
.encode();
1372+
let encrypted_inner_packet =
1373+
encrypt_failure_packet(secondary_shared_secret, &inner_packet);
13681374
encrypt_failure_packet(
13691375
incoming_packet_shared_secret,
1370-
&encrypted_phantom_packet.data[..],
1376+
&encrypted_inner_packet.data[..],
13711377
)
13721378
} else {
13731379
let packet = build_failure_packet(

0 commit comments

Comments
 (0)