summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2015-05-13 19:01:17 -0400
committerJesse Luehrs <doy@tozt.net>2015-05-13 19:01:17 -0400
commit14b532933eaef71ead0d716b7b23db3c22df00d6 (patch)
treeab1a0e8d3d5ab6f08f2adfc308246b39c9ada480 /tests
parenta8143dc0ec29bff92787be1abfa580109cca139c (diff)
downloadmatasano-14b532933eaef71ead0d716b7b23db3c22df00d6.tar.gz
matasano-14b532933eaef71ead0d716b7b23db3c22df00d6.zip
problem 29
Diffstat (limited to 'tests')
-rw-r--r--tests/set4.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/set4.rs b/tests/set4.rs
index 495f548..1d31a85 100644
--- a/tests/set4.rs
+++ b/tests/set4.rs
@@ -133,3 +133,25 @@ fn problem_27 () {
}
// problem 28 is just matasano::sha1_mac
+
+#[test]
+fn problem_29 () {
+ let key: Vec<u8> = ::rand::thread_rng()
+ .gen_iter()
+ .take(::rand::thread_rng().gen_range(5, 25))
+ .collect();
+
+ let valid_input = b"comment1=cooking%20MCs;userdata=foo;comment2=%20like%20a%20pound%20of%20bacon";
+ let valid_mac = matasano::sha1_mac(valid_input, &key[..]);
+ let possibles = matasano::crack_sha1_mac_length_extension(valid_input, valid_mac, b";admin=true");
+ assert!(
+ possibles.iter().all(|&(ref input, _)| {
+ input.ends_with(b";admin=true")
+ })
+ );
+ assert!(
+ possibles.iter().any(|&(ref input, ref mac)| {
+ &matasano::sha1_mac(&input[..], &key[..])[..] == &mac[..]
+ })
+ );
+}