Home > Mobile >  Is there a good 32 bit Hash-function to use for idempotence?
Is there a good 32 bit Hash-function to use for idempotence?

Time:08-08

We try to implement idempotence. We do not want to process two times the same file. In our process I change the file to a base64 string. I thought about using a Hash-Algorithm to parse this string into a 32 bit Hash-String. I can only use a 32bit Hash-String, since the proccess after mine is expecting only this field length.

I thought about using MD5, but it does not seem like the best solution. I am not sure how an attack will affect the outcome of our process like it's explained here:

https://security.stackexchange.com/questions/19906/is-md5-considered-insecure

Can someone help me out with a good Hash-Algorithm or how I can make sure that MD5 is no security problem for my situation?

CodePudding user response:

There's no such thing as a "secure" 32 bit hash. Any 32 bit hash will require at most ~2^32 units of work to find a message that generates a given target hash, and ~2^16 units of work to find 2 messages with the same hash. In fact depending on access patterns it's likely that you will accidentally encounter multiple messages with the same hash. You need to figure out what the consequences of those attacks would be, and if you can't tolerate them then you need a larger hash size or a different design.

If you don't need any security guarantees then md5 truncated to 32 bits will likely meet your needs, but you may find one of the 32-bit hash algorithms in Guava Hashing to be simpler to use and better optimised for your use case.

  • Related