Originally published by Robert Beisert at fortcollinsprogram.robert-beisert.com

Protecting Integrity with Encryption

We’ve looked at how cryptography can help protect the confidentiality of data, but that only solves one of the three basic security issues. These issues are:

Confidentiality – no one else can read
Integrity – the recipient gets the right message
Availability – the recipient CAN get the right message

Availability is a messy problem with no easy answer, but Integrity can be addressed with the same basic principles we use to protect Confidentiality.

It’s time to talk about HASHES.


A hash is a fixed-size output that represents some amount of data.

What on earth is that good for? Well, if you send a file over the internet, you want to make sure that the recipient gets the file you sent, and not one a hacker swapped in. If you send a single value that can only be generated if you know the right key and have the right data, it’s easy for the recipient to tell whether the data has been messed up in transit.

We use a hash function that looks quite a bit like an encryption to produce a secure hash. Of course, if security isn’t an issue, you don’t really need a key, but that’s a different story for another time.

Theoretical hash – AES

Suppose we tweak the AES encryption that we’ve already looked at. We know that the standard AES takes 128-bits of input and a key, and uses the key to generate a key schedule.

For this experiment, let’s swap the key and the data.

Now, instead of producing a key schedule, we’ll just use each 128-bit block of data for each round key. Because we need something inside of the matrix, let’s put a 128-bit key in there.

Now all we do is perform the EXACT SAME operations (with no round limit, so we can feed ALL our data in as the “key schedule”). This will produce a 128-bit data block that represents our key and the data (a 128-bit hash, if you will).

Now, when we send our data out to our recipients, we attach the hash at the end. The recipient knows the key, so they can produce the correct hash if (and only if) the data is correct. All they have to do is use our tweaked AES algorithm.

This basically demonstrates how we can tweak modern encryption techniques to protect integrity.

photo by: