Skip to content

Commit

Permalink
crypto-common: move ParBlocks* from cipher crate (#1052)
Browse files Browse the repository at this point in the history
Moves `ParBlocks`/`ParBlocksSizeUser` from the `cipher` crate so it can
be reused in the `universal-hash` crate (see #965, #1051).

The `cipher` crate re-exports them in an API-compatible way, so this is
not a breaking change.
  • Loading branch information
tarcieri committed Jul 16, 2022
1 parent ea33e32 commit 74db581
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
12 changes: 1 addition & 11 deletions cipher/src/lib.rs
Expand Up @@ -51,21 +51,11 @@ pub use crypto_common::{
generic_array,
typenum::{self, consts},
AlgorithmName, Block, InnerIvInit, InvalidLength, Iv, IvSizeUser, Key, KeyInit, KeyIvInit,
KeySizeUser,
KeySizeUser, ParBlocks, ParBlocksSizeUser,
};
use generic_array::{ArrayLength, GenericArray};

/// Trait for loading current IV state.
pub trait IvState: IvSizeUser {
/// Returns current IV state.
fn iv_state(&self) -> Iv<Self>;
}

/// Types which process blocks in parallel.
pub trait ParBlocksSizeUser: BlockSizeUser {
/// Number of blocks which can be processed in parallel.
type ParBlocksSize: ArrayLength<Block<Self>>;
}

/// Parallel blocks on which [`ParBlocksSizeUser`] implementors operate.
pub type ParBlocks<T> = GenericArray<Block<T>, <T as ParBlocksSizeUser>::ParBlocksSize>;
12 changes: 12 additions & 0 deletions crypto-common/src/lib.rs
Expand Up @@ -25,10 +25,16 @@ use rand_core::{CryptoRng, RngCore};

/// Block on which [`BlockSizeUser`] implementors operate.
pub type Block<B> = GenericArray<u8, <B as BlockSizeUser>::BlockSize>;

/// Parallel blocks on which [`ParBlocksSizeUser`] implementors operate.
pub type ParBlocks<T> = GenericArray<Block<T>, <T as ParBlocksSizeUser>::ParBlocksSize>;

/// Output array of [`OutputSizeUser`] implementors.
pub type Output<T> = GenericArray<u8, <T as OutputSizeUser>::OutputSize>;

/// Key used by [`KeySizeUser`] implementors.
pub type Key<B> = GenericArray<u8, <B as KeySizeUser>::KeySize>;

/// Initialization vector (nonce) used by [`IvSizeUser`] implementors.
pub type Iv<B> = GenericArray<u8, <B as IvSizeUser>::IvSize>;

Expand All @@ -51,6 +57,12 @@ impl<T: BlockSizeUser> BlockSizeUser for &mut T {
type BlockSize = T::BlockSize;
}

/// Types which can process blocks in parallel.
pub trait ParBlocksSizeUser: BlockSizeUser {
/// Number of blocks which can be processed in parallel.
type ParBlocksSize: ArrayLength<Block<Self>>;
}

/// Types which return data with the given size.
pub trait OutputSizeUser {
/// Size of the output in bytes.
Expand Down

0 comments on commit 74db581

Please sign in to comment.