Truncating a hash function's output should, in theory, not increase the likelihood of a collision more than you would expect based on the truncated output size. This makes sense when thinking about the the ideal hash function, a random function.

Since real-world hashes are not random functions, what properties of algorithms like sha2 make us comfortable with truncating, and what (popular) hashes exist out there that are known to have issues?


You really should never be truncating a hash. Really you're talking about the difference between traditional hashing algorithms and cryptographic hashing algorithms. A cryptographic hash algorithm has to not be predictable, while a traditional hash algorithm doesn't have that concern. You aren't guaranteed perfect random distribution, so really you shouldn't ever be truncating a hash in any situation.

Could you specify a situation where people "feel comfortable truncating a SHA2 hash"? I don't know what you're referring to.

  • 3
    $\begingroup$ I feel comfortable truncating SHA2 as long as the truncated size is sufficient for my desired security level. NIST does so as well (consider SHA-512/256 as an example) $\endgroup$ – CodesInChaos Apr 25 '16 at 7:30
  • $\begingroup$ Then there you go. While cryptographic hashes don't create a perfect uniform distribution, they do a 'good enough' job where it's not a concern, and truncation is acceptable. $\endgroup$ – Daisetsu Apr 25 '16 at 7:33

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