!! Also check out the new improved library. !!
A while ago I did some QT programming. I think the QT API is very good and useful. I like things about C++ more than Java, but at the same time QT takes away most of the annoyances with C++. Especially, developing cross-platform GUI applications is very nice with QT.
One thing I missed was a simple encryption library. I mean, there is QCA, but how simple is it to use?
So, I did the forbidden thing, and implemented my own encryption library. Ok – it is for many reasons a very stupid thing to do. But it was fun, I did it anyway, it works, and I will share it with you
Well, I did another forbidden thing; I based my library on RC5 – a very elegant and simple encryption algorithm, protected by patents (at least in the US, where I do not live). Anyway, it is of course allowed to make an open source implementation of RC5.
The downloadable package contains three things: the library, a command line encryption utility using the library, and a little command line “unit test” tool. The files are named as:
- main.cpp – test utility
- simpleqtrc5.* – the library
- simpleqtrc5_test.* – the unit test tool
As always with QT, building is very easy:
$ qmake
$ make
I used QT 4.5 and QT 4.6. Perhaps you are fine with older versions as well.
I suggest you have a look in the main.cpp-file, or simpleqtrc5.h for examples, instructions and documentation.
The library of course uses QT datatypes, so you can use it very naturally from any QT code. The core is implemented in somewhat optimized C code, that only uses QT datatypes, so it should be 100% portable. There are no non-QT dependencies.
I have implemented both a 32 bit version and a 64 bit version of the algorithm. Of course, both versions work on any CPU, and you chose algorithm at runtime. 32 bit algorithm is faster on 32 bit cpu, and 64 bit algorithm is faster on 64 bit cpu. Maybe this is the only 64-bit implementation of RC5?
Performance is reasonable, as you can see in this example (Ubuntu 11.04, x64):
$ time md5sum 100Mb.bin
28a8c7a11327880877f21c78b7222273 100Mb.bin
real 0m0.238s
user 0m0.220s
sys 0m0.010s
$ time openssl enc -e -aes-128-cbc -k p4ssw0rd -in 100Mb.bin -out 100Mb.aes.enc
real 0m0.580s
user 0m0.510s
sys 0m0.060s
$ time openssl enc -d -aes-128-cbc -k p4ssw0rd -in 100Mb.aes.enc -out 100Mb.aes.dec
real 0m0.619s
user 0m0.460s
sys 0m0.150s
$ md5sum 100Mb.aes.dec
28a8c7a11327880877f21c78b7222273 100Mb.aes.dec
$ time ./SimpleQtRC5 -e -p p4ssw0rd -i 100Mb.bin -o 100Mb.rc5.enc
real 0m1.678s
user 0m1.540s
sys 0m0.120s
$ time ./SimpleQtRC5 -d -p p4ssw0rd -i 100Mb.rc5.enc -o 100Mb.rc5.dec
real 0m2.064s
user 0m1.970s
sys 0m0.090s
$ md5sum 100Mb.rc5.dec
28a8c7a11327880877f21c78b7222273 100Mb.rc5.dec
$ ls -l 100Mb.*
-rw-r--r-- 1 freke freke 104857600 2011-05-04 19:16 100Mb.aes.dec
-rw-r--r-- 1 freke freke 104857632 2011-05-04 19:15 100Mb.aes.enc
-rw-r--r-- 1 freke freke 104857600 2011-05-04 19:10 100Mb.bin
-rw-r--r-- 1 freke freke 104857600 2011-05-04 19:19 100Mb.rc5.dec
-rw-r--r-- 1 freke freke 104857634 2011-05-04 19:19 100Mb.rc5.enc
Above you can see:
- Calculating md5 sum of 100Mb-file
- Encrypting using openssl/aes-128 in 0.6s
- Decrypting using openssl/aes-128 in 0.6s
- Calculating md5sum to confirm that decryption recovered original file
- Encrypting using QT/RC5 in 1.7s
- Decrypting using QT/RC5 in 2.1s
- Calculating md5sum to confirm that decryption recovered original file
- Listing 100Mb files
The test program is quite simple to use:
$ ./SimpleQtRC5
SimpleRC5 (v0.0)
USAGE:
SimpleRC5 -t testfile
SimpleRC5 -e OPTIONS
SimpleRC5 -d OPTIONS
SimpleRC5 -h
OPTIONS:
-k SecretFile (preferred to -p)
-p Secret (default = )
-i IndataFile
-o OutdataFile
-w32 : use 32-bit words
-w64 : use 64-bit words
-w : use native CPU words (default)
-cbc : CBC
-cfb : CFB (default)
-n : no header
-v : verbose
The only thing to explain is that without the header, the program can not itself figure out what options to use to decrypt (32/64 bit or cbc/cfb). The header does not reveal anything at all.
!! Please download the new and improved library !!
You can download the source: SimpleQtRC5-0.1.tgz.
If you have any questions, suggestions or complaints just let me know! I really believe the library is stable and secure, and simple to use! I might document it better if anyone cares about it.