Many ordinary users would really not care about message digests or hash functions.
To shed light on this, here is an introduction with the following basic facts:
- Data transmitted over the Internet heavily relies on checksums.
- The TCP protocol used to transmit data over the Internet relies on verification of these checksums to make sure that packets sent from your computer to various web sites are correct and not damaged when they reach the web sites, or, the other end.
- Several times, we tend to download huge files like Linux distributions from the Internet. The creators of those ISO files or images give us some hashes along with them to validate that the whole ISO or image was downloaded correctly and not mixed up in transit.
- The hash functions for Fedora 17 or Ubuntu 12.04 LTS Linux Operating System ISO files can be viewed at this link.
- Therefore, I would view a hash as a digital signature of the entire file downloaded to tell me if there was a change in the file contents while it was downloaded.
- If the hashes match, you got a perfectly valid ISO or image file. If they don’t, there was either an error or there was a compromise on the ISO image. Anyway, you would not proceed to use the ISO image or file if the hash did not match.
- Hashes tell you that the content you received was not changed. They assure you that what you have downloaded was accurate and matching up to what was posted up for you to download.
- Verifying the hash also saves you the trouble of installing a defective ISO image onto your computer and later finding that it was corrupt and you need to download it again.
- Lastly, these can also be used in email communication to tell receivers of your email that it was not altered while it was in transit. They also form the basis of the digital signature when you sign an e-mail using a digital certificate.
In short, hashes help us to calculate a single set of digits that are like a checksum of the file. In Linux, you can have hashes for almost any file on your computer. The functions to do this are free and the most common is explained below, with an example.
To experiment with various hash functions, you can try the following with a smaller file:
gedit hello.txt <enter>
Save the file
Now try the following commands in a terminal window to see the hashes generated for each hash type.
openssl dgst -md5 hello.txt <enter>
openssl dgst -md4 hello.txt <enter>
openssl dgst -ripemd160 hello.txt <enter>
openssl dgst -sha hello.txt <enter>
openssl dgst -sha1 hello.txt <enter>
openssl dgst -sha224 hello.txt <enter>
openssl dgst -sha256 hello.txt <enter>
openssl dgst -sha384 hello.txt <enter>
openssl dgst -sha512 hello.txt <enter>
openssl dgst -whirlpool hello.txt <enter>
openssl md5 xubuntu-15.04-desktop-amd64.iso <enter>
The above validates the hash of the downloaded Xubuntu 15.04 desktop linux distribution. It guarantees that the file that was downloaded on the hard disk is the same as that on the website.
MD5, MD4, SHA1, SHA224, and so on are the types of hashes that can be generated using the openssl program in Linux. Most popular are MD5, SHA256.
Guess what? Hashes are also used in communication over a wireless LAN.