summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2015-04-07 01:05:28 -0400
committerJesse Luehrs <doy@tozt.net>2015-04-07 01:05:28 -0400
commit4213d57bdf70b6339bc4affdc751c296f9aa14f0 (patch)
treed5edc98e6a650e3c08734724b91e98f6d4ec7deb
parent6c827b1db129cb4d60e4cc27d6f6759b79773aa2 (diff)
downloadmatasano-4213d57bdf70b6339bc4affdc751c296f9aa14f0.tar.gz
matasano-4213d57bdf70b6339bc4affdc751c296f9aa14f0.zip
problem 25
-rw-r--r--Cargo.toml4
-rw-r--r--data/25.txt79
-rw-r--r--src/crack.rs8
-rw-r--r--src/lib.rs1
-rw-r--r--tests/set4.rs50
5 files changed, 142 insertions, 0 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 2fb4b94..bbbd731 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -15,6 +15,10 @@ path = "tests/set2.rs"
name = "set3"
path = "tests/set3.rs"
+[[test]]
+name = "set4"
+path = "tests/set4.rs"
+
[dependencies]
rustc-serialize = "0.3"
openssl = "0.5"
diff --git a/data/25.txt b/data/25.txt
new file mode 100644
index 0000000..14283df
--- /dev/null
+++ b/data/25.txt
@@ -0,0 +1,79 @@
+I'm back and I'm ringin' the bell
+A rockin' on the mike while the fly girls yell
+In ecstasy in the back of me
+Well that's my DJ Deshay cuttin' all them Z's
+Hittin' hard and the girlies goin' crazy
+Vanilla's on the mike, man I'm not lazy.
+
+I'm lettin' my drug kick in
+It controls my mouth and I begin
+To just let it flow, let my concepts go
+My posse's to the side yellin', Go Vanilla Go!
+
+Smooth 'cause that's the way I will be
+And if you don't give a damn, then
+Why you starin' at me
+So get off 'cause I control the stage
+There's no dissin' allowed
+I'm in my own phase
+The girlies sa y they love me and that is ok
+And I can dance better than any kid n' play
+
+Stage 2 -- Yea the one ya' wanna listen to
+It's off my head so let the beat play through
+So I can funk it up and make it sound good
+1-2-3 Yo -- Knock on some wood
+For good luck, I like my rhymes atrocious
+Supercalafragilisticexpialidocious
+I'm an effect and that you can bet
+I can take a fly girl and make her wet.
+
+I'm like Samson -- Samson to Delilah
+There's no denyin', You can try to hang
+But you'll keep tryin' to get my style
+Over and over, practice makes perfect
+But not if you're a loafer.
+
+You'll get nowhere, no place, no time, no girls
+Soon -- Oh my God, homebody, you probably eat
+Spaghetti with a spoon! Come on and say it!
+
+VIP. Vanilla Ice yep, yep, I'm comin' hard like a rhino
+Intoxicating so you stagger like a wino
+So punks stop trying and girl stop cryin'
+Vanilla Ice is sellin' and you people are buyin'
+'Cause why the freaks are jockin' like Crazy Glue
+Movin' and groovin' trying to sing along
+All through the ghetto groovin' this here song
+Now you're amazed by the VIP posse.
+
+Steppin' so hard like a German Nazi
+Startled by the bases hittin' ground
+There's no trippin' on mine, I'm just gettin' down
+Sparkamatic, I'm hangin' tight like a fanatic
+You trapped me once and I thought that
+You might have it
+So step down and lend me your ear
+'89 in my time! You, '90 is my year.
+
+You're weakenin' fast, YO! and I can tell it
+Your body's gettin' hot, so, so I can smell it
+So don't be mad and don't be sad
+'Cause the lyrics belong to ICE, You can call me Dad
+You're pitchin' a fit, so step back and endure
+Let the witch doctor, Ice, do the dance to cure
+So come up close and don't be square
+You wanna battle me -- Anytime, anywhere
+
+You thought that I was weak, Boy, you're dead wrong
+So come on, everybody and sing this song
+
+Say -- Play that funky music Say, go white boy, go white boy go
+play that funky music Go white boy, go white boy, go
+Lay down and boogie and play that funky music till you die.
+
+Play that funky music Come on, Come on, let me hear
+Play that funky music white boy you say it, say it
+Play that funky music A little louder now
+Play that funky music, white boy Come on, Come on, Come on
+Play that funky music
diff --git a/src/crack.rs b/src/crack.rs
index 39a8e1a..abfd84a 100644
--- a/src/crack.rs
+++ b/src/crack.rs
@@ -427,6 +427,14 @@ pub fn recover_mt19937_key_from_time (token: &[u8]) -> Option<u32> {
return None;
}
+pub fn crack_aes_128_ctr_random_access<F> (ciphertext: &[u8], edit: F) -> Vec<u8> where F: Fn(&[u8], usize, &[u8]) -> Vec<u8> {
+ let empty_plaintext: Vec<u8> = ::std::iter::repeat(b'\x00')
+ .take(ciphertext.len())
+ .collect();
+ let keystream = edit(ciphertext, 0, &empty_plaintext[..]);
+ return fixed_xor(&keystream[..], ciphertext);
+}
+
fn crack_single_byte_xor_with_confidence (input: &[u8]) -> (u8, f64) {
let mut min_diff = 100.0;
let mut best_key = 0;
diff --git a/src/lib.rs b/src/lib.rs
index 2d6ebeb..6cfb2d3 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -42,3 +42,4 @@ pub use crack::recover_mersenne_twister_seed_from_time;
pub use crack::clone_mersenne_twister_from_output;
pub use crack::recover_16_bit_mt19937_key;
pub use crack::recover_mt19937_key_from_time;
+pub use crack::crack_aes_128_ctr_random_access;
diff --git a/tests/set4.rs b/tests/set4.rs
new file mode 100644
index 0000000..3967f85
--- /dev/null
+++ b/tests/set4.rs
@@ -0,0 +1,50 @@
+extern crate matasano;
+extern crate rand;
+
+use rand::Rng;
+
+mod util;
+
+#[test]
+fn problem_25 () {
+ let key = util::random_aes_128_key();
+ let nonce: u64 = rand::thread_rng().gen();
+ let plaintext = util::read("data/25.txt");
+
+ let ciphertext = matasano::aes_128_ctr(&plaintext[..], &key[..], nonce);
+ let edit = |ciphertext: &[u8], offset: usize, newtext: &[u8]| {
+ let block_start_number = offset / 16;
+ let block_start = block_start_number * 16;
+ let block_end_number = (offset + newtext.len() - 1) / 16;
+ let block_end = std::cmp::min(
+ (block_end_number + 1) * 16,
+ ciphertext.len()
+ );
+ let mut plaintext = matasano::aes_128_ctr_with_counter(
+ &ciphertext[block_start..block_end],
+ &key[..],
+ nonce,
+ (offset / 16) as u64
+ );
+ for i in 0..newtext.len() {
+ plaintext[offset - block_start + i] = newtext[i];
+ }
+ let new_ciphertext = matasano::aes_128_ctr_with_counter(
+ &plaintext[..],
+ &key[..],
+ nonce,
+ (offset / 16) as u64
+ );
+
+ return ciphertext
+ .iter()
+ .take(block_start)
+ .chain(new_ciphertext.iter())
+ .chain(ciphertext.iter().skip(block_end))
+ .map(|x| *x)
+ .collect();
+ };
+
+ let got = matasano::crack_aes_128_ctr_random_access(&ciphertext[..], edit);
+ assert_eq!(&got[..], &plaintext[..]);
+}