Skip to content

Commit 9745ef6

Browse files
authored
cfb8: remove tail processing (#105)
The code was copied from the `AsyncStreamCipher` trait and can be specialized for CFB-8.
1 parent 1403f56 commit 9745ef6

2 files changed

Lines changed: 6 additions & 16 deletions

File tree

cfb8/src/decrypt.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,10 @@ where
7373
{
7474
/// Decrypt data using `InOutBuf`.
7575
pub fn decrypt_inout(&mut self, data: InOutBuf<'_, '_, u8>) {
76-
let (blocks, mut tail) = data.into_chunks();
76+
let (blocks, tail) = data.into_chunks();
77+
// Block size is equal to 1 byte, so the tail must be always empty
78+
assert!(tail.is_empty());
7779
self.decrypt_blocks_inout(blocks);
78-
let n = tail.len();
79-
if n != 0 {
80-
let mut block = Block::<Self>::default();
81-
block[..n].copy_from_slice(tail.get_in());
82-
self.decrypt_block(&mut block);
83-
tail.get_out().copy_from_slice(&block[..n]);
84-
}
8580
}
8681

8782
/// Decrypt data in place.

cfb8/src/encrypt.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,10 @@ where
7373
{
7474
/// Encrypt data using `InOutBuf`.
7575
pub fn encrypt_inout(&mut self, data: InOutBuf<'_, '_, u8>) {
76-
let (blocks, mut tail) = data.into_chunks();
76+
let (blocks, tail) = data.into_chunks();
77+
// Block size is equal to 1 byte, so the tail must be always empty
78+
assert!(tail.is_empty());
7779
self.encrypt_blocks_inout(blocks);
78-
let n = tail.len();
79-
if n != 0 {
80-
let mut block = Block::<Self>::default();
81-
block[..n].copy_from_slice(tail.get_in());
82-
self.encrypt_block(&mut block);
83-
tail.get_out().copy_from_slice(&block[..n]);
84-
}
8580
}
8681

8782
/// Encrypt data in place.

0 commit comments

Comments
 (0)