From 4afd858ae4974f82f9997b9184bc3d8d71d29b6e Mon Sep 17 00:00:00 2001 From: weidai Date: Thu, 14 Dec 2006 11:41:39 +0000 Subject: [PATCH] port to Borland C++Builder 2006 --- Readme.txt | 15 ++++++++------- adler32.h | 2 +- algebra.cpp | 7 ------- config.h | 25 +++++++++++++++++++++---- crc.h | 2 +- datatest.cpp | 6 ++++++ dmac.h | 2 +- eccrypto.cpp | 5 +++-- factory.h | 4 +++- files.cpp | 1 - filters.h | 2 +- gfpcrypt.cpp | 7 +++++-- haval.h | 3 ++- hmac.cpp | 6 ++++-- hmac.h | 19 +++++++------------ iterhash.h | 9 +++++---- lubyrack.h | 9 ++++++--- md2.h | 3 ++- md5mac.h | 2 +- misc.h | 11 +++++++++-- modes.cpp | 2 +- modes.h | 3 ++- panama.h | 10 +++++----- rc2.h | 3 ++- rijndael.cpp | 1 - salsa.cpp | 2 +- salsa.h | 7 ++----- seal.h | 7 ++----- secblock.h | 10 ++-------- seckey.h | 42 +++++++++++++++++++++++++++++------------- simple.h | 12 +----------- socketft.h | 2 ++ strciphr.cpp | 2 +- strciphr.h | 8 ++++++-- test.cpp | 9 +++++---- ttmac.h | 2 +- xormac.h | 13 ++++++++++--- 37 files changed, 158 insertions(+), 117 deletions(-) diff --git a/Readme.txt b/Readme.txt index daf481141..4ea278b2f 100644 --- a/Readme.txt +++ b/Readme.txt @@ -54,12 +54,13 @@ This library includes: - FIPS 140-2 Validated You are welcome to use it for any purpose without paying me, but see -license.txt for the fine print. +License.txt for the fine print. This version of Crypto++ has been compiled successfully with MSVC 6.0 SP5 -and .NET 2003 on Windows XP, GCC 2.95.4 on FreeBSD 4.6, GCC 2.95.3 on -Linux 2.4 and SunOS 5.8, GCC 3.4 on Cygwin 1.5.10, and Metrowerks -CodeWarrior 8.3 for Windows and MacOS. +and .NET 2005 on Windows XP SP2, GCC 3.4.2 on FreeBSD 5.4, GCC 4.1.2 on +Linux 2.6, GCC 3.4.4 on Cygwin 1.5.21, GCC 3.3 and 4.0.1 on MacOS X 10.4, +and Borland C++Builder 2006. For an update to date list of supported compilers +and operating systems, please visit http://www.cryptopp.com. *** Important Usage Notes *** @@ -149,8 +150,8 @@ may come up. If you run into any problems, please try the Crypto++ mailing list. The subscription information and the list archive are available on -http://www.cryptopp.com. You can also email me directly at -cryptopp@weidai.com, but you will probably get a faster response through +http://www.cryptopp.com. You can also email me directly by visiting +http://www.weidai.com, but you will probably get a faster response through the mailing list. *** History *** @@ -356,6 +357,6 @@ the mailing list. 5.4 - added Salsa20 - updated Whirlpool to version 3.0 - - ported to GCC 4.1 + - ported to GCC 4.1 and Borland C++Builder 2006 Written by Wei Dai diff --git a/adler32.h b/adler32.h index 28c309be2..bff6b35e2 100644 --- a/adler32.h +++ b/adler32.h @@ -9,7 +9,7 @@ NAMESPACE_BEGIN(CryptoPP) class Adler32 : public HashTransformation { public: - enum {DIGESTSIZE = 4}; + CRYPTOPP_CONSTANT(DIGESTSIZE = 4) Adler32() {Reset();} void Update(const byte *input, size_t length); void TruncatedFinal(byte *hash, size_t size); diff --git a/algebra.cpp b/algebra.cpp index 599ea3292..810a32a98 100644 --- a/algebra.cpp +++ b/algebra.cpp @@ -66,14 +66,7 @@ template const T& AbstractEuclideanDomain::Gcd(const Element &a, co template const typename QuotientRing::Element& QuotientRing::MultiplicativeInverse(const Element &a) const { Element g[3]={m_modulus, a}; -#ifdef __BCPLUSPLUS__ - // BC++50 workaround - Element v[3]; - v[0]=m_domain.Identity(); - v[1]=m_domain.MultiplicativeIdentity(); -#else Element v[3]={m_domain.Identity(), m_domain.MultiplicativeIdentity()}; -#endif Element y; unsigned int i0=0, i1=1, i2=2; diff --git a/config.h b/config.h index 30414e596..947c60798 100644 --- a/config.h +++ b/config.h @@ -108,7 +108,7 @@ typedef unsigned int word32; #define WORD64_AVAILABLE typedef unsigned long long word64; #define W64LIT(x) x##LL -#elif defined(_MSC_VER) || defined(__BCPLUSPLUS__) +#elif defined(_MSC_VER) || defined(__BORLANDC__) #define WORD64_AVAILABLE typedef unsigned __int64 word64; #define W64LIT(x) x##ui64 @@ -138,7 +138,7 @@ typedef unsigned int word32; typedef word32 word; typedef word64 dword; #else - typedef word8 hword; + typedef byte hword; typedef word16 word; typedef word32 dword; #endif @@ -147,7 +147,7 @@ typedef unsigned int word32; const unsigned int WORD_SIZE = sizeof(word); const unsigned int WORD_BITS = WORD_SIZE * 8; -#if defined(_MSC_VER) || defined(__BCPLUSPLUS__) +#if defined(_MSC_VER) // || defined(__BORLANDC__) intrinsics don't work on BCB 2006 #define INTEL_INTRINSICS #define FAST_ROTATE #elif defined(__MWERKS__) && TARGET_CPU_PPC @@ -165,10 +165,12 @@ const unsigned int WORD_BITS = WORD_SIZE * 8; #endif #ifndef CRYPTOPP_L1_CACHE_ALIGN - #ifdef _MSC_VER + #if defined(_MSC_VER) #define CRYPTOPP_L1_CACHE_ALIGN(x) __declspec(align(CRYPTOPP_L1_CACHE_LINE_SIZE)) x #elif defined(__GNUC__) #define CRYPTOPP_L1_CACHE_ALIGN(x) x __attribute__((aligned(CRYPTOPP_L1_CACHE_LINE_SIZE))) + #else + #define CRYPTOPP_L1_CACHE_ALIGN(x) x #endif #endif @@ -199,6 +201,11 @@ NAMESPACE_END # pragma warning(disable: 4231 4250 4251 4275 4660 4661 4786 4355) #endif +#ifdef __BORLANDC__ +// 8037: non-const function called for const object. needed to work around BCB2006 bug +# pragma warn -8037 +#endif + #if (defined(_MSC_VER) && _MSC_VER <= 1300) || defined(__MWERKS__) || defined(_STLPORT_VERSION) #define CRYPTOPP_DISABLE_UNCAUGHT_EXCEPTION #endif @@ -224,6 +231,12 @@ NAMESPACE_END # define CRYPTOPP_NOINLINE #endif +// how to declare class constants +#if defined(_MSC_VER) && _MSC_VER < 1300 +# define CRYPTOPP_CONSTANT(x) enum {x}; +#else +# define CRYPTOPP_CONSTANT(x) static const int x; +#endif // ***************** determine availability of OS features ******************** @@ -316,6 +329,8 @@ NAMESPACE_END #if defined(__MWERKS__) #define CRYPTOPP_EXTERN_DLL_TEMPLATE_CLASS extern class CRYPTOPP_DLL +#elif defined(__BORLANDC__) +#define CRYPTOPP_EXTERN_DLL_TEMPLATE_CLASS template class CRYPTOPP_DLL #else #define CRYPTOPP_EXTERN_DLL_TEMPLATE_CLASS extern template class CRYPTOPP_DLL #endif @@ -328,6 +343,8 @@ NAMESPACE_END #if defined(__MWERKS__) #define CRYPTOPP_EXTERN_STATIC_TEMPLATE_CLASS extern class +#elif defined(__BORLANDC__) +#define CRYPTOPP_EXTERN_STATIC_TEMPLATE_CLASS template class #else #define CRYPTOPP_EXTERN_STATIC_TEMPLATE_CLASS extern template class #endif diff --git a/crc.h b/crc.h index 1696174fa..23f14618a 100644 --- a/crc.h +++ b/crc.h @@ -19,7 +19,7 @@ const word32 CRC32_NEGL = 0xffffffffL; class CRC32 : public HashTransformation { public: - enum {DIGESTSIZE = 4}; + CRYPTOPP_CONSTANT(DIGESTSIZE = 4) CRC32(); void Update(const byte *input, size_t length); void TruncatedFinal(byte *hash, size_t size); diff --git a/datatest.cpp b/datatest.cpp index 4a2d95044..1942326a5 100644 --- a/datatest.cpp +++ b/datatest.cpp @@ -264,6 +264,9 @@ void TestSymmetricCipher(TestData &v) if (test == "Encrypt") { std::auto_ptr encryptor(ObjectFactoryRegistry::Registry().CreateObject(name.c_str())); + ConstByteArrayParameter iv; + if (pairs.GetValue(Name::IV(), iv) && iv.size() != encryptor->IVSize()) + SignalTestFailure(); encryptor->SetKey((const byte *)key.data(), key.size(), pairs); int seek = pairs.GetIntValueWithDefault("Seek", 0); if (seek) @@ -276,6 +279,9 @@ void TestSymmetricCipher(TestData &v) else if (test == "Decrypt") { std::auto_ptr decryptor(ObjectFactoryRegistry::Registry().CreateObject(name.c_str())); + ConstByteArrayParameter iv; + if (pairs.GetValue(Name::IV(), iv) && iv.size() != decryptor->IVSize()) + SignalTestFailure(); decryptor->SetKey((const byte *)key.data(), key.size(), pairs); int seek = pairs.GetIntValueWithDefault("Seek", 0); if (seek) diff --git a/dmac.h b/dmac.h index c0f81b3d2..6d4c0b706 100644 --- a/dmac.h +++ b/dmac.h @@ -12,7 +12,7 @@ class CRYPTOPP_NO_VTABLE DMAC_Base : public SameKeyLengthAs, public MessageAu public: static std::string StaticAlgorithmName() {return std::string("DMAC(") + T::StaticAlgorithmName() + ")";} - enum {DIGESTSIZE=T::BLOCKSIZE}; + CRYPTOPP_CONSTANT(DIGESTSIZE=T::BLOCKSIZE) DMAC_Base() {} diff --git a/eccrypto.cpp b/eccrypto.cpp index 74cb95e14..876ee7988 100644 --- a/eccrypto.cpp +++ b/eccrypto.cpp @@ -535,10 +535,11 @@ bool DL_GroupParameters_EC::ValidateElement(unsigned int level, const Elemen if (gpc) pass = pass && gpc->Exponentiate(this->GetGroupPrecomputation(), Integer::One()) == g; } - if (level >= 2) + if (level >= 2 && pass) { const Integer &q = GetSubgroupOrder(); - pass = pass && IsIdentity(gpc ? gpc->Exponentiate(this->GetGroupPrecomputation(), q) : ExponentiateElement(g, q)); + Element gq = gpc ? gpc->Exponentiate(this->GetGroupPrecomputation(), q) : ExponentiateElement(g, q); + pass = pass && IsIdentity(gq); } return pass; } diff --git a/factory.h b/factory.h index 50e4313a3..ad8a84f05 100644 --- a/factory.h +++ b/factory.h @@ -84,8 +84,10 @@ template struct RegisterDefaultFactoryFor { RegisterDefaultFactoryFor(const char *name=NULL) { + // BCB2006 workaround + std::string n = name ? std::string(name) : std::string(ConcreteClass::StaticAlgorithmName()); ObjectFactoryRegistry::Registry(). - RegisterFactory(name ? name : ConcreteClass::StaticAlgorithmName(), new DefaultObjectFactory); + RegisterFactory(n, new DefaultObjectFactory); }}; template diff --git a/files.cpp b/files.cpp index ac7e0c0f3..f9fecbe62 100644 --- a/files.cpp +++ b/files.cpp @@ -118,7 +118,6 @@ size_t FileStore::CopyRangeTo2(BufferedTransformation &target, lword &begin, lwo return 0; // don't try to seek beyond the end of file } m_stream->seekg(newPosition); - lword total = 0; try { assert(!m_waiting); diff --git a/filters.h b/filters.h index 9cc70ef0b..fc5c6e80c 100644 --- a/filters.h +++ b/filters.h @@ -110,7 +110,7 @@ class CRYPTOPP_DLL MeterFilter : public Bufferless struct MessageRange { - inline bool operator<(const MessageRange &b) + inline bool operator<(const MessageRange &b) const // BCB2006 workaround: this has to be a member function {return message < b.message || (message == b.message && position < b.position);} unsigned int message; lword position; lword size; }; diff --git a/gfpcrypt.cpp b/gfpcrypt.cpp index a82c492fa..6d9ffcebd 100644 --- a/gfpcrypt.cpp +++ b/gfpcrypt.cpp @@ -148,8 +148,11 @@ bool DL_GroupParameters_IntegerBased::ValidateElement(unsigned int level, const // and at most 1 bit is leaked if it's false bool fullValidate = (GetFieldType() == 2 && level >= 3) || !FastSubgroupCheckAvailable(); - if (fullValidate) - pass = pass && IsIdentity(gpc ? gpc->Exponentiate(GetGroupPrecomputation(), q) : ExponentiateElement(g, q)); + if (fullValidate && pass) + { + Integer gp = gpc ? gpc->Exponentiate(GetGroupPrecomputation(), q) : ExponentiateElement(g, q); + pass = pass && IsIdentity(gp); + } else if (GetFieldType() == 1) pass = pass && Jacobi(g, p) == 1; } diff --git a/haval.h b/haval.h index c9860aae4..d3fb4c3dc 100644 --- a/haval.h +++ b/haval.h @@ -11,7 +11,8 @@ NAMESPACE_BEGIN(CryptoPP) class HAVAL : public IteratedHash { public: - enum {DIGESTSIZE = 32, HAVAL_VERSION = 1}; + enum {HAVAL_VERSION = 1}; + CRYPTOPP_CONSTANT(DIGESTSIZE = 32) /// digestSize can be 16, 20, 24, 28, or 32 (Default=32)
/// pass can be 3, 4 or 5 (Default=3) diff --git a/hmac.cpp b/hmac.cpp index dc9fc9b2a..d4a649c08 100644 --- a/hmac.cpp +++ b/hmac.cpp @@ -20,6 +20,8 @@ void HMAC_Base::UncheckedSetKey(const byte *userKey, unsigned int keylength, con if (!blockSize) throw InvalidArgument("HMAC: can only be used with a block-based hash function"); + m_buf.resize(2*AccessHash().BlockSize() + AccessHash().DigestSize()); + if (keylength <= blockSize) memcpy(AccessIpad(), userKey, keylength); else @@ -33,8 +35,8 @@ void HMAC_Base::UncheckedSetKey(const byte *userKey, unsigned int keylength, con for (unsigned int i=0; i, public MessageAuthenticationCode +class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE HMAC_Base : public VariableKeyLength<16, 0, INT_MAX>, public MessageAuthenticationCode { public: HMAC_Base() : m_innerHashKeyed(false) {} @@ -23,15 +23,14 @@ class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE HMAC_Base : public VariableKeyLength<16, 0 protected: virtual HashTransformation & AccessHash() =0; - virtual byte * AccessIpad() =0; - virtual byte * AccessOpad() =0; - virtual byte * AccessInnerHash() =0; + byte * AccessIpad() {return m_buf;} + byte * AccessOpad() {return m_buf + AccessHash().BlockSize();} + byte * AccessInnerHash() {return m_buf + 2*AccessHash().BlockSize();} private: void KeyInnerHash(); - enum {IPAD=0x36, OPAD=0x5c}; - + SecByteBlock m_buf; bool m_innerHashKeyed; }; @@ -41,7 +40,8 @@ template class HMAC : public MessageAuthenticationCodeImpl > { public: - enum {DIGESTSIZE=T::DIGESTSIZE, BLOCKSIZE=T::BLOCKSIZE}; + CRYPTOPP_CONSTANT(DIGESTSIZE=T::DIGESTSIZE) + CRYPTOPP_CONSTANT(BLOCKSIZE=T::BLOCKSIZE) HMAC() {} HMAC(const byte *key, size_t length=HMAC_Base::DEFAULT_KEYLENGTH) @@ -52,12 +52,7 @@ class HMAC : public MessageAuthenticationCodeImpl > private: HashTransformation & AccessHash() {return m_hash;} - byte * AccessIpad() {return m_ipad;} - byte * AccessOpad() {return m_opad;} - byte * AccessInnerHash() {return m_innerHash;} - FixedSizeSecBlock m_ipad, m_opad; - FixedSizeSecBlock m_innerHash; T m_hash; }; diff --git a/iterhash.h b/iterhash.h index 2f417ce91..7db3c4fbf 100644 --- a/iterhash.h +++ b/iterhash.h @@ -62,8 +62,9 @@ class CRYPTOPP_NO_VTABLE IteratedHash : public IteratedHashBase +template class CRYPTOPP_NO_VTABLE IteratedHashWithStaticTransform : public ClonableImpl, T_Transform> > { public: - enum {DIGESTSIZE = T_DigestSize}; + CRYPTOPP_CONSTANT(DIGESTSIZE = T_DigestSize ? T_DigestSize : T_StateSize) unsigned int DigestSize() const {return DIGESTSIZE;}; protected: diff --git a/lubyrack.h b/lubyrack.h index af3a77ba1..e8fd2f748 100644 --- a/lubyrack.h +++ b/lubyrack.h @@ -10,11 +10,14 @@ NAMESPACE_BEGIN(CryptoPP) -template struct DigestSizeDoubleWorkaround {enum {RESULT = 2*T::DIGESTSIZE};}; // VC60 workaround +template struct DigestSizeDoubleWorkaround // VC60 workaround +{ + CRYPTOPP_CONSTANT(RESULT = 2*T::DIGESTSIZE) +}; //! algorithm info template -struct LR_Info : public VariableKeyLength<16, 0, 2*(UINT_MAX/2), 2>, public FixedBlockSize::RESULT> +struct LR_Info : public VariableKeyLength<16, 0, 2*(INT_MAX/2), 2>, public FixedBlockSize::RESULT> { static std::string StaticAlgorithmName() {return std::string("LR/")+T::StaticAlgorithmName();} }; @@ -38,7 +41,7 @@ class LR : public LR_Info, public BlockCipherDocumentation } protected: - enum {S=T::DIGESTSIZE}; + CRYPTOPP_CONSTANT(S=T::DIGESTSIZE) unsigned int L; // key length / 2 SecByteBlock key; diff --git a/md2.h b/md2.h index dc2892228..a92bf975d 100644 --- a/md2.h +++ b/md2.h @@ -17,7 +17,8 @@ class MD2 : public HashTransformation unsigned int DigestSize() const {return DIGESTSIZE;} static const char * StaticAlgorithmName() {return "MD2";} - enum {DIGESTSIZE = 16, BLOCKSIZE = 16}; + CRYPTOPP_CONSTANT(DIGESTSIZE = 16) + CRYPTOPP_CONSTANT(BLOCKSIZE = 16) private: void Transform(); diff --git a/md5mac.h b/md5mac.h index 318dde82a..4daa71b2b 100644 --- a/md5mac.h +++ b/md5mac.h @@ -13,7 +13,7 @@ class CRYPTOPP_NO_VTABLE MD5MAC_Base : public FixedKeyLength<16>, public Iterate { public: static std::string StaticAlgorithmName() {return "MD5-MAC";} - enum {DIGESTSIZE = 16}; + CRYPTOPP_CONSTANT(DIGESTSIZE = 16) MD5MAC_Base() {SetStateSize(DIGESTSIZE);} diff --git a/misc.h b/misc.h index 1c8125871..2c71deb44 100644 --- a/misc.h +++ b/misc.h @@ -8,6 +8,10 @@ #include #endif +#ifdef __BORLANDC__ +#include +#endif + NAMESPACE_BEGIN(CryptoPP) // ************** compile-time assertion *************** @@ -291,6 +295,8 @@ inline unsigned int GetAlignment(T *dummy=NULL) // VC60 workaround return __alignof(T); #elif defined(__GNUC__) return __alignof__(T); +#elif defined(CRYPTOPP_SLOW_WORD64) + return UnsignedMin(4U, sizeof(T)); #else return sizeof(T); #endif @@ -370,7 +376,7 @@ inline void IncrementCounterByOne(byte *output, const byte *input, unsigned int { int i, carry; for (i=s-1, carry=1; i>=0 && carry; i--) - carry = !(output[i] = input[i]+1); + carry = ((output[i] = input[i]+1) == 0); memcpy_s(output, s, input, i+1); } @@ -543,7 +549,7 @@ inline byte BitReverse(byte value) { value = ((value & 0xAA) >> 1) | ((value & 0x55) << 1); value = ((value & 0xCC) >> 2) | ((value & 0x33) << 2); - return rotlFixed(value, 4); + return rotlFixed(value, 4U); } inline word16 BitReverse(word16 value) @@ -796,6 +802,7 @@ inline void PutWord(bool assumeAligned, ByteOrder order, byte *block, T value, c if (assumeAligned) { assert(IsAligned(block)); + assert(IsAligned(xorBlock)); if (xorBlock) *reinterpret_cast(block) = ConditionalByteReverse(order, value) ^ *reinterpret_cast(xorBlock); else diff --git a/modes.cpp b/modes.cpp index cdd4c2653..295fc341b 100644 --- a/modes.cpp +++ b/modes.cpp @@ -45,7 +45,7 @@ void CTR_ModePolicy::SeekToIteration(lword iterationCount) } } -void CTR_ModePolicy::GetNextIV(byte *IV) +void CTR_ModePolicy::CipherGetNextIV(byte *IV) { IncrementCounterByOne(IV, m_counterArray, BlockSize()); } diff --git a/modes.h b/modes.h index 04e501667..98547d49f 100644 --- a/modes.h +++ b/modes.h @@ -64,6 +64,7 @@ class CRYPTOPP_NO_VTABLE ModePolicyCommonTemplate : public CipherModeBase, publi { unsigned int GetAlignment() const {return m_cipher->BlockAlignment();} void CipherSetKey(const NameValuePairs ¶ms, const byte *key, size_t length); + void CipherGetNextIV(byte *IV) {CipherModeBase::GetNextIV(IV);} }; template @@ -147,7 +148,7 @@ class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CTR_ModePolicy : public ModePolicyCommonTe public: bool IsRandomAccess() const {return true;} IV_Requirement IVRequirement() const {return STRUCTURED_IV;} - void GetNextIV(byte *IV); + void CipherGetNextIV(byte *IV); static const char * CRYPTOPP_API StaticAlgorithmName() {return "CTR";} private: diff --git a/panama.h b/panama.h index ffad8aea5..1f24609bc 100644 --- a/panama.h +++ b/panama.h @@ -18,9 +18,9 @@ class CRYPTOPP_NO_VTABLE Panama protected: typedef word32 Stage[8]; - enum {STAGES = 32}; + CRYPTOPP_CONSTANT(STAGES = 32) - FixedSizeSecBlock m_state; + FixedSizeSecBlock m_state; unsigned int m_bstart; }; @@ -29,7 +29,7 @@ template class PanamaHash : protected Panama, public AlgorithmImpl, PanamaHash > { public: - enum {DIGESTSIZE = 32}; + CRYPTOPP_CONSTANT(DIGESTSIZE = 32) PanamaHash() {Panama::Reset();} unsigned int DigestSize() const {return DIGESTSIZE;} void TruncatedFinal(byte *hash, size_t size); @@ -43,7 +43,7 @@ class PanamaHash : protected Panama, public AlgorithmImpl -class HermeticHashFunctionMAC : public AlgorithmImpl > >, T_Info> +class HermeticHashFunctionMAC : public AlgorithmImpl > >, T_Info> { public: void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms) @@ -127,7 +127,7 @@ class PanamaCipherPolicy : public AdditiveCipherConcretePolicy, template struct PanamaCipher : public PanamaCipherInfo, public SymmetricCipherDocumentation { - typedef SymmetricCipherFinal, AdditiveCipherTemplate<> > > Encryption; + typedef SymmetricCipherFinal, AdditiveCipherTemplate<> >, PanamaCipherInfo > Encryption; typedef Encryption Decryption; }; diff --git a/rc2.h b/rc2.h index 8a619ab1b..90c2a060f 100644 --- a/rc2.h +++ b/rc2.h @@ -13,7 +13,8 @@ NAMESPACE_BEGIN(CryptoPP) //! _ struct RC2_Info : public FixedBlockSize<8>, public VariableKeyLength<16, 1, 128> { - enum {DEFAULT_EFFECTIVE_KEYLENGTH = 1024, MAX_EFFECTIVE_KEYLENGTH = 1024}; + CRYPTOPP_CONSTANT(DEFAULT_EFFECTIVE_KEYLENGTH = 1024) + CRYPTOPP_CONSTANT(MAX_EFFECTIVE_KEYLENGTH = 1024) static const char *StaticAlgorithmName() {return "RC2";} }; diff --git a/rijndael.cpp b/rijndael.cpp index 5749c59fd..fb79e2558 100644 --- a/rijndael.cpp +++ b/rijndael.cpp @@ -63,7 +63,6 @@ void Rijndael::Base::UncheckedSetKey(const byte *userKey, unsigned int keylen, c word32 temp, *rk = m_key; const word32 *rc = rcon; - unsigned int i=0; GetUserKey(BIG_ENDIAN_ORDER, rk, keylen/4, userKey, keylen); diff --git a/salsa.cpp b/salsa.cpp index a3c18ef92..5a84b7343 100755 --- a/salsa.cpp +++ b/salsa.cpp @@ -12,7 +12,7 @@ void Salsa20_TestInstantiations() Salsa20::Encryption x; } -void Salsa20_Policy::GetNextIV(byte *IV) const +void Salsa20_Policy::CipherGetNextIV(byte *IV) { word32 j6 = m_state[6] + 1; word32 j7 = m_state[7] + (j6 == 0); diff --git a/salsa.h b/salsa.h index dd66d157f..8d6bedf2e 100755 --- a/salsa.h +++ b/salsa.h @@ -8,20 +8,17 @@ NAMESPACE_BEGIN(CryptoPP) //! _ -struct Salsa20_Info : public VariableKeyLength<32, 16, 32, 16, SimpleKeyingInterface::STRUCTURED_IV> +struct Salsa20_Info : public VariableKeyLength<32, 16, 32, 16, SimpleKeyingInterface::STRUCTURED_IV, 8> { static const char *StaticAlgorithmName() {return "Salsa20";} }; class CRYPTOPP_NO_VTABLE Salsa20_Policy : public AdditiveCipherConcretePolicy, public Salsa20_Info { -public: - unsigned int IVSize() const {return 8;} - void GetNextIV(byte *IV) const; - protected: void CipherSetKey(const NameValuePairs ¶ms, const byte *key, size_t length); void OperateKeystream(KeystreamOperation operation, byte *output, const byte *input, size_t iterationCount); + void CipherGetNextIV(byte *IV); void CipherResynchronize(byte *keystreamBuffer, const byte *IV); bool IsRandomAccess() const {return true;} void SeekToIteration(lword iterationCount); diff --git a/seal.h b/seal.h index fd4ba031b..fc53c2f01 100644 --- a/seal.h +++ b/seal.h @@ -7,7 +7,7 @@ NAMESPACE_BEGIN(CryptoPP) //! _ template -struct SEAL_Info : public FixedKeyLength<20, SimpleKeyingInterface::INTERNALLY_GENERATED_IV> +struct SEAL_Info : public FixedKeyLength<20, SimpleKeyingInterface::INTERNALLY_GENERATED_IV, 4> { static const char *StaticAlgorithmName() {return B::ToEnum() == LITTLE_ENDIAN_ORDER ? "SEAL-3.0-LE" : "SEAL-3.0-BE";} }; @@ -15,13 +15,10 @@ struct SEAL_Info : public FixedKeyLength<20, SimpleKeyingInterface::INTERNALLY_G template class CRYPTOPP_NO_VTABLE SEAL_Policy : public AdditiveCipherConcretePolicy, public SEAL_Info { -public: - unsigned int IVSize() const {return 4;} - void GetNextIV(byte *IV) const {UnalignedPutWord(BIG_ENDIAN_ORDER, IV, m_outsideCounter+1);} - protected: void CipherSetKey(const NameValuePairs ¶ms, const byte *key, size_t length); void OperateKeystream(KeystreamOperation operation, byte *output, const byte *input, size_t iterationCount); + void CipherGetNextIV(byte *IV) {UnalignedPutWord(BIG_ENDIAN_ORDER, IV, m_outsideCounter+1);} void CipherResynchronize(byte *keystreamBuffer, const byte *IV); bool IsRandomAccess() const {return true;} void SeekToIteration(lword iterationCount); diff --git a/secblock.h b/secblock.h index 3095d10e2..5f0299a5d 100644 --- a/secblock.h +++ b/secblock.h @@ -235,23 +235,17 @@ class SecBlock ~SecBlock() {m_alloc.deallocate(m_ptr, m_size);} +#ifndef __BORLANDC__ operator const void *() const {return m_ptr;} operator void *() {return m_ptr;} -#if defined(__GNUC__) && __GNUC__ < 3 // reduce warnings - operator const void *() - {return m_ptr;} -#endif operator const T *() const {return m_ptr;} +#endif operator T *() {return m_ptr;} -#if defined(__GNUC__) && __GNUC__ < 3 // reduce warnings - operator const T *() - {return m_ptr;} -#endif // T *operator +(size_type offset) // {return m_ptr+offset;} diff --git a/seckey.h b/seckey.h index b5e8824f3..6fe56b89a 100644 --- a/seckey.h +++ b/seckey.h @@ -21,7 +21,7 @@ template class FixedBlockSize { public: - enum {BLOCKSIZE = N}; + CRYPTOPP_CONSTANT(BLOCKSIZE = N) }; // ************** rounds *************** @@ -31,7 +31,7 @@ template class FixedRounds { public: - enum {ROUNDS = R}; + CRYPTOPP_CONSTANT(ROUNDS = R) }; //! to be inherited by ciphers with variable number of rounds @@ -39,7 +39,9 @@ template // use INT_ class VariableRounds { public: - enum {DEFAULT_ROUNDS = D, MIN_ROUNDS = N, MAX_ROUNDS = M}; + CRYPTOPP_CONSTANT(DEFAULT_ROUNDS = D) + CRYPTOPP_CONSTANT(MIN_ROUNDS = N) + CRYPTOPP_CONSTANT(MAX_ROUNDS = M) static unsigned int StaticGetDefaultRounds(size_t keylength) {return DEFAULT_ROUNDS;} protected: @@ -65,17 +67,21 @@ class VariableRounds // ************** key length *************** //! to be inherited by keyed algorithms with fixed key length -template +template class FixedKeyLength { public: - enum {KEYLENGTH=N, MIN_KEYLENGTH=N, MAX_KEYLENGTH=N, DEFAULT_KEYLENGTH=N}; - enum {IV_REQUIREMENT = IV_REQ}; + CRYPTOPP_CONSTANT(KEYLENGTH=N) + CRYPTOPP_CONSTANT(MIN_KEYLENGTH=N) + CRYPTOPP_CONSTANT(MAX_KEYLENGTH=N) + CRYPTOPP_CONSTANT(DEFAULT_KEYLENGTH=N) + CRYPTOPP_CONSTANT(IV_REQUIREMENT = IV_REQ) + CRYPTOPP_CONSTANT(IV_LENGTH = IV_L) static size_t CRYPTOPP_API StaticGetValidKeyLength(size_t) {return KEYLENGTH;} }; /// support query of variable key length, template parameters are default, min, max, multiple (default multiple 1) -template +template class VariableKeyLength { // make these private to avoid Doxygen documenting them in all derived classes @@ -83,11 +89,17 @@ class VariableKeyLength CRYPTOPP_COMPILE_ASSERT(N % Q == 0); CRYPTOPP_COMPILE_ASSERT(M % Q == 0); CRYPTOPP_COMPILE_ASSERT(N < M); - CRYPTOPP_COMPILE_ASSERT(D >= N && M >= D); + CRYPTOPP_COMPILE_ASSERT(D >= N); + CRYPTOPP_COMPILE_ASSERT(M >= D); public: - enum {MIN_KEYLENGTH=N, MAX_KEYLENGTH=M, DEFAULT_KEYLENGTH=D, KEYLENGTH_MULTIPLE=Q}; - enum {IV_REQUIREMENT = IV_REQ}; + CRYPTOPP_CONSTANT(MIN_KEYLENGTH=N) + CRYPTOPP_CONSTANT(MAX_KEYLENGTH=M) + CRYPTOPP_CONSTANT(DEFAULT_KEYLENGTH=D) + CRYPTOPP_CONSTANT(KEYLENGTH_MULTIPLE=Q) + CRYPTOPP_CONSTANT(IV_REQUIREMENT=IV_REQ) + CRYPTOPP_CONSTANT(IV_LENGTH=IV_L) + static size_t CRYPTOPP_API StaticGetValidKeyLength(size_t n) { if (n < (size_t)MIN_KEYLENGTH) @@ -107,13 +119,16 @@ template class SameKeyLengthAs { public: - enum {MIN_KEYLENGTH=T::MIN_KEYLENGTH, MAX_KEYLENGTH=T::MAX_KEYLENGTH, DEFAULT_KEYLENGTH=T::DEFAULT_KEYLENGTH}; - enum {IV_REQUIREMENT = T::IV_REQUIREMENT}; + CRYPTOPP_CONSTANT(MIN_KEYLENGTH=T::MIN_KEYLENGTH) + CRYPTOPP_CONSTANT(MAX_KEYLENGTH=T::MAX_KEYLENGTH) + CRYPTOPP_CONSTANT(DEFAULT_KEYLENGTH=T::DEFAULT_KEYLENGTH) + CRYPTOPP_CONSTANT(IV_REQUIREMENT = T::IV_REQUIREMENT) + CRYPTOPP_CONSTANT(IV_LENGTH = T::IV_LENGTH) static size_t CRYPTOPP_API StaticGetValidKeyLength(size_t keylength) {return T::StaticGetValidKeyLength(keylength);} }; -// ************** implementation helper for SimpledKeyed *************** +// ************** implementation helper for SimpleKeyed *************** //! _ template @@ -125,6 +140,7 @@ class CRYPTOPP_NO_VTABLE SimpleKeyingInterfaceImpl : public BASE size_t DefaultKeyLength() const {return INFO::DEFAULT_KEYLENGTH;} size_t GetValidKeyLength(size_t n) const {return INFO::StaticGetValidKeyLength(n);} typename BASE::IV_Requirement IVRequirement() const {return (typename BASE::IV_Requirement)INFO::IV_REQUIREMENT;} + unsigned int IVSize() const {return INFO::IV_LENGTH;} }; template diff --git a/simple.h b/simple.h index 1710cf50c..a37c6d164 100644 --- a/simple.h +++ b/simple.h @@ -199,17 +199,7 @@ class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Store : public AutoSignaling::GenerateByte() } template -inline void AdditiveCipherTemplate::ProcessData(byte *outString, const byte *inString, size_t length) +void AdditiveCipherTemplate::ProcessData(byte *outString, const byte *inString, size_t length) { if (m_leftOver > 0) { diff --git a/strciphr.h b/strciphr.h index e905d7b19..ee5ba5dfb 100644 --- a/strciphr.h +++ b/strciphr.h @@ -64,7 +64,8 @@ struct CRYPTOPP_DLL CRYPTOPP_NO_VTABLE AdditiveCipherAbstractPolicy virtual bool CanOperateKeystream() const {return false;} virtual void OperateKeystream(KeystreamOperation operation, byte *output, const byte *input, size_t iterationCount) {assert(false);} virtual void CipherSetKey(const NameValuePairs ¶ms, const byte *key, size_t length) =0; - virtual void CipherResynchronize(byte *keystreamBuffer, const byte *iv) {throw NotImplemented("StreamTransformation: this object doesn't support resynchronization");} + virtual void CipherGetNextIV(byte *iv) {throw NotImplemented("SimpleKeyingInterface: this object doesn't support GetNextIV()");} + virtual void CipherResynchronize(byte *keystreamBuffer, const byte *iv) {throw NotImplemented("SimpleKeyingInterface: this object doesn't support resynchronization");} virtual bool IsRandomAccess() const =0; virtual void SeekToIteration(lword iterationCount) {assert(!IsRandomAccess()); throw NotImplemented("StreamTransformation: this object doesn't support random access");} }; @@ -123,6 +124,7 @@ class CRYPTOPP_NO_VTABLE AdditiveCipherTemplate : public BASE public: byte GenerateByte(); void ProcessData(byte *outString, const byte *inString, size_t length); + void GetNextIV(byte *iv) {this->AccessPolicy().CipherGetNextIV(iv);} void Resynchronize(const byte *iv); unsigned int OptimalBlockSize() const {return this->GetPolicy().GetBytesPerIteration();} unsigned int GetOptimalNextBlockSize() const {return (unsigned int)this->m_leftOver;} @@ -156,7 +158,8 @@ class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CFB_CipherAbstractPolicy virtual bool CanIterate() const {return false;} virtual void Iterate(byte *output, const byte *input, CipherDir dir, size_t iterationCount) {assert(false);} virtual void CipherSetKey(const NameValuePairs ¶ms, const byte *key, size_t length) =0; - virtual void CipherResynchronize(const byte *iv) {throw NotImplemented("StreamTransformation: this object doesn't support resynchronization");} + virtual void CipherGetNextIV(byte *iv) {throw NotImplemented("SimpleKeyingInterface: this object doesn't support GetNextIV()");} + virtual void CipherResynchronize(const byte *iv) {throw NotImplemented("SimpleKeyingInterface: this object doesn't support resynchronization");} }; template @@ -221,6 +224,7 @@ class CRYPTOPP_NO_VTABLE CFB_CipherTemplate : public BASE { public: void ProcessData(byte *outString, const byte *inString, size_t length); + void GetNextIV(byte *iv) {this->AccessPolicy().CipherGetNextIV(iv);} void Resynchronize(const byte *iv); unsigned int OptimalBlockSize() const {return this->GetPolicy().GetBytesPerIteration();} unsigned int GetOptimalNextBlockSize() const {return (unsigned int)m_leftOver;} diff --git a/test.cpp b/test.cpp index 7a13bfc83..cd7f0e7a3 100644 --- a/test.cpp +++ b/test.cpp @@ -39,6 +39,11 @@ #include #endif +#ifdef __BORLANDC__ +#pragma comment(lib, "cryptlib_bds.lib") +#pragma comment(lib, "ws2_32.lib") +#endif + USING_NAMESPACE(CryptoPP) USING_NAMESPACE(std) @@ -84,11 +89,7 @@ bool Validate(int, bool, const char *); int (*AdhocTest)(int argc, char *argv[]) = NULL; -#ifdef __BCPLUSPLUS__ -int cmain(int argc, char *argv[]) -#else int CRYPTOPP_API main(int argc, char *argv[]) -#endif { #ifdef _CRTDBG_LEAK_CHECK_DF // Turn on leak-checking diff --git a/ttmac.h b/ttmac.h index a8ca6d5c9..2e9b2629b 100644 --- a/ttmac.h +++ b/ttmac.h @@ -13,7 +13,7 @@ class CRYPTOPP_NO_VTABLE TTMAC_Base : public FixedKeyLength<20>, public Iterated { public: static std::string StaticAlgorithmName() {return std::string("Two-Track-MAC");} - enum {DIGESTSIZE=20}; + CRYPTOPP_CONSTANT(DIGESTSIZE=20) TTMAC_Base() {SetStateSize(DIGESTSIZE*2);} diff --git a/xormac.h b/xormac.h index 3afb816d8..cbd590c59 100644 --- a/xormac.h +++ b/xormac.h @@ -10,7 +10,10 @@ NAMESPACE_BEGIN(CryptoPP) -template struct DigestSizeSubtract4Workaround {enum {RESULT = T::DIGESTSIZE-4};}; // VC60 workaround +template struct DigestSizeSubtract4Workaround // VC60 workaround +{ + CRYPTOPP_CONSTANT(RESULT = T::DIGESTSIZE-4); +}; template class CRYPTOPP_NO_VTABLE XMACC_Base : public FixedKeyLength::RESULT, SimpleKeyingInterface::INTERNALLY_GENERATED_IV>, @@ -18,7 +21,7 @@ class CRYPTOPP_NO_VTABLE XMACC_Base : public FixedKeyLength::RESULT> m_key; - enum {BUFFER_SIZE = ((T::DIGESTSIZE) / sizeof(HashWordType))}; // VC60 workaround + CRYPTOPP_CONSTANT(BUFFER_SIZE = (T::DIGESTSIZE / sizeof(HashWordType))); // VC60 workaround +#ifdef __BORLANDC__ + FixedSizeSecBlock m_buffer; +#else FixedSizeSecBlock m_buffer; +#endif word32 m_counter, m_index; };