Wednesday, June 11, 2014

Encryption Test

So, how can one tell whether something is encrypted?

One way is to try to compress a chunk of the encrypted data.  If it compresses at all, then the encryption is suspect.

Let's test the encryption of the swap partition.

# swapon
NAME TYPE SIZE USED PRIO
/dev/dm-0 partition 3.8G 151.2M -1

# dd if=/dev/dm- of=swaptest bs=1M count=1
1+0 records in
1+0 records out
1048576 bytes (1.0 MB) copied, 0.011246 s, 93.2 MB/s

# ls -al swaptest
-rw-r--r--. 1 root root 1048576 Jun 12 08:50 swaptest

# gzip -9 swaptest

# ls -al swaptest.gz
-rw-r--r--. 1 root root 1044778 Jun 12 08:50 swaptest.gz


Hmm, it actually compressed a little bit, so my swap encryption is suspect, probably due to some repeating headers, but if it reduced by half, then it would have been clear that there is no encryption at all.

Let's look at the swaptest file with hexedit and see whether there is readable stuff in there:

# dd if=/dev/dm- of=swaptest bs=1M count=1

# hexedit swaptest

00000FB4 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ....................
00000FC8 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ....................
00000FDC 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ....................
00000FF0 00 00 00 00 00 00 53 57 41 50 53 50 41 43 45 32 42 B4 A7 26 ......SWAPSPACE2B..&
00001004 59 5F 1E FC 09 62 95 E2 DC A4 9D 5D DE 08 5C 6D 96 06 A0 FD Y_...b.....]..\m....
00001018 20 E3 62 AE 92 5B 7D A6 68 20 4E 43 72 84 6B E9 AE CF 7F F3 .b..[}.h NCr.k.....
0000102C C9 98 4A 78 8D 84 B6 7E 44 93 43 86 C5 C7 B2 1A CE A6 82 91 ..Jx...~D.C.........
00001040 50 CE 42 93 BD 22 F2 E7 C9 5A 37 21 62 4A 2E FD 6D A5 34 17 P.B.."...Z7!bJ..m.4.


OK, that explains it. The first kilobyte is zeroes, which will compress nicely.  After that, it looks OK - whew!

No comments:

Post a Comment

On topic comments are welcome. Junk will be deleted.