Backed out use of "static const" to declare constant; switch to "enum" (Issue 255)

This commit is contained in:
Jeffrey Walton 2016-09-06 04:04:03 -04:00
parent 45323bddd8
commit a62aee441f
21 changed files with 62 additions and 66 deletions

View File

@ -15,11 +15,6 @@ void ThreeWay_TestInstantiations()
}
#endif
// Hack for OS X 10.5 ld, http://github.com/weidai11/cryptopp/issues/255
static const size_t s_unused1 = ThreeWay::KEYLENGTH;
static const size_t s_unused2 = ThreeWayEncryption::KEYLENGTH;
static const size_t s_unused3 = ThreeWayDecryption::KEYLENGTH;
static const word32 START_E = 0x0b0b; // round constant of first encryption round
static const word32 START_D = 0xb1b1; // round constant of first decryption round
#ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562

10
cast.h
View File

@ -11,6 +11,8 @@
NAMESPACE_BEGIN(CryptoPP)
//! \class CAST
//! \brief CAST block cipher base
class CAST
{
protected:
@ -29,6 +31,8 @@ struct CAST128_Info : public FixedBlockSize<8>, public VariableKeyLength<16, 5,
//! \sa <a href="http://www.weidai.com/scan-mirror/cs.html#CAST-128">CAST-128</a>
class CAST128 : public CAST128_Info, public BlockCipherDocumentation
{
//! \class Base
//! \brief CAST128 block cipher default operation
class CRYPTOPP_NO_VTABLE Base : public CAST, public BlockCipherImpl<CAST128_Info>
{
public:
@ -39,12 +43,16 @@ class CAST128 : public CAST128_Info, public BlockCipherDocumentation
FixedSizeSecBlock<word32, 32> K;
};
//! \class Enc
//! \brief CAST128 block cipher encryption operation
class CRYPTOPP_NO_VTABLE Enc : public Base
{
public:
void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
};
//! \class Dec
//! \brief CAST128 block cipher decryption operation
class CRYPTOPP_NO_VTABLE Dec : public Base
{
public:
@ -68,6 +76,8 @@ struct CAST256_Info : public FixedBlockSize<16>, public VariableKeyLength<16, 16
//! \sa <a href="http://www.weidai.com/scan-mirror/cs.html#CAST-256">CAST-256</a>
class CAST256 : public CAST256_Info, public BlockCipherDocumentation
{
//! \class Base
//! \brief CAST256 block cipher default operation
class CRYPTOPP_NO_VTABLE Base : public CAST, public BlockCipherImpl<CAST256_Info>
{
public:

View File

@ -544,8 +544,9 @@ NAMESPACE_END
# define CRYPTOPP_NOINLINE
#endif
// how to declare class constants
#if (defined(_MSC_VER) && _MSC_VER <= 1300) || defined(__INTEL_COMPILER) || defined(__BORLANDC__)
// How to declare class constants
// Use enum for OS X 10.5 ld, http://github.com/weidai11/cryptopp/issues/255
#if (defined(_MSC_VER) && _MSC_VER <= 1300) || defined(__INTEL_COMPILER) || defined(__BORLANDC__) || (defined(__APPLE__) && (__GNUC__ == 4) && (__GNUC_MINOR__ <= 2))
# define CRYPTOPP_CONSTANT(x) enum {x};
#else
# define CRYPTOPP_CONSTANT(x) static const int x;

View File

@ -544,8 +544,9 @@ NAMESPACE_END
# define CRYPTOPP_NOINLINE
#endif
// how to declare class constants
#if (defined(_MSC_VER) && _MSC_VER <= 1300) || defined(__INTEL_COMPILER) || defined(__BORLANDC__)
// How to declare class constants
// Use enum for OS X 10.5 ld, http://github.com/weidai11/cryptopp/issues/255
#if (defined(_MSC_VER) && _MSC_VER <= 1300) || defined(__INTEL_COMPILER) || defined(__BORLANDC__) || (defined(__APPLE__) && (__GNUC__ == 4) && (__GNUC_MINOR__ <= 2))
# define CRYPTOPP_CONSTANT(x) enum {x};
#else
# define CRYPTOPP_CONSTANT(x) static const int x;

View File

@ -20,12 +20,6 @@
NAMESPACE_BEGIN(CryptoPP)
// Hack for OS X 10.5 ld, http://github.com/weidai11/cryptopp/issues/255
static const size_t s_unused1 = DES::KEYLENGTH;
static const size_t s_unused2 = DES_EDE2::KEYLENGTH;
static const size_t s_unused3 = DES_EDE3::KEYLENGTH;
static const size_t s_unused4 = DES_XEX3::KEYLENGTH;
typedef BlockGetAndPut<word32, BigEndian> Block;
// Richard Outerbridge's initial permutation algorithm

View File

@ -4,9 +4,6 @@
NAMESPACE_BEGIN(CryptoPP)
// Hack for OS X 10.5 ld, http://github.com/weidai11/cryptopp/issues/255
static const size_t s_unused = GOST::KEYLENGTH;
// these are the S-boxes given in Applied Cryptography 2nd Ed., p. 333
const byte GOST::Base::sBox[8][16]={
{4, 10, 9, 2, 13, 8, 0, 14, 6, 11, 1, 12, 7, 15, 5, 3},

View File

@ -7,9 +7,6 @@
NAMESPACE_BEGIN(CryptoPP)
// Hack for OS X 10.5 ld, http://github.com/weidai11/cryptopp/issues/255
static const size_t s_unused = IDEA::KEYLENGTH;
static const int IDEA_KEYLEN=(6*IDEA::ROUNDS+4); // key schedule length in # of word16s
#define low16(x) ((x)&0xffff) // compiler should be able to optimize this away if word is 16 bits

View File

@ -7,9 +7,9 @@
#include "modes.h"
#include "misc.h"
#ifndef NDEBUG
//#ifndef NDEBUG
#include "des.h"
#endif
//#endif
NAMESPACE_BEGIN(CryptoPP)

34
modes.h
View File

@ -16,7 +16,7 @@
NAMESPACE_BEGIN(CryptoPP)
//! \class CipherModeDocumentation
//! \brief Classes for operating block cipher modes of operation
//! \brief Block cipher mode of operation information
//! \details Each class derived from this one defines two types, Encryption and Decryption,
//! both of which implement the SymmetricCipher interface.
//! For each mode there are two classes, one of which is a template class,
@ -31,6 +31,8 @@ struct CipherModeDocumentation : public SymmetricCipherDocumentation
{
};
//! \class CipherModeBase
//! \brief Block cipher mode of operation information
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CipherModeBase : public SymmetricCipher
{
public:
@ -85,6 +87,9 @@ protected:
AlignedSecByteBlock m_register;
};
//! \class ModePolicyCommonTemplate
//! \brief Block cipher mode of operation common operations
//! \tparam POLICY_INTERFACE common operations
template <class POLICY_INTERFACE>
class CRYPTOPP_NO_VTABLE ModePolicyCommonTemplate : public CipherModeBase, public POLICY_INTERFACE
{
@ -101,6 +106,8 @@ void ModePolicyCommonTemplate<POLICY_INTERFACE>::CipherSetKey(const NameValuePai
SetFeedbackSize(feedbackSize);
}
//! \class CFB_ModePolicy
//! \brief CFB block cipher mode of operation
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CFB_ModePolicy : public ModePolicyCommonTemplate<CFB_CipherAbstractPolicy>
{
public:
@ -129,6 +136,8 @@ inline void CopyOrZero(void *dest, const void *src, size_t s)
memset(dest, 0, s);
}
//! \class OFB_ModePolicy
//! \brief OFB block cipher mode of operation
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE OFB_ModePolicy : public ModePolicyCommonTemplate<AdditiveCipherAbstractPolicy>
{
public:
@ -143,6 +152,8 @@ private:
void CipherResynchronize(byte *keystreamBuffer, const byte *iv, size_t length);
};
//! \class CTR_ModePolicy
//! \brief CTR block cipher mode of operation
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CTR_ModePolicy : public ModePolicyCommonTemplate<AdditiveCipherAbstractPolicy>
{
public:
@ -166,6 +177,8 @@ protected:
AlignedSecByteBlock m_counterArray;
};
//! \class BlockOrientedCipherModeBase
//! \brief Block cipher mode of operation default implementation
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE BlockOrientedCipherModeBase : public CipherModeBase
{
public:
@ -193,6 +206,8 @@ protected:
SecByteBlock m_buffer;
};
//! \class ECB_OneWay
//! \brief ECB block cipher mode of operation default implementation
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE ECB_OneWay : public BlockOrientedCipherModeBase
{
public:
@ -204,6 +219,8 @@ public:
static const char * CRYPTOPP_API StaticAlgorithmName() {return "ECB";}
};
//! \class CBC_ModeBase
//! \brief CBC block cipher mode of operation default implementation
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CBC_ModeBase : public BlockOrientedCipherModeBase
{
public:
@ -213,12 +230,16 @@ public:
static const char * CRYPTOPP_API StaticAlgorithmName() {return "CBC";}
};
//! \class CBC_Encryption
//! \brief CBC block cipher mode of operation encryption operation
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CBC_Encryption : public CBC_ModeBase
{
public:
void ProcessData(byte *outString, const byte *inString, size_t length);
};
//! \class CBC_CTS_Encryption
//! \brief CBC-CTS block cipher mode of operation encryption operation
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CBC_CTS_Encryption : public CBC_Encryption
{
public:
@ -237,6 +258,8 @@ protected:
byte *m_stolenIV;
};
//! \class CBC_Decryption
//! \brief CBC block cipher mode of operation decryption operation
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CBC_Decryption : public CBC_ModeBase
{
public:
@ -258,6 +281,8 @@ protected:
AlignedSecByteBlock m_temp;
};
//! \class CBC_CTS_Decryption
//! \brief CBC-CTS block cipher mode of operation decryption operation
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CBC_CTS_Decryption : public CBC_Decryption
{
public:
@ -265,7 +290,8 @@ public:
void ProcessLastBlock(byte *outString, const byte *inString, size_t length);
};
//! _
//! \class CipherModeFinalTemplate_CipherHolder
//! \brief Block cipher mode of operation aggregate
template <class CIPHER, class BASE>
class CipherModeFinalTemplate_CipherHolder : protected ObjectHolder<CIPHER>, public AlgorithmImpl<BASE, CipherModeFinalTemplate_CipherHolder<CIPHER, BASE> >
{
@ -296,8 +322,8 @@ public:
};
//! \class CipherModeFinalTemplate_ExternalCipher
//! \tparam BASE CipherModeFinalTemplate_CipherHolder class
//! \brief OFB block cipher mode of operation.
//! \tparam BASE CipherModeFinalTemplate_CipherHolder base class
//! \details
template <class BASE>
class CipherModeFinalTemplate_ExternalCipher : public BASE
{

View File

@ -17,9 +17,6 @@ NAMESPACE_BEGIN(CryptoPP)
# pragma warning(disable: 4731)
#endif
// Hack for OS X 10.5 ld, http://github.com/weidai11/cryptopp/issues/255
static const size_t s_unused = PanamaCipher<>::KEYLENGTH;
template <class B>
void Panama<B>::Reset()
{

10
safer.h
View File

@ -1,7 +1,7 @@
// safer.h - written and placed in the public domain by Wei Dai
//! \file safer.h
//! \brief Classes for the SAFER block cipher
//! \brief Classes for the SAFER and SAFER-K block ciphers
#ifndef CRYPTOPP_SAFER_H
#define CRYPTOPP_SAFER_H
@ -12,10 +12,12 @@
NAMESPACE_BEGIN(CryptoPP)
//! \class SAFER
//! \brief SAFER base class
//! \brief SAFER block cipher
class SAFER
{
public:
//! \class Base
//! \brief SAFER block cipher default operation
class CRYPTOPP_NO_VTABLE Base : public BlockCipher
{
public:
@ -30,12 +32,16 @@ public:
static const byte log_tab[256];
};
//! \class Enc
//! \brief SAFER block cipher encryption operation
class CRYPTOPP_NO_VTABLE Enc : public Base
{
public:
void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
};
//! \class Dec
//! \brief SAFER block cipher decryption operation
class CRYPTOPP_NO_VTABLE Dec : public Base
{
public:

View File

@ -40,10 +40,6 @@ void Salsa20_TestInstantiations()
}
#endif
// Hack for OS X 10.5 ld, http://github.com/weidai11/cryptopp/issues/255
// static const size_t s_unused1 = Salsa20::KEYLENGTH;
static const size_t s_unused2 = XSalsa20::KEYLENGTH;
void Salsa20_Policy::CipherSetKey(const NameValuePairs &params, const byte *key, size_t length)
{
m_rounds = params.GetIntValueWithDefault(Name::Rounds(), 20);

View File

@ -17,9 +17,6 @@ void SEAL_TestInstantiations()
}
#endif
// Hack for OS X 10.5 ld, http://github.com/weidai11/cryptopp/issues/255
static const size_t s_unused = SEAL<>::KEYLENGTH;
struct SEAL_Gamma
{
SEAL_Gamma(const byte *key)

View File

@ -6,9 +6,6 @@
NAMESPACE_BEGIN(CryptoPP)
// Hack for OS X 10.5 ld, http://github.com/weidai11/cryptopp/issues/255
static const size_t s_unused = SEED::KEYLENGTH;
static const word32 s_kc[16] = {
0x9e3779b9, 0x3c6ef373, 0x78dde6e6, 0xf1bbcdcc, 0xe3779b99, 0xc6ef3733, 0x8dde6e67, 0x1bbcdccf,
0x3779b99e, 0x6ef3733c, 0xdde6e678, 0xbbcdccf1, 0x779b99e3, 0xef3733c6, 0xde6e678d, 0xbcdccf1b};

View File

@ -12,9 +12,6 @@
NAMESPACE_BEGIN(CryptoPP)
// Hack for OS X 10.5 ld, http://github.com/weidai11/cryptopp/issues/255
static const size_t s_unused = SHARK::KEYLENGTH;
static word64 SHARKTransform(word64 a)
{
static const byte iG[8][8] = {

View File

@ -17,9 +17,6 @@
NAMESPACE_BEGIN(CryptoPP)
// Hack for OS X 10.5 ld, http://github.com/weidai11/cryptopp/issues/255
static const size_t s_unused = SKIPJACK::KEYLENGTH;
/**
* The F-table byte permutation (see description of the G-box permutation)
*/

View File

@ -19,7 +19,7 @@ struct SKIPJACK_Info : public FixedBlockSize<8>, public FixedKeyLength<10>
};
//! \class SKIPJACK
//! \brief SKIPJACK block cipher information
//! \brief SKIPJACK block cipher
//! \sa <a href="http://www.weidai.com/scan-mirror/cs.html#SKIPJACK">SKIPJACK</a>
class SKIPJACK : public SKIPJACK_Info, public BlockCipherDocumentation
{

View File

@ -18,9 +18,6 @@
NAMESPACE_BEGIN(CryptoPP)
// Hack for OS X 10.5 ld, http://github.com/weidai11/cryptopp/issues/255
static const size_t s_unused = Square::KEYLENGTH;
// apply theta to a roundkey
static void SquareTransform (word32 in[4], word32 out[4])
{

View File

@ -6,9 +6,6 @@
NAMESPACE_BEGIN(CryptoPP)
// Hack for OS X 10.5 ld, http://github.com/weidai11/cryptopp/issues/255
static const size_t s_unused = TEA::KEYLENGTH;
static const word32 DELTA = 0x9e3779b9;
typedef BlockGetAndPut<word32, BigEndian> Block;

View File

@ -6,9 +6,6 @@
NAMESPACE_BEGIN(CryptoPP)
// Hack for OS X 10.5 ld, http://github.com/weidai11/cryptopp/issues/255
static const size_t s_unused = TTMAC::KEYLENGTH;
void TTMAC_Base::UncheckedSetKey(const byte *userKey, unsigned int keylength, const NameValuePairs &)
{
AssertValidKeyLength(keylength);

View File

@ -15,9 +15,6 @@ void WAKE_TestInstantiations()
}
#endif
// Hack for OS X 10.5 ld, http://github.com/weidai11/cryptopp/issues/255
static const size_t s_unused = WAKE_OFB<>::KEYLENGTH;
inline word32 WAKE_Base::M(word32 x, word32 y)
{
word32 w = x+y;