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
//! Block cryptosystems

use generic_array::ArrayLength;
use typenum::uint::Unsigned;

pub mod blowfish;

/// Block encryptor definition
pub trait BlockEncrypt {
    /// Single block size
    type BlockSize: Unsigned + ArrayLength<u8>;

    /// Single block size
    fn block_size() -> usize {
        Self::BlockSize::to_usize()
    }

    /// Encrypt single block of data
    fn encrypt_block<I, O>(&self, input: I, output: O)
        where I: AsRef<[u8]>,
              O: AsMut<[u8]>;
}

/// Block decryptor definition
pub trait BlockDecrypt {
    /// Single block size
    type BlockSize: Unsigned + ArrayLength<u8>;

    /// Single block size
    fn block_size() -> usize {
        Self::BlockSize::to_usize()
    }

    /// Decrypt single block of data
    fn decrypt_block<I, O>(&self, input: I, output: O)
        where I: AsRef<[u8]>,
              O: AsMut<[u8]>;
}