3
$\begingroup$

Out of these algorithms…

  • MD5
  • SHA1
  • SHA224
  • SHA256
  • SHA384
  • SHA512

… which has the least chance of collision, and which is the most secure at the time of writing this?

$\endgroup$
  • 19
    $\begingroup$ you literally ordered them from least secure to most secure $\endgroup$ – Richie Frame May 18 '16 at 18:24
18
$\begingroup$

As Richie Frame noted in the comments, you basically listed them in order of ascending collision resistance.

The latter hashes have greater collision resistance due to their increased output size. With the exception of SHA-1 and MD5, this is denoted by the number in the name of the algorithm. For example, SHA-512 produces 512 bits of output.

The size of the output influences the collision resistance due to the birthday paradox.

To quote Wikipedia:

The "birthday paradox" places an upper bound on collision resistance: if a hash function produces N bits of output, an attacker who computes only $2^{N/2}$ (or $ \sqrt{2^N}$) hash operations on random input is likely to find two matching outputs.

So SHA-512 should have the greatest theoretical collision resistance.

Note that MD5 and SHA1 should probably not be selected as a candidate when developing anything new and should only be used for compatibility purposes when required.

The SHA-2 algorithms calculate their digests in an almost identical manner, so generally we assume they are equally secure, digest sizes aside.

| improve this answer | |
$\endgroup$
  • 5
    $\begingroup$ At this point, I think SHA1 also belongs in the "only for compatibility" category. $\endgroup$ – Gordon Davisson May 19 '16 at 0:58
  • 4
    $\begingroup$ I disagree with the comment about not using MD5 and SHA1. It depends on your intended use for the hash. If you need it for some security-related purposes, then don't use them. If you need them for one of the many other uses for a hash, then they can work better than the more complex, slower functions. Let's say for example finding duplicate records by first hashing all entries in a table, finding duplicate hashes, then comparing the underlying records with matching hashes to see if they are really duplicates or not. The MD5 hash will work great for this purpose and be much faster. $\endgroup$ – Itsme2003 May 19 '16 at 4:18
  • 6
    $\begingroup$ @Itsme2003 I understand and agree with you. However the OP did specifically inquire about the security of the algorithms in question and not their performance. And this is crypto.stackexchange: Generally when people talk about hash functions here, it's implied they are talking about a cryptographically secure one. $\endgroup$ – Ella Rose May 19 '16 at 4:28
  • $\begingroup$ Comments about hash algorithms are correct in that it depends on what one is using them for. For say BloomFilters, faster is generally better since collisions come with the nature of the bit set implementation. $\endgroup$ – Darrell Teague May 30 at 0:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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