summaryrefslogtreecommitdiff
path: root/tea.cpp
diff options
context:
space:
mode:
authorJeffrey Walton <noloader@gmail.com>2019-06-02 05:29:08 -0400
committerJeffrey Walton <noloader@gmail.com>2019-06-02 05:29:08 -0400
commit959494871fab813780b3f8a0e36bf2fdbbffb766 (patch)
tree33b188937aefa293fef8435cf4036a9cfd44907b /tea.cpp
parent9538f2d71544fd48c55dc94cbc12ae24d26cef45 (diff)
downloadcryptopp-git-959494871fab813780b3f8a0e36bf2fdbbffb766.tar.gz
Guard use of volatile cast in TEA and XTEA
Diffstat (limited to 'tea.cpp')
-rw-r--r--tea.cpp15
1 files changed, 11 insertions, 4 deletions
diff --git a/tea.cpp b/tea.cpp
index 30e75832..32708c93 100644
--- a/tea.cpp
+++ b/tea.cpp
@@ -4,6 +4,13 @@
#include "tea.h"
#include "misc.h"
+// http://github.com/weidai11/cryptopp/issues/503
+#if defined(__xlC__) || defined(__SUNPRO_CC)
+# define MAYBE_VOLATILE(x) (*const_cast<volatile word32*>(&x))
+#else
+# define MAYBE_VOLATILE(x) (x)
+#endif
+
NAMESPACE_BEGIN(CryptoPP)
static const word32 DELTA = 0x9e3779b9;
@@ -26,7 +33,7 @@ void TEA::Enc::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byt
Block::Get(inBlock)(y)(z);
// http://github.com/weidai11/cryptopp/issues/503
- while (*const_cast<volatile word32*>(&sum) != m_limit)
+ while (MAYBE_VOLATILE(sum) != m_limit)
{
sum += DELTA;
y += ((z << 4) + m_k[0]) ^ (z + sum) ^ ((z >> 5) + m_k[1]);
@@ -42,7 +49,7 @@ void TEA::Dec::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byt
Block::Get(inBlock)(y)(z);
// http://github.com/weidai11/cryptopp/issues/503
- while (*const_cast<volatile word32*>(&sum) != 0)
+ while (MAYBE_VOLATILE(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]);
@@ -66,7 +73,7 @@ void XTEA::Enc::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, by
Block::Get(inBlock)(y)(z);
// http://github.com/weidai11/cryptopp/issues/503
- while (*const_cast<volatile word32*>(&sum) != m_limit)
+ while (MAYBE_VOLATILE(sum) != m_limit)
{
y += ((z<<4 ^ z>>5) + z) ^ (sum + m_k[sum&3]);
sum += DELTA;
@@ -82,7 +89,7 @@ void XTEA::Dec::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, by
Block::Get(inBlock)(y)(z);
// http://github.com/weidai11/cryptopp/issues/503
- while (*const_cast<volatile word32*>(&sum) != 0)
+ while (MAYBE_VOLATILE(sum) != 0)
{
z -= ((y<<4 ^ y>>5) + y) ^ (sum + m_k[sum>>11 & 3]);
sum -= DELTA;