Hashing: How and Why to Check a File's Hash Value

Consider the following situation. You have been working for days on a PowerPoint presentation for work or school, and have been keeping the file on a shared computer, a network drive or even a personal flash drive. You put the final touches on your presentation the night before it’s due, save the file and get ready for a good night's sleep. The next day, you confidently begin your presentation. But imagine your surprise when you and your audience see the following image on your third slide:


You’ve been pranked. If you're lucky, everyone got a good laugh out of it. If not, there may be more serious consequences, depending on the situation. This sort of everyday  scenario raises an obvious question. Short of opening the file and manually perusing each slide in the presentation, how could you be sure that it had not been modified by any of the pranksters you may share your computer or network with? More seriously, how can we verify the integrity of a file that may or may not have been modified by a malicious individual seeking to infect out computer or network with a dangerous piece of malware?

In this article, we’ll consider these questions and discuss the pros and cons of one simple means by which we can verify a file’s integrity to ensure that it has not been tampered with, namely, by verifying its hash value. We’ll conclude with a quick tutorial on how to verify a file’s hash value on Mac, Linux and Windows systems, and provide some links to a few lectures on cryptographic hash functions culled from the series of courses listed in our collection of free online computer science courses. Our primary sources along the way will be Everyday Cryptography by Keith M. Martin, and Applied Cryptography by Bruce Schneier.

Malware comes in many different guises. As the Electronic Frontier Foundation writes in their Surveillance Self-Defense Project, malware is frequently spread by "trick[ing] the computer user into running a software program that does something the user wouldn't have wanted." Let's say you decide to download a file from a website you know and trust, and from which you have safely downloaded files in the past. How do you know, for example, that the file you have downloaded onto your computer is in fact the one intended by the trusted website? How do you know it was not altered in transit? How do you know it was not swapped for another file by a malicious attacker? And how can you determine this without running the file first? 

One simple way to verify a file's integrity is by confirming its hash value. In Everyday Cryptography, Martin writes: “Hash functions can be used to provide checks against accidental changes to data and, in certain cases, deliberate manipulation of data . . . As such they are sometimes referred to as modification detection codes or manipulation detection codes” (emphasis in original, Martin, p. 188). In our opening example, a suitable hash function would have allowed you to detect that your presentation had been modified in some way without ever opening it.

So, what is a hash function? The primary practical property of a hash function is that it compresses arbitrarily long inputs into a fixed length output (Martin, p. 189, Schneier, section 2.4). Furthermore, slight differences in the input data result in large differences in the output data. “A single bit change in the pre-image [i.e. the file you’re hashing] changes, on the average, half of the bits in the hash value,” (Schneier, section 2.4). Two of the most commonly used cryptographic hash functions are known as MD5 and SHA1. Schnier quotes NIST’s description of the SHA hash function as found in the Federal Register:
The SHA is called secure because it is designed to be computationally infeasible to recover a message corresponding to a given message digest, or to find two different messages which produce the same message digest. Any change to a message in transit will, with a very high probability, result in a different message digest. (Schneier, section 18.7.)
Here’s a simple example. I have created a plain text file named hello.txt on my Desktop. The file contains a single line that reads: “Hello there.” Applying the well-known sha1 hash function to the file produces the following hash value:
4177876fcf6806ef65c4c1a1abf464087bfbf337.

If I edit the file and remove the period from the end of the line so that it reads “Hello there”, the hash function now returns an entirely different value: 33ab5639bfd8e7b95eb1d8d0b87781d4ffea4d5d.

If I then return the file to its original state by adding the period back in to the end of the sentence, the hash value of the newly edited file will be the same as the original hash. And we would have seen much the same result (though it would have taken a good bit longer to compute!) if my original file had been a copy of the complete works of Shakespeare from which I then removed a period.  

Let’s consider a more practical example. The Electronic Frontier Foundation provides a number of recommendations on how to reduce your risk of malware infection in its Surveillance Self-Defense Project. At the top of their list, we read: “Currently, running a minority operating system [their examples are Linux and  MacOS -ed.] significantly diminishes the risk of infection because fewer malware applications have been targeted at these platforms. (The overwhelming majority of existing malware targets only a single particular operating system.)” This is more security through obscurity than anything else, but it’s still fun to try out new things, so after a bit of reading you decide to download a copy of the latest version of Ubuntu from an online repository.

How can you check to make sure that the file you’ve downloaded is the official one intended by Ubuntu’s developers and has not been manipulated or corrupted in transit? One way is to confirm that the file’s hash value is equivalent to the one provided by the developers. So you go to the page that lists the download’s hash value and make a note of it. Next, you run the hash function on the file you downloaded. If the resulting value is equivalent to the expected one, you have successfully verified the file’s hash.

However, it is critical to note here that verifying a file’s hash value by itself can only establish a relatively weak form of data integrity, in comparison with more robust mechanisms such as digital signature schemes which can provide a stronger form of integrity verification and even authentication. (Martin, pp. 186-189.) This is because a hash value such as we are discussing here cannot tell us anything about the origin of a digital file. For example, assume that unbeknownst to you, the site you’ve downloaded your file from has itself been compromised, and the attacker has: 1) replaced the download file with a piece of malware, and 2) also replaced the corresponding hash value that you use to check the file’s integrity with the hash value of the malware.

If you then verify the hash value of your downloaded file, you have done nothing more than verify the integrity of the malware! And you’re none the wiser because the site itself was compromised! At the same time, however, if you found out through another source that the site and file were compromised, you could then identify the malicious file and distinguish it from the legitimate source file. In a digital signature scheme, as mentioned above, the developer could digitally sign the legitimate hash value with a trusted key. In this way, the question of trust is then displaced to the question of signature authentication.

A second concern regarding this method of determining data integrity is the security of the hash functions themselves. There are known practical and theoretical vulnerabilities in two hash functions that are among the most common in use for these exact purposes on the web today: MD5 and SHA1. A discussion of these vulnerabilities is beyond the scope of the present article, but more information can be easily found online.

Still, as Bruce Schnier states, “we cannot use [one-way hash functions] to determine with certainty that the two strings are equal, but we can use them to get a reasonable assurance of accuracy.” (Schneier, section 2.4). In other words, hash functions can help us establish a basic level of data integrity. In our opening example, simply making a note of the hash and then checking it the next day would have sufficed to establish that the file had been tampered with. But, of course, if the file had been secured or encrypted to begin with, it never would have even been an issue in the first place.

Finally, how does one actually compute the hash value of a file? It is actually rather simple, but the specifics depend on your choice of operating system. MacOS and Linux systems come bundled with basic functionality to check any file’s hash value, while Microsoft Windows systems require you to download a piece of software to accomplish the task. Two of the most common functions used to verify file hashes are known as MD5 and SHA1. We’ll consider each in turn.

MacOS
1) Open up a command line Terminal.
2) Type “openssl md5 </path/to/file>” into the terminal and press enter.
2A) As an alternative to #2, you can also type “openssl md5 ” into the terminal, then drag and drop the target file into the Terminal window, and press enter.
3) The terminal will then return the MD5 hash value of the given file.

To compute the hash value of the file using a different hash function, type the name of that function into the terminal command in place of “md5”. For example, to compute the sha1 hash of a file, you would type: “openssl sha1 ” followed by the file path. To see a list of all the message digest commands available on your machine, type “openssl —help” into the command line terminal.

Linux (Debian-based)

1) Open up a command line Terminal.
2) Type: “md5sum </path/to/file>”. Then press enter.
3) The terminal will return the MD5 hash value of the given file.

To compute the hash value of the file using a different hash function, type the appropriate command into the terminal in front of the path to the target file. For example, “sha1sum </path/to/file>” will compute the file’s sha1 hash value. To see what other hash functions are available on your system, type “man dgst” into the terminal. 

Windows
Windows systems apparently do not come bundled with a built-in utility to check hash values. However, there are a number of different pieces of software you can download to accomplish the task. Microsoft Support lists the File Checksum Integrity Verifier, but warns that this is not supported by Microsoft and is only of use on Windows 2000, Windows XP and Windows Server 2003. This discussion at superuser provides a number of different extant options.

Video Lectures on Hash Functions
As always, comments, questions, suggestions and angry tirades are welcome below.

Taxidermy Taxi'ing For Takeoff: Dutch Inventors Mount Dead Things To Drones

Drone technology is advancing rapidly, so much so that some versions are available for civilian use. Two Dutchmen have taken this opportunity to amass a taxidermied aerial zoo.

What?

According to the Daily Mail UK, it all started with a flying cat. Perhaps in the name of great, crazy art, or perhaps just thinking that a unique cat video would lead to instant fame, inventors Arjen Beltman and Bart Jansen stretched a dead and stuffed feline over a four-rotor remote-controlled drone device. The rest is weird history.

This is real.  This really happened.

Jansen stated, 'Flight is man's greatest achievement, so why not give it to more animals? The world needs more flying animals.' He and Beltman then went on to aid a Dutch boy by giving his dead pet rat a new life as a three-rotor drone captain.  The cat and rat drones then went for a spin together, like a very disturbing episode of "Tom And Jerry."

Other projects from these not-quite-Wright Brothers include an aerial ostrich (with propellers!) that finally gives the flightless creature some time among its brethren in the skies.  Their most recent endeavor, a shark mounted to a winged jet engine, proves that even sea creatures can get in on the fun of flight.

Is it wrong to ask if they'll have a human funeral package option available?  

Great, now we have to worry about shark attacks from the SKY, too?



One For The Road: New Portable Breathalyzer For Self-86'ing

Sometimes it's just hard to tell when you've had that liiiittle bit too much to drink.  Now, technology has got your back, before the cops (or worse) have you flat on it.  Meet the DrinkMate.

As reported by shortlist.com, the device claims to be the smallest Breathalyzer in the world, measuring in at 4.7 by 1.5 centimeters (plus the smartphone you have to dock it to.)  It is accurate down to .01% of a BAC (blood-alcohol content) and is a much better judge of whether you should drive than you slapping yourself in the bathroom mirror trying to decide if you're capably lucid.

The device is currently under Kickstarter development from the Washington-based company Edge Tech Labs and is simple enough for use even after a few too many.  Small enough to be kept on a keychain, it only requires plugging into a mini-USB port on a smartphone, then it uses a semiconductor-based sensor to suss out your sobriety (or complete lack thereof.)

DrinkMate operates similarly to a device previously discussed here, the Alcohoot.  However, the DrinkMate is smaller and is priced significantly less ($25.95 as opposed to the Alcohoot's $99.)  Now you can drink safely and still have plenty of money left over to buy your friends a round.

Cool, spooky, stern-warning posters from the past not included, so we'll leave one here for you.

I Only Have i's For You: Is The Apple Watch The Fruit Of All Knowledge? (iGadgetry Release, Part Two)

The gods have spoken, the skies have parted, and the now-immortal Apple Watch has descended from the heavens to grace your wrist like a miracle on a (obviously customizable and interchangeable) watch strap.  Your precious iShinything will never be more than a glance away.

As reported by theverge.com, Apple's Tim Cook describes the watch as a "comprehensive health and fitness device" - that's right, the damn doodad could change you from slacker to lip-smacker.  Chart your heart rate or sleeping habits and monitor other fitness stats like steps taken and calories burned (so you can learn exactly how much better it is for you to walk to Dunkin' Donuts instead of drive.)  It'll even warn you if you've been sitting too long.  Yes, the brilliant Apple Watch can function as your mom, telling you to go outside.

The innovative Taptic Engine can tell the difference between a tap and a press (called "Force Touch", which sounds like the Apple Watch maybe wants to be mounted to a leather bondage cuff), allowing for your fondling to give it extra special commands (effectively recreating the "right click" element of a mouse...or a particularly sensitive wrist-mounted love slave.)

The input mechanics offer a Digital Crown that enables zooming, scrolling, and navigation, sans obstruction of the main display.  The display itself is a flexible Retina panel, laminated to the popular high-end watch covering of sapphire crystal.  The Guardian UK reports some neat variations on the watch's style, among other things.

Siri's there (that bitch is everywhere...she'll buzz your wrist and tell you where to turn.)  Maps are there.  Tunes are there.  Obviously.  It also has Bluetooth to beam your soundtrack to other devices around you.

Onboard Facebook, Twitter, email, blah blah blah.  What about something NEW?  How about Apple Pay, which acts like a credit card that only requires a touch of the watch to receptive payment systems?  You're like a sultan - simply grab and item and touch the till on your way out - those organic apples are now yours, sans any unnecessary human interaction.

Fascinatingly, the Apple Watch can be charged inductively, meaning you don't need to plug it in.  This development will likely spur on other breakthroughs for technology that was formerly required to be wired.

Oh, and it tells time to a universal standard.  So you know exactly how much of it you've been wasting, messing around with your aggravatingly awesome new Apple Watch.

How else are you supposed to tell time in the future?

BTW, this is what some of the rest of the world looks like, in case you stop noticing.

I Only Have i's For You: Apple Unveils Latest iGadgetry (Part One)

It's like Christmas for the computer crowd.  Today, Apple is releasing not only their sixth and latest version of the iPhone, but also a rumored iWatch product that will make its popular technology more portable (because you weren't dithering with enough iSchwag already.)  Here are some of the new features you get to enjoy while phasing out all of humanity around you.

-According to the telegraph.co.uk, the iPhone has been hailed as "the world's most popular camera."  The iPhone 6 will now feature advanced image stabilization with exceptional low-light capabilities (for all those various and vilifying bar images that you'll end up deleting lest they end up on social media.)

-The camera also has the capacity to shoot at 240 frames per second, making it all the more easy to be extraordinarily creepy as you sneak photos of hotties on the subway.

-The 8-megapixel camera has "focus pixels", which are extra important to help make sure all your illicit imagery is crystal clear - your nudie-questing hackers will thank you.

-An integrated M8 motion chip and barometer work in conjunction with a new onboard health app or Nike's fitness app to maybe someday give you all sorts of data on the exercise you swear you'll do tomorrow.

-Worldwide cell service providers have teamed up to make your iPhone 6 able to complete calls over any 4G network, voice-over-LTE, and voice-over-WiFi.  Every single person at the NSA was reported to be seen malevolently drumming their fingers together and orgasmically murmuring, "Exxxcellent."

-Onscreen multi-tasking, because god forbid your ADD not get its fix.  Also, double the transistors of the iPhone 5 (2 BILLION!) making a 25% faster CPU and 50% faster graphics.  MORE CAT GIFS.  RIGHT NOW.  FASTER.  MORE.

-A record-breaking size:  6.5 mm of sleek sexy slimness, because even if Americans can't be svelte, our tech toys can be!

-Oh, and 1.3 million apps.  No big deal.  We've come a long way since phones only carried onboard Snake.  Is there a modern Snake app to be had, for old time's sake?  Maybe some Tetris?  This technological whirlwind shouldn't eradicate the simpler elegances of life.  WAIT A SECOND, IT PLAYS GAMES IN HIGHER RESOLUTION THAN CONSOLES.  SCREW SNAKE AND THOSE STUPID RUSSIAN BRICKS.

Pre-sale starts Friday, plebes.  Too bad you weren't in the line outside the Apple store in NYC.  It started last week.

Once rumors of the fabled "iWatch" wearable are confirmed, more information will be posted here.  Watch (iWatch?) this space.

That's evolution, baby.










Chomping At The Bit(coin): Paypal Now Accepts Popular Cryptocurrency

The bitcoin revolution has ascended rapidly, and the options for using cryptocurrency are expanding just as quickly to meet the demand. Now, the major online payment service PayPal has begun to accept bitcoin as part of its operations.

The internet-only monetary system of bitcoin has grown not only in popularity but in value recently, and according to fastcompany.com, had been considered an option by PayPal in the past. PayPal has now officially adopted the cryptocurrency, which will help to speed along transactions completed via their subsidiary Braintree's mobile app, One Touch PayPal. This expedites e-payments using a program called Coinbase.

Braintree CEO Bill Ready stated, "This will be PayPal's first foray into bitcoin...We think both the One Touch mobile payments that we announced as well as bitcoin will be high interest to merchants."

PayPal customers, including the cab-hailing app Uber and the apartment-letting service Airbnb, will now be open to accepting your bit-loot. With the scope of the company's usage on the internet, many more vendors will likely follow this trend.

Lesser-known e-currency provider Dogecoin are just happy they have a cool racecar.

Space Station Sunday! Space Crafts On The Spacecraft

It's a hot new technology on Earth, and now it's moving on up...literally. NASA announced this week that it will be sending a 3-D printer to the International Space Station on September 19th.

As reported by itproportal.com, the microwave-sized 3-D printer was created by NASA in conjunction with the "Made In Space" organization. The printer will aid astronauts by printing out small spare parts or tools that they otherwise might have had to wait days or weeks for, if sent up on a conventional supply launch.

NASA's 3-D printing project manager Niki Werkheiser stated, "The on-demand capability can revolutionise the constrained supply chain model we are limited to today and will be critical for exploration missions." If successful, NASA could feasibly equip long-distance space missions with printers for supplies of all sorts, someday maybe even including 3-D printed food.

The upcoming efforts will also be the first test of what happens with 3-D printing equipment in a microgravity environment. It is estimated that the machine would require 15 minutes to an hour to complete a task, hence perhaps as little as two hours for a design to be created on Earth, emailed to the ISS, and printed out for use in space. The printer is operable by the astronauts themselves, but can also be controlled by - who else - ground control at the Marshall Spaceflight Center's Operations Support Center.

According to madeinspace.us, the printer went through a battery of tests to prove its mettle for microgravity, including EMI (electromagnetic interference), materials compliance, vibration endurance (for launch survival), human factors, and the ability to interface with elements aboard the ISS.  Thanks to Made In Space working closely with NASA, the required space-safety tests were passed with flying colors, and the printer was certified mission-ready this June.

The Made In Space company's enthusiasm for the project was bountiful, and they are excited not only by where the achievements will lead in the future, but what will be possible very soon.  Made In Space CEO Aaron Kemmer said, “Passing the final tests and shipping the hardware are significant milestones, but they ultimately lead to an even more meaningful one – the capability for anyone on Earth to have the option of printing objects on the ISS. This is unprecedented access to space. If you want to 3D print in space, contact us now."

The possibilities seem as vast as the stars...

As is the norm for NASA, even the device's development looked cool.