Skip to content

Commit

Permalink
aes-kw: implement KeyInit for Kek
Browse files Browse the repository at this point in the history
  • Loading branch information
baloo committed Nov 6, 2024
1 parent 92cd9e1 commit a7db55d
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions aes-kw/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use aes::cipher::{
array::Array,
typenum::{Unsigned, U16, U24, U32},
Block, BlockCipherDecBackend, BlockCipherDecClosure, BlockCipherDecrypt, BlockCipherEncBackend,
BlockCipherEncClosure, BlockCipherEncrypt, BlockSizeUser, KeyInit,
BlockCipherEncClosure, BlockCipherEncrypt, BlockSizeUser, Key, KeyInit, KeySizeUser,
};

#[cfg(feature = "alloc")]
Expand Down Expand Up @@ -152,12 +152,6 @@ impl<Aes> Kek<Aes>
where
Aes: KeyInit + BlockSizeUser<BlockSize = U16> + BlockCipherEncrypt + BlockCipherDecrypt,
{
/// Constructs a new Kek based on the appropriate raw key material.
pub fn new(key: &Array<u8, Aes::KeySize>) -> Self {
let cipher = Aes::new(key);
Kek { cipher }
}

/// AES Key Wrap, as defined in RFC 3394.
///
/// The `out` buffer will be overwritten, and must be exactly [`IV_LEN`]
Expand Down Expand Up @@ -424,6 +418,27 @@ where
}
}

impl<Aes> KeyInit for Kek<Aes>
where
Aes: KeyInit + BlockSizeUser<BlockSize = U16> + BlockCipherEncrypt + BlockCipherDecrypt,
{
fn new(key: &Key<Self>) -> Self {
let cipher = Aes::new(key);
Kek { cipher }
}
}

impl<Aes> KeySizeUser for Kek<Aes>
where
Aes: KeyInit + BlockSizeUser<BlockSize = U16> + BlockCipherEncrypt + BlockCipherDecrypt,
{
type KeySize = Aes::KeySize;

fn key_size() -> usize {
Aes::key_size()
}
}

struct WCtx<'a> {
n: usize,
block: &'a mut Block<Self>,
Expand Down

0 comments on commit a7db55d

Please sign in to comment.