9 static const word32 DELTA = 0x9e3779b9;
12 void TEA::Base::UncheckedSetKey(
const byte *userKey,
unsigned int length,
const NameValuePairs ¶ms)
14 AssertValidKeyLength(length);
17 m_limit = GetRoundsAndThrowIfInvalid(params,
this) * DELTA;
20 void TEA::Enc::ProcessAndXorBlock(
const byte *inBlock,
const byte *xorBlock, byte *outBlock)
const 23 Block::Get(inBlock)(y)(z);
26 while (sum != m_limit)
29 y += ((z << 4) + m_k[0]) ^ (z + sum) ^ ((z >> 5) + m_k[1]);
30 z += ((y << 4) + m_k[2]) ^ (y + sum) ^ ((y >> 5) + m_k[3]);
36 void TEA::Dec::ProcessAndXorBlock(
const byte *inBlock,
const byte *xorBlock, byte *outBlock)
const 39 Block::Get(inBlock)(y)(z);
44 z -= ((y << 4) + m_k[2]) ^ (y + sum) ^ ((y >> 5) + m_k[3]);
45 y -= ((z << 4) + m_k[0]) ^ (z + sum) ^ ((z >> 5) + m_k[1]);
52 void XTEA::Base::UncheckedSetKey(
const byte *userKey,
unsigned int length,
const NameValuePairs ¶ms)
54 AssertValidKeyLength(length);
57 m_limit = GetRoundsAndThrowIfInvalid(params,
this) * DELTA;
60 void XTEA::Enc::ProcessAndXorBlock(
const byte *inBlock,
const byte *xorBlock, byte *outBlock)
const 63 Block::Get(inBlock)(y)(z);
68 while ((sum&0xffffffff) != m_limit)
71 while (sum != m_limit)
74 y += ((z<<4 ^ z>>5) + z) ^ (sum + m_k[sum&3]);
76 z += ((y<<4 ^ y>>5) + y) ^ (sum + m_k[sum>>11 & 3]);
82 void XTEA::Dec::ProcessAndXorBlock(
const byte *inBlock,
const byte *xorBlock, byte *outBlock)
const 85 Block::Get(inBlock)(y)(z);
90 while ((sum&0xffffffff) != 0)
96 z -= ((y<<4 ^ y>>5) + y) ^ (sum + m_k[sum>>11 & 3]);
98 y -= ((z<<4 ^ z>>5) + z) ^ (sum + m_k[sum&3]);
104 #define MX ((z>>5^y<<2)+(y>>3^z<<4))^((sum^y)+(m_k[(p&3)^e]^z)) 106 void BTEA::Enc::ProcessAndXorBlock(
const byte *inBlock,
const byte *xorBlock, byte *outBlock)
const 108 CRYPTOPP_UNUSED(xorBlock);
112 unsigned int n = m_blockSize / 4;
113 word32 *v = (word32*)(
void *)outBlock;
116 word32 y = v[0], z = v[n-1], e;
117 word32 p, q = 6+52/n;
124 for (p = 0; p < n-1; p++)
136 void BTEA::Dec::ProcessAndXorBlock(
const byte *inBlock,
const byte *xorBlock, byte *outBlock)
const 138 CRYPTOPP_UNUSED(xorBlock);
142 unsigned int n = m_blockSize / 4;
143 word32 *v = (word32*)(
void *)outBlock;
146 word32 y = v[0], z = v[n-1], e;
147 word32 p, q = 6+52/n;
148 word32 sum = q * DELTA;
153 for (p = n-1; p > 0; p--)
Utility functions for the Crypto++ library.
Access a block of memory.
bool IsAlignedOn(const void *ptr, unsigned int alignment)
Determines whether ptr is aligned to a minimum value.
T ConditionalByteReverse(ByteOrder order, T value)
Reverses bytes in a value depending upon endianess.
Classes for the TEA, BTEA and XTEA block ciphers.
#define CRYPTOPP_ASSERT(exp)
Debugging and diagnostic assertion.
Access a block of memory.
Crypto++ library namespace.
Interface for retrieving values given their names.