+fn do_oracle_attack(address: &str, variant: packet::Variant) {
+ // 16 bytes encrypted data from 'Packet::random_packet_data([4])'.
+ 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::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: {}", deciphered)
+ }
+ Some(ref other) =>
+ println!("The oracle machine hasn't found the clear block: {}", other),
+ _ =>
+ println!("The oracle machine hasn't found the clear block"),
+ }
+}
+
+enum Mode {
+ Help,
+ ServerAlone,
+ GenKey,
+ Tests,
+ OracleWeak,
+ OracleFixed,
+}
+
+fn mode() -> Mode {
+ let args = os::args();
+
+ if args.iter().any(|a| a.as_slice() == "--help" || a.as_slice() == "-h") {
+ return Help
+ }
+
+ if args.len() <= 1 {
+ ServerAlone
+ } else {
+ match args[1].as_slice() {
+ "genkey" => GenKey,
+ "tests" => Tests,
+ "oracle-weak" => OracleWeak,
+ "oracle-fixed" => OracleFixed,
+ _ => ServerAlone,
+ }
+ }
+}
+