From 307b73948c18f26a4ff12fc29f9055397a999f44 Mon Sep 17 00:00:00 2001 From: Ummon Date: Wed, 5 Nov 2014 17:45:10 +0100 Subject: [PATCH] Cypher -> Cipher. --- lab1_rust/src/crypto.rs | 4 ++-- lab1_rust/src/end_point.rs | 2 ++ lab1_rust/src/main.rs | 10 +++++----- lab1_rust/src/oracle_machine.rs | 17 +++++++++-------- 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/lab1_rust/src/crypto.rs b/lab1_rust/src/crypto.rs index d9fe182..31b224f 100644 --- a/lab1_rust/src/crypto.rs +++ b/lab1_rust/src/crypto.rs @@ -33,11 +33,11 @@ pub fn encrypt(plaindata: &[u8], iv: &[u8]) -> Option> { } /// Decrypt may fail if the provided data size isn't a multiple of 16. -pub fn decrypt(cypherdata: &[u8], iv: &[u8]) -> Option> { +pub fn decrypt(cipherdata: &[u8], iv: &[u8]) -> Option> { let c = symm::Crypter::new(symm::AES_256_CBC); c.init(symm::Decrypt, KEY_C, iv.to_vec()); c.pad(false); // Padding disabled! - let r = c.update(cypherdata); + let r = c.update(cipherdata); let rest = c.finalize(); if rest.is_empty() { Some(r) diff --git a/lab1_rust/src/end_point.rs b/lab1_rust/src/end_point.rs index cb67226..9492d95 100644 --- a/lab1_rust/src/end_point.rs +++ b/lab1_rust/src/end_point.rs @@ -83,6 +83,7 @@ impl Client { }}) } + #[allow(dead_code)] pub fn close(&mut self) -> IoResult<()> { self.end_point.close() } @@ -257,6 +258,7 @@ impl EndPoint { EndPoint { socket: socket, current_timestamp: 0 , variant: variant} } + #[allow(dead_code)] fn close(&mut self) -> IoResult<()> { try!(self.socket.close_read()); try!(self.socket.close_write()); diff --git a/lab1_rust/src/main.rs b/lab1_rust/src/main.rs index 0b14951..967e0c7 100644 --- a/lab1_rust/src/main.rs +++ b/lab1_rust/src/main.rs @@ -28,16 +28,16 @@ fn print_usage() { fn do_oracle_attack(address: &str, variant: packet::Variant) { // 16 bytes encrypted data from 'Packet::random_packet_data([4])'. - let cypher_block: [u8, ..16] = [254, 9, 228, 149, 60, 42, 165, 34, 233, 75, 112, 57, 37, 9, 116, 103]; // Known by the attacker. - let xor_operand: [u8, ..16] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3]; // This is the IV or the previous 16 bytes cypherblock. In our case we took the IV. + let cipher_block: [u8, ..16] = [254, 9, 228, 149, 60, 42, 165, 34, 233, 75, 112, 57, 37, 9, 116, 103]; // Known by the attacker. + let xor_operand: [u8, ..16] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3]; // This is the IV or the previous 16 bytes cipherblock. In our case we took the IV. let expected_clear_block: [u8, ..16] = [44, 92, 31, 98, 220, 84, 226, 53, 58, 94, 45, 25, 242, 6, 199, 1]; // To be found by the attacker. - match oracle_machine::decypher(address, PORT, &xor_operand, &cypher_block, variant) { - Some(ref decyphered) if decyphered.as_slice() == expected_clear_block => { + match oracle_machine::decipher(address, PORT, &xor_operand, &cipher_block, variant) { + Some(ref deciphered) if deciphered.as_slice() == expected_clear_block => { println!("The oracle machine has found the clear block!:"); println!(" Expected block: {}", expected_clear_block.to_vec()); - println!(" Decrypted block: {}", decyphered) + println!(" Decrypted block: {}", deciphered) } Some(ref other) => println!("The oracle machine hasn't found the clear block: {}", other), diff --git a/lab1_rust/src/oracle_machine.rs b/lab1_rust/src/oracle_machine.rs index 2feb31b..a5be2d7 100644 --- a/lab1_rust/src/oracle_machine.rs +++ b/lab1_rust/src/oracle_machine.rs @@ -6,9 +6,9 @@ use packet; use packet::{ Packet, Error }; use end_point::EndPoint; -/// Try to decypher a cyphered data block by using the previous xor operand and an oracle on the provided address and port. +/// Try to decipher a ciphered data block by using the previous xor operand and an oracle on the provided address and port. /// May prints some message on the stdout. -pub fn decypher(address: &str, port: u16, original_xor_operand: &[u8, ..16], cypherblock: &[u8, ..16], variant: packet::Variant) -> Option> { +pub fn decipher(address: &str, port: u16, original_xor_operand: &[u8, ..16], cipherblock: &[u8, ..16], variant: packet::Variant) -> Option> { let mut end_point = EndPoint::new( match TcpStream::connect(address, port) { Ok(s) => s, @@ -22,10 +22,10 @@ pub fn decypher(address: &str, port: u16, original_xor_operand: &[u8, ..16], cyp let mut final_packet = [0u8, ..2 + 1 + 8 + 32 + 10]; final_packet[1] = 1 + 8 + 32 + 10; // Data length. - copy_memory(final_packet.slice_mut(2 + 1 + 8 + 16, 2 + 1 + 8 + 32), cypherblock); + copy_memory(final_packet.slice_mut(2 + 1 + 8 + 16, 2 + 1 + 8 + 32), cipherblock); - let mut decypher_block = [0u8, ..16]; // The result. - let mut x_prime_block = [0u8, ..16]; // The cypher block ('cypherblock') after AES and before XOR. + 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 current_timestamp = 0u64; let mut first_byte = 0u8; // Used to save the first byte for the first iteration. @@ -49,7 +49,8 @@ pub fn decypher(address: &str, port: u16, original_xor_operand: &[u8, ..16], cyp forged_xor_operand(&mut final_packet)[byte] = v; match end_point.send_raw_with_result(final_packet) { - Ok(Ok(Packet { t: Error(packet::AuthError), .. })) => { + 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 byte == 15 && get_mac_mismatch_error { @@ -61,7 +62,7 @@ pub fn decypher(address: &str, port: u16, original_xor_operand: &[u8, ..16], cyp let padding_value = 16 - byte; x_prime_block[byte] = v ^ (padding_value as u8); - decypher_block[byte] = x_prime_block[byte] ^ original_xor_operand[byte]; + decipher_block[byte] = x_prime_block[byte] ^ original_xor_operand[byte]; // We set the processed bytes of the forged XOR operand to have the next padding value. for i in range(16 - padding_value, 16) { @@ -93,5 +94,5 @@ pub fn decypher(address: &str, port: u16, original_xor_operand: &[u8, ..16], cyp byte -= 1; } - Some(decypher_block.to_vec()) + Some(decipher_block.to_vec()) } \ No newline at end of file -- 2.43.0