dendrobates-t-azureus/aes-t-tables/src/naive_flush_and_reload.rs

59 lines
1.5 KiB
Rust
Raw Normal View History

2020-09-22 14:36:07 +02:00
use crate::{CacheStatus, ChannelFatalError, SideChannelError, SingleAddrCacheSideChannel};
use cache_utils::calibration::only_reload;
use cache_utils::flush;
#[derive(Debug)]
pub struct NaiveFlushAndReload {
pub threshold: u64,
current: Option<*const u8>,
}
impl NaiveFlushAndReload {
pub fn from_threshold(threshold: u64) -> Self {
NaiveFlushAndReload {
threshold,
current: None,
}
}
}
impl SingleAddrCacheSideChannel for NaiveFlushAndReload {
2020-09-22 17:09:46 +02:00
/// # Safety
///
/// addr needs to be a valid pointer
unsafe fn test_single(&mut self, addr: *const u8) -> Result<CacheStatus, SideChannelError> {
2020-09-22 14:36:07 +02:00
if self.current != Some(addr) {
return Err(SideChannelError::AddressNotReady(addr));
2020-09-22 14:36:07 +02:00
}
let t = unsafe { only_reload(addr) };
if t > self.threshold {
Ok(CacheStatus::Miss)
} else {
Ok(CacheStatus::Hit)
}
}
2020-09-22 17:09:46 +02:00
/// # Safety:
///
/// addr needs to be a valid pointer
unsafe fn prepare_single(&mut self, addr: *const u8) -> Result<(), SideChannelError> {
2020-09-22 14:36:07 +02:00
unsafe { flush(addr) };
self.current = Some(addr);
Ok(())
}
fn victim_single(&mut self, operation: &dyn Fn()) {
operation()
}
2020-09-22 17:09:46 +02:00
/// # Safety
///
/// addr needs to be a valid pointer
unsafe fn calibrate_single(
2020-09-22 14:36:07 +02:00
&mut self,
_addresses: impl IntoIterator<Item = *const u8>,
) -> Result<(), ChannelFatalError> {
Ok(())
}
}