diff --git a/cipher/CHANGELOG.md b/cipher/CHANGELOG.md index a9c211993..1efe36504 100644 --- a/cipher/CHANGELOG.md +++ b/cipher/CHANGELOG.md @@ -13,9 +13,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Seeking implementation in the stream cipher wrapper ([#2052]) +### Removed +- `BlockCipherEncrypt::encrypt_padded*` and `BlockCipherDecrypt::decrypt_padded*` methods. + Users of the ECB mode should use the `ecb-mode` crate instead. ([#2245]) + [#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 ## 0.4.4 (2022-03-09) ### Changed diff --git a/cipher/src/block.rs b/cipher/src/block.rs index a184233a7..b44bd9b3f 100644 --- a/cipher/src/block.rs +++ b/cipher/src/block.rs @@ -81,90 +81,6 @@ pub trait BlockCipherEncrypt: BlockSizeUser + Sized { InOutBuf::new(in_blocks, out_blocks) .map(|blocks| self.encrypt_with_backend(BlocksCtx { blocks })) } - - /// Pad input and encrypt. Returns resulting ciphertext slice. - /// - /// Returns [`PadError`] if length of output buffer is not sufficient. - #[cfg(feature = "block-padding")] - #[inline] - fn encrypt_padded_inout<'out, P: Padding>( - &self, - data: InOutBufReserved<'_, 'out, u8>, - ) -> Result<&'out [u8], PadError> { - let mut buf = data.into_padded_blocks::
()?; - self.encrypt_blocks_inout(buf.get_blocks()); - if let Some(block) = buf.get_tail_block() { - self.encrypt_block_inout(block); - } - Ok(buf.into_out()) - } - - /// Pad input and encrypt in-place. Returns resulting ciphertext slice. - /// - /// Returns [`PadError`] if length of output buffer is not sufficient. - #[cfg(feature = "block-padding")] - #[inline] - fn encrypt_padded<'a, P: Padding>( - &self, - buf: &'a mut [u8], - msg_len: usize, - ) -> Result<&'a [u8], PadError> { - let buf = InOutBufReserved::from_mut_slice(buf, msg_len).map_err(|_| PadError)?; - self.encrypt_padded_inout::
(buf) - } - - /// Pad input and encrypt buffer-to-buffer. Returns resulting ciphertext slice. - /// - /// Returns [`PadError`] if length of output buffer is not sufficient. - #[cfg(feature = "block-padding")] - #[inline] - fn encrypt_padded_b2b<'a, P: Padding>( - &self, - msg: &[u8], - out_buf: &'a mut [u8], - ) -> Result<&'a [u8], PadError> { - let buf = InOutBufReserved::from_slices(msg, out_buf).map_err(|_| PadError)?; - self.encrypt_padded_inout::
(buf)
- }
-
- /// Pad `msg` with padding algorithm `P`, encrypt it into a newly allocated `Vec`,
- /// and return the resulting ciphertext vector.
- ///
- /// # Panics
- /// If `NoPadding` is used with a message size that is not a multiple of the cipher block size.
- #[cfg(all(feature = "block-padding", feature = "alloc"))]
- #[inline]
- fn encrypt_padded_vec ();
- let buf_blocks_len = if pad_type_id == TypeId::of:: (msg, &mut buf)
- .expect("`buf` has enough space for encryption")
- .len();
- buf.truncate(res_len);
- buf
- }
}
/// Decrypt-only functionality for block ciphers.
@@ -218,72 +134,6 @@ pub trait BlockCipherDecrypt: BlockSizeUser {
InOutBuf::new(in_blocks, out_blocks)
.map(|blocks| self.decrypt_with_backend(BlocksCtx { blocks }))
}
-
- /// Decrypt input and unpad it. Returns resulting plaintext slice.
- ///
- /// Returns [`block_padding::Error`] if padding is malformed or if input length is
- /// not multiple of `Self::BlockSize`.
- #[cfg(feature = "block-padding")]
- #[inline]
- fn decrypt_padded_inout<'out, P: Padding>(
- &self,
- data: InOutBuf<'_, 'out, u8>,
- ) -> Result<&'out [u8], block_padding::Error> {
- let (mut blocks, tail) = data.into_chunks();
- if !tail.is_empty() {
- return Err(block_padding::Error);
- }
- self.decrypt_blocks_inout(blocks.reborrow());
- P::unpad_blocks:: (buf.into())
- }
-
- /// Decrypt input and unpad it buffer-to-buffer. Returns resulting
- /// plaintext slice.
- ///
- /// Returns [`block_padding::Error`] if padding is malformed or if input length is
- /// not multiple of `Self::BlockSize`.
- #[cfg(feature = "block-padding")]
- #[inline]
- fn decrypt_padded_b2b<'a, P: Padding>(
- &self,
- in_buf: &[u8],
- out_buf: &'a mut [u8],
- ) -> Result<&'a [u8], block_padding::Error> {
- if out_buf.len() < in_buf.len() {
- return Err(block_padding::Error);
- }
- let n = in_buf.len();
- // note: `new` always returns `Ok` here
- let buf = InOutBuf::new(in_buf, &mut out_buf[..n]).map_err(|_| block_padding::Error)?;
- self.decrypt_padded_inout:: (buf)
- }
-
- /// Decrypt input and unpad it in a newly allocated Vec. Returns resulting
- /// plaintext `Vec`.
- ///
- /// Returns [`block_padding::Error`] if padding is malformed or if input length is
- /// not multiple of `Self::BlockSize`.
- #[cfg(all(feature = "block-padding", feature = "alloc"))]
- #[inline]
- fn decrypt_padded_vec (buf, &mut out)?.len();
- out.truncate(len);
- Ok(out)
- }
}
impl