From 5a9739c92223101c2b7073e051397e8fa51ef071 Mon Sep 17 00:00:00 2001 From: weidai Date: Fri, 18 Jun 2010 00:51:12 +0000 Subject: [PATCH] add "volatile" to prevent compiler optimizing away code --- base32.cpp | 2 +- base64.cpp | 2 +- gcm.cpp | 2 +- gcm.h | 4 ++-- gost.cpp | 2 +- gost.h | 2 +- hex.cpp | 2 +- idea.cpp | 2 +- idea.h | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/base32.cpp b/base32.cpp index 56bce6e5..0568f072 100644 --- a/base32.cpp +++ b/base32.cpp @@ -25,7 +25,7 @@ void Base32Decoder::IsolatedInitialize(const NameValuePairs ¶meters) const int *Base32Decoder::GetDefaultDecodingLookupArray() { - static bool s_initialized = false; + static volatile bool s_initialized = false; static int s_array[256]; if (!s_initialized) diff --git a/base64.cpp b/base64.cpp index f86dc6e5..7571f2b8 100644 --- a/base64.cpp +++ b/base64.cpp @@ -28,7 +28,7 @@ void Base64Encoder::IsolatedInitialize(const NameValuePairs ¶meters) const int *Base64Decoder::GetDecodingLookupArray() { - static bool s_initialized = false; + static volatile bool s_initialized = false; static int s_array[256]; if (!s_initialized) diff --git a/gcm.cpp b/gcm.cpp index 986aa2a9..83672270 100644 --- a/gcm.cpp +++ b/gcm.cpp @@ -17,7 +17,7 @@ NAMESPACE_BEGIN(CryptoPP) word16 GCM_Base::s_reductionTable[256]; -bool GCM_Base::s_reductionTableInitialized = false; +volatile bool GCM_Base::s_reductionTableInitialized = false; void GCM_Base::GCTR::IncrementCounterBy256() { diff --git a/gcm.h b/gcm.h index 851ae802..0133ffef 100644 --- a/gcm.h +++ b/gcm.h @@ -64,7 +64,7 @@ protected: byte *HashKey() {return m_buffer+2*REQUIRED_BLOCKSIZE;} byte *MulTable() {return m_buffer+3*REQUIRED_BLOCKSIZE;} - class GCTR : public CTR_Mode_ExternalCipher::Encryption + class CRYPTOPP_DLL GCTR : public CTR_Mode_ExternalCipher::Encryption { protected: void IncrementCounterBy256(); @@ -72,7 +72,7 @@ protected: GCTR m_ctr; static word16 s_reductionTable[256]; - static bool s_reductionTableInitialized; + static volatile bool s_reductionTableInitialized; enum {REQUIRED_BLOCKSIZE = 16, HASH_BLOCKSIZE = 16}; }; diff --git a/gost.cpp b/gost.cpp index 1775238d..bbd82975 100644 --- a/gost.cpp +++ b/gost.cpp @@ -27,7 +27,7 @@ const byte GOST::Base::sBox[8][16]={ {14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7 }}; */ -bool GOST::Base::sTableCalculated = false; +volatile bool GOST::Base::sTableCalculated = false; word32 GOST::Base::sTable[4][256]; void GOST::Base::UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &) diff --git a/gost.h b/gost.h index 044c18d9..e6fe4693 100644 --- a/gost.h +++ b/gost.h @@ -27,7 +27,7 @@ class GOST : public GOST_Info, public BlockCipherDocumentation static void PrecalculateSTable(); static const byte sBox[8][16]; - static bool sTableCalculated; + static volatile bool sTableCalculated; static word32 sTable[4][256]; FixedSizeSecBlock key; diff --git a/hex.cpp b/hex.cpp index b6484a5d..5731df55 100644 --- a/hex.cpp +++ b/hex.cpp @@ -28,7 +28,7 @@ void HexDecoder::IsolatedInitialize(const NameValuePairs ¶meters) const int *HexDecoder::GetDefaultDecodingLookupArray() { - static bool s_initialized = false; + static volatile bool s_initialized = false; static int s_array[256]; if (!s_initialized) diff --git a/idea.cpp b/idea.cpp index b0768fad..bbbdbaca 100644 --- a/idea.cpp +++ b/idea.cpp @@ -30,7 +30,7 @@ CRYPTOPP_COMPILE_ASSERT(sizeof(IDEA::Word) >= 2); } #ifdef IDEA_LARGECACHE -bool IDEA::Base::tablesBuilt = false; +volatile bool IDEA::Base::tablesBuilt = false; word16 IDEA::Base::log[0x10000]; word16 IDEA::Base::antilog[0x10000]; diff --git a/idea.h b/idea.h index ce026a13..2ab5713a 100644 --- a/idea.h +++ b/idea.h @@ -43,7 +43,7 @@ private: static inline void LookupMUL(word &a, word b); void LookupKeyLogs(); static void BuildLogTables(); - static bool tablesBuilt; + static volatile bool tablesBuilt; static word16 log[0x10000], antilog[0x10000]; #endif };