diff --git a/config.h b/config.h index 1089c11c..b3642802 100644 --- a/config.h +++ b/config.h @@ -177,7 +177,7 @@ NAMESPACE_END # pragma warning(disable: 4231 4250 4251 4275 4660 4661 4786 4355) #endif -#if !(defined(_MSC_VER) && _MSC_VER <= 1300) +#if !(defined(_MSC_VER) && _MSC_VER <= 1300) && !defined(__MWERKS__) #define CRYPTOPP_UNCAUGHT_EXCEPTION_AVAILABLE #endif @@ -271,12 +271,16 @@ NAMESPACE_END #if defined(CRYPTOPP_MANUALLY_INSTANTIATE_TEMPLATES) && !defined(CRYPTOPP_IMPORTS) #define CRYPTOPP_DLL_TEMPLATE_CLASS template class CRYPTOPP_DLL +#elif defined(__MWERKS__) +#define CRYPTOPP_DLL_TEMPLATE_CLASS extern class CRYPTOPP_DLL #else #define CRYPTOPP_DLL_TEMPLATE_CLASS extern template class CRYPTOPP_DLL #endif #if defined(CRYPTOPP_MANUALLY_INSTANTIATE_TEMPLATES) && !defined(CRYPTOPP_EXPORTS) #define CRYPTOPP_STATIC_TEMPLATE_CLASS template class +#elif defined(__MWERKS__) +#define CRYPTOPP_STATIC_TEMPLATE_CLASS extern class #else #define CRYPTOPP_STATIC_TEMPLATE_CLASS extern template class #endif diff --git a/crypto++.mcp b/crypto++.mcp index 5f087ac5..fff134e3 100644 Binary files a/crypto++.mcp and b/crypto++.mcp differ diff --git a/dll.cpp b/dll.cpp index ae67c129..24f4d8df 100644 --- a/dll.cpp +++ b/dll.cpp @@ -20,6 +20,23 @@ NAMESPACE_BEGIN(CryptoPP) +#ifdef __MWERKS__ +// CodeWarrior 8 workaround: explicit instantiations have to appear after member function definitions +CRYPTOPP_DLL_TEMPLATE_CLASS DL_GroupParameters_EC; +CRYPTOPP_DLL_TEMPLATE_CLASS DL_GroupParameters_EC; +CRYPTOPP_DLL_TEMPLATE_CLASS DL_FixedBasePrecomputationImpl; +CRYPTOPP_STATIC_TEMPLATE_CLASS IteratedHashBase; +CRYPTOPP_DLL_TEMPLATE_CLASS IteratedHashBase; +CRYPTOPP_STATIC_TEMPLATE_CLASS IteratedHashBase; +CRYPTOPP_DLL_TEMPLATE_CLASS CFB_CipherTemplate >; +CRYPTOPP_DLL_TEMPLATE_CLASS CFB_EncryptionTemplate >; +CRYPTOPP_DLL_TEMPLATE_CLASS CFB_DecryptionTemplate >; +CRYPTOPP_DLL_TEMPLATE_CLASS AdditiveCipherTemplate<>; +CRYPTOPP_DLL_TEMPLATE_CLASS AdditiveCipherTemplate >; +CRYPTOPP_DLL_TEMPLATE_CLASS AdditiveCipherTemplate >; +CRYPTOPP_DLL_TEMPLATE_CLASS AbstractEuclideanDomain; +#endif + template<> const byte PKCS_DigestDecoration::decoration[] = {0x30,0x21,0x30,0x09,0x06,0x05,0x2B,0x0E,0x03,0x02,0x1A,0x05,0x00,0x04,0x14}; template<> const unsigned int PKCS_DigestDecoration::length = sizeof(PKCS_DigestDecoration::decoration); diff --git a/eccrypto.h b/eccrypto.h index 20a69409..3005fafa 100644 --- a/eccrypto.h +++ b/eccrypto.h @@ -212,9 +212,6 @@ struct DL_Keys_EC template struct ECDSA; -CRYPTOPP_DLL_TEMPLATE_CLASS DL_PrivateKey_WithSignaturePairwiseConsistencyTest, ECDSA >; -CRYPTOPP_DLL_TEMPLATE_CLASS DL_PrivateKey_WithSignaturePairwiseConsistencyTest, ECDSA >; - //! . template struct DL_Keys_ECDSA @@ -248,6 +245,9 @@ struct ECDSA : public DL_SS, DL_Algorithm_ECDSA, DL_Signat { }; +CRYPTOPP_DLL_TEMPLATE_CLASS DL_PrivateKey_WithSignaturePairwiseConsistencyTest, ECDSA >; +CRYPTOPP_DLL_TEMPLATE_CLASS DL_PrivateKey_WithSignaturePairwiseConsistencyTest, ECDSA >; + //! ECNR template struct ECNR : public DL_SS, DL_Algorithm_ECNR, DL_SignatureMessageEncodingMethod_NR, H> diff --git a/gf2n.h b/gf2n.h index b1cfba48..e50576de 100644 --- a/gf2n.h +++ b/gf2n.h @@ -236,12 +236,6 @@ private: SecWordBlock reg; }; -CRYPTOPP_DLL_TEMPLATE_CLASS AbstractGroup; -CRYPTOPP_DLL_TEMPLATE_CLASS AbstractRing; -CRYPTOPP_DLL_TEMPLATE_CLASS AbstractEuclideanDomain; -CRYPTOPP_DLL_TEMPLATE_CLASS EuclideanDomainOf; -CRYPTOPP_DLL_TEMPLATE_CLASS QuotientRing >; - //! GF(2^n) with Polynomial Basis class CRYPTOPP_DLL GF2NP : public QuotientRing > { @@ -353,6 +347,13 @@ inline CryptoPP::PolynomialMod2 operator/(const CryptoPP::PolynomialMod2 &a, con //! inline CryptoPP::PolynomialMod2 operator%(const CryptoPP::PolynomialMod2 &a, const CryptoPP::PolynomialMod2 &b) {return a.Modulo(b);} +// CodeWarrior 8 workaround: put these template instantiations after overloaded operator declarations +CRYPTOPP_DLL_TEMPLATE_CLASS AbstractGroup; +CRYPTOPP_DLL_TEMPLATE_CLASS AbstractRing; +CRYPTOPP_DLL_TEMPLATE_CLASS AbstractEuclideanDomain; +CRYPTOPP_DLL_TEMPLATE_CLASS EuclideanDomainOf; +CRYPTOPP_DLL_TEMPLATE_CLASS QuotientRing >; + NAMESPACE_END NAMESPACE_BEGIN(std) diff --git a/gfpcrypt.h b/gfpcrypt.h index 0bc6b3bb..206c0bf6 100644 --- a/gfpcrypt.h +++ b/gfpcrypt.h @@ -372,10 +372,6 @@ public: struct DSA; -CRYPTOPP_DLL_TEMPLATE_CLASS DL_PublicKey_GFP; -CRYPTOPP_DLL_TEMPLATE_CLASS DL_PrivateKey_GFP; -CRYPTOPP_DLL_TEMPLATE_CLASS DL_PrivateKey_WithSignaturePairwiseConsistencyTest, DSA>; - //! . struct DL_Keys_DSA { @@ -413,6 +409,10 @@ struct CRYPTOPP_DLL DSA : public DL_SS< MAX_PRIME_LENGTH = 1024, PRIME_LENGTH_MULTIPLE = 64}; }; +CRYPTOPP_DLL_TEMPLATE_CLASS DL_PublicKey_GFP; +CRYPTOPP_DLL_TEMPLATE_CLASS DL_PrivateKey_GFP; +CRYPTOPP_DLL_TEMPLATE_CLASS DL_PrivateKey_WithSignaturePairwiseConsistencyTest, DSA>; + //! . template class DL_EncryptionAlgorithm_Xor : public DL_SymmetricEncryptionAlgorithm diff --git a/hrtimer.cpp b/hrtimer.cpp index 904bc52f..38763fbf 100644 --- a/hrtimer.cpp +++ b/hrtimer.cpp @@ -4,8 +4,7 @@ #include "hrtimer.h" #include "misc.h" #include // for NULL - -#ifdef HIGHRES_TIMER_AVAILABLE +#include #if defined(CRYPTOPP_WIN32_AVAILABLE) #include @@ -19,73 +18,6 @@ NAMESPACE_BEGIN(CryptoPP) -word64 Timer::GetCurrentTimerValue() -{ -#if defined(CRYPTOPP_WIN32_AVAILABLE) - LARGE_INTEGER now; - if (!QueryPerformanceCounter(&now)) - throw Exception(Exception::OTHER_ERROR, "Timer: QueryPerformanceCounter failed with error " + IntToString(GetLastError())); - return now.QuadPart; -#elif defined(CRYPTOPP_UNIX_AVAILABLE) - timeval now; - gettimeofday(&now, NULL); - return (word64)now.tv_sec * 1000000 + now.tv_usec; -#endif -} - -word64 Timer::TicksPerSecond() -{ -#if defined(CRYPTOPP_WIN32_AVAILABLE) - static LARGE_INTEGER freq = {0}; - if (freq.QuadPart == 0) - { - if (!QueryPerformanceFrequency(&freq)) - throw Exception(Exception::OTHER_ERROR, "Timer: QueryPerformanceFrequency failed with error " + IntToString(GetLastError())); - } - return freq.QuadPart; -#elif defined(CRYPTOPP_UNIX_AVAILABLE) - return 1000000; -#endif -} - -word64 ThreadUserTimer::GetCurrentTimerValue() -{ -#if defined(CRYPTOPP_WIN32_AVAILABLE) - static bool getCurrentThreadImplemented = true; - if (getCurrentThreadImplemented) - { - FILETIME now, ignored; - if (!GetThreadTimes(GetCurrentThread(), &ignored, &ignored, &ignored, &now)) - { - DWORD lastError = GetLastError(); - if (lastError == ERROR_CALL_NOT_IMPLEMENTED) - { - getCurrentThreadImplemented = false; - goto GetCurrentThreadNotImplemented; - } - throw Exception(Exception::OTHER_ERROR, "ThreadUserTimer: GetThreadTimes failed with error " + IntToString(lastError)); - } - return now.dwLowDateTime + ((word64)now.dwHighDateTime << 32); - } -GetCurrentThreadNotImplemented: - return (word64)clock() * (10*1000*1000 / CLOCKS_PER_SEC); -#elif defined(CRYPTOPP_UNIX_AVAILABLE) - tms now; - times(&now); - return now.tms_utime; -#endif -} - -word64 ThreadUserTimer::TicksPerSecond() -{ -#if defined(CRYPTOPP_WIN32_AVAILABLE) - return 10*1000*1000; -#elif defined(CRYPTOPP_UNIX_AVAILABLE) - static const long ticksPerSecond = sysconf(_SC_CLK_TCK); - return ticksPerSecond; -#endif -} - double TimerBase::ConvertTo(word64 t, Unit unit) { static unsigned long unitsPerSecondTable[] = {1, 1000, 1000*1000, 1000*1000*1000}; @@ -120,6 +52,79 @@ unsigned long TimerBase::ElapsedTime() return (unsigned long)elapsed; } -NAMESPACE_END +word64 ThreadUserTimer::GetCurrentTimerValue() +{ +#if defined(CRYPTOPP_WIN32_AVAILABLE) + static bool getCurrentThreadImplemented = true; + if (getCurrentThreadImplemented) + { + FILETIME now, ignored; + if (!GetThreadTimes(GetCurrentThread(), &ignored, &ignored, &ignored, &now)) + { + DWORD lastError = GetLastError(); + if (lastError == ERROR_CALL_NOT_IMPLEMENTED) + { + getCurrentThreadImplemented = false; + goto GetCurrentThreadNotImplemented; + } + throw Exception(Exception::OTHER_ERROR, "ThreadUserTimer: GetThreadTimes failed with error " + IntToString(lastError)); + } + return now.dwLowDateTime + ((word64)now.dwHighDateTime << 32); + } +GetCurrentThreadNotImplemented: + return (word64)clock() * (10*1000*1000 / CLOCKS_PER_SEC); +#elif defined(CRYPTOPP_UNIX_AVAILABLE) + tms now; + times(&now); + return now.tms_utime; +#else + return clock(); +#endif +} + +word64 ThreadUserTimer::TicksPerSecond() +{ +#if defined(CRYPTOPP_WIN32_AVAILABLE) + return 10*1000*1000; +#elif defined(CRYPTOPP_UNIX_AVAILABLE) + static const long ticksPerSecond = sysconf(_SC_CLK_TCK); + return ticksPerSecond; +#else + return CLOCKS_PER_SEC; +#endif +} + +#ifdef HIGHRES_TIMER_AVAILABLE + +word64 Timer::GetCurrentTimerValue() +{ +#if defined(CRYPTOPP_WIN32_AVAILABLE) + LARGE_INTEGER now; + if (!QueryPerformanceCounter(&now)) + throw Exception(Exception::OTHER_ERROR, "Timer: QueryPerformanceCounter failed with error " + IntToString(GetLastError())); + return now.QuadPart; +#elif defined(CRYPTOPP_UNIX_AVAILABLE) + timeval now; + gettimeofday(&now, NULL); + return (word64)now.tv_sec * 1000000 + now.tv_usec; +#endif +} + +word64 Timer::TicksPerSecond() +{ +#if defined(CRYPTOPP_WIN32_AVAILABLE) + static LARGE_INTEGER freq = {0}; + if (freq.QuadPart == 0) + { + if (!QueryPerformanceFrequency(&freq)) + throw Exception(Exception::OTHER_ERROR, "Timer: QueryPerformanceFrequency failed with error " + IntToString(GetLastError())); + } + return freq.QuadPart; +#elif defined(CRYPTOPP_UNIX_AVAILABLE) + return 1000000; +#endif +} #endif + +NAMESPACE_END diff --git a/hrtimer.h b/hrtimer.h index 3b74b016..4c7402c4 100644 --- a/hrtimer.h +++ b/hrtimer.h @@ -5,8 +5,6 @@ NAMESPACE_BEGIN(CryptoPP) -#ifdef HIGHRES_TIMER_AVAILABLE - class TimerBase { public: @@ -28,17 +26,8 @@ private: word64 m_start; }; -//! high resolution timer -class Timer : public TimerBase -{ -public: - Timer(Unit unit = TimerBase::SECONDS, bool stuckAtZero = false) : TimerBase(unit, stuckAtZero) {} - word64 GetCurrentTimerValue(); - word64 TicksPerSecond(); -}; - //! measure CPU time spent executing instructions of this thread (if supported by OS) -/*! /note This only works correctly on Windows NT or later. On Unix it reports process time, and on Windows 98 wall clock time. +/*! /note This only works correctly on Windows NT or later. On Unix it reports process time, and others wall clock time. */ class ThreadUserTimer : public TimerBase { @@ -48,6 +37,17 @@ public: word64 TicksPerSecond(); }; +#ifdef HIGHRES_TIMER_AVAILABLE + +//! high resolution timer +class Timer : public TimerBase +{ +public: + Timer(Unit unit = TimerBase::SECONDS, bool stuckAtZero = false) : TimerBase(unit, stuckAtZero) {} + word64 GetCurrentTimerValue(); + word64 TicksPerSecond(); +}; + #endif NAMESPACE_END diff --git a/test.cpp b/test.cpp index 77546d2c..fcb7b250 100644 --- a/test.cpp +++ b/test.cpp @@ -24,7 +24,7 @@ #include #endif -#ifdef USE_BERKELEY_STYLE_SOCKETS +#if defined(USE_BERKELEY_STYLE_SOCKETS) && !defined(macintosh) #include #include #endif