commit f6eaa54b060a7aad7fc57a33ef8fe4e97b52e556
parent 10cf862cee4e13cf11557802ef8f56342b3e3f1b
Author: Jared Tobin <jared@jtobin.ca>
Date: Thu, 1 Jun 2017 21:32:13 +1200
Tweaks.
Diffstat:
2 files changed, 8 insertions(+), 14 deletions(-)
diff --git a/lib/aes_ecb/src/main.rs b/lib/aes_ecb/src/main.rs
@@ -7,15 +7,7 @@ use openssl::symm::{Cipher, Crypter, Mode};
use std::io::{self, Read};
use clap::{App, Arg};
-fn fixed_xor(target: Vec<u8>, partner: Vec<u8>) -> Vec<u8> {
- assert_eq!(target.len(), partner.len());
-
- target
- .iter()
- .zip(partner)
- .map(|(&l, r)| l ^ r)
- .collect()
-}
+const KEY_SIZE: usize = 16;
fn crypt(cipher: Cipher,
mode: Mode,
@@ -30,7 +22,7 @@ fn crypt(cipher: Cipher,
let decrypted_len = match crypter.update(&input, result.as_mut_slice()) {
Ok(val) => val,
- Err(err) => panic!("{}", err)
+ Err(err) => panic!("couldn't calculate len: {}", err)
};
(&result[0..decrypted_len]).to_vec()
@@ -45,7 +37,7 @@ fn new_crypter_unpadded(
let mut crypter = match Crypter::new(cipher, mode, key, iv) {
Ok(val) => val,
- Err(err) => panic!("{}", err)
+ Err(err) => panic!("can't create crypter: {}", err)
};
crypter.pad(false);
@@ -81,7 +73,7 @@ fn main() {
let decoded = match base64::decode(&buffer) {
Ok(val) => val,
- Err(err) => panic!("{}", err)
+ Err(err) => panic!("can't decode from base64: {}", err)
};
let mode = match args.occurrences_of("mode") {
@@ -91,7 +83,7 @@ fn main() {
let key = match args.value_of("key") {
Some(text) =>
- if text.len() == 16 {
+ if text.len() == KEY_SIZE {
text.as_bytes()
} else {
panic!("invalid key length!");
diff --git a/lib/ecb_detector/src/main.rs b/lib/ecb_detector/src/main.rs
@@ -4,6 +4,8 @@ extern crate base64;
use std::collections::HashSet;
use std::io::{self, Read};
+const KEY_SIZE: usize = 16;
+
fn ecb_detector(encoded: &[u8], size: usize) -> bool {
let mut blocks = HashSet::new();
@@ -28,7 +30,7 @@ fn main() {
Err(err) => panic!("{}", err)
};
- let ecb = ecb_detector(&decoded[..], 16);
+ let ecb = ecb_detector(&decoded[..], KEY_SIZE);
if ecb {
println!("likely ecb");