Finish challenge 25 and update License
This commit is contained in:
11
src/ctr.rs
11
src/ctr.rs
@@ -1,13 +1,6 @@
|
||||
use crate::bytes::Bytes;
|
||||
use crate::cbc;
|
||||
use openssl::symm;
|
||||
|
||||
fn xor(a: &Vec<u8>, b: &Vec<u8>) -> Vec<u8> {
|
||||
Iterator::zip(a.iter(), b.iter())
|
||||
.map(|z| *(z.0) ^ *(z.1))
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn encrypt(key: &Bytes, nonce: u64, data: &Bytes) -> Bytes {
|
||||
decrypt(key, nonce, data)
|
||||
}
|
||||
@@ -20,8 +13,8 @@ pub fn decrypt(Bytes(key): &Bytes, nonce: u64, Bytes(data): &Bytes) -> Bytes {
|
||||
for cipher in data.chunks(block_size) {
|
||||
let mut keyinput = nonce.to_le_bytes().to_vec();
|
||||
keyinput.append(&mut counter.to_le_bytes().to_vec());
|
||||
let keystream = cbc::enrypt_aes_128_ecb_block(key, &keyinput);
|
||||
let mut data = xor(&keystream, &cipher.to_vec());
|
||||
let keystream = crate::cbc::enrypt_aes_128_ecb_block(key, &keyinput);
|
||||
let mut data = crate::utils::xor(&keystream, &cipher.to_vec());
|
||||
result.append(&mut data);
|
||||
counter += 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user