Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

tea.cpp

00001 // tea.cpp - modified by Wei Dai from code in the original paper 00002 00003 #include "pch.h" 00004 #include "tea.h" 00005 #include "misc.h" 00006 00007 NAMESPACE_BEGIN(CryptoPP) 00008 00009 const word32 TEA::Base::DELTA = 0x9e3779b9; 00010 00011 void TEA::Base::UncheckedSetKey(CipherDir direction, const byte *userKey, unsigned int length) 00012 { 00013 AssertValidKeyLength(length); 00014 00015 GetUserKey(BIG_ENDIAN_ORDER, k.begin(), 4, userKey, KEYLENGTH); 00016 } 00017 00018 typedef BlockGetAndPut<word32, BigEndian> Block; 00019 00020 void TEA::Enc::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const 00021 { 00022 word32 y, z; 00023 Block::Get(inBlock)(y)(z); 00024 00025 word32 sum = 0; 00026 for (int i=0; i<ROUNDS; i++) 00027 { 00028 sum += DELTA; 00029 y += (z << 4) + k[0] ^ z + sum ^ (z >> 5) + k[1]; 00030 z += (y << 4) + k[2] ^ y + sum ^ (y >> 5) + k[3]; 00031 } 00032 00033 Block::Put(xorBlock, outBlock)(y)(z); 00034 } 00035 00036 typedef BlockGetAndPut<word32, BigEndian> Block; 00037 00038 void TEA::Dec::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const 00039 { 00040 word32 y, z; 00041 Block::Get(inBlock)(y)(z); 00042 00043 word32 sum = DELTA << LOG_ROUNDS; 00044 for (int i=0; i<ROUNDS; i++) 00045 { 00046 z -= (y << 4) + k[2] ^ y + sum ^ (y >> 5) + k[3]; 00047 y -= (z << 4) + k[0] ^ z + sum ^ (z >> 5) + k[1]; 00048 sum -= DELTA; 00049 } 00050 00051 Block::Put(xorBlock, outBlock)(y)(z); 00052 } 00053 00054 NAMESPACE_END

Generated on Wed Jul 28 08:07:09 2004 for Crypto++ by doxygen 1.3.7