1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
macro_rules! constuct_cipher {
    ($name:ident, $sbox:expr) => {

        #[derive(Clone, Copy)]
        pub struct $name {
            c: Gost89
        }

        impl BlockCipher for $name {
            type KeySize = U32;
            type BlockSize = U8;
            type ParBlocks = U1;

            fn new(key: &GenericArray<u8, U32>) -> Self {
                let mut c = Gost89 { sbox: &$sbox, key: Default::default() };
                LE::read_u32_into(key, &mut c.key);
                Self { c }
            }

            #[inline]
            fn encrypt_block(&self, block: &mut Block) {
                self.c.encrypt(block);
            }

            #[inline]
            fn decrypt_block(&self, block: &mut Block) {
                self.c.decrypt(block);
            }
        }

        impl_opaque_debug!($name);
    }
}