Encryption -- it's not as lame as you think but far more intesting than you know (maybe)

Today at the office I gave a presentation on encryption.  Attendance was very very light (4pm on a friday, no surprise ... ?) and I was even asked if I wanted to reschedule -- na, I'll do it twice if I have to.  Wow did they miss out.  I had discovered that the methods of applying encryption were amazingly important, and I'll be damned if I couldn't replicated it.  I wanted to see this for myself as it broke every rule I had known or in other words, perfect.  First I tried hacking up a jpeg file until someone pointed out the obvious -- it's got it's own "encryption" and suggested I bounce it over to bmp, a raw format.  What a great idea and how did I miss it? But I'm getting ahead of myself, let me step back and talk about encryption...

Encryption in and of itself is very technical once you get into the modern age.  Very specific, lots of math, probability, etc make it a subject most people just glaze over and shut down.  I'll do you one better.  I see your glazing and raise you an awesome visual.  While doing my research for this presentation, I ran across something absolutely facinating which I touched base on earlier...

Encryption algorithm and of itself is not the whole story.  Not even close.  I'm seriously starting to wonder if, holistically, its method is JUST as important than its computation/execution.  Why?  Allow me to explain and consider this image. (warning -- shamelessness !!!)

Told ya but it's perfect for this example.  What if I told you that you can visualize flaws in encryption easily?  So easily that anyone could look at it and say "...uhhhh NO".  First, let me take half a step back and explain concept of block cipher modes.

For the sake of simplicity I am going to speak directly about AES - Advanced Encryption Standard.  Something we've probably all ran into at some point (you aren't using WEP on your wireless router... are you?) and if you've done any encryption, it was probably considered.  Within AES, you have quite a few options in WHAT block mode you wish to use.  Why is that important?  If you asked that, please read the next paragraph closely...

Block cipher modes tell the algorithm -how- to go about encrypting the blocks of which that have been specified for jumblin'.  The concept is rather simplistic but its operation is not -- take a given block of bits (32, 64, etc) and dictate how, from block to block, they are encrypted.  In this case, AES is exactly 128 bits, no more, no less which in and of itself doesn't make it more or less secure, but I'll get to that.  This operation varies quite wildly in application, all the way to "I have no idea how this could possibly decrypt correctly, ever" -- but does it really matter?  As always, of course it does.

I'm going to take that image, toss it into the all mighty AES and show the results of the default encryption.  What do you expect to see?  A bunch of junk right?  Well, take a look.

Out of the box, the default type is CBC, also known as cipher block chaining.  The result looks like a hot mess, almost like TV snow and I like this.  This is what I expect encryption to look like.  So let's have a go at another supported type, CFB, cipher feedback.  The results are not all that surprising...

The hot mess is indeed different, but still results in a snow-like effect.  Finally, we move to another supported version, ECB or Electronic cookbook...  prepare yourself for a surprise.

Yep, you can still see what the image was.  Kind of a problem.  So why is this?  Why does this happen?  How is this possible?!  It's simple.  I don't want to speak globally but the encryption types I run across are all symmetric, and rely on blocks in a given size and apply their method to those given blocks.  The blocks in and of themselves are very nicely protected in this case by AES, however, instead of rolling that encryption along, ECB take the same key and apply it to every single block. Other methods do not do this, as illustrated above.

Bottom line - how it's applied matters, so pay attention to those modes !  If you're curious or which to replicate this yourself, grab the bits here Example.cs (1.95 kb) and snag the example image at RileyRacing.com (convert to bmp first).  If you really do indeed care about how the different modes work, wikipedia (no, really) has a great write up on how they all work.  What started me down this path was the example on the previous link, showing why ECB isn't full of win, and it makes sense.

Comments are closed