diff --git a/cipher/CHANGELOG.md b/cipher/CHANGELOG.md index 1efe36504..cc959c7ef 100644 --- a/cipher/CHANGELOG.md +++ b/cipher/CHANGELOG.md @@ -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 diff --git a/cipher/src/stream.rs b/cipher/src/stream.rs index 42ea8b72d..33902bb19 100644 --- a/cipher/src/stream.rs +++ b/cipher/src/stream.rs @@ -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; @@ -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::::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::::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