aboutsummaryrefslogtreecommitdiffstats
path: root/src/block/tea/tea.cpp
diff options
context:
space:
mode:
authorlloyd <[email protected]>2008-11-08 19:46:52 +0000
committerlloyd <[email protected]>2008-11-08 19:46:52 +0000
commitf1c459725da56fd8ed5766e7779300182fa26bcf (patch)
tree32295cec92df1155563ae8a535dc695d6800d7f6 /src/block/tea/tea.cpp
parent8dba7b5264403e781bbb86ff61850e4377dca7b9 (diff)
Split ciphers into block and stream ciphers. Move base class headers
Diffstat (limited to 'src/block/tea/tea.cpp')
-rw-r--r--src/block/tea/tea.cpp56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/block/tea/tea.cpp b/src/block/tea/tea.cpp
new file mode 100644
index 000000000..c5bd1b1fa
--- /dev/null
+++ b/src/block/tea/tea.cpp
@@ -0,0 +1,56 @@
+/*************************************************
+* TEA Source File *
+* (C) 1999-2007 Jack Lloyd *
+*************************************************/
+
+#include <botan/tea.h>
+#include <botan/loadstor.h>
+
+namespace Botan {
+
+/*************************************************
+* TEA Encryption *
+*************************************************/
+void TEA::enc(const byte in[], byte out[]) const
+ {
+ u32bit L = load_be<u32bit>(in, 0), R = load_be<u32bit>(in, 1);
+
+ u32bit S = 0;
+ for(u32bit j = 0; j != 32; ++j)
+ {
+ S += 0x9E3779B9;
+ L += ((R << 4) + K[0]) ^ (R + S) ^ ((R >> 5) + K[1]);
+ R += ((L << 4) + K[2]) ^ (L + S) ^ ((L >> 5) + K[3]);
+ }
+
+ store_be(out, L, R);
+ }
+
+/*************************************************
+* TEA Decryption *
+*************************************************/
+void TEA::dec(const byte in[], byte out[]) const
+ {
+ u32bit L = load_be<u32bit>(in, 0), R = load_be<u32bit>(in, 1);
+
+ u32bit S = 0xC6EF3720;
+ for(u32bit j = 0; j != 32; ++j)
+ {
+ R -= ((L << 4) + K[2]) ^ (L + S) ^ ((L >> 5) + K[3]);
+ L -= ((R << 4) + K[0]) ^ (R + S) ^ ((R >> 5) + K[1]);
+ S -= 0x9E3779B9;
+ }
+
+ store_be(out, L, R);
+ }
+
+/*************************************************
+* TEA Key Schedule *
+*************************************************/
+void TEA::key(const byte key[], u32bit)
+ {
+ for(u32bit j = 0; j != 4; ++j)
+ K[j] = load_be<u32bit>(key, j);
+ }
+
+}