# If I compute the SHA-1 of all possible 40 digits hexadecimal strings, will I get all possible sha1 hashes? [duplicate]

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?

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

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].

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.