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
2 changes: 2 additions & 0 deletions cipher/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Removed
- `BlockCipherEncrypt::encrypt_padded*` and `BlockCipherDecrypt::decrypt_padded*` methods.
Users of the ECB mode should use the `ecb-mode` crate instead. ([#2245])
- `AsyncStreamCipher` trait ([#2280])

[#1759]: https://github.com/RustCrypto/traits/pull/1759
[#2052]: https://github.com/RustCrypto/traits/pull/2052
[#2237]: https://github.com/RustCrypto/traits/pull/2237
[#2245]: https://github.com/RustCrypto/traits/pull/2245
[#2280]: https://github.com/RustCrypto/traits/pull/2280

## 0.4.4 (2022-03-09)
### Changed
Expand Down
74 changes: 0 additions & 74 deletions cipher/src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
//! See the [RustCrypto/stream-ciphers](https://github.com/RustCrypto/stream-ciphers) repository
//! for ciphers implementation.

use crate::block::{BlockModeDecrypt, BlockModeEncrypt};
use common::Block;
use inout::{InOutBuf, NotEqualError};

mod core_api;
Expand All @@ -20,78 +18,6 @@ pub use errors::{OverflowError, StreamCipherError};
#[cfg(feature = "stream-wrapper")]
pub use wrapper::StreamCipherCoreWrapper;

/// Asynchronous stream cipher trait.
pub trait AsyncStreamCipher: Sized {
/// Encrypt data using `InOutBuf`.
fn encrypt_inout(mut self, data: InOutBuf<'_, '_, u8>)
where
Self: BlockModeEncrypt,
{
let (blocks, mut tail) = data.into_chunks();
self.encrypt_blocks_inout(blocks);
let n = tail.len();
if n != 0 {
let mut block = Block::<Self>::default();
block[..n].copy_from_slice(tail.get_in());
self.encrypt_block(&mut block);
tail.get_out().copy_from_slice(&block[..n]);
}
}

/// Decrypt data using `InOutBuf`.
fn decrypt_inout(mut self, data: InOutBuf<'_, '_, u8>)
where
Self: BlockModeDecrypt,
{
let (blocks, mut tail) = data.into_chunks();
self.decrypt_blocks_inout(blocks);
let n = tail.len();
if n != 0 {
let mut block = Block::<Self>::default();
block[..n].copy_from_slice(tail.get_in());
self.decrypt_block(&mut block);
tail.get_out().copy_from_slice(&block[..n]);
}
}
/// Encrypt data in place.
fn encrypt(self, buf: &mut [u8])
where
Self: BlockModeEncrypt,
{
self.encrypt_inout(buf.into());
}

/// Decrypt data in place.
fn decrypt(self, buf: &mut [u8])
where
Self: BlockModeDecrypt,
{
self.decrypt_inout(buf.into());
}

/// Encrypt data from buffer to buffer.
///
/// # Errors
/// Returns [`NotEqualError`] if provided `in_buf` and `out_buf` have different lengths.
fn encrypt_b2b(self, in_buf: &[u8], out_buf: &mut [u8]) -> Result<(), NotEqualError>
where
Self: BlockModeEncrypt,
{
InOutBuf::new(in_buf, out_buf).map(|b| self.encrypt_inout(b))
}

/// Decrypt data from buffer to buffer.
///
/// # Errors
/// Returns [`NotEqualError`] if provided `in_buf` and `out_buf` have different lengths.
fn decrypt_b2b(self, in_buf: &[u8], out_buf: &mut [u8]) -> Result<(), NotEqualError>
where
Self: BlockModeDecrypt,
{
InOutBuf::new(in_buf, out_buf).map(|b| self.decrypt_inout(b))
}
}

/// Stream cipher trait.
///
/// This trait applies only to synchronous stream ciphers, which generate a keystream and
Expand Down