Skip to content

Commit

Permalink
Drop message in handshake
Browse files Browse the repository at this point in the history
  • Loading branch information
nyonson committed Sep 25, 2024
1 parent d4e4fd5 commit 173c175
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions protocol/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ impl<'a> Handshake<'a> {
packet_buffer: &mut [u8],
) -> Result<(), Error> {
// Find the end of the garbage.
let (garbage, message) = split_garbage(
let (garbage, ciphertext) = split_garbage(
buffer,
self.remote_garbage_terminator
.ok_or(Error::HandshakeOutOfOrder)?,
Expand All @@ -781,7 +781,7 @@ impl<'a> Handshake<'a> {
// is used to authenticate the received garbage through
// the AAD.
if self.current_buffer_index == 0 {
found_version_packet = self.decrypt_packet(message, packet_buffer, Some(garbage))?;
found_version_packet = self.decrypt_packet(ciphertext, packet_buffer, Some(garbage))?;
}

// If the first packet is a decoy, or if this is a follow up
Expand All @@ -792,7 +792,7 @@ impl<'a> Handshake<'a> {
// version of the protocol, but it does move the cipher
// states forward. It could be extended in the future.
while !found_version_packet {
found_version_packet = self.decrypt_packet(message, packet_buffer, None)?;
found_version_packet = self.decrypt_packet(ciphertext, packet_buffer, None)?;
}

Ok(())
Expand All @@ -808,7 +808,7 @@ impl<'a> Handshake<'a> {
/// True if the decrypted packet is the version packet.
fn decrypt_packet(
&mut self,
message: &[u8],
ciphertext: &[u8],
packet_buffer: &mut [u8],
garbage: Option<&[u8]>,
) -> Result<bool, Error> {
Expand All @@ -819,11 +819,11 @@ impl<'a> Handshake<'a> {

if self.current_packet_length_bytes.is_none() {
// Bounds check on the input buffer.
if message.len() < self.current_buffer_index + NUM_LENGTH_BYTES {
if ciphertext.len() < self.current_buffer_index + NUM_LENGTH_BYTES {
return Err(Error::CiphertextTooSmall);
}
let packet_length = packet_handler.packet_reader.decypt_len(
message[self.current_buffer_index..NUM_LENGTH_BYTES]
ciphertext[self.current_buffer_index..NUM_LENGTH_BYTES]
.try_into()
.expect("Buffer slice must be exactly 3 bytes long"),
);
Expand All @@ -838,11 +838,11 @@ impl<'a> Handshake<'a> {
.ok_or(Error::HandshakeOutOfOrder)?;

// Bounds check on input buffer.
if message.len() < self.current_buffer_index + NUM_LENGTH_BYTES + packet_length {
if ciphertext.len() < self.current_buffer_index + NUM_LENGTH_BYTES + packet_length {
return Err(Error::CiphertextTooSmall);
}
packet_handler.packet_reader.decrypt_contents(
&message[self.current_buffer_index + NUM_LENGTH_BYTES
&ciphertext[self.current_buffer_index + NUM_LENGTH_BYTES
..self.current_buffer_index + NUM_LENGTH_BYTES + packet_length],
packet_buffer,
garbage,
Expand Down Expand Up @@ -890,7 +890,7 @@ fn split_garbage(buffer: &[u8], garbage_term: [u8; 16]) -> Result<(&[u8], &[u8])
} else if buffer.len() >= (MAX_NUM_GARBAGE_BYTES + NUM_GARBAGE_TERMINTOR_BYTES) {
Err(Error::MaxGarbageLength)
} else {
// Terminator not found, the message needs more information.
// Terminator not found, the buffer needs more information.
Err(Error::CiphertextTooSmall)
}
}
Expand Down

0 comments on commit 173c175

Please sign in to comment.