9 static const word32 DELTA = 0x9e3779b9;
12 #define UINT32_CAST(x) ((word32*)(void*)(x)) 13 #define CONST_UINT32_CAST(x) ((const word32*)(const void*)(x)) 15 void TEA::Base::UncheckedSetKey(
const byte *userKey,
unsigned int length,
const NameValuePairs ¶ms)
17 AssertValidKeyLength(length);
20 m_limit = GetRoundsAndThrowIfInvalid(params,
this) * DELTA;
23 void TEA::Enc::ProcessAndXorBlock(
const byte *inBlock,
const byte *xorBlock, byte *outBlock)
const 26 Block::Get(inBlock)(y)(z);
29 while (*const_cast<volatile word32*>(&sum) != m_limit)
32 y += ((z << 4) + m_k[0]) ^ (z + sum) ^ ((z >> 5) + m_k[1]);
33 z += ((y << 4) + m_k[2]) ^ (y + sum) ^ ((y >> 5) + m_k[3]);
39 void TEA::Dec::ProcessAndXorBlock(
const byte *inBlock,
const byte *xorBlock, byte *outBlock)
const 41 word32 y, z, sum = m_limit;
42 Block::Get(inBlock)(y)(z);
45 while (*const_cast<volatile word32*>(&sum) != 0)
47 z -= ((y << 4) + m_k[2]) ^ (y + sum) ^ ((y >> 5) + m_k[3]);
48 y -= ((z << 4) + m_k[0]) ^ (z + sum) ^ ((z >> 5) + m_k[1]);
55 void XTEA::Base::UncheckedSetKey(
const byte *userKey,
unsigned int length,
const NameValuePairs ¶ms)
57 AssertValidKeyLength(length);
60 m_limit = GetRoundsAndThrowIfInvalid(params,
this) * DELTA;
63 void XTEA::Enc::ProcessAndXorBlock(
const byte *inBlock,
const byte *xorBlock, byte *outBlock)
const 66 Block::Get(inBlock)(y)(z);
69 while (*const_cast<volatile word32*>(&sum) != m_limit)
71 y += ((z<<4 ^ z>>5) + z) ^ (sum + m_k[sum&3]);
73 z += ((y<<4 ^ y>>5) + y) ^ (sum + m_k[sum>>11 & 3]);
79 void XTEA::Dec::ProcessAndXorBlock(
const byte *inBlock,
const byte *xorBlock, byte *outBlock)
const 81 word32 y, z, sum = m_limit;
82 Block::Get(inBlock)(y)(z);
85 while (*const_cast<volatile word32*>(&sum) != 0)
87 z -= ((y<<4 ^ y>>5) + y) ^ (sum + m_k[sum>>11 & 3]);
89 y -= ((z<<4 ^ z>>5) + z) ^ (sum + m_k[sum&3]);
95 #define MX ((z>>5^y<<2)+(y>>3^z<<4))^((sum^y)+(m_k[(p&3)^e]^z)) 97 void BTEA::Enc::ProcessAndXorBlock(
const byte *inBlock,
const byte *xorBlock, byte *outBlock)
const 99 CRYPTOPP_UNUSED(xorBlock);
103 unsigned int n = m_blockSize / 4;
104 word32 *v = UINT32_CAST(outBlock);
107 word32 y, z = v[n-1], e;
108 word32 p, q = 6+52/n;
115 for (p = 0; p < n-1; p++)
127 void BTEA::Dec::ProcessAndXorBlock(
const byte *inBlock,
const byte *xorBlock, byte *outBlock)
const 129 CRYPTOPP_UNUSED(xorBlock);
133 unsigned int n = m_blockSize / 4;
134 word32 *v = UINT32_CAST(outBlock);
137 word32 y = v[0], z, e;
138 word32 p, q = 6+52/n;
139 word32 sum = q * DELTA;
144 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 endianness.
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.