Clean up sha-1 and start with md4 implementation

This commit is contained in:
2022-08-20 13:33:29 -04:00
parent c12b1c45a6
commit 106b8febaf
4 changed files with 187 additions and 45 deletions

View File

@@ -1,4 +1,4 @@
use crate::{bytes::Bytes, cbc, ctr, ecb, parser, sha1, utils};
use crate::{bytes::Bytes, cbc, ctr, ecb, md4, parser, sha1, utils};
pub fn challenge25() {
let cipher = utils::read_base64("data/25.txt");
@@ -139,28 +139,28 @@ pub fn challenge27() {
pub fn challenge28() {
let mut sha1 = sha1::Sha1::default();
let i1 = Bytes(vec![b'a'; 64]);
let e1 = Bytes::from_hex("0098ba824b5c16427bd7a1122a5a442a25ec644d");
let o1 = sha1.hash(&i1);
assert_eq!(e1, o1);
assert_eq!(
Bytes::from_hex("0098ba824b5c16427bd7a1122a5a442a25ec644d"),
sha1.hash(&Bytes(vec![b'a'; 64]))
);
sha1.reset();
let i2 = Bytes(vec![b'a'; 128]);
let e2 = Bytes::from_hex("ad5b3fdbcb526778c2839d2f151ea753995e26a0");
let o2 = sha1.hash(&i2);
assert_eq!(e2, o2);
assert_eq!(
Bytes::from_hex("ad5b3fdbcb526778c2839d2f151ea753995e26a0"),
sha1.hash(&Bytes(vec![b'a'; 128]))
);
sha1.reset();
let i3 = Bytes(vec![b'a'; 3]);
let e3 = Bytes::from_hex("7e240de74fb1ed08fa08d38063f6a6a91462a815");
let o3 = sha1.hash(&i3);
assert_eq!(e3, o3);
assert_eq!(
Bytes::from_hex("7e240de74fb1ed08fa08d38063f6a6a91462a815"),
sha1.hash(&Bytes(vec![b'a'; 3])),
);
sha1.reset();
let i4 = Bytes(vec![]);
let e4 = Bytes::from_hex("da39a3ee5e6b4b0d3255bfef95601890afd80709");
let o4 = sha1.hash(&i4);
assert_eq!(e4, o4);
assert_eq!(
Bytes::from_hex("da39a3ee5e6b4b0d3255bfef95601890afd80709"),
sha1.hash(&Bytes(vec![])),
);
// Verify that you cannot tamper with the message without breaking the MAC
// you've produced, and that you can't produce a new MAC without knowing the
@@ -232,5 +232,42 @@ pub fn challenge29() {
}
pub fn challenge30() {
// Second verse, same as the first, but use MD4 instead of SHA-1. Having
// done this attack once against SHA-1, the MD4 variant should take much
// less time; mostly just the time you'll spend Googling for an
// implementation of MD4.
assert_eq!(
md4::hash(&Bytes::from_utf8("")),
Bytes::from_hex("31d6cfe0d16ae931b73c59d7e0c089c0"),
);
// assert_eq!(
// md4::hash(&Bytes::from_utf8("a")),
// Bytes::from_hex("bde52cb31de33e46245e05fbdbd6fb24"),
// );
// assert_eq!(
// md4::hash(&Bytes::from_utf8("abc")),
// Bytes::from_hex("a448017aaf21d8525fc10ae87aa6729d"),
// );
// assert_eq!(
// md4::hash(&Bytes::from_utf8("message digest")),
// Bytes::from_hex("d9130a8164549fe818874806e1c7014b"),
// );
// assert_eq!(
// md4::hash(&Bytes::from_utf8("abcdefghijklmnopqrstuvwxyz")),
// Bytes::from_hex("d79e1c308aa5bbcdeea8ed63df412da9"),
// );
// assert_eq!(
// md4::hash(&Bytes::from_utf8(
// "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
// )),
// Bytes::from_hex("043f8582f241db351ce627e153e7f0e4"),
// );
// assert_eq!(
// md4::hash(&Bytes::from_utf8(
// "12345678901234567890123456789012345678901234567890123456789012345678901234567890"
// )),
// Bytes::from_hex("e33b4ddc9c38f2199c3e7b164fcc0536"),
// );
println!("[xxxx] Challenge 30: tbd");
}