Skip to main content
2 of 2
replaced http://security.stackexchange.com/ with https://security.stackexchange.com/

Since hash functions have a much larger input space than output space, collisions are a normal feature, and it is expected that every possible output corresponds to a lot of matching inputs.

As a rule, collisions are not a problem for password hashing. The previous paragraph means that, for every hash output (in particular the one stored in the server database) then there are many matching passwords which are all equivalent. However:

  • to find any single password which matches the stored output, you have to break preimage resistance of the hash function;
  • to find a second password which yields the same hash than a known password, you have to break second preimage resistance of the hash function.

A "cryptographically secure" hash function with an output of n bits ought to offer resistance 2n to both kind of attacks, so no real problem here. Known a collision in abstracto does not give much power to any attacker: the attacker can use a given password, and he has a "spare" with the same effect; so what ?

As for the reduction of space when iterating the function, see this previous answer. Summary: space reduction does occur, but not below an inner space of size 2n/2, which moreover:

  • requires a lot of effort to be actually reached;
  • cannot be efficiently characterized (you cannot easily know if a given value is part of that inner space or not).

Use SHA-256 and be happy.

Thomas Pornin
  • 328.6k
  • 60
  • 800
  • 969