How to Determine Hashing Algorithm for SHA1, SHA256 and SHA512 Hashes on Linux
Not sure whether the 1GB file which you have just downloaded was transferred successfully without any error? Actually there is a way to check this. By using a hash algorithm that produces a fingerprint of the downloaded file, it is able to verify that the file is exactly the same as the source. Just like the human fingerprint, the resulting character string is unique and only that file would have that fingerprint. Similar to Fedora, sites that offer large downloads will publish a list of the hashes as well. To verify that the file has been downloaded correctly, all you have to do is to make sure that the hash of your files are the same as the published hash.
Although the MD5 hashing algorithm was popular in the past, it has been slowly replaced by the SHA family of hashes. One of the major problem with MD5 is the possibility to create multiple files having the same fingerprint. One popular case among cryptographers, a security researchers claimed that he can predict who would win the presidential election. To prove his point, he has created a file with the winning result in it and released the MD5 hash. Once the election is over, he would release the file to prove that his prediction was right. But the fact is, he has created several files with the candidates name in it and manipulated the file in a certain way that every file had the exact MD5 fingerprint.
There are many different Secure Hash Algorithms (SHA) like the SHA1, SHA256 and SHA512. SHA256 and SHA512 both use the same algorithm, while process the data in different sized chunks. SHA256 uses 32 bit blocks and SHA512 uses 64 bit blocks.
SHA1 is close to MD5 with some concerns about the uniqueness of the resulting hashes and thus, it is not approved for many cryptographic uses since 2010. However if you find a site which publishes SHA1 hashes, you can verify them like this:
The output will be shown as below:
SHA256 hashes are generated using the same way:
And the result is similar, except the fingerprint string is longer:
Same goes for SHA512:
The fingerprint will be even longer:
Rather than just publishing the fingerprint string in isolation, some sites show a checksum file that contains all the hash detail in a machine readable form that the various
sha commands can use to verify files. A checksum file for the net install 32 bit Intel version of Fedora 19 might look like following:
To check this use the
-c parameter like this:
sha256sum -c Fedora-19-i386-CHECKSUM
Where Fedora-19-i386-CHECKSUM is the name of the file containing the fingerprint information as shown above.
If everything is right, then the output will look like this:
In case there is some error in the downloaded file, the output will show:
sha256sum: WARNING: 1 computed checksum did NOT match
Your Linux distribution also consists of
sha384 commands. These two hash algorithms are truncated versions of SHA256 and SHA512. They can be used in exactly the same way as the
sha512 commands. Try producing hashes uses and notice the differences in the output.