Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can a zero byte text file generate a hash when hashed with sha1sum, sha256sum etc? What data are the programs hashing to generate a hash value?


QuickHash in Linux

Terminal Commands

share|improve this question
up vote 14 down vote accepted

Hash algorithms read the input and process it, no matter if there's data at all. This is a valid and wanted behaviour and is even used to verify if a certain implementation is correct. This leads to "null-hashes" for all major algorithms.

To sum it up: da39a3ee5e6b4b0d3255bfef95601890afd80709 is the sha1-hash for an empty file everywhere, the same is true with the null-hashes of other alrogrithms.

share|improve this answer
Well you learn something new everyday! I didn't know there was a "null value" for every algorithm. Many thanks. – Gizmo_the_Great Feb 26 '13 at 23:28
The hash algorithms have a predetermined initial condition - kind of like a number which they start with and mutate as they read in data. If there's no data to read, the hash is just a result of that preset initial condition. – Kevin Feb 26 '13 at 23:31

All hash algorithms in Quick Hash are Merkle–Damgård constructions. As such, they pad the message to a multiple of the block size.

Quick Hash's algorithms achieve this by appending a 1 bit, as many 0 bits as needed, and finally the message length.

This allows hashing messages of arbitrary length, including zero-length messages.

share|improve this answer
If my edit reason is confusing, I initially misread your answer and reworded it "for clarity", then realized my edit was wrong and went back and fixed it. The system consolidated the two explanations because it was within the same time window. – fixer1234 May 3 '15 at 21:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .