Skip to content
Merged
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
31 changes: 15 additions & 16 deletions belt-mac/src/block_api.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use belt_block::BeltBlock;
use cipher::{BlockCipherEncBackend, BlockCipherEncClosure, BlockCipherEncrypt};
use core::fmt;
use digest::{
Expand All @@ -17,9 +16,9 @@ use digest::zeroize::{Zeroize, ZeroizeOnDrop};

/// Generic core BeltMac instance, which operates over blocks.
#[derive(Clone)]
pub struct BeltMacCore<C = BeltBlock>
pub struct BeltMacCore<C>
where
C: BlockCipherEncrypt + SmallBlockSizeUser + Clone,
C: BlockCipherEncrypt + SmallBlockSizeUser,
{
cipher: C,
state: Block<C>,
Expand All @@ -28,30 +27,30 @@ where

impl<C> BlockSizeUser for BeltMacCore<C>
where
C: BlockCipherEncrypt + SmallBlockSizeUser + Clone,
C: BlockCipherEncrypt + SmallBlockSizeUser,
{
type BlockSize = C::BlockSize;
}

impl<C> OutputSizeUser for BeltMacCore<C>
where
C: BlockCipherEncrypt + SmallBlockSizeUser + Clone,
C: BlockCipherEncrypt + SmallBlockSizeUser,
{
type OutputSize = C::BlockSize;
}

impl<C> InnerUser for BeltMacCore<C>
where
C: BlockCipherEncrypt + SmallBlockSizeUser + Clone,
C: BlockCipherEncrypt + SmallBlockSizeUser,
{
type Inner = C;
}

impl<C> MacMarker for BeltMacCore<C> where C: BlockCipherEncrypt + SmallBlockSizeUser + Clone {}
impl<C> MacMarker for BeltMacCore<C> where C: BlockCipherEncrypt + SmallBlockSizeUser {}

impl<C> InnerInit for BeltMacCore<C>
where
C: BlockCipherEncrypt + SmallBlockSizeUser + Clone,
C: BlockCipherEncrypt + SmallBlockSizeUser,
{
#[inline]
fn inner_init(cipher: C) -> Self {
Expand All @@ -64,14 +63,14 @@ where

impl<C> BufferKindUser for BeltMacCore<C>
where
C: BlockCipherEncrypt + SmallBlockSizeUser + Clone,
C: BlockCipherEncrypt + SmallBlockSizeUser,
{
type BufferKind = Lazy;
}

impl<C> UpdateCore for BeltMacCore<C>
where
C: BlockCipherEncrypt + SmallBlockSizeUser + Clone,
C: BlockCipherEncrypt + SmallBlockSizeUser,
{
#[inline]
fn update_blocks(&mut self, blocks: &[Block<Self>]) {
Expand Down Expand Up @@ -101,7 +100,7 @@ where

impl<C> Reset for BeltMacCore<C>
where
C: BlockCipherEncrypt + SmallBlockSizeUser + Clone,
C: BlockCipherEncrypt + SmallBlockSizeUser,
{
#[inline(always)]
fn reset(&mut self) {
Expand All @@ -111,7 +110,7 @@ where

impl<C> FixedOutputCore for BeltMacCore<C>
where
C: BlockCipherEncrypt + SmallBlockSizeUser + Clone,
C: BlockCipherEncrypt + SmallBlockSizeUser,
{
#[inline]
fn finalize_fixed_core(&mut self, buffer: &mut Buffer<Self>, out: &mut Output<Self>) {
Expand Down Expand Up @@ -148,7 +147,7 @@ where

impl<C> AlgorithmName for BeltMacCore<C>
where
C: BlockCipherEncrypt + SmallBlockSizeUser + Clone,
C: BlockCipherEncrypt + SmallBlockSizeUser,
{
fn write_alg_name(f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("BeltMac")
Expand All @@ -157,7 +156,7 @@ where

impl<C> fmt::Debug for BeltMacCore<C>
where
C: BlockCipherEncrypt + SmallBlockSizeUser + Clone,
C: BlockCipherEncrypt + SmallBlockSizeUser,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("BeltMacCore { ... }")
Expand All @@ -167,7 +166,7 @@ where
#[cfg(feature = "zeroize")]
impl<C> Drop for BeltMacCore<C>
where
C: BlockCipherEncrypt + SmallBlockSizeUser + Clone,
C: BlockCipherEncrypt + SmallBlockSizeUser,
{
fn drop(&mut self) {
self.state.zeroize();
Expand All @@ -176,7 +175,7 @@ where

#[cfg(feature = "zeroize")]
impl<C> ZeroizeOnDrop for BeltMacCore<C> where
C: BlockCipherEncrypt + SmallBlockSizeUser + Clone + ZeroizeOnDrop
C: BlockCipherEncrypt + SmallBlockSizeUser + ZeroizeOnDrop
{
}

Expand Down
5 changes: 3 additions & 2 deletions belt-mac/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ use digest::block_api::SmallBlockSizeUser;

digest::buffer_fixed!(
/// BeltMac instance generic over block cipher.
pub struct GenericBeltMac<C: BlockCipherEncrypt + SmallBlockSizeUser + Clone>(block_api::BeltMacCore<C>);
impl: ResetMacTraits AlgorithmName InnerInit;
#[derive(Clone)]
pub struct GenericBeltMac<C: BlockCipherEncrypt + SmallBlockSizeUser>(block_api::BeltMacCore<C>);
impl: BaseFixedTraits MacMarker Reset FixedOutputReset AlgorithmName InnerInit;
);

/// BeltMac instance.
Expand Down
28 changes: 14 additions & 14 deletions cbc-mac/src/block_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,38 +18,38 @@ use digest::zeroize::{Zeroize, ZeroizeOnDrop};
#[derive(Clone)]
pub struct CbcMacCore<C>
where
C: BlockCipherEncrypt + SmallBlockSizeUser + Clone,
C: BlockCipherEncrypt + SmallBlockSizeUser,
{
cipher: C,
state: Block<C>,
}

impl<C> BlockSizeUser for CbcMacCore<C>
where
C: BlockCipherEncrypt + SmallBlockSizeUser + Clone,
C: BlockCipherEncrypt + SmallBlockSizeUser,
{
type BlockSize = C::BlockSize;
}

impl<C> OutputSizeUser for CbcMacCore<C>
where
C: BlockCipherEncrypt + SmallBlockSizeUser + Clone,
C: BlockCipherEncrypt + SmallBlockSizeUser,
{
type OutputSize = C::BlockSize;
}

impl<C> InnerUser for CbcMacCore<C>
where
C: BlockCipherEncrypt + SmallBlockSizeUser + Clone,
C: BlockCipherEncrypt + SmallBlockSizeUser,
{
type Inner = C;
}

impl<C> MacMarker for CbcMacCore<C> where C: BlockCipherEncrypt + SmallBlockSizeUser + Clone {}
impl<C> MacMarker for CbcMacCore<C> where C: BlockCipherEncrypt + SmallBlockSizeUser {}

impl<C> InnerInit for CbcMacCore<C>
where
C: BlockCipherEncrypt + SmallBlockSizeUser + Clone,
C: BlockCipherEncrypt + SmallBlockSizeUser,
{
#[inline]
fn inner_init(cipher: C) -> Self {
Expand All @@ -60,14 +60,14 @@ where

impl<C> BufferKindUser for CbcMacCore<C>
where
C: BlockCipherEncrypt + SmallBlockSizeUser + Clone,
C: BlockCipherEncrypt + SmallBlockSizeUser,
{
type BufferKind = Eager;
}

impl<C> UpdateCore for CbcMacCore<C>
where
C: BlockCipherEncrypt + SmallBlockSizeUser + Clone,
C: BlockCipherEncrypt + SmallBlockSizeUser,
{
#[inline]
fn update_blocks(&mut self, blocks: &[Block<Self>]) {
Expand Down Expand Up @@ -97,7 +97,7 @@ where

impl<C> Reset for CbcMacCore<C>
where
C: BlockCipherEncrypt + SmallBlockSizeUser + Clone,
C: BlockCipherEncrypt + SmallBlockSizeUser,
{
#[inline(always)]
fn reset(&mut self) {
Expand All @@ -107,7 +107,7 @@ where

impl<C> FixedOutputCore for CbcMacCore<C>
where
C: BlockCipherEncrypt + SmallBlockSizeUser + Clone,
C: BlockCipherEncrypt + SmallBlockSizeUser,
{
#[inline]
fn finalize_fixed_core(&mut self, buffer: &mut Buffer<Self>, out: &mut Output<Self>) {
Expand All @@ -123,7 +123,7 @@ where

impl<C> AlgorithmName for CbcMacCore<C>
where
C: BlockCipherEncrypt + SmallBlockSizeUser + Clone + AlgorithmName,
C: BlockCipherEncrypt + SmallBlockSizeUser + AlgorithmName,
{
fn write_alg_name(f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("CbcMac<")?;
Expand All @@ -134,7 +134,7 @@ where

impl<C> fmt::Debug for CbcMacCore<C>
where
C: BlockCipherEncrypt + SmallBlockSizeUser + Clone + AlgorithmName,
C: BlockCipherEncrypt + SmallBlockSizeUser + AlgorithmName,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("CbcMacCore<")?;
Expand All @@ -146,7 +146,7 @@ where
#[cfg(feature = "zeroize")]
impl<C> Drop for CbcMacCore<C>
where
C: BlockCipherEncrypt + SmallBlockSizeUser + Clone,
C: BlockCipherEncrypt + SmallBlockSizeUser,
{
fn drop(&mut self) {
self.state.zeroize();
Expand All @@ -155,7 +155,7 @@ where

#[cfg(feature = "zeroize")]
impl<C> ZeroizeOnDrop for CbcMacCore<C> where
C: BlockCipherEncrypt + SmallBlockSizeUser + Clone + ZeroizeOnDrop
C: BlockCipherEncrypt + SmallBlockSizeUser + ZeroizeOnDrop
{
}

Expand Down
7 changes: 4 additions & 3 deletions cbc-mac/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ use digest::block_api::CoreProxy;

digest::buffer_fixed!(
/// Generic CBC-MAC instance.
pub struct CbcMac<C: BlockCipherEncrypt + SmallBlockSizeUser + Clone>(block_api::CbcMacCore<C>);
impl: ResetMacTraits InnerInit;
#[derive(Clone)]
pub struct CbcMac<C: BlockCipherEncrypt + SmallBlockSizeUser>(block_api::CbcMacCore<C>);
impl: BaseFixedTraits MacMarker Reset FixedOutputReset InnerInit;
);

impl<C> AlgorithmName for CbcMac<C>
where
C: BlockCipherEncrypt + SmallBlockSizeUser + Clone + AlgorithmName,
C: BlockCipherEncrypt + SmallBlockSizeUser + AlgorithmName,
{
fn write_alg_name(f: &mut fmt::Formatter<'_>) -> fmt::Result {
<Self as CoreProxy>::Core::write_alg_name(f)
Expand Down
4 changes: 2 additions & 2 deletions cmac/src/block_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,14 @@ fn xor<N: ArraySize>(buf: &mut Array<u8, N>, data: &Array<u8, N>) {
}

/// Helper trait implemented for cipher supported by CMAC
pub trait CmacCipher: SmallBlockSizeUser + BlockCipherEncrypt + Clone {
pub trait CmacCipher: SmallBlockSizeUser + BlockCipherEncrypt {
/// Double block. See the [`Dbl`] trait docs for more information.
fn dbl(block: Block<Self>) -> Block<Self>;
}

impl<C> CmacCipher for C
where
Self: SmallBlockSizeUser + BlockCipherEncrypt + Clone,
Self: SmallBlockSizeUser + BlockCipherEncrypt,
Block<Self>: Dbl,
{
fn dbl(block: Block<Self>) -> Block<Self> {
Expand Down
3 changes: 2 additions & 1 deletion cmac/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ use digest::block_api::{AlgorithmName, CoreProxy};

digest::buffer_fixed!(
/// Generic CMAC instance.
#[derive(Clone)]
pub struct Cmac<C: CmacCipher>(block_api::CmacCore<C>);
impl: ResetMacTraits InnerInit;
impl: BaseFixedTraits MacMarker Reset FixedOutputReset InnerInit;
);

impl<C: CmacCipher + AlgorithmName> AlgorithmName for Cmac<C> {
Expand Down
4 changes: 2 additions & 2 deletions pmac/src/block_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ fn xor<N: ArraySize>(buf: &mut Array<u8, N>, data: &Array<u8, N>) {
///
/// Currently this trait is implemented for all block cipher encryptors
/// with block size equal to 64 and 128 bits.
pub trait PmacCipher: SmallBlockSizeUser + BlockCipherEncrypt + Clone {
pub trait PmacCipher: SmallBlockSizeUser + BlockCipherEncrypt {
/// Double block. See the [`Dbl`] trait docs for more information.
fn dbl(block: Block<Self>) -> Block<Self>;
/// Reverse double block.. See the [`Dbl`] trait docs for more information.
Expand All @@ -226,7 +226,7 @@ pub trait PmacCipher: SmallBlockSizeUser + BlockCipherEncrypt + Clone {

impl<C> PmacCipher for C
where
Self: SmallBlockSizeUser + BlockCipherEncrypt + Clone,
Self: SmallBlockSizeUser + BlockCipherEncrypt,
Block<Self>: Dbl,
{
fn dbl(block: Block<Self>) -> Block<Self> {
Expand Down
3 changes: 2 additions & 1 deletion pmac/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ use digest::block_api::{AlgorithmName, CoreProxy};

digest::buffer_fixed!(
/// Generic PMAC instance with `LC_SIZE` = 20.
#[derive(Clone)]
pub struct Pmac<C: PmacCipher>(block_api::PmacCore<C, 20>);
impl: ResetMacTraits InnerInit;
impl: BaseFixedTraits MacMarker Reset FixedOutputReset InnerInit;
);

impl<C: PmacCipher + AlgorithmName> AlgorithmName for Pmac<C> {
Expand Down
Loading