add "volatile" to prevent compiler optimizing away code

pull/2/head
weidai 2010-06-18 00:51:12 +00:00
parent 1fb6fa4fc8
commit 5a9739c922
9 changed files with 10 additions and 10 deletions

View File

@ -25,7 +25,7 @@ void Base32Decoder::IsolatedInitialize(const NameValuePairs &parameters)
const int *Base32Decoder::GetDefaultDecodingLookupArray() const int *Base32Decoder::GetDefaultDecodingLookupArray()
{ {
static bool s_initialized = false; static volatile bool s_initialized = false;
static int s_array[256]; static int s_array[256];
if (!s_initialized) if (!s_initialized)

View File

@ -28,7 +28,7 @@ void Base64Encoder::IsolatedInitialize(const NameValuePairs &parameters)
const int *Base64Decoder::GetDecodingLookupArray() const int *Base64Decoder::GetDecodingLookupArray()
{ {
static bool s_initialized = false; static volatile bool s_initialized = false;
static int s_array[256]; static int s_array[256];
if (!s_initialized) if (!s_initialized)

View File

@ -17,7 +17,7 @@
NAMESPACE_BEGIN(CryptoPP) NAMESPACE_BEGIN(CryptoPP)
word16 GCM_Base::s_reductionTable[256]; word16 GCM_Base::s_reductionTable[256];
bool GCM_Base::s_reductionTableInitialized = false; volatile bool GCM_Base::s_reductionTableInitialized = false;
void GCM_Base::GCTR::IncrementCounterBy256() void GCM_Base::GCTR::IncrementCounterBy256()
{ {

4
gcm.h
View File

@ -64,7 +64,7 @@ protected:
byte *HashKey() {return m_buffer+2*REQUIRED_BLOCKSIZE;} byte *HashKey() {return m_buffer+2*REQUIRED_BLOCKSIZE;}
byte *MulTable() {return m_buffer+3*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: protected:
void IncrementCounterBy256(); void IncrementCounterBy256();
@ -72,7 +72,7 @@ protected:
GCTR m_ctr; GCTR m_ctr;
static word16 s_reductionTable[256]; static word16 s_reductionTable[256];
static bool s_reductionTableInitialized; static volatile bool s_reductionTableInitialized;
enum {REQUIRED_BLOCKSIZE = 16, HASH_BLOCKSIZE = 16}; enum {REQUIRED_BLOCKSIZE = 16, HASH_BLOCKSIZE = 16};
}; };

View File

@ -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 }}; {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]; word32 GOST::Base::sTable[4][256];
void GOST::Base::UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &) void GOST::Base::UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &)

2
gost.h
View File

@ -27,7 +27,7 @@ class GOST : public GOST_Info, public BlockCipherDocumentation
static void PrecalculateSTable(); static void PrecalculateSTable();
static const byte sBox[8][16]; static const byte sBox[8][16];
static bool sTableCalculated; static volatile bool sTableCalculated;
static word32 sTable[4][256]; static word32 sTable[4][256];
FixedSizeSecBlock<word32, 8> key; FixedSizeSecBlock<word32, 8> key;

View File

@ -28,7 +28,7 @@ void HexDecoder::IsolatedInitialize(const NameValuePairs &parameters)
const int *HexDecoder::GetDefaultDecodingLookupArray() const int *HexDecoder::GetDefaultDecodingLookupArray()
{ {
static bool s_initialized = false; static volatile bool s_initialized = false;
static int s_array[256]; static int s_array[256];
if (!s_initialized) if (!s_initialized)

View File

@ -30,7 +30,7 @@ CRYPTOPP_COMPILE_ASSERT(sizeof(IDEA::Word) >= 2);
} }
#ifdef IDEA_LARGECACHE #ifdef IDEA_LARGECACHE
bool IDEA::Base::tablesBuilt = false; volatile bool IDEA::Base::tablesBuilt = false;
word16 IDEA::Base::log[0x10000]; word16 IDEA::Base::log[0x10000];
word16 IDEA::Base::antilog[0x10000]; word16 IDEA::Base::antilog[0x10000];

2
idea.h
View File

@ -43,7 +43,7 @@ private:
static inline void LookupMUL(word &a, word b); static inline void LookupMUL(word &a, word b);
void LookupKeyLogs(); void LookupKeyLogs();
static void BuildLogTables(); static void BuildLogTables();
static bool tablesBuilt; static volatile bool tablesBuilt;
static word16 log[0x10000], antilog[0x10000]; static word16 log[0x10000], antilog[0x10000];
#endif #endif
}; };