<commit_before>// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

//use std::vec::Vec;
use aes::{KeySize, KeySize128, KeySize192, KeySize256};
use symmetriccipher::{BlockEncryptor, BlockDecryptor};

pub struct AesNiEncryptor {
    rounds: uint,
    round_keys: Vec<u8>
}

pub struct AesNiDecryptor {
    rounds: uint,
    round_keys: Vec<u8>
}

impl AesNiEncryptor {
    pub fn new(key_size: KeySize, key: &[u8]) -> AesNiEncryptor {
        let (rounds, setup_function) = match key_size {
            KeySize128 => (10, setup_working_key_aesni_128),
            KeySize192 => (12, setup_working_key_aesni_192),
            KeySize256 => (14, setup_working_key_aesni_256)
        };
        let round_keys = Vec::from_elem(16 * (rounds + 1), 0u8);
        let mut e = AesNiEncryptor {
            rounds: rounds,
            round_keys: round_keys
        };
        setup_function(key, Encryption, e.round_keys[mut]);
        return e;
    }
}

impl AesNiDecryptor {
    pub fn new(key_size: KeySize, key: &[u8]) -> AesNiDecryptor {
        let (rounds, setup_function) = match key_size {
            KeySize128 => (10, setup_working_key_aesni_128),
            KeySize192 => (12, setup_working_key_aesni_192),
            KeySize256 => (14, setup_working_key_aesni_256)
        };
        let round_keys = Vec::from_elem(16 * (rounds + 1), 0u8);
        let mut d = AesNiDecryptor {
            rounds: rounds,
            round_keys: round_keys
        };
        setup_function(key, Decryption, d.round_keys[mut]);
        return d;
    }
}

impl BlockEncryptor for AesNiEncryptor {
    fn block_size(&self) -> uint { 16 }
    fn encrypt_block(&self, input: &[u8], output: &mut [u8]) {
        encrypt_block_aseni(self.rounds, input, self.round_keys[], output);
    }
}

impl BlockDecryptor for AesNiDecryptor {
    fn block_size(&self) -> uint { 16 }
    fn decrypt_block(&self, input: &[u8], output: &mut [u8]) {
        decrypt_block_aseni(self.rounds, input, self.round_keys[], output);
    }
}

enum KeyType {
    Encryption,
    Decryption
}

#[inline(always)]<commit_msg>Use array instead of vec for aesni<commit_after>// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use aes::{KeySize, KeySize128, KeySize192, KeySize256};
use symmetriccipher::{BlockEncryptor, BlockDecryptor};

pub struct AesNiEncryptor {
    rounds: uint,
    round_keys: [u8, ..240]
}

pub struct AesNiDecryptor {
    rounds: uint,
    round_keys: [u8, ..240]
}

impl AesNiEncryptor {
    pub fn new(key_size: KeySize, key: &[u8]) -> AesNiEncryptor {
        let (rounds, setup_function) = match key_size {
            KeySize128 => (10, setup_working_key_aesni_128),
            KeySize192 => (12, setup_working_key_aesni_192),
            KeySize256 => (14, setup_working_key_aesni_256)
        };
        let mut e = AesNiEncryptor {
            rounds: rounds,
            round_keys: [0u8, ..240]
        };
        setup_function(key, Encryption, e.round_keys.slice_mut(0, size(e.rounds)));
        return e;
    }
}

impl AesNiDecryptor {
    pub fn new(key_size: KeySize, key: &[u8]) -> AesNiDecryptor {
        let (rounds, setup_function) = match key_size {
            KeySize128 => (10, setup_working_key_aesni_128),
            KeySize192 => (12, setup_working_key_aesni_192),
            KeySize256 => (14, setup_working_key_aesni_256)
        };
        let mut d = AesNiDecryptor {
            rounds: rounds,
            round_keys: [0u8, ..240]
        };
        setup_function(key, Decryption, d.round_keys.slice_mut(0, size(d.rounds)));
        return d;
    }

}

impl BlockEncryptor for AesNiEncryptor {
    fn block_size(&self) -> uint { 16 }
    fn encrypt_block(&self, input: &[u8], output: &mut [u8]) {
        encrypt_block_aseni(self.rounds, input, self.round_keys.slice(0, size(self.rounds))[], output);
    }
}

impl BlockDecryptor for AesNiDecryptor {
    fn block_size(&self) -> uint { 16 }
    fn decrypt_block(&self, input: &[u8], output: &mut [u8]) {
        decrypt_block_aseni(self.rounds, input, self.round_keys.slice(0, size(self.rounds))[], output);
    }
}

enum KeyType {
    Encryption,
    Decryption
}

#[inline(always)]
fn size(rounds: uint) -> uint { 16 * (rounds + 1) }

#[inline(always)]
{'fraction_non_alphanumeric': 0.12521186440677967, 'fraction_numerical': 0.03792372881355932, 'mean_word_length': 2.8792111750205422, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1326470', 'n_tokens_mistral': 1762, 'n_tokens_neox': 1623, 'n_words': 379}