0
$\begingroup$

Wikipedia says sha1 produces a 160-bit (20-byte) hash value. So if I compute the SHA-1 of all possible SHA-1 values, which as far as I understand is at current time impossible both to calculate and store, will I get all possible SHA-1 values? Would I be able to collide anything?

$\endgroup$

marked as duplicate by woliveirajr, CodesInChaos Sep 26 '15 at 11:55

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 7
    $\begingroup$ Related: crypto.stackexchange.com/questions/301/… - it is almost a duplicate, as same answers apply, but they are about SHA-2. $\endgroup$ – Neil Slater Sep 25 '15 at 10:20
  • $\begingroup$ If it's the same answer, with the same rational, the only diff being the number of bytes ... could be closed as a dup. $\endgroup$ – woliveirajr Sep 25 '15 at 19:04
  • 1
    $\begingroup$ I've edited the duplicate question so it's applicable to more hashes. $\endgroup$ – CodesInChaos Sep 26 '15 at 11:59
1
$\begingroup$

No. And it's probably a good thing that that's not the case.

All cryptographic hashes (inc. SHA-1) are designed to have no obvious correlation between their input and output. If there is too much of a correlation, then they are considered broken.

If each string of 160 bits produced a different output, that would be a correlation.

That would also mean that all cryptographically secure pseudorandom number generators would have a small bias.

[It's very possible that there are some outputs that cannot be produced by SHA-1].

$\endgroup$
0
$\begingroup$

SHA-1 is not a perfect hash function for the input set that is identical to the output set. Moreover, it is not designed to be one. So basically we can see the output of SHA-1 as a random bit string. SHA-1 and modern hashes simply rely on the output size to be reasonably sure that there won't be any collisions; it simply takes to long - on average - to create a collision.

This however won't work if you consider an arbitrary amount of inputs. Actually, after about half of the output size, you would start to expect to find a collision. If you go on and input more and more values the chances of having collisions will grow to 1. Once you have computed the hashes of N + 1 values, you must have generated a collision of course, so the chance will be 1.

This is all theoretical of course, as you will never be able to create $2^{80}$ inputs, let alone hash them. Closely related to this are cycles within a PRNG. You may want to read about those to understand more about the problem.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.