HMAC-MD5 (HMAC with MD5)
Overview
Section titled “Overview”HMAC-MD5 is a message authentication code built from HMAC (Keyed-Hash Message Authentication Code) using MD5. It is not encryption; it produces a tag from a key and message to detect tampering. Treat the spelling variant “HMCA-MD5” as referring to HMAC-MD5.
How it is computed
Section titled “How it is computed”MD5 has a 64-byte block size.
- Normalize the key
- If the key is longer than 64 bytes:
K = MD5(K) - If the key is shorter than 64 bytes:
K = K || 0x00...(zero-pad to 64 bytes)
- If the key is longer than 64 bytes:
- Prepare 64 bytes of
ipad = 0x36and 64 bytes ofopad = 0x5c - Inner hash:
MD5((K ⊕ ipad) || message) - Outer hash:
MD5((K ⊕ opad) || inner)
The formula is:
HMAC(K, m) = MD5((K ⊕ opad) || MD5((K ⊕ ipad) || m))
Use in NTLMv2
Section titled “Use in NTLMv2”- NTLMv2 Hash:
HMAC-MD5(key=NTHash, msg=Uppercase(Username) + Domain)Username/Domainare UTF-16LE. - NTProofStr:
HMAC-MD5(key=NTLMv2 Hash, msg=ServerChallenge + Blob) - NTLMv2 Response:
NTProofStr || Blob
Security considerations
Section titled “Security considerations”- HMAC does not rely on MD5’s collision resistance, so it is more secure than plain MD5.
- Even so, HMAC-MD5 is for legacy use; choose a stronger construction such as HMAC-SHA-256 for new designs.
Rust representation
Section titled “Rust representation”[dependencies]hmac = "0.12"md-5 = "0.10"hex = "0.4"use hmac::{Hmac, Mac};use md5::Md5;
type HmacMd5 = Hmac<Md5>;
pub fn hmac_md5(key: &[u8], message: &[u8]) -> [u8; 16] { let mut mac = HmacMd5::new_from_slice(key).expect("HMAC accepts any key size"); mac.update(message); let result = mac.finalize().into_bytes(); let mut out = [0u8; 16]; out.copy_from_slice(&result); out}
fn main() { let tag = hmac_md5(b"key", b"message"); println!("HMAC-MD5: {}", hex::encode(tag));}Related pages
Section titled “Related pages”- For NTHash, see NTHash (NT hash).
- For its use in NTLMv2 responses, see NTLM Authentication.

