Using Cryptographic Hashes for Hash Tables

Choosing a good hash function for a hash table is difficult to say the least.  Even if you can achieve good distribution and performance for a given hash function it`s still most likely dependent on table size and the type of input.  Resizing the table or getting unexpected input can quickly turn an otherwise good choice into a bad one.  Using a cryptographic hash function reduces nearly all of the problems.  Any and all table sizes are now equally supported.  Strings, numbers, and even binary data are all valid input.  And since a change in a single bit of input has an avalanche effect on the output, uniform distribution is achieved.  Really, the only possible negative is performance.  But it`s not nearly as bad as you probably think.  

We tested 100 bytes of random data and did the test 1,000,000 times using the hash functions MD5, SHA1, and a typical MULTIPLIER type hash function.  Of course the basic hash function was the fastest at 0.66 microseconds per hash.  MD5 used 0.78 microseconds per hash while SHA1 consumed 1.02 microseconds per hash.  All in all, the small hit in performance seems well worth the gains in being able to use variable table sizes and any type of input without concern.  Testing was done using wolfSSL`s cryptography functionality in the CTaoCrypt module.