X-Git-Url: http://git.euphorik.ch/?p=crypto_lab1.git;a=blobdiff_plain;f=lab1_rust%2Fsrc%2Fpacket.rs;fp=lab1_rust%2Fsrc%2Fpacket.rs;h=8b02ccdf0e46d52dc772f0803aa504cdec5f4d70;hp=c81fe20aff6aa7b57161d6762de51c17f35e839c;hb=fe03a7f9df6b8f4cf03e2399aeb68a7dc2605a67;hpb=4e2d63f98c464119e7b475a8f981b99d991c3727 diff --git a/lab1_rust/src/packet.rs b/lab1_rust/src/packet.rs index c81fe20..8b02ccd 100644 --- a/lab1_rust/src/packet.rs +++ b/lab1_rust/src/packet.rs @@ -158,19 +158,19 @@ impl Packet { _ => () } - // Compute the MAC. It depends of the choosen variant. + // Computes the MAC. It depends of the choosen variant. let mac = crypto::compute_mac(data.slice_to(match variant { Weak => data_size, _ => data.len() })); - // Encrypt. + // Encrypts. let encrypted_data = match crypto::encrypt(data.as_slice(), iv_from_timestamp(self.timestamp).as_slice()) { Some(d) => d, _ => return Err(EncryptError) }; - // Write packet length. + // Writes packet length. try_write_io!(output.write_be_u16((encrypted_data.len() + FIXED_PACKET_SIZE) as u16)); - // Write packet type. + // Writes packet type. try_write_io!(output.write_u8( match self.t { Command(_) => 0x00, @@ -180,13 +180,13 @@ impl Packet { } )); - // Write timestamp. + // Writes timestamp. try_write_io!(output.write_be_u64(self.timestamp)); - // Write encrypted data. + // Writes encrypted data. try_write_io!(output.write(encrypted_data.as_slice())); - // Write the MAC. + // Writes the MAC. try_write_io!(output.write(mac)); Ok(()) @@ -199,7 +199,7 @@ impl Packet { let data_size = try_read_io!(input.read_be_u16()); - // Read and check the packet type. + // Reads and checks the packet type. let packet_type = try_read_io!(input.read_u8()); if ![0x00, 0xFF, 0x0A, 0x0B].iter().any(|p| *p == packet_type) { consume(input, data_size as uint - 1); @@ -217,7 +217,7 @@ impl Packet { _ => return Err(UnconsistentEncryptedSizeError) }; - // Read the MAC. + // Reads the MAC. let mut mac_read = [0u8, ..10]; if try_read_io!(input.read(mac_read)) != mac_read.len() { return Err(UnconsistentMACSizeError) @@ -225,7 +225,7 @@ impl Packet { match variant { Fixed if mac_read != crypto::compute_mac(data.as_slice()) => return Err(MACMismatchError), _ => () }; - // Control the size and the content of the padding then remove it. + // Controls the size and the content of the padding then removes it. if packet_type == 0x00 || packet_type == 0xFF { match data.last() { Some(&padding_size) => { @@ -267,7 +267,7 @@ impl Packet { } } -// Build an initialization vector: 64 * 0u8 + timestamp (128 bits). +// Builds an initialization vector: 64 * 0u8 + timestamp (128 bits). fn iv_from_timestamp(timestamp: u64) -> Vec { let mut iv = io::MemWriter::with_capacity(16); let _ = iv.write_be_u64(0u64);