Verifying Checksums

MD5 checksums are a great way of determine if a downloaded file is free of errors, and/or unwanted malware. I recently used the the MD5 checksum tool to diagnose a corrupt Ubuntu image after encountering installation problems.

Similar methods are employed in a variety of daily cryptography, iOS (and the mac AppStore), SSL validation certificates, and HTTPS to name a few.

While it is best practice to check all files, walled eco-systems like iOS do this automatically, in reality anytime you are receiving a file from a high-risk source, an obscure mirror, torrent, random thumb drive, this is even more important.

MD5

Regardless of the reason, the process is the following:

First locate the checksum from a reputable, trusted source. In this case I located the hash on Ubuntu’s Hashes Page.

MD5 Checksum : Filename
1
7ad57cadae955bd04019389d4b9c1dcb *ubuntu-12.10-desktop-amd64.iso

Next, the process of interrogating the file:

Open a terminal, navigate to the directory containing the file.

OSX: Interrogating MD5 Checksum
1
2
$ md5 ubuntu-12.10-desktop-amd64.iso  # MD5 filename.iso
7ad57cadae955bd04019389d4b9c1dcb  # expected result.
Ubuntu: Interrogating MD5 Checksum
1
2
$ md5sum ubuntu-12.10-desktop-amd64.iso  # MD5 filename.iso
7ad57cadae955bd04019389d4b9c1dcb  # expected result.

Alternatively, you can calculate an MD5 hash of any file. This can be a secure way of being certain that two files really are duplicates.

This is accomplished via the following process:

OSX: Creating MD5 Checksum
1
$ openssl md5 filename.iso

SHA1

Less frequently you may encounter SHA1 checksums because it is a newer, stronger algorithm. While theoretically the MD5 checksum is a very stronghas a very low possibility of collisions. A collision is when two separate files yield the same checksum. In cases like this, it is statistically improbable for a user to experience this scenario, however it is possible to show up taking into account every file in the universe.

Next, the process of interrogating the file:

OSX: Interrogating SHA1 Checksum
1
2
$ /usr/bin/openssl sha1 filename.iso  # or any other extension
# compare output to expected result.
Ubuntu: Interrogating SHA1 Checksum
1
2
$ sha1sum -c filename.iso  # or any other extension
# compare output to expected result.