summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2015-03-25 19:40:08 -0400
committerJesse Luehrs <doy@tozt.net>2015-03-25 19:40:08 -0400
commit3eed3478478d54ca44c1842f460b44078ad5316e (patch)
tree79471ef118bd971d454500acb818ce1ee871e725 /tests
parent5797ffea73ebd0981d33064147822051476325d9 (diff)
downloadmatasano-3eed3478478d54ca44c1842f460b44078ad5316e.tar.gz
matasano-3eed3478478d54ca44c1842f460b44078ad5316e.zip
problem 14
Diffstat (limited to 'tests')
-rw-r--r--tests/lib.rs30
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/lib.rs b/tests/lib.rs
index 3ddeae1..3f66d16 100644
--- a/tests/lib.rs
+++ b/tests/lib.rs
@@ -252,3 +252,33 @@ fn problem_13 () {
decrypter(ciphertext).map(|params| params == expected).unwrap_or(false)
}));
}
+
+#[test]
+fn problem_14 () {
+ let padding = b"Um9sbGluJyBpbiBteSA1LjAKV2l0aCBteSByYWct\
+ dG9wIGRvd24gc28gbXkgaGFpciBjYW4gYmxvdwpU\
+ aGUgZ2lybGllcyBvbiBzdGFuZGJ5IHdhdmluZyBq\
+ dXN0IHRvIHNheSBoaQpEaWQgeW91IHN0b3A/IE5v\
+ LCBJIGp1c3QgZHJvdmUgYnkK".from_base64().unwrap();
+ let front_padding: Vec<u8> = thread_rng()
+ .gen_iter()
+ .take(thread_rng().gen_range(1, 100))
+ .collect();
+ let fixed_padding = |input: &[u8]| -> Vec<u8> {
+ return front_padding
+ .iter()
+ .chain(input.iter())
+ .chain(padding.iter())
+ .map(|x| *x)
+ .collect()
+ };
+
+ let key = random_aes_128_key();
+ let random_encrypter = |input: &[u8]| {
+ let padded_input = fixed_padding(input);
+ return matasano::encrypt_aes_128_ecb(&padded_input[..], &key[..]);
+ };
+
+ let got = matasano::crack_padded_aes_128_ecb_with_prefix(&random_encrypter);
+ assert_eq!(got, padding);
+}