Skip to content

Commit a62aee4

Browse files
committed
Backed out use of "static const" to declare constant; switch to "enum" (Issue 255)
1 parent 45323bd commit a62aee4

21 files changed

+62
-66
lines changed

3way.cpp

-5
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@ void ThreeWay_TestInstantiations()
1515
}
1616
#endif
1717

18-
// Hack for OS X 10.5 ld, http://github.com/weidai11/cryptopp/issues/255
19-
static const size_t s_unused1 = ThreeWay::KEYLENGTH;
20-
static const size_t s_unused2 = ThreeWayEncryption::KEYLENGTH;
21-
static const size_t s_unused3 = ThreeWayDecryption::KEYLENGTH;
22-
2318
static const word32 START_E = 0x0b0b; // round constant of first encryption round
2419
static const word32 START_D = 0xb1b1; // round constant of first decryption round
2520
#ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562

cast.h

+10
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
NAMESPACE_BEGIN(CryptoPP)
1313

14+
//! \class CAST
15+
//! \brief CAST block cipher base
1416
class CAST
1517
{
1618
protected:
@@ -29,6 +31,8 @@ struct CAST128_Info : public FixedBlockSize<8>, public VariableKeyLength<16, 5,
2931
//! \sa <a href="http://www.weidai.com/scan-mirror/cs.html#CAST-128">CAST-128</a>
3032
class CAST128 : public CAST128_Info, public BlockCipherDocumentation
3133
{
34+
//! \class Base
35+
//! \brief CAST128 block cipher default operation
3236
class CRYPTOPP_NO_VTABLE Base : public CAST, public BlockCipherImpl<CAST128_Info>
3337
{
3438
public:
@@ -39,12 +43,16 @@ class CAST128 : public CAST128_Info, public BlockCipherDocumentation
3943
FixedSizeSecBlock<word32, 32> K;
4044
};
4145

46+
//! \class Enc
47+
//! \brief CAST128 block cipher encryption operation
4248
class CRYPTOPP_NO_VTABLE Enc : public Base
4349
{
4450
public:
4551
void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
4652
};
4753

54+
//! \class Dec
55+
//! \brief CAST128 block cipher decryption operation
4856
class CRYPTOPP_NO_VTABLE Dec : public Base
4957
{
5058
public:
@@ -68,6 +76,8 @@ struct CAST256_Info : public FixedBlockSize<16>, public VariableKeyLength<16, 16
6876
//! \sa <a href="http://www.weidai.com/scan-mirror/cs.html#CAST-256">CAST-256</a>
6977
class CAST256 : public CAST256_Info, public BlockCipherDocumentation
7078
{
79+
//! \class Base
80+
//! \brief CAST256 block cipher default operation
7181
class CRYPTOPP_NO_VTABLE Base : public CAST, public BlockCipherImpl<CAST256_Info>
7282
{
7383
public:

config.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -544,8 +544,9 @@ NAMESPACE_END
544544
# define CRYPTOPP_NOINLINE
545545
#endif
546546

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

config.recommend

+3-2
Original file line numberDiff line numberDiff line change
@@ -544,8 +544,9 @@ NAMESPACE_END
544544
# define CRYPTOPP_NOINLINE
545545
#endif
546546

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

des.cpp

-6
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,6 @@
2020

2121
NAMESPACE_BEGIN(CryptoPP)
2222

23-
// Hack for OS X 10.5 ld, http://github.com/weidai11/cryptopp/issues/255
24-
static const size_t s_unused1 = DES::KEYLENGTH;
25-
static const size_t s_unused2 = DES_EDE2::KEYLENGTH;
26-
static const size_t s_unused3 = DES_EDE3::KEYLENGTH;
27-
static const size_t s_unused4 = DES_XEX3::KEYLENGTH;
28-
2923
typedef BlockGetAndPut<word32, BigEndian> Block;
3024

3125
// Richard Outerbridge's initial permutation algorithm

gost.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44

55
NAMESPACE_BEGIN(CryptoPP)
66

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

idea.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77

88
NAMESPACE_BEGIN(CryptoPP)
99

10-
// Hack for OS X 10.5 ld, http://github.com/weidai11/cryptopp/issues/255
11-
static const size_t s_unused = IDEA::KEYLENGTH;
12-
1310
static const int IDEA_KEYLEN=(6*IDEA::ROUNDS+4); // key schedule length in # of word16s
1411

1512
#define low16(x) ((x)&0xffff) // compiler should be able to optimize this away if word is 16 bits

modes.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
#include "modes.h"
88
#include "misc.h"
99

10-
#ifndef NDEBUG
10+
//#ifndef NDEBUG
1111
#include "des.h"
12-
#endif
12+
//#endif
1313

1414
NAMESPACE_BEGIN(CryptoPP)
1515

modes.h

+35-9
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
NAMESPACE_BEGIN(CryptoPP)
1717

1818
//! \class CipherModeDocumentation
19-
//! \brief Classes for operating block cipher modes of operation
20-
//! \details Each class derived from this one defines two types, Encryption and Decryption,
19+
//! \brief Block cipher mode of operation information
20+
//! \details Each class derived from this one defines two types, Encryption and Decryption,
2121
//! both of which implement the SymmetricCipher interface.
2222
//! For each mode there are two classes, one of which is a template class,
2323
//! and the other one has a name that ends in "_ExternalCipher".
@@ -31,6 +31,8 @@ struct CipherModeDocumentation : public SymmetricCipherDocumentation
3131
{
3232
};
3333

34+
//! \class CipherModeBase
35+
//! \brief Block cipher mode of operation information
3436
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CipherModeBase : public SymmetricCipher
3537
{
3638
public:
@@ -70,7 +72,7 @@ class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CipherModeBase : public SymmetricCipher
7072
if (!(feedbackSize == 0 || feedbackSize == BlockSize()))
7173
throw InvalidArgument("CipherModeBase: feedback size cannot be specified for this cipher mode");
7274
}
73-
75+
7476
// Thanks to Zireael, http://github.com/weidai11/cryptopp/pull/46
7577
#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
7678
virtual void ResizeBuffers();
@@ -85,6 +87,9 @@ class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CipherModeBase : public SymmetricCipher
8587
AlignedSecByteBlock m_register;
8688
};
8789

90+
//! \class ModePolicyCommonTemplate
91+
//! \brief Block cipher mode of operation common operations
92+
//! \tparam POLICY_INTERFACE common operations
8893
template <class POLICY_INTERFACE>
8994
class CRYPTOPP_NO_VTABLE ModePolicyCommonTemplate : public CipherModeBase, public POLICY_INTERFACE
9095
{
@@ -101,6 +106,8 @@ void ModePolicyCommonTemplate<POLICY_INTERFACE>::CipherSetKey(const NameValuePai
101106
SetFeedbackSize(feedbackSize);
102107
}
103108

109+
//! \class CFB_ModePolicy
110+
//! \brief CFB block cipher mode of operation
104111
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CFB_ModePolicy : public ModePolicyCommonTemplate<CFB_CipherAbstractPolicy>
105112
{
106113
public:
@@ -129,6 +136,8 @@ inline void CopyOrZero(void *dest, const void *src, size_t s)
129136
memset(dest, 0, s);
130137
}
131138

139+
//! \class OFB_ModePolicy
140+
//! \brief OFB block cipher mode of operation
132141
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE OFB_ModePolicy : public ModePolicyCommonTemplate<AdditiveCipherAbstractPolicy>
133142
{
134143
public:
@@ -143,6 +152,8 @@ class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE OFB_ModePolicy : public ModePolicyCommonTe
143152
void CipherResynchronize(byte *keystreamBuffer, const byte *iv, size_t length);
144153
};
145154

155+
//! \class CTR_ModePolicy
156+
//! \brief CTR block cipher mode of operation
146157
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CTR_ModePolicy : public ModePolicyCommonTemplate<AdditiveCipherAbstractPolicy>
147158
{
148159
public:
@@ -166,6 +177,8 @@ class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CTR_ModePolicy : public ModePolicyCommonTe
166177
AlignedSecByteBlock m_counterArray;
167178
};
168179

180+
//! \class BlockOrientedCipherModeBase
181+
//! \brief Block cipher mode of operation default implementation
169182
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE BlockOrientedCipherModeBase : public CipherModeBase
170183
{
171184
public:
@@ -178,7 +191,7 @@ class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE BlockOrientedCipherModeBase : public Ciphe
178191

179192
protected:
180193
bool RequireAlignedInput() const {return true;}
181-
194+
182195
// Thanks to Zireael, http://github.com/weidai11/cryptopp/pull/46
183196
#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
184197
void ResizeBuffers();
@@ -193,6 +206,8 @@ class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE BlockOrientedCipherModeBase : public Ciphe
193206
SecByteBlock m_buffer;
194207
};
195208

209+
//! \class ECB_OneWay
210+
//! \brief ECB block cipher mode of operation default implementation
196211
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE ECB_OneWay : public BlockOrientedCipherModeBase
197212
{
198213
public:
@@ -204,6 +219,8 @@ class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE ECB_OneWay : public BlockOrientedCipherMod
204219
static const char * CRYPTOPP_API StaticAlgorithmName() {return "ECB";}
205220
};
206221

222+
//! \class CBC_ModeBase
223+
//! \brief CBC block cipher mode of operation default implementation
207224
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CBC_ModeBase : public BlockOrientedCipherModeBase
208225
{
209226
public:
@@ -213,12 +230,16 @@ class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CBC_ModeBase : public BlockOrientedCipherM
213230
static const char * CRYPTOPP_API StaticAlgorithmName() {return "CBC";}
214231
};
215232

233+
//! \class CBC_Encryption
234+
//! \brief CBC block cipher mode of operation encryption operation
216235
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CBC_Encryption : public CBC_ModeBase
217236
{
218237
public:
219238
void ProcessData(byte *outString, const byte *inString, size_t length);
220239
};
221240

241+
//! \class CBC_CTS_Encryption
242+
//! \brief CBC-CTS block cipher mode of operation encryption operation
222243
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CBC_CTS_Encryption : public CBC_Encryption
223244
{
224245
public:
@@ -237,13 +258,15 @@ class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CBC_CTS_Encryption : public CBC_Encryption
237258
byte *m_stolenIV;
238259
};
239260

261+
//! \class CBC_Decryption
262+
//! \brief CBC block cipher mode of operation decryption operation
240263
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CBC_Decryption : public CBC_ModeBase
241264
{
242265
public:
243266
void ProcessData(byte *outString, const byte *inString, size_t length);
244-
267+
245268
protected:
246-
269+
247270
// Thanks to Zireael, http://github.com/weidai11/cryptopp/pull/46
248271
#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
249272
void ResizeBuffers();
@@ -258,14 +281,17 @@ class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CBC_Decryption : public CBC_ModeBase
258281
AlignedSecByteBlock m_temp;
259282
};
260283

284+
//! \class CBC_CTS_Decryption
285+
//! \brief CBC-CTS block cipher mode of operation decryption operation
261286
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CBC_CTS_Decryption : public CBC_Decryption
262287
{
263288
public:
264289
unsigned int MinLastBlockSize() const {return BlockSize()+1;}
265290
void ProcessLastBlock(byte *outString, const byte *inString, size_t length);
266291
};
267292

268-
//! _
293+
//! \class CipherModeFinalTemplate_CipherHolder
294+
//! \brief Block cipher mode of operation aggregate
269295
template <class CIPHER, class BASE>
270296
class CipherModeFinalTemplate_CipherHolder : protected ObjectHolder<CIPHER>, public AlgorithmImpl<BASE, CipherModeFinalTemplate_CipherHolder<CIPHER, BASE> >
271297
{
@@ -296,8 +322,8 @@ class CipherModeFinalTemplate_CipherHolder : protected ObjectHolder<CIPHER>, pub
296322
};
297323

298324
//! \class CipherModeFinalTemplate_ExternalCipher
299-
//! \tparam BASE CipherModeFinalTemplate_CipherHolder class
300-
//! \brief OFB block cipher mode of operation.
325+
//! \tparam BASE CipherModeFinalTemplate_CipherHolder base class
326+
//! \details
301327
template <class BASE>
302328
class CipherModeFinalTemplate_ExternalCipher : public BASE
303329
{

panama.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ NAMESPACE_BEGIN(CryptoPP)
1717
# pragma warning(disable: 4731)
1818
#endif
1919

20-
// Hack for OS X 10.5 ld, http://github.com/weidai11/cryptopp/issues/255
21-
static const size_t s_unused = PanamaCipher<>::KEYLENGTH;
22-
2320
template <class B>
2421
void Panama<B>::Reset()
2522
{

safer.h

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// safer.h - written and placed in the public domain by Wei Dai
22

33
//! \file safer.h
4-
//! \brief Classes for the SAFER block cipher
4+
//! \brief Classes for the SAFER and SAFER-K block ciphers
55

66
#ifndef CRYPTOPP_SAFER_H
77
#define CRYPTOPP_SAFER_H
@@ -12,10 +12,12 @@
1212
NAMESPACE_BEGIN(CryptoPP)
1313

1414
//! \class SAFER
15-
//! \brief SAFER base class
15+
//! \brief SAFER block cipher
1616
class SAFER
1717
{
1818
public:
19+
//! \class Base
20+
//! \brief SAFER block cipher default operation
1921
class CRYPTOPP_NO_VTABLE Base : public BlockCipher
2022
{
2123
public:
@@ -30,12 +32,16 @@ class SAFER
3032
static const byte log_tab[256];
3133
};
3234

35+
//! \class Enc
36+
//! \brief SAFER block cipher encryption operation
3337
class CRYPTOPP_NO_VTABLE Enc : public Base
3438
{
3539
public:
3640
void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
3741
};
3842

43+
//! \class Dec
44+
//! \brief SAFER block cipher decryption operation
3945
class CRYPTOPP_NO_VTABLE Dec : public Base
4046
{
4147
public:

salsa.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@ void Salsa20_TestInstantiations()
4040
}
4141
#endif
4242

43-
// Hack for OS X 10.5 ld, http://github.com/weidai11/cryptopp/issues/255
44-
// static const size_t s_unused1 = Salsa20::KEYLENGTH;
45-
static const size_t s_unused2 = XSalsa20::KEYLENGTH;
46-
4743
void Salsa20_Policy::CipherSetKey(const NameValuePairs &params, const byte *key, size_t length)
4844
{
4945
m_rounds = params.GetIntValueWithDefault(Name::Rounds(), 20);

seal.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ void SEAL_TestInstantiations()
1717
}
1818
#endif
1919

20-
// Hack for OS X 10.5 ld, http://github.com/weidai11/cryptopp/issues/255
21-
static const size_t s_unused = SEAL<>::KEYLENGTH;
22-
2320
struct SEAL_Gamma
2421
{
2522
SEAL_Gamma(const byte *key)

seed.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66

77
NAMESPACE_BEGIN(CryptoPP)
88

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

shark.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212

1313
NAMESPACE_BEGIN(CryptoPP)
1414

15-
// Hack for OS X 10.5 ld, http://github.com/weidai11/cryptopp/issues/255
16-
static const size_t s_unused = SHARK::KEYLENGTH;
17-
1815
static word64 SHARKTransform(word64 a)
1916
{
2017
static const byte iG[8][8] = {

skipjack.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717

1818
NAMESPACE_BEGIN(CryptoPP)
1919

20-
// Hack for OS X 10.5 ld, http://github.com/weidai11/cryptopp/issues/255
21-
static const size_t s_unused = SKIPJACK::KEYLENGTH;
22-
2320
/**
2421
* The F-table byte permutation (see description of the G-box permutation)
2522
*/

0 commit comments

Comments
 (0)