summaryrefslogtreecommitdiff
path: root/tea.cpp
diff options
context:
space:
mode:
authorJeffrey Walton <noloader@gmail.com>2017-09-16 08:20:35 -0400
committerJeffrey Walton <noloader@gmail.com>2017-09-16 08:20:35 -0400
commitfc0867827e5547c628bb1d45b01efd1d7bd6a142 (patch)
tree23360624319bb9e65061bc633134c99c945ff2dd /tea.cpp
parent4670e3d5bce96c1a6105e2d4092b3d38c0e92893 (diff)
downloadcryptopp-git-fc0867827e5547c628bb1d45b01efd1d7bd6a142.tar.gz
Fix TEA and XTE hand with IBM XL C/C++ compiler (GH #503)
It looks like Sun compilers had problems with the loop in the past, too. The Sun workarounds did not help with XL C/C++, however.
Diffstat (limited to 'tea.cpp')
-rw-r--r--tea.cpp36
1 files changed, 12 insertions, 24 deletions
diff --git a/tea.cpp b/tea.cpp
index 3c0daa4c..7ca65367 100644
--- a/tea.cpp
+++ b/tea.cpp
@@ -19,11 +19,11 @@ void TEA::Base::UncheckedSetKey(const byte *userKey, unsigned int length, const
void TEA::Enc::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const
{
- word32 y, z;
+ word32 y, z, sum = 0;
Block::Get(inBlock)(y)(z);
- word32 sum = 0;
- while (sum != m_limit)
+ // http://github.com/weidai11/cryptopp/issues/503
+ while (*const_cast<volatile word32*>(&sum) != m_limit)
{
sum += DELTA;
y += ((z << 4) + m_k[0]) ^ (z + sum) ^ ((z >> 5) + m_k[1]);
@@ -35,11 +35,11 @@ void TEA::Enc::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byt
void TEA::Dec::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const
{
- word32 y, z;
+ word32 y, z, sum = m_limit;
Block::Get(inBlock)(y)(z);
- word32 sum = m_limit;
- while (sum != 0)
+ // http://github.com/weidai11/cryptopp/issues/503
+ while (*const_cast<volatile word32*>(&sum) != 0)
{
z -= ((y << 4) + m_k[2]) ^ (y + sum) ^ ((y >> 5) + m_k[3]);
y -= ((z << 4) + m_k[0]) ^ (z + sum) ^ ((z >> 5) + m_k[1]);
@@ -59,17 +59,11 @@ void XTEA::Base::UncheckedSetKey(const byte *userKey, unsigned int length, cons
void XTEA::Enc::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const
{
- word32 y, z;
+ word32 y, z, sum = 0;
Block::Get(inBlock)(y)(z);
-#ifdef __SUNPRO_CC
- // workaround needed on Sun Studio 12u1 Sun C++ 5.10 SunOS_i386 128229-02 2009/09/21
- size_t sum = 0;
- while ((sum&0xffffffff) != m_limit)
-#else
- word32 sum = 0;
- while (sum != m_limit)
-#endif
+ // http://github.com/weidai11/cryptopp/issues/503
+ while (*const_cast<volatile word32*>(&sum) != m_limit)
{
y += ((z<<4 ^ z>>5) + z) ^ (sum + m_k[sum&3]);
sum += DELTA;
@@ -81,17 +75,11 @@ void XTEA::Enc::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, by
void XTEA::Dec::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const
{
- word32 y, z;
+ word32 y, z, sum = m_limit;
Block::Get(inBlock)(y)(z);
-#ifdef __SUNPRO_CC
- // workaround needed on Sun Studio 12u1 Sun C++ 5.10 SunOS_i386 128229-02 2009/09/21
- size_t sum = m_limit;
- while ((sum&0xffffffff) != 0)
-#else
- word32 sum = m_limit;
- while (sum != 0)
-#endif
+ // http://github.com/weidai11/cryptopp/issues/503
+ while (*const_cast<volatile word32*>(&sum) != 0)
{
z -= ((y<<4 ^ y>>5) + y) ^ (sum + m_k[sum>>11 & 3]);
sum -= DELTA;