The cryptographic strength of the HMAC depends upon the size of the secret key that is used and the security of the underlying hash function used. It has been proven that the security of an HMAC construction is directly related to security properties of the hash function used. The most common attack against HMACs is brute force to uncover the secret key. HMACs are substantially less affected by collisions than their underlying hashing algorithms alone. In particular, Mihir Bellare proved that HMAC is a
pseudo-random function (PRF) under the sole assumption that the compression function is a PRF. Therefore, HMAC-MD5 does not suffer from the same weaknesses that have been found in MD5. RFC 2104 requires that "keys longer than
B bytes are first hashed using
H" which leads to a confusing pseudo-collision: if the key is longer than the hash block size (e.g. 64 bytes for SHA-1), then HMAC(k, m) is computed as HMAC(H(k), m). This property is sometimes raised as a possible weakness of HMAC in password-hashing scenarios: it has been demonstrated that it's possible to find a long ASCII string and a random value whose hash will be also an ASCII string, and both values will produce the same HMAC output. In 2006,
Jongsung Kim,
Alex Biryukov,
Bart Preneel, and
Seokhie Hong showed how to distinguish HMAC with reduced versions of MD5 and SHA-1 or full versions of
HAVAL,
MD4, and
SHA-0 from a
random function or HMAC with a random function. Differential distinguishers allow an attacker to devise a forgery attack on HMAC. Furthermore, differential and rectangle distinguishers can lead to
second-preimage attacks. HMAC with the full version of MD4 can be
forged with this knowledge. These attacks do not contradict the security proof of HMAC, but provide insight into HMAC based on existing cryptographic hash functions. In 2009,
Xiaoyun Wang et al. presented a distinguishing attack on HMAC-MD5 without using related keys. It can distinguish an instantiation of HMAC with MD5 from an instantiation with a random function with 297 queries with probability 0.87. In 2011 an informational RFC 6151 was published to summarize security considerations in
MD5 and HMAC-MD5. For HMAC-MD5 the RFC summarizes that – although the security of the
MD5 hash function itself is severely compromised – the currently known
"attacks on HMAC-MD5 do not seem to indicate a practical vulnerability when used as a message authentication code", but it also adds that
"for a new protocol design, a ciphersuite with HMAC-MD5 should not be included". In May 2011, RFC 6234 was published detailing the abstract theory and source code for SHA-based HMACs. ==Examples==