MD4

Type Alias MD4 

Source
pub type MD4 = MD4_Generic;
Expand description

The official MD4 hash algorithm

§Quick Start

In order to use the module MD4, you don’t have to import (or use) cryptocol::hash::md4::md4 directly because the module cryptocol::hash::md4 is re-exported. All you have to do is only import MD4 in the module cryptocol::hash. Example shows how to import and use MD4.

§Example

use std::string::*;
use cryptocol::hash::MD4;
 
let mut hash = MD4::new();
 
let mut txt = "";
hash.digest_str(txt);
println!("Msg =\t\"{}\"\nHash =\t{}\n", txt, hash);
assert_eq!(hash.get_hash_value_in_string(), "31D6CFE0D16AE931B73C59D7E0C089C0");
 
let txt_stirng = String::from("A");
hash.digest_string(&txt_stirng);
println!("Msg =\t\"{}\"\nHash =\t{}\n", txt_stirng, hash);
assert_eq!(hash.to_string(), "D5EF20EEB3F75679F86CF57F93ED0FFE");
 
let txt_array = ['W' as u8, 'o' as u8, 'w' as u8];
hash.digest_array(&txt_array);
println!("Msg =\t\"{:?}\"\nHash =\t{}\n", txt_array, hash);
assert_eq!(hash.get_hash_value_in_string(), "6407C0E728DA762A04924ADFE630974C");
 
txt = "This data is 26-byte long.";
hash.digest_str(txt);
println!("Msg =\t\"{}\"\nHash =\t{}\n", txt, hash);
assert_eq!(hash.to_string(), "4F4A24D124B996BEA395344419F9A06B");
 
txt = "The unit of data length is not byte but bit.";
hash.digest_str(txt);
println!("Msg =\t\"{}\"\nHash =\t{}\n", txt, hash);
assert_eq!(hash.get_hash_value_in_string(), "9DE35D8FCF68E74867FFB63F28625ABE");
 
txt = "I am testing MD4 for the data whose length is sixty-two bytes.";
hash.digest_str(txt);
println!("Msg =\t\"{}\"\nHash =\t{}\n", txt, hash);
assert_eq!(hash.to_string(), "3A9F1487472B3A4315E0C90DC5CB3A2E");
 
txt = "I am testing MD4 for the message which is sixty-four bytes long.";
hash.digest_str(txt);
println!("Msg =\t\"{}\"\nHash =\t{}\n", txt, hash);
assert_eq!(hash.get_hash_value_in_string(), "6CDB5B2BFF823A4A7B23675180EB7BEF");
 
txt = "I am testing MD4 for the case data whose length is more than sixty-four bytes is given.";
hash.digest_str(txt);
println!("Msg =\t\"{}\"\nHash =\t{}", txt, hash);
assert_eq!(hash.to_string(), "56771653687981390B0EB2A7D0A40DBB");

Aliased Type§

pub struct MD4 { /* private fields */ }