X-Git-Url: http://git.euphorik.ch/?p=crypto_lab1.git;a=blobdiff_plain;f=lab1_rust%2Fsrc%2Foracle_machine.rs;fp=lab1_rust%2Fsrc%2Foracle_machine.rs;h=316f06ef475e50e7c9e443058126f7bcef6c9a6e;hp=3d72ddf4375e0c8b74363e19df4bc0a693765df7;hb=c484911fa250681026144ddb9e521daa2c2b4351;hpb=d3d8743586e533af4f32c1edfcff6377161d7cf4 diff --git a/lab1_rust/src/oracle_machine.rs b/lab1_rust/src/oracle_machine.rs index 3d72ddf..316f06e 100644 --- a/lab1_rust/src/oracle_machine.rs +++ b/lab1_rust/src/oracle_machine.rs @@ -7,8 +7,8 @@ use packet::{ Packet, Error }; use end_point::EndPoint; /// Try to decipher a ciphered data block by using the previous XOR operand and an oracle on the provided address and port. -/// May print some message on stdout. -pub fn decipher(address: &str, port: u16, original_xor_operand: &[u8, ..16], cipherblock: &[u8, ..16], variant: packet::Variant) -> Option> { +/// May print some messages on stdout. +pub fn decipher(address: &str, port: u16, original_xor_operand: &[u8, ..16], cipher_block: &[u8, ..16], variant: packet::Variant) -> Option> { let mut end_point = EndPoint::new( match TcpStream::connect(address, port) { Ok(s) => s, @@ -23,10 +23,10 @@ pub fn decipher(address: &str, port: u16, original_xor_operand: &[u8, ..16], cip // See 'packet::Packet' documentation for a complete description about the binary packet structure. let mut final_packet = [0u8, ..2 + 1 + 8 + 32 + 10]; final_packet[1] = (final_packet.len() as u8) - 2; // Data length. - copy_memory(final_packet.slice_mut(2 + 1 + 8 + 16, 2 + 1 + 8 + 32), cipherblock); + copy_memory(final_packet.slice_mut(2 + 1 + 8 + 16, 2 + 1 + 8 + 32), cipher_block); let mut decipher_block = [0u8, ..16]; // The result. - let mut x_prime_block = [0u8, ..16]; // The cipher block ('cipherblock') after AES and before XOR. + let mut x_prime_block = [0u8, ..16]; // The cipher block ('cipher_block') after AES and before XOR. let mut current_timestamp = 0u64; let mut first_byte = 0u8; // Used to save the first byte for the first iteration. @@ -53,7 +53,8 @@ pub fn decipher(address: &str, port: u16, original_xor_operand: &[u8, ..16], cip Ok(Ok(p @ Packet { t: Error(packet::AuthError), .. })) => { println!("We received a MAC Error: {}", p); - // If we already got a MAC mismatch for the first byte then the second byte is incremented and the loop is replayed. + // If we already got a MAC mismatch for the first byte then + // the second byte is incremented and the main loop is replayed for the first byte. if byte == 15 && get_mac_mismatch_error { forged_xor_operand(&mut final_packet)[14] += 1; continue 'main_loop;