pub struct TimingValidator { /* private fields */ }Expand description
Timing attack prevention validator
This validator provides utilities to prevent timing attacks by ensuring constant-time operations where necessary.
Implementations§
Source§impl TimingValidator
impl TimingValidator
Sourcepub fn constant_time_compare(&self, a: &[u8], b: &[u8]) -> bool
pub fn constant_time_compare(&self, a: &[u8], b: &[u8]) -> bool
Perform constant-time comparison of two byte slices
This function performs a constant-time comparison to prevent timing attacks. It returns true if the slices are equal, false otherwise.
§Arguments
a- First byte sliceb- Second byte slice
§Returns
Returns true if the slices are equal, false otherwise.
The comparison is performed in constant time to prevent timing attacks.
Sourcepub fn constant_time_select<T: Copy>(&self, choice: bool, a: T, b: T) -> T
pub fn constant_time_select<T: Copy>(&self, choice: bool, a: T, b: T) -> T
Sourcepub fn constant_time_assign<T: Copy>(&self, choice: bool, dst: &mut T, src: T)
pub fn constant_time_assign<T: Copy>(&self, choice: bool, dst: &mut T, src: T)
Constant-time conditional assignment
Assigns src to dst if choice is true, otherwise leaves dst unchanged.
The assignment is performed in constant time.
§Arguments
choice- Boolean choicedst- Destination to potentially assign tosrc- Source value to assign
Sourcepub fn constant_time_copy(&self, choice: bool, dst: &mut [u8], src: &[u8])
pub fn constant_time_copy(&self, choice: bool, dst: &mut [u8], src: &[u8])
Sourcepub fn validate_timing_safety(&self, operation: &str) -> Result<()>
pub fn validate_timing_safety(&self, operation: &str) -> Result<()>
Validate that an operation is timing-safe
This function can be used to validate that operations are performed in constant time to prevent timing attacks.
§Arguments
operation- Name of the operation being validated
§Returns
Returns Ok(()) if timing validation is enabled and the operation
is considered safe, or an error if timing validation fails.
Sourcepub fn set_timing_validation(&mut self, enabled: bool)
pub fn set_timing_validation(&mut self, enabled: bool)
Sourcepub fn is_timing_validation_enabled(&self) -> bool
pub fn is_timing_validation_enabled(&self) -> bool
Check if timing validation is enabled
§Returns
Returns true if timing validation is enabled, false otherwise.
Trait Implementations§
Source§impl Clone for TimingValidator
impl Clone for TimingValidator
Source§fn clone(&self) -> TimingValidator
fn clone(&self) -> TimingValidator
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more