From a3b6ece7ab341b5b14135baeccea7d5e4c086771 Mon Sep 17 00:00:00 2001 From: weidai Date: Fri, 4 Oct 2002 17:31:41 +0000 Subject: Initial revision --- tea.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 tea.cpp (limited to 'tea.cpp') diff --git a/tea.cpp b/tea.cpp new file mode 100644 index 00000000..3b5d181c --- /dev/null +++ b/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 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> 5) + k[1]; + z += (y << 4) + k[2] ^ y + sum ^ (y >> 5) + k[3]; + } + + Block::Put(xorBlock, outBlock)(y)(z); +} + +typedef BlockGetAndPut 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> 5) + k[3]; + y -= (z << 4) + k[0] ^ z + sum ^ (z >> 5) + k[1]; + sum -= DELTA; + } + + Block::Put(xorBlock, outBlock)(y)(z); +} + +NAMESPACE_END -- cgit v1.2.1