I've already asked this question on SO, but I think that this forum is more appropriate to discuss security issues.

My point is that most OO languages has a way to get a unique hash code for an object:

  • Python: obj.__hash__()
  • Java: obj.hashCode()
  • .NET: obj.GetHashCode()

It is well known that for Python a Denial of Service vulnerability (pdf from the original congress) has been addressed since version 3.30 through a seed randomization (even though it is not working for a single-window interpreter).

My question is why that concern has been ignored in the default implementation of .Net hash? From a security standpoint, what is the correct approach: shouldn't the same seed randomization be suggested also to .Net framework team developers?


1 Answer 1


The purpose of the hash methods listed (methods provided by common objects to conform to an interface used by standard collections) is to map all possible values for which a hash is calculated to the full range of valid values of the hash value's type. The randomness used in this mapping is not for security. The mapping must be sufficiently random so that sequences and common patterns will not cause uneven distribution in the use of buckets common to hash based collections.

Hash maps, multimaps, and sets may be used in larger security schemes but, by themselves, are not intended to be secure. They are simply collections designed to provide indexed lookup. Hashes used this way provide much faster indices than binary trees.

The term hashCode is actually misleading in this way. Creating a hash for a string type so that a hash map can be indexed using such a string is not an encoding. The resulting hash value arising from such a hashing algorithm may map back to a large number of object values, but the intention in this context is NOT to hide those object values from an attacker.

In the case of MD5 or SHA hash algorithms used in security protocols, the intention is to create a mathematically low probability of guessing the input value from the hash in any practically achievable number of tries. The methods provided by common objects in these languages so that they may be inserted into collections that index them using buckets should NEVER be used to replace the hash algorithms designed to be used in security protocols.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .