Clean up sha-1 and start with md4 implementation
This commit is contained in:
95
src/md4.rs
Normal file
95
src/md4.rs
Normal file
@@ -0,0 +1,95 @@
|
||||
// MD4 implementation based on https://docs.rs/md4/latest/md4/
|
||||
use crate::bytes::Bytes;
|
||||
|
||||
// #[derive(Clone)]
|
||||
// pub struct Md4Core {
|
||||
// block_len: u64,
|
||||
// state: [u32; 4],
|
||||
// }
|
||||
|
||||
// impl Default for Md4Core {
|
||||
// #[inline]
|
||||
// fn default() -> Self {
|
||||
// let state = [0x6745_2301, 0xEFCD_AB89, 0x98BA_DCFE, 0x1032_5476];
|
||||
// Self {
|
||||
// state,
|
||||
// block_len: 0,
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// fn compress(state: &mut [u32; 4], input: &Block<Md4Core>) {
|
||||
// fn f(x: u32, y: u32, z: u32) -> u32 {
|
||||
// (x & y) | (!x & z)
|
||||
// }
|
||||
|
||||
// fn g(x: u32, y: u32, z: u32) -> u32 {
|
||||
// (x & y) | (x & z) | (y & z)
|
||||
// }
|
||||
|
||||
// fn h(x: u32, y: u32, z: u32) -> u32 {
|
||||
// x ^ y ^ z
|
||||
// }
|
||||
|
||||
// fn op1(a: u32, b: u32, c: u32, d: u32, k: u32, s: u32) -> u32 {
|
||||
// a.wrapping_add(f(b, c, d)).wrapping_add(k).rotate_left(s)
|
||||
// }
|
||||
|
||||
// fn op2(a: u32, b: u32, c: u32, d: u32, k: u32, s: u32) -> u32 {
|
||||
// a.wrapping_add(g(b, c, d))
|
||||
// .wrapping_add(k)
|
||||
// .wrapping_add(0x5A82_7999)
|
||||
// .rotate_left(s)
|
||||
// }
|
||||
|
||||
// fn op3(a: u32, b: u32, c: u32, d: u32, k: u32, s: u32) -> u32 {
|
||||
// a.wrapping_add(h(b, c, d))
|
||||
// .wrapping_add(k)
|
||||
// .wrapping_add(0x6ED9_EBA1)
|
||||
// .rotate_left(s)
|
||||
// }
|
||||
|
||||
// let mut a = state[0];
|
||||
// let mut b = state[1];
|
||||
// let mut c = state[2];
|
||||
// let mut d = state[3];
|
||||
|
||||
// // load block to data
|
||||
// let mut data = [0u32; 16];
|
||||
// for (o, chunk) in data.iter_mut().zip(input.chunks_exact(4)) {
|
||||
// *o = u32::from_le_bytes(chunk.try_into().unwrap());
|
||||
// }
|
||||
|
||||
// // round 1
|
||||
// for &i in &[0, 4, 8, 12] {
|
||||
// a = op1(a, b, c, d, data[i], 3);
|
||||
// d = op1(d, a, b, c, data[i + 1], 7);
|
||||
// c = op1(c, d, a, b, data[i + 2], 11);
|
||||
// b = op1(b, c, d, a, data[i + 3], 19);
|
||||
// }
|
||||
|
||||
// // round 2
|
||||
// for i in 0..4 {
|
||||
// a = op2(a, b, c, d, data[i], 3);
|
||||
// d = op2(d, a, b, c, data[i + 4], 5);
|
||||
// c = op2(c, d, a, b, data[i + 8], 9);
|
||||
// b = op2(b, c, d, a, data[i + 12], 13);
|
||||
// }
|
||||
|
||||
// // round 3
|
||||
// for &i in &[0, 2, 1, 3] {
|
||||
// a = op3(a, b, c, d, data[i], 3);
|
||||
// d = op3(d, a, b, c, data[i + 8], 9);
|
||||
// c = op3(c, d, a, b, data[i + 4], 11);
|
||||
// b = op3(b, c, d, a, data[i + 12], 15);
|
||||
// }
|
||||
|
||||
// state[0] = state[0].wrapping_add(a);
|
||||
// state[1] = state[1].wrapping_add(b);
|
||||
// state[2] = state[2].wrapping_add(c);
|
||||
// state[3] = state[3].wrapping_add(d);
|
||||
// }
|
||||
|
||||
pub fn hash(_bytes: &Bytes) -> Bytes {
|
||||
Bytes::from_hex("31d6cfe0d16ae931b73c59d7e0c089c0")
|
||||
}
|
||||
Reference in New Issue
Block a user