use std::slice::bytes::copy_memory;
use packet;
use packet::{ Packet, Error };
use end_point::EndPoint;
use std::slice::bytes::copy_memory;
use packet;
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 prints some message on the stdout.
+/// 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<Vec<u8>> {
let mut end_point = EndPoint::new(
match TcpStream::connect(address, port) {
pub fn decipher(address: &str, port: u16, original_xor_operand: &[u8, ..16], cipherblock: &[u8, ..16], variant: packet::Variant) -> Option<Vec<u8>> {
let mut end_point = EndPoint::new(
match TcpStream::connect(address, port) {
copy_memory(final_packet.slice_mut(2 + 1 + 8 + 16, 2 + 1 + 8 + 32), cipherblock);
let mut decipher_block = [0u8, ..16]; // The result.
copy_memory(final_packet.slice_mut(2 + 1 + 8 + 16, 2 + 1 + 8 + 32), cipherblock);
let mut decipher_block = [0u8, ..16]; // The result.
x_prime_block[byte] = v ^ (padding_value as u8);
decipher_block[byte] = x_prime_block[byte] ^ original_xor_operand[byte];
x_prime_block[byte] = v ^ (padding_value as u8);
decipher_block[byte] = x_prime_block[byte] ^ original_xor_operand[byte];
for i in range(16 - padding_value, 16) {
forged_xor_operand(&mut final_packet)[i] = x_prime_block[i] ^ ((padding_value as u8) + 1);
}
for i in range(16 - padding_value, 16) {
forged_xor_operand(&mut final_packet)[i] = x_prime_block[i] ^ ((padding_value as u8) + 1);
}
- // Special case for the first byte: we have to test all the values.
+ // Special case for the first byte: we have to test all the values to avoid a valid padding
+ // which is not [.., 0x01], for instance [.., 0x02, 0x02]. It's a very rare case but not impossible.