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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
macro_rules! gost94_impl {
    ($state:ident, $sbox:expr) => {
        use digest::{consts::U32, BlockInput, FixedOutputDirty, Reset, Update};
        use $crate::gost94::{Block, Gost94, SBox};

        /// GOST94 state
        #[derive(Clone)]
        pub struct $state {
            sh: Gost94,
        }

        impl Default for $state {
            fn default() -> Self {
                $state {
                    sh: Gost94::new($sbox, Block::default()),
                }
            }
        }

        impl BlockInput for $state {
            type BlockSize = U32;
        }

        impl Update for $state {
            fn update(&mut self, input: impl AsRef<[u8]>) {
                let input = input.as_ref();
                self.sh.update(input);
            }
        }

        impl FixedOutputDirty for $state {
            type OutputSize = U32;

            fn finalize_into_dirty(&mut self, out: &mut digest::Output<Self>) {
                self.sh.finalize_into_dirty(out)
            }
        }

        impl Reset for $state {
            fn reset(&mut self) {
                self.sh.reset()
            }
        }

        opaque_debug::implement!($state);
        digest::impl_write!($state);
    };
}