summaryrefslogtreecommitdiff
path: root/c5/tea.cpp
diff options
context:
space:
mode:
authorweidai <weidai@57ff6487-cd31-0410-9ec3-f628ee90f5f0>2002-10-04 17:31:41 +0000
committerweidai <weidai@57ff6487-cd31-0410-9ec3-f628ee90f5f0>2002-10-04 17:31:41 +0000
commitc912a49655335d3ef28d663ac4dd5e9e23640b09 (patch)
tree9c40eacb5ff5cc4e0e08aa04f54f202eff1db67a /c5/tea.cpp
parent3017e8f108ce3bdf2f485f195c80312032fcc14c (diff)
downloadcryptopp-CRYPTOPP_5_1@2.tar.gz
git-svn-id: svn://svn.code.sf.net/p/cryptopp/code/trunk@2 57ff6487-cd31-0410-9ec3-f628ee90f5f0
Diffstat (limited to 'c5/tea.cpp')
-rw-r--r--c5/tea.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/c5/tea.cpp b/c5/tea.cpp
new file mode 100644
index 0000000..3b5d181
--- /dev/null
+++ b/c5/tea.cpp
@@ -0,0 +1,54 @@
+// tea.cpp - modified by Wei Dai from code in the original paper
+
+#include "pch.h"
+#include "tea.h"
+#include "misc.h"
+
+NAMESPACE_BEGIN(CryptoPP)
+
+const word32 TEA::Base::DELTA = 0x9e3779b9;
+
+void TEA::Base::UncheckedSetKey(CipherDir direction, const byte *userKey, unsigned int length)
+{
+ AssertValidKeyLength(length);
+
+ GetUserKey(BIG_ENDIAN_ORDER, k.begin(), 4, userKey, KEYLENGTH);
+}
+
+typedef BlockGetAndPut<word32, BigEndian> Block;
+
+void TEA::Enc::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const
+{
+ word32 y, z;
+ Block::Get(inBlock)(y)(z);
+
+ word32 sum = 0;
+ for (int i=0; i<ROUNDS; i++)
+ {
+ sum += DELTA;
+ y += (z << 4) + k[0] ^ z + sum ^ (z >> 5) + k[1];
+ z += (y << 4) + k[2] ^ y + sum ^ (y >> 5) + k[3];
+ }
+
+ Block::Put(xorBlock, outBlock)(y)(z);
+}
+
+typedef BlockGetAndPut<word32, BigEndian> Block;
+
+void TEA::Dec::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const
+{
+ word32 y, z;
+ Block::Get(inBlock)(y)(z);
+
+ word32 sum = DELTA << LOG_ROUNDS;
+ for (int i=0; i<ROUNDS; i++)
+ {
+ z -= (y << 4) + k[2] ^ y + sum ^ (y >> 5) + k[3];
+ y -= (z << 4) + k[0] ^ z + sum ^ (z >> 5) + k[1];
+ sum -= DELTA;
+ }
+
+ Block::Put(xorBlock, outBlock)(y)(z);
+}
+
+NAMESPACE_END