cryptopals

Matasano's cryptopals challenges (cryptopals.com).
Log | Files | Refs | README | LICENSE

commit 82199b959a615099180a4ba71867a76735b35fb4
parent 9e353091275011ee2b74f13ccea30e21d65ddcdb
Author: Jared Tobin <jared@jtobin.ca>
Date:   Fri, 19 May 2017 18:31:00 +1200

Misc fixes.

Diffstat:
Mdocs/s1.md | 4+---
Mlib/aes_ecb/src/main.rs | 30+++++++++++++++++++++---------
2 files changed, 22 insertions(+), 12 deletions(-)

diff --git a/docs/s1.md b/docs/s1.md @@ -156,11 +156,9 @@ I like openssl, heck the rules: Alternatively: $ cat data/s1/q7_input.txt | tr -d '\n' | ./bin/aes_ecb | head -2 - 'm back and I'm ringin' the bell + I'm back and I'm ringin' the bell A rockin' on the mike while the fly girls yell -NB. missing the initial 'I' there for some reason. - #### 1.8 $ cat data/s1/q8_input.txt | parallel \ diff --git a/lib/aes_ecb/src/main.rs b/lib/aes_ecb/src/main.rs @@ -5,6 +5,24 @@ extern crate openssl; use openssl::symm::{Cipher, Crypter, Mode}; use std::io::{self, Read}; +fn new_crypter_unpadded( + cipher: Cipher, + mode: Mode, + key: &[u8], + iv: Option<&[u8]> + ) -> Crypter { + let mut crypter = match Crypter::new(cipher, mode, key, iv) { + Ok(val) => val, + Err(err) => panic!("{}", err) + }; + + crypter.pad(false); + + crypter +} + +// FIXME better command line args + fn main() { let mut buffer = String::new(); @@ -22,21 +40,15 @@ fn main() { let key = b"YELLOW SUBMARINE"; let iv = None; - let mut crypter = match Crypter::new(cipher, mode, key, iv) { - Ok(val) => val, - Err(err) => panic!("{}", err) - }; - - crypter.pad(false); - - let mut result = vec![0u8; decoded_len + cipher.key_len()]; + let mut crypter = new_crypter_unpadded(cipher, mode, key, iv); + let mut result = vec![0u8; decoded_len + cipher.key_len()]; let decrypted_len = match crypter.update(&decoded, result.as_mut_slice()) { Ok(val) => val, Err(err) => panic!("{}", err) }; - let output = &result[1..decrypted_len]; + let output = &result[0..decrypted_len]; println!("{}", String::from_utf8_lossy(output)); }