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
macro_rules! gost94_impl {
    ($state:ident, $sbox:expr) => {

    use $crate::gost94::{Gost94, SBox, Block};
    use digest;
    use digest::generic_array::GenericArray;
    use digest::generic_array::typenum::U32;

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

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

    impl Default for $state {
        fn default() -> Self {
            Self::new()
        }
    }

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

    impl digest::Input for $state {
        fn process(&mut self, input: &[u8]) {
            self.sh.process(input);
        }
    }

    impl digest::FixedOutput for $state {
        type OutputSize = U32;

        fn fixed_result(self) -> GenericArray<u8, Self::OutputSize> {
            self.sh.fixed_result()
        }
    }

    impl_opaque_debug!($state);
}}