File tree Expand file tree Collapse file tree 1 file changed +7
-14
lines changed Expand file tree Collapse file tree 1 file changed +7
-14
lines changed Original file line number Diff line number Diff line change @@ -203,20 +203,13 @@ impl PeerChannelEncryptor {
203
203
nonce[ 4 ..] . copy_from_slice ( & n. to_le_bytes ( ) [ ..] ) ;
204
204
205
205
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
+ } )
220
213
}
221
214
222
215
#[ inline]
You can’t perform that action at this time.
0 commit comments