Why aren't cryptographic hash functions used in data structures?
-
While some algorithms like MD5 haven't quite stood the test of time with regards to the security industry, others like the SHA family of functions have (thus far). Yet despite the discovery, or theoretical existence of collisions within their domains, cryptographic hash functions still provide an incredibly well distributed range of fixed length output mappings for data of arbitrary length and type â why arenât they used in data structures more often? Isnât the goal of a hash table (provided a good function) to map every input to a unique key, such that chaining, nested tables and other collision handling techniques become entirely moot? Itâs certainly convenient being able to feed almost anything to a function, and know the exact length of the key you will receive! Seems like an ideal use for retired security protocols to me.
-
Answer:
I would like to read other answers, as I'm not an expert. Cryptographic functions are stronger than general hash functions, in the sense that they don't only avoid collisions, but also don't reveal any information about the original text. This last constraint is not required for a hash function used in a hash table, for example. So, usually the hash functions for purposes other than cryptography are more efficient. Other point, which I think is more important, is that, for instance, SHA outputs a number that is 160-512 bits long. I don't see how can this be really useful for a hashtable, for example. Usually, hash functions for hashtables use the 'mod' operator in order to generate values that fit the table size. And that generates the collision problem. So, collision problem is, in my view, inherent to hashtables and not (totally) related to underlying hash function. Obviously that a good hash function would minimize such problem, but not eliminate it. (sorry for any english mistakes)
Anonymous at Quora Visit the source
Other answers
Cryptographic hash functions such as SHA1 are expensive to compute compared to the simple hash functions being used in most hash-tables. It turns out that in practice, if you want to make your code run fast, it's important to keep the hash-functions computations very simple and fast, and in fact, most implementations optimize for a faster hash function than for its hashing quality.
Omer Strulovich
We use hash tables because we can have fast lookup. Theoretically, with a proper hash function, we can have a lookup in O(1). Cryptographic hash functions like SHA-1 shall produce a hash where the probability of collision is negligible. So yes, I do agree that it can be used as a proper hash function. But computing the hash is quite expensive when compared with a simple mod hash function used in hash tables. Moreover the hash is 160 bits long, which means that the hash table can hash to 2^160 locations. If each location is just 1 bit long, the size of hash table is 2^160 bits = 2^82 ZB. As of 2013, the entire size of WWW is thought to be about 4 ZB. Now that's SHA-1, which has been broken for years now, and most of us have already moved to SHA-2, which produces even longer hash [224 - 512 bits]. Think about the size of hash tables now.
Robin Thomas
Related Q & A:
- Why doesn't MySQL upload my data properly?Best solution by php-mysql-tutorial.com
- Why can't WD-40 or other petroleum based lubricants be used on airsoft guns?Best solution by Yahoo! Answers
- Why aren't images in Wikipedia displayed?Best solution by Yahoo! Answers
- Why aren't Youtube comments shown?Best solution by Yahoo! Answers
- Why aren't any programs opening on my computer?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.