Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions lightning/src/crypto/streams.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,10 @@ impl<T: Readable> LengthReadableArgs<([u8; 32], [u8; 32])> for ChaChaDualPolyRea
ChaChaDualPolyReader { chacha: &mut chacha, poly: &mut mac, read_len: 0, read: s };

let readable: T = Readable::read(&mut chacha_stream)?;
chacha_stream.read.eat_remaining()?;
while chacha_stream.read.bytes_remain() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused by this change. eat_remaining will consume the remaining bytes and error if we didn't read all of the bytes in the initial call to read, which seems correct to me. Doesn't any bytes remaining indicate a buggy node, since they incorrectly encoded the length we were supposed to read in the LengthLimitedReader? If we're reading multiple objects, seems like the underlying Readable should be on a tuple and still not have any bytes remaining.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eat_remaining will read those bytes directly, though, rather than going through the chacha_stream. Note that we call eat_remaining on chacha_stream.read not on chacha_stream. As a result, any bytes which get read via that will not be included in the HMAC, which seems wrong.

let mut buf = [0; 256];
chacha_stream.read(&mut buf)?;
}

let read_len = chacha_stream.read_len;

Expand Down Expand Up @@ -203,7 +206,10 @@ impl<T: Readable> LengthReadableArgs<[u8; 32]> for ChaChaPolyReadAdapter<T> {
let s = FixedLengthReader::new(r, decrypted_len);
let mut chacha_stream = ChaChaPolyReader { chacha: &mut chacha, read: s };
let readable: T = Readable::read(&mut chacha_stream)?;
chacha_stream.read.eat_remaining()?;
while chacha_stream.read.bytes_remain() {
let mut buf = [0; 256];
chacha_stream.read(&mut buf)?;
}

let mut tag = [0 as u8; 16];
r.read_exact(&mut tag)?;
Expand Down
Loading