开发者

Does truncating a sha-160 hash produce a reasonable hash?

开发者 https://www.devze.com 2023-02-18 07:53 出处:网络
I have a sha-160 computation that开发者_运维百科 gives me a 160 bit hash of my data, but I expect this is way larger than necessary. So I\'m thinking I could truncate the resulting hash down to say th

I have a sha-160 computation that开发者_运维百科 gives me a 160 bit hash of my data, but I expect this is way larger than necessary. So I'm thinking I could truncate the resulting hash down to say the low 64 bits and use that.

Does taking the low 64 bits of a sha-160 hash computation give a reasonably random 64 bit hash?


Part of what it means for something to be a good hash is that any fixed subset of its bits is also (so far as possible, given how many bits) a good hash. The low 64 bits of a SHA-160 hash should be a good 64-bit hash, in so far as there is such a thing.

Note that for some purposes 64 bits really isn't all that many. For instance, if anything breaks in your application when someone finds two different things with the same hash, you probably want something longer: on average it will only take a modest number of billions of trials to find two things with the same 64-bit hash, no matter what your hashing algorithm.

What bad thing would happen if you just used all 160 bits?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号