Mark
Mark

Reputation: 833

Do hashing algorithms guarantee unique outputs if the same salt is used for unique inputs?

We have a view into a system that uses a value for the unique id that another company we want to share information with will not accept. I was thinking of using an one way encryption hash similar to what is done with passwords. The concern is can the hashing algorithm created output values be guaranteed unique if the inputs are guaranteed unique and the salt is constant?

Upvotes: 2

Views: 492

Answers (5)

Woot4Moo
Woot4Moo

Reputation: 24336

In short no. The longer answer is the perfect oracle would be able to solve the question you posed. Since no one has ever proven the existence of a perfect oracle it is currently believed to be impossible. The other side of it isn't that it is impossible just that we as a collective are not intelligent enough to figure this out. Similar to P != NP

Upvotes: 0

Answer is yes. Same id input with same salt will always produce same output.

But, if your question is about guaranteeing that outputs will always be unique, the answer is no. There is a very small statistical probability that the hashing will create the same output twice even if the inputs are different and the salt constant.

Upvotes: 4

Paul Rubel
Paul Rubel

Reputation: 27232

Is your question can two different values hash to the same thing or is it are hashes deterministic?

If it's the former then yes, you can have hash collisions. A well designed cryptographically strong hash should make it difficult to find two values hashing to the same value though or to find an input that matches a given hash but they can't guarantee uniqueness.

By the pigeon-hole principal: if your hash is a constant size, say 64 bits (without loss of generality) you will have at most 2^64 unique output hash values. Since there are more than 2^64 potential inputs if you're using strings, a collision is guaranteed after your hash at most 2^64+1 items.

Upvotes: 3

Paŭlo Ebermann
Paŭlo Ebermann

Reputation: 74790

In principle, there is no hashing algorithm without collisions if the input size is larger than the output size. (In your case, the relevant input size would be the size of this part which changes from one input to the next.)

Whether there are collisions also for shorter inputs is a property of the hashing algorithm, but the idea is that the probability of these should be quite small (about 1/(2^output size) for each pair of input, for a good algorithm).

Upvotes: 3

Richard Schneider
Richard Schneider

Reputation: 35477

Yes the same hash will be produced when the input and salt are the same. Note that different inputs may produce the same hash.

Upvotes: 1

Related Questions