Skip to content

Commit 5a23ac0

Browse files
committed
Clean up some nits in peer_channel_encryptor
1 parent 226e8cf commit 5a23ac0

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

lightning/src/ln/peer_channel_encryptor.rs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -203,20 +203,13 @@ impl PeerChannelEncryptor {
203203
nonce[4..].copy_from_slice(&n.to_le_bytes()[..]);
204204

205205
let mut chacha = ChaCha20Poly1305RFC::new(key, &nonce, h);
206-
if chacha
207-
.variable_time_decrypt(
208-
&cyphertext[0..cyphertext.len() - 16],
209-
res,
210-
&cyphertext[cyphertext.len() - 16..],
211-
)
212-
.is_err()
213-
{
214-
return Err(LightningError {
215-
err: "Bad MAC".to_owned(),
216-
action: msgs::ErrorAction::DisconnectPeer { msg: None },
217-
});
218-
}
219-
Ok(())
206+
let hmac = &cyphertext[cyphertext.len() - 16..];
207+
let mac_check =
208+
chacha.variable_time_decrypt(&cyphertext[0..cyphertext.len() - 16], res, hmac);
209+
mac_check.map_err(|()| LightningError {
210+
err: "Bad MAC".to_owned(),
211+
action: msgs::ErrorAction::DisconnectPeer { msg: None },
212+
})
220213
}
221214

222215
#[inline]

0 commit comments

Comments
 (0)