Skip to content

Commit

Permalink
crypto-common: test for weak keys
Browse files Browse the repository at this point in the history
  • Loading branch information
baloo committed Jan 29, 2025
1 parent aa00ba4 commit e8d5fb6
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions crypto-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,11 @@ pub trait KeyInit: KeySizeUser + Sized {
rng.try_fill_bytes(&mut key)?;
Ok(key)
}

/// Check if a key might be considered weak
fn weak_key_test(_key: &Key<Self>) -> Result<(), WeakKeyError> {
Ok(())
}
}

/// Types which can be initialized from key and initialization vector (nonce).
Expand Down Expand Up @@ -387,3 +392,16 @@ impl fmt::Display for InvalidLength {
}

impl core::error::Error for InvalidLength {}

/// The error type returned when a key is tested to be weak the [`KeyInit::weak_key_test`].
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
pub struct WeakKeyError;

impl fmt::Display for WeakKeyError {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
f.write_str("WeakKey")
}
}

impl core::error::Error for WeakKeyError {}

0 comments on commit e8d5fb6

Please sign in to comment.