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
20 changes: 10 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 20 additions & 16 deletions belt-mac/src/block_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ use digest::{
array::{Array, ArraySize},
block_api::{
AlgorithmName, Block, BlockSizeUser, Buffer, BufferKindUser, FixedOutputCore, Lazy,
UpdateCore,
SmallBlockSizeUser, UpdateCore,
},
common::{BlockSizes, InnerInit, InnerUser},
block_buffer::BlockSizes,
common::{InnerInit, InnerUser},
};

#[cfg(feature = "zeroize")]
Expand All @@ -18,7 +19,7 @@ use digest::zeroize::{Zeroize, ZeroizeOnDrop};
#[derive(Clone)]
pub struct BeltMacCore<C = BeltBlock>
where
C: BlockCipherEncrypt + Clone,
C: BlockCipherEncrypt + SmallBlockSizeUser + Clone,
{
cipher: C,
state: Block<C>,
Expand All @@ -27,30 +28,30 @@ where

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

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

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

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

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

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

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

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

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

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

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

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

#[inline(always)]
fn xor<N: ArraySize>(buf: &mut Array<u8, N>, data: &Array<u8, N>) {
Expand Down
3 changes: 2 additions & 1 deletion belt-mac/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ pub use digest::{self, KeyInit, Mac};
pub mod block_api;

use cipher::BlockCipherEncrypt;
use digest::block_api::SmallBlockSizeUser;

digest::buffer_fixed!(
/// BeltMac instance generic over block cipher.
pub struct GenericBeltMac<C: BlockCipherEncrypt + Clone>(block_api::BeltMacCore<C>);
pub struct GenericBeltMac<C: BlockCipherEncrypt + SmallBlockSizeUser + Clone>(block_api::BeltMacCore<C>);
impl: ResetMacTraits AlgorithmName InnerInit;
);

Expand Down
36 changes: 20 additions & 16 deletions cbc-mac/src/block_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ use digest::{
array::{Array, ArraySize},
block_api::{
AlgorithmName, Block, BlockSizeUser, Buffer, BufferKindUser, Eager, FixedOutputCore,
UpdateCore,
SmallBlockSizeUser, UpdateCore,
},
common::{BlockSizes, InnerInit, InnerUser},
block_buffer::BlockSizes,
common::{InnerInit, InnerUser},
};

#[cfg(feature = "zeroize")]
Expand All @@ -17,38 +18,38 @@ use digest::zeroize::{Zeroize, ZeroizeOnDrop};
#[derive(Clone)]
pub struct CbcMacCore<C>
where
C: BlockCipherEncrypt + Clone,
C: BlockCipherEncrypt + SmallBlockSizeUser + Clone,
{
cipher: C,
state: Block<C>,
}

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

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

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

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

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

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

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

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

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

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

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

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

#[inline(always)]
fn xor<N: ArraySize>(buf: &mut Array<u8, N>, data: &Array<u8, N>) {
Expand Down
6 changes: 3 additions & 3 deletions cbc-mac/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#![forbid(unsafe_code)]
#![warn(missing_docs)]

pub use digest::{self, KeyInit, Mac};
pub use digest::{self, KeyInit, Mac, block_api::SmallBlockSizeUser};

mod block_api;

Expand All @@ -18,13 +18,13 @@ use digest::block_api::CoreProxy;

digest::buffer_fixed!(
/// Generic CBC-MAC instance.
pub struct CbcMac<C: BlockCipherEncrypt + Clone>(block_api::CbcMacCore<C>);
pub struct CbcMac<C: BlockCipherEncrypt + SmallBlockSizeUser + Clone>(block_api::CbcMacCore<C>);
impl: ResetMacTraits InnerInit;
);

impl<C> AlgorithmName for CbcMac<C>
where
C: BlockCipherEncrypt + Clone + AlgorithmName,
C: BlockCipherEncrypt + SmallBlockSizeUser + Clone + AlgorithmName,
{
fn write_alg_name(f: &mut fmt::Formatter<'_>) -> fmt::Result {
<Self as CoreProxy>::Core::write_alg_name(f)
Expand Down
9 changes: 5 additions & 4 deletions cmac/src/block_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ use digest::{
array::{Array, ArraySize},
block_api::{
AlgorithmName, Block, BlockSizeUser, Buffer, BufferKindUser, FixedOutputCore, Lazy,
UpdateCore,
SmallBlockSizeUser, UpdateCore,
},
common::{BlockSizes, InnerInit, InnerUser},
block_buffer::BlockSizes,
common::{InnerInit, InnerUser},
};

#[cfg(feature = "zeroize")]
Expand Down Expand Up @@ -139,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: BlockSizeUser + BlockCipherEncrypt + Clone {
pub trait CmacCipher: SmallBlockSizeUser + BlockCipherEncrypt + Clone {
/// Double block. See the [`Dbl`] trait docs for more information.
fn dbl(block: Block<Self>) -> Block<Self>;
}

impl<C> CmacCipher for C
where
Self: BlockSizeUser + BlockCipherEncrypt + Clone,
Self: SmallBlockSizeUser + BlockCipherEncrypt + Clone,
Block<Self>: Dbl,
{
fn dbl(block: Block<Self>) -> Block<Self> {
Expand Down
Loading