note 52500 deleted from function.md5 by joey
| From: | joey@php.net | Date: | Sun, 17 Jul 2011 08:45:40 +0000 |
| Subject: | note 52500 deleted from function.md5 by joey | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-181618@lists.php.net to get a copy of this message | ||
Note Submitter: tommiboy
----
Regarding those many posts about MD5 and this-or-that hash function being "broken" or
insecure because it has collisions, please note the following:
1. Every hash function has collisions, that is what hash functions are made for. MD5, as an example,
turns N bits of input into 128 bits of output. Obviously, whenever N > 128 bits, then there MUST
be collisions. This does not mean the function is broken, it means that the function does EXACTLY
what you want it to do - it makes a secret unrecoverable.
The important thing about "secure" hash functions is that it is hard to calculate an input
that will produce a certain output (e.g. the same output as another user's password). It is
impossible to reconstruct a password from a hash if the password has more than 128 bits since
several passwords necessarily map to the same hash. No matter which supercomputers you use, you have
a set of equations with several unknowns. It is possible to find SOME password that produces a valid
hash, though.
For every reasonable scenario, however, MD5 will do just fine. If you are concerned, store the
password length as well.
2. Chaining the hash function means 128 bits of input producing 128 bits of output, this does not
make sense, really. In fact, you greatly increase the likelihood of finding SOME password that
produces the same double-hash.
3. Chaining MD5 with SHA makes little sense, too, as you feed 128 bits into a function that returns
256 bits. So the information that you keep around is 50% redundant. Security is in no way enhanced.
4. You can add "salt", i.e. a constant or variable string (for example calculated from the
user id) that is concatenated to the input of the hash function, but that does not really make
things a lot better. It does make a dictionary attack against a stolen password database harder, if
nothing else.
5. Concerns about this-or-that hash being not good enough are rather silly since there are a lot of
other ways which are by several orders of magnitude cheaper and easier to break into your system. It
is not likely that any sane person will attempt to find collisions of a hash function to break into
one single account. Users are only too happy to give out their password to "the administator
who must verify that their password is correct".
6. What happens if two users accidentially choose passwords that have a hash collision? First, this
will probably never happen, and second, if it does happen, then there is not much harm. Two users
can have the same password and none of them will ever notice.