Skip to main content

primitives/ciphers/
block.rs

1use aes::{cipher::BlockEncrypt, Aes128Enc};
2
3use crate::{algebra::field::binary::Gf2_128, types::Positive};
4
5pub type U8x16 = Gf2_128;
6
7pub trait BlockCipher {
8    type Block: AsRef<[u8]> + AsMut<[u8]> + Default + Copy;
9    type BlockByteLen: Positive;
10
11    fn encrypt(&self, inp: &Self::Block) -> Self::Block;
12}
13
14impl BlockCipher for Aes128Enc {
15    type Block = Gf2_128;
16    type BlockByteLen = typenum::U16;
17
18    fn encrypt(&self, block: &U8x16) -> U8x16 {
19        let mut out_block = U8x16::default();
20        self.encrypt_block_b2b(&block.to_le_block(), out_block.as_ne_block_mut());
21        out_block
22    }
23}