Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions aes/src/armv8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use cipher::{
AlgorithmName, BlockCipherDecClosure, BlockCipherDecrypt, BlockCipherEncClosure,
BlockCipherEncrypt, BlockSizeUser, Key, KeyInit, KeySizeUser,
consts::{self, U16, U24, U32},
crypto_common::WeakKeyError,
};
use core::fmt;

Expand Down Expand Up @@ -104,11 +103,6 @@ macro_rules! define_aes_impl {
let decrypt = $name_back_dec::from(encrypt.clone());
Self { encrypt, decrypt }
}

#[inline]
fn weak_key_test(key: &Key<Self>) -> Result<(), WeakKeyError> {
crate::weak_key_test(&key.0)
}
}

impl From<$name_enc> for $name {
Expand Down Expand Up @@ -187,11 +181,6 @@ macro_rules! define_aes_impl {
let backend = $name_back_enc::new(key);
Self { backend }
}

#[inline]
fn weak_key_test(key: &Key<Self>) -> Result<(), WeakKeyError> {
crate::weak_key_test(&key.0)
}
}

impl BlockSizeUser for $name_enc {
Expand Down Expand Up @@ -247,11 +236,6 @@ macro_rules! define_aes_impl {
let backend = encrypt.clone().into();
Self { backend }
}

#[inline]
fn weak_key_test(key: &Key<Self>) -> Result<(), WeakKeyError> {
crate::weak_key_test(&key.0)
}
}

impl From<$name_enc> for $name_dec {
Expand Down
16 changes: 0 additions & 16 deletions aes/src/autodetect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use cipher::{
AlgorithmName, BlockCipherDecClosure, BlockCipherDecrypt, BlockCipherEncClosure,
BlockCipherEncrypt, BlockSizeUser, Key, KeyInit, KeySizeUser,
consts::{U16, U24, U32},
crypto_common::WeakKeyError,
};
use core::fmt;
use core::mem::ManuallyDrop;
Expand Down Expand Up @@ -100,11 +99,6 @@ macro_rules! define_aes_impl {

Self { inner, token }
}

#[inline]
fn weak_key_test(key: &Key<Self>) -> Result<(), WeakKeyError> {
crate::weak_key_test(&key.0)
}
}

impl Clone for $name {
Expand Down Expand Up @@ -204,11 +198,6 @@ macro_rules! define_aes_impl {

Self { inner, token }
}

#[inline]
fn weak_key_test(key: &Key<Self>) -> Result<(), WeakKeyError> {
crate::weak_key_test(&key.0)
}
}

impl Clone for $name_enc {
Expand Down Expand Up @@ -325,11 +314,6 @@ macro_rules! define_aes_impl {

Self { inner, token }
}

#[inline]
fn weak_key_test(key: &Key<Self>) -> Result<(), WeakKeyError> {
crate::weak_key_test(&key.0)
}
}

impl Clone for $name_dec {
Expand Down
32 changes: 1 addition & 31 deletions aes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,41 +149,11 @@ cfg_if! {
}

pub use cipher;
use cipher::{array::Array, consts::U16, crypto_common::WeakKeyError};
use cipher::{array::Array, consts::U16};

/// 128-bit AES block
pub type Block = Array<u8, U16>;

/// Check if any bit of the upper half of the key is set.
///
/// This follows the interpretation laid out in section `11.4.10.4 Reject of weak keys`
/// from the [TPM specification][0]:
/// ```text
/// In the case of AES, at least one bit in the upper half of the key must be set
/// ```
///
/// [0]: https://trustedcomputinggroup.org/wp-content/uploads/TPM-2.0-1.83-Part-1-Architecture.pdf#page=82
pub(crate) fn weak_key_test<const N: usize>(key: &[u8; N]) -> Result<(), WeakKeyError> {
let t = match N {
16 => u64::from_ne_bytes(key[..8].try_into().unwrap()),
24 => {
let t1 = u64::from_ne_bytes(key[..8].try_into().unwrap());
let t2 = u32::from_ne_bytes(key[8..12].try_into().unwrap());
t1 | u64::from(t2)
}
32 => {
let t1 = u64::from_ne_bytes(key[..8].try_into().unwrap());
let t2 = u64::from_ne_bytes(key[8..16].try_into().unwrap());
t1 | t2
}
_ => unreachable!(),
};
match t {
0 => Err(WeakKeyError),
_ => Ok(()),
}
}

#[cfg(test)]
mod tests {
#[cfg(feature = "zeroize")]
Expand Down
16 changes: 0 additions & 16 deletions aes/src/ni.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ use cipher::{
AlgorithmName, BlockCipherDecClosure, BlockCipherDecrypt, BlockCipherEncClosure,
BlockCipherEncrypt, BlockSizeUser, Key, KeyInit, KeySizeUser,
consts::{self, U16, U24, U32},
crypto_common::WeakKeyError,
};
use core::fmt;

Expand Down Expand Up @@ -119,11 +118,6 @@ macro_rules! define_aes_impl {
let decrypt = $name_dec::from(&encrypt);
Self { encrypt, decrypt }
}

#[inline]
fn weak_key_test(key: &Key<Self>) -> Result<(), WeakKeyError> {
crate::weak_key_test(&key.0)
}
}

impl From<$name_enc> for $name {
Expand Down Expand Up @@ -199,11 +193,6 @@ macro_rules! define_aes_impl {
backend: $name_back_enc::new(key),
}
}

#[inline]
fn weak_key_test(key: &Key<Self>) -> Result<(), WeakKeyError> {
crate::weak_key_test(&key.0)
}
}

impl BlockSizeUser for $name_enc {
Expand Down Expand Up @@ -264,11 +253,6 @@ macro_rules! define_aes_impl {
fn new(key: &Key<Self>) -> Self {
$name_enc::new(key).into()
}

#[inline]
fn weak_key_test(key: &Key<Self>) -> Result<(), WeakKeyError> {
crate::weak_key_test(&key.0)
}
}

impl From<$name_enc> for $name_dec {
Expand Down
16 changes: 0 additions & 16 deletions aes/src/soft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use cipher::{
BlockCipherEncBackend, BlockCipherEncClosure, BlockCipherEncrypt, BlockSizeUser, Key, KeyInit,
KeySizeUser, ParBlocksSizeUser,
consts::{U16, U24, U32},
crypto_common::WeakKeyError,
inout::InOut,
};
use core::fmt;
Expand Down Expand Up @@ -56,11 +55,6 @@ macro_rules! define_aes_impl {
keys: $fixslice_key_schedule(key.into()),
}
}

#[inline]
fn weak_key_test(key: &Key<Self>) -> Result<(), WeakKeyError> {
crate::weak_key_test(&key.0)
}
}

impl BlockSizeUser for $name {
Expand Down Expand Up @@ -133,11 +127,6 @@ macro_rules! define_aes_impl {
let inner = $name::new(key);
Self { inner }
}

#[inline]
fn weak_key_test(key: &Key<Self>) -> Result<(), WeakKeyError> {
crate::weak_key_test(&key.0)
}
}

impl BlockSizeUser for $name_enc {
Expand Down Expand Up @@ -182,11 +171,6 @@ macro_rules! define_aes_impl {
let inner = $name::new(key);
Self { inner }
}

#[inline]
fn weak_key_test(key: &Key<Self>) -> Result<(), WeakKeyError> {
crate::weak_key_test(&key.0)
}
}

impl From<$name_enc> for $name_dec {
Expand Down
16 changes: 0 additions & 16 deletions aes/src/x86.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use cipher::{
BlockCipherEncBackend, BlockCipherEncClosure, BlockCipherEncrypt, BlockSizeUser, InOut, Key,
KeyInit, KeySizeUser, ParBlocksSizeUser,
consts::{U8, U16, U24, U32},
crypto_common::WeakKeyError,
};
#[cfg(all(target_arch = "x86_64", any(aes_avx256, aes_avx512)))]
use cipher::{Array, InOutBuf, consts::U30, typenum::Unsigned};
Expand Down Expand Up @@ -208,11 +207,6 @@ macro_rules! define_aes_impl {
let decrypt = $name_dec::from(&encrypt);
Self { encrypt, decrypt }
}

#[inline]
fn weak_key_test(key: &Key<Self>) -> Result<(), WeakKeyError> {
crate::weak_key_test(&key.0)
}
}

impl From<$name_enc> for $name {
Expand Down Expand Up @@ -296,11 +290,6 @@ macro_rules! define_aes_impl {
features: Features::new(),
}
}

#[inline]
fn weak_key_test(key: &Key<Self>) -> Result<(), WeakKeyError> {
crate::weak_key_test(&key.0)
}
}

impl BlockSizeUser for $name_enc {
Expand Down Expand Up @@ -371,11 +360,6 @@ macro_rules! define_aes_impl {
fn new(key: &Key<Self>) -> Self {
$name_enc::new(key).into()
}

#[inline]
fn weak_key_test(key: &Key<Self>) -> Result<(), WeakKeyError> {
crate::weak_key_test(&key.0)
}
}

impl From<$name_enc> for $name_dec {
Expand Down
24 changes: 0 additions & 24 deletions aes/tests/weak.rs

This file was deleted.