1 use crate::Result; 2 3 /// Block cipher mode of operation. 4 /// 5 /// Block modes govern how a block cipher processes data spanning multiple blocks. 6 pub trait Mode { 7 /// Block size of the underlying cipher in bytes. block_size(&self) -> usize8 fn block_size(&self) -> usize; 9 10 /// Encrypt a single block `src` using the initialization vector `iv` to a ciphertext block `dst`. Both `iv` and dst` are updated. 11 /// The buffer `iv`, `dst` and `src` are expected to be at least as large as the block size of 12 /// the underlying cipher. encrypt( &mut self, iv: &mut [u8], dst: &mut [u8], src: &[u8], ) -> Result<()>13 fn encrypt( 14 &mut self, 15 iv: &mut [u8], 16 dst: &mut [u8], 17 src: &[u8], 18 ) -> Result<()>; 19 20 /// Decrypt a single ciphertext block `src` using the initialization vector `iv` to a plaintext block `dst`. Both `iv` and dst` are updated. 21 /// The buffer `iv`, `dst` and `src` are expected to be at least as large as the block size of 22 /// the underlying cipher. decrypt( &mut self, iv: &mut [u8], dst: &mut [u8], src: &[u8], ) -> Result<()>23 fn decrypt( 24 &mut self, 25 iv: &mut [u8], 26 dst: &mut [u8], 27 src: &[u8], 28 ) -> Result<()>; 29 } 30