summaryrefslogtreecommitdiffstats
path: root/botan/src/block/xtea/xtea.cpp
diff options
context:
space:
mode:
authorKeith Isdale <keith.isdale@nokia.com>2010-07-26 14:56:53 +1000
committerKeith Isdale <keith.isdale@nokia.com>2010-07-26 14:56:53 +1000
commit9f034793bcfc51c2b7c1dd14db806f7258f9a9eb (patch)
tree63bd0f50ce5b77828ad8205eafd7b9412810499e /botan/src/block/xtea/xtea.cpp
parent619d92cfef29e653bfdf852e83888e50cfc4348f (diff)
parent65271649dbc90f3af1184ad1b23bdb64c0c07d07 (diff)
Merge branch 'master' of git://git-nokia.trolltech.com.au/qtsoftware/research/qtuitest
Diffstat (limited to 'botan/src/block/xtea/xtea.cpp')
-rw-r--r--botan/src/block/xtea/xtea.cpp64
1 files changed, 64 insertions, 0 deletions
diff --git a/botan/src/block/xtea/xtea.cpp b/botan/src/block/xtea/xtea.cpp
new file mode 100644
index 0000000..5047f65
--- /dev/null
+++ b/botan/src/block/xtea/xtea.cpp
@@ -0,0 +1,64 @@
+/*
+* XTEA
+* (C) 1999-2009 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
+
+#include <botan/xtea.h>
+#include <botan/loadstor.h>
+#include <botan/parsing.h>
+
+namespace Botan {
+
+/*
+* XTEA Encryption
+*/
+void XTEA::enc(const byte in[], byte out[]) const
+ {
+ u32bit L = load_be<u32bit>(in, 0), R = load_be<u32bit>(in, 1);
+
+ for(u32bit j = 0; j != 32; ++j)
+ {
+ L += (((R << 4) ^ (R >> 5)) + R) ^ EK[2*j];
+ R += (((L << 4) ^ (L >> 5)) + L) ^ EK[2*j+1];
+ }
+
+ store_be(out, L, R);
+ }
+
+/*
+* XTEA Decryption
+*/
+void XTEA::dec(const byte in[], byte out[]) const
+ {
+ u32bit L = load_be<u32bit>(in, 0), R = load_be<u32bit>(in, 1);
+
+ for(u32bit j = 0; j != 32; ++j)
+ {
+ R -= (((L << 4) ^ (L >> 5)) + L) ^ EK[63 - 2*j];
+ L -= (((R << 4) ^ (R >> 5)) + R) ^ EK[62 - 2*j];
+ }
+
+ store_be(out, L, R);
+ }
+
+/*
+* XTEA Key Schedule
+*/
+void XTEA::key_schedule(const byte key[], u32bit)
+ {
+ SecureBuffer<u32bit, 4> UK;
+ for(u32bit i = 0; i != 4; ++i)
+ UK[i] = load_be<u32bit>(key, i);
+
+ u32bit D = 0;
+ for(u32bit i = 0; i != 64; i += 2)
+ {
+ EK[i ] = D + UK[D % 4];
+ D += 0x9E3779B9;
+ EK[i+1] = D + UK[(D >> 11) % 4];
+ }
+ }
+
+}