jacopone/jacopone/
mod.rs

1mod thread;
2use self::thread::{ParallelThread, FinalThread};
3pub use self::thread::hash;
4use super::cipherdata::*;
5
6
7///enviroment for encryption and decryption
8pub struct Jacopone{
9    parallel_threads: ParallelThread,
10}
11
12impl Jacopone {
13
14    ///create a jacopone enviroment to encrypt/decrypt using thread_count threads
15    /// ```
16    /// use jacopone::*;
17    /// let jacopone = Jacopone::new(4);
18    /// ```
19    pub fn new(thread_count: u8) -> Jacopone {
20        Jacopone {parallel_threads: thread::ParallelThread::new(thread_count)}
21    }
22
23
24    /// encrypt given CipherData
25    ///
26    /// ```
27    /// use jacopone::*;
28    /// let jacopone = Jacopone::new(4);
29    /// let message = "i'm not a safe algorithm".as_bytes().to_vec();
30    /// //I'm sorry, it has to be 60 bytes long
31    /// let nonce = vec![1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
32    ///     0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0];
33    /// let key = vec![12,45,8,43,1,2,65,9,1,4,7,9,1,9,3,5,2,4,9,4,1,2,6,9,1,3,6,9,1,9,4,6];
34    /// let counter = 42;
35    ///
36    /// let data = CipherData::new(message, key, nonce, counter);
37    ///
38    /// let ciphertext = jacopone.encrypt(data);
39    /// ```
40    pub fn encrypt(&self, data: CipherData) -> Vec<u8> {
41        
42        //parallel encryption/decryption
43        let mut ciphertext = self.parallel_threads.encrypt(CipherData::clone(&data));
44        
45        //encryption/decryption of last portion
46        let ending = FinalThread::finalize_encryption(data);
47        ciphertext.extend_from_slice(&ending);
48        ciphertext
49    }
50}