33
$\begingroup$

I've read something to the effect that the HMAC construct is able to lessen the problem of collisions in the underlying hash.

Does that mean that something like HMAC-MD5 still might be considered safe for authenticating encrypted data?

$\endgroup$
2

2 Answers 2

39
$\begingroup$

Yes, there are currently no known attacks on HMAC-MD5.

In particular, after the first collision attacks on MD5, Mihir Bellare (one of the inventors of HMAC) came up with a new security proof for HMAC that doesn't require collision resistance:

"Abstract: HMAC was proved by Bellare, Canetti and Krawczyk (1996) to be a PRF assuming that (1) the underlying compression function is a PRF, and (2) the iterated hash function is weakly collision-resistant. However, recent attacks show that assumption (2) is false for MD5 and SHA-1, removing the proof-based support for HMAC in these cases. This paper proves that HMAC is a PRF under the sole assumption that the compression function is a PRF. This recovers a proof based guarantee since no known attacks compromise the pseudorandomness of the compression function, and it also helps explain the resistance-to-attack that HMAC has shown even when implemented with hash functions whose (weak) collision resistance is compromised. We also show that an even weaker-than-PRF condition on the compression function, namely that it is a privacy-preserving MAC, suffices to establish HMAC is a secure MAC as long as the hash function meets the very weak requirement of being computationally almost universal, where again the value lies in the fact that known attacks do not invalidate the assumptions made."

However, this does not mean you should use HMAC-MD5 in new cryptosystem designs. To paraphrase Bruce Schneier, "attacks only get better, never worse." We already have practical collision attacks for MD5, showing that it does not meet its original security goals; it's possible that, any day now, someone might figure out a way to extend those into some new attack which would compromise the security of HMAC-MD5. A much better choice would be to use HMAC with a hash function having no known attacks, such as SHA-2 or SHA-3.

$\endgroup$
3
  • $\begingroup$ SHA-2 has known attacks: en.wikipedia.org/wiki/SHA-2 $\endgroup$
    – baptx
    Aug 2, 2019 at 13:43
  • 3
    $\begingroup$ @baptx Any cryptographic primitive has "known attacks". The question is if they break the full amount of rounds significantly. For SHA-2 they currently don't. Unless you can substantiate that SHA-2 has been broken with any significance, I would want to remove these comments from the answer. $\endgroup$
    – Maarten Bodewes
    Sep 19, 2019 at 10:42
  • $\begingroup$ "recent attacks show that assumption (2) is false for MD5" which recent attacks? the chosen-prefix attack? why does it mean that? $\endgroup$ Dec 29, 2019 at 16:23
6
$\begingroup$

Ilmari Karonen's answer is correct when HMAC is used for its intended purpose, but that doesn't mean that HMAC is completely unaffected by MD5's collisions:

hmac

Given a specific Key, note that K xor opad and K xor ipad are independent of the message m. This means that any collision in H((K xor ipad) || m) will result in a colliding HMAC, even with two different messages.

For HmacMd5, K xor ipad would be 64 bytes long. So if you find two messages m1 and m2 with at least a 64 byte common prefix pre, you can calculate a key K = pre xor ipad that will create a collision between H((K xor ipad) || m1) and H((K xor ipad) || m2), leading to a complete collision in the whole HMAC.

This can be exploited two ways:

  • You don't trust the person that generated the key, and HMAC is being misused as a sort of checksum.
  • An attacker gains access to the key, and can use MD5's chosen prefix attack to cause collisions.

But as the accepted answer states, if the key is secret and controlled by you or trusted parties, HmacMd5 is still secure.

$\endgroup$
3
  • 2
    $\begingroup$ Yes, there was already this kind of answer until it got deleted. The question explicitly states "for authenticating encrypted data". The use for calculating checksums and the availability of the key are perpendicular to that part of the question. Welcome to crypto anyway, these kind of well written answers are very welcome here! $\endgroup$
    – Maarten Bodewes
    Jan 23, 2016 at 13:44
  • 4
    $\begingroup$ I agree, however this information will be useful to a lot of people arriving on this page and it does not give incorrect information with respect to the initial question. It states clearly hmacmd5 is still secure if used correctly. $\endgroup$ Jan 23, 2016 at 13:47
  • $\begingroup$ But any algorithm could be insecure if used incorrectly. A private key needs to be kept secret by definition. $\endgroup$
    – Phil_1984_
    Jun 26, 2021 at 1:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.