Is it okay to truncate a SHA256 hash to 128 bits?

Posted by Sunny Hirai on Stack Overflow See other posts from Stack Overflow or by Sunny Hirai
Published on 2010-06-11T22:54:43Z Indexed on 2010/06/11 23:02 UTC
Read the original article Hit count: 268

Filed under:
|
|
|

MD5 and SHA-1 hashes have weaknesses against collision attacks. SHA256 does not but it outputs 256 bits. Can I safely take the first or last 128 bits and use that as the hash? I know it will be weaker (because it has less bits) but otherwise will it work?

Basically I want to use this to uniquely identify files in a file system that might one day contain a trillion files. I'm aware of the birthday problem and a 128 bit hash should yield about a 1 in a trillion chance on a trillion files that there would be two different files with the same hash. I can live with those odds.

What I can't live with is if somebody could easily, deliberately, insert a new file with the same hash and the same beginning characters of the file. I believe in MD5 and SHA1 this is possible.

© Stack Overflow or respective owner

Related posts about hash

Related posts about md5