Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do cryptographic hashes provide really unique results?

Tags:

algorithm

hash

I was wondering whether md5, sha1 and anothers return unique values.

For example, sha1() for test returns a94a8fe5ccb19ba61c4c0873d391e987982fbbd3, which is 40 characters long. So, sha1 for strings larger than 40 chars must be the same (of course it's scrambled, because the given input may contain whitespaces and special chars etc.).

Due to this, when we are storing users' passwords, they can enter either their original password or some super-long one, which nobody knows.

Is this right, or do these hash algorithms provide really unique results - I'm quite sure it's hardly possible.

like image 535
Mikulas Dite Avatar asked Jun 17 '10 09:06

Mikulas Dite


1 Answers

(Note: You're asking about hashing functions, not encryption).

It's impossible for them to be unique, by definition. They take a large input and reduce its size. It obviously follows, then, that they can't represent all the information they have compressed. So no, they don't provide "truly unique" results.

What they do provide, however, is "collision resistant" results. I.e. they try and show that two slightly different datas produce a significantly different hash.

like image 61
Noon Silk Avatar answered Sep 22 '22 06:09

Noon Silk