Skip to content

Commit

Permalink
add "volatile" to prevent compiler optimizing away code
Browse files Browse the repository at this point in the history
  • Loading branch information
weidai11 committed Jun 18, 2010
1 parent 1fb6fa4 commit 5a9739c
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion base32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void Base32Decoder::IsolatedInitialize(const NameValuePairs &parameters)

const int *Base32Decoder::GetDefaultDecodingLookupArray()
{
static bool s_initialized = false;
static volatile bool s_initialized = false;
static int s_array[256];

if (!s_initialized)
Expand Down
2 changes: 1 addition & 1 deletion base64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void Base64Encoder::IsolatedInitialize(const NameValuePairs &parameters)

const int *Base64Decoder::GetDecodingLookupArray()
{
static bool s_initialized = false;
static volatile bool s_initialized = false;
static int s_array[256];

if (!s_initialized)
Expand Down
2 changes: 1 addition & 1 deletion gcm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
4 changes: 2 additions & 2 deletions gcm.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE GCM_Base : public AuthenticatedSymmetricCi
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();
};

GCTR m_ctr;
static word16 s_reductionTable[256];
static bool s_reductionTableInitialized;
static volatile bool s_reductionTableInitialized;
enum {REQUIRED_BLOCKSIZE = 16, HASH_BLOCKSIZE = 16};
};

Expand Down
2 changes: 1 addition & 1 deletion gost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 &)
Expand Down
2 changes: 1 addition & 1 deletion gost.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<word32, 8> key;
Expand Down
2 changes: 1 addition & 1 deletion hex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void HexDecoder::IsolatedInitialize(const NameValuePairs &parameters)

const int *HexDecoder::GetDefaultDecodingLookupArray()
{
static bool s_initialized = false;
static volatile bool s_initialized = false;
static int s_array[256];

if (!s_initialized)
Expand Down
2 changes: 1 addition & 1 deletion idea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down
2 changes: 1 addition & 1 deletion idea.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class IDEA : public IDEA_Info, public BlockCipherDocumentation
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
};
Expand Down

0 comments on commit 5a9739c

Please sign in to comment.