8#if defined(__xlC__) || defined(__SUNPRO_CC)
9# define MAYBE_VOLATILE(x) (*const_cast<volatile word32*>(&x))
11# define MAYBE_VOLATILE(x) (x)
14NAMESPACE_BEGIN(CryptoPP)
16static const word32 DELTA = 0x9e3779b9;
19#define UINT32_CAST(x) ((word32*)(void*)(x))
20#define CONST_UINT32_CAST(x) ((const word32*)(const void*)(x))
22void TEA::Base::UncheckedSetKey(
const byte *userKey,
unsigned int length,
const NameValuePairs ¶ms)
24 AssertValidKeyLength(length);
27 m_limit = GetRoundsAndThrowIfInvalid(params,
this) * DELTA;
30void TEA::Enc::ProcessAndXorBlock(
const byte *inBlock,
const byte *xorBlock,
byte *outBlock)
const
33 Block::Get(inBlock)(y)(z);
36 while (MAYBE_VOLATILE(sum) != m_limit)
39 y += ((z << 4) + m_k[0]) ^ (z + sum) ^ ((z >> 5) + m_k[1]);
40 z += ((y << 4) + m_k[2]) ^ (y + sum) ^ ((y >> 5) + m_k[3]);
46void TEA::Dec::ProcessAndXorBlock(
const byte *inBlock,
const byte *xorBlock,
byte *outBlock)
const
48 word32 y, z, sum = m_limit;
49 Block::Get(inBlock)(y)(z);
52 while (MAYBE_VOLATILE(sum) != 0)
54 z -= ((y << 4) + m_k[2]) ^ (y + sum) ^ ((y >> 5) + m_k[3]);
55 y -= ((z << 4) + m_k[0]) ^ (z + sum) ^ ((z >> 5) + m_k[1]);
62void XTEA::Base::UncheckedSetKey(
const byte *userKey,
unsigned int length,
const NameValuePairs ¶ms)
64 AssertValidKeyLength(length);
67 m_limit = GetRoundsAndThrowIfInvalid(params,
this) * DELTA;
70void XTEA::Enc::ProcessAndXorBlock(
const byte *inBlock,
const byte *xorBlock,
byte *outBlock)
const
73 Block::Get(inBlock)(y)(z);
76 while (MAYBE_VOLATILE(sum) != m_limit)
78 y += ((z<<4 ^ z>>5) + z) ^ (sum + m_k[sum&3]);
80 z += ((y<<4 ^ y>>5) + y) ^ (sum + m_k[sum>>11 & 3]);
86void XTEA::Dec::ProcessAndXorBlock(
const byte *inBlock,
const byte *xorBlock,
byte *outBlock)
const
88 word32 y, z, sum = m_limit;
89 Block::Get(inBlock)(y)(z);
92 while (MAYBE_VOLATILE(sum) != 0)
94 z -= ((y<<4 ^ y>>5) + y) ^ (sum + m_k[sum>>11 & 3]);
96 y -= ((z<<4 ^ z>>5) + z) ^ (sum + m_k[sum&3]);
102#define MX ((z>>5^y<<2)+(y>>3^z<<4))^((sum^y)+(m_k[(p&3)^e]^z))
104void BTEA::Enc::ProcessAndXorBlock(
const byte *inBlock,
const byte *xorBlock,
byte *outBlock)
const
106 CRYPTOPP_UNUSED(xorBlock);
107 CRYPTOPP_ASSERT(
IsAlignedOn(inBlock,GetAlignmentOf<word32>()));
108 CRYPTOPP_ASSERT(
IsAlignedOn(outBlock,GetAlignmentOf<word32>()));
110 unsigned int n = m_blockSize / 4;
111 word32 *v = UINT32_CAST(outBlock);
122 for (p = 0; p < n-1; p++)
134void BTEA::Dec::ProcessAndXorBlock(
const byte *inBlock,
const byte *xorBlock,
byte *outBlock)
const
136 CRYPTOPP_UNUSED(xorBlock);
137 CRYPTOPP_ASSERT(
IsAlignedOn(inBlock,GetAlignmentOf<word32>()));
138 CRYPTOPP_ASSERT(
IsAlignedOn(outBlock,GetAlignmentOf<word32>()));
140 unsigned int n = m_blockSize / 4;
141 word32 *v = UINT32_CAST(outBlock);
151 for (p = n-1; p > 0; p--)
Interface for retrieving values given their names.
Access a block of memory.
unsigned int word32
32-bit unsigned datatype
@ BIG_ENDIAN_ORDER
byte order is big-endian
Utility functions for the Crypto++ library.
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.
void GetUserKey(ByteOrder order, T *out, size_t outlen, const byte *in, size_t inlen)
Copy bytes in a buffer to an array of elements in big-endian order.
Access a block of memory.
Classes for the TEA, BTEA and XTEA block ciphers.