diff options
author | weidai <weidai11@users.noreply.github.com> | 2004-06-20 17:56:15 +0000 |
---|---|---|
committer | weidai <weidai11@users.noreply.github.com> | 2004-06-20 17:56:15 +0000 |
commit | bdf3852cf0cf46a2fbcce196339cbf51a0902e6d (patch) | |
tree | 2499058561875821704789052533e0c6c2c79891 | |
parent | 319016f6b70944bdf16bdc9011d5c7176512d0da (diff) | |
download | cryptopp-git-bdf3852cf0cf46a2fbcce196339cbf51a0902e6d.tar.gz |
port to CodeWarrior 8.3
-rw-r--r-- | config.h | 6 | ||||
-rw-r--r-- | crypto++.mcp | bin | 862921 -> 739753 bytes | |||
-rw-r--r-- | dll.cpp | 17 | ||||
-rw-r--r-- | eccrypto.h | 6 | ||||
-rw-r--r-- | gf2n.h | 13 | ||||
-rw-r--r-- | gfpcrypt.h | 8 | ||||
-rw-r--r-- | hrtimer.cpp | 103 | ||||
-rw-r--r-- | hrtimer.h | 20 | ||||
-rw-r--r-- | test.cpp | 2 |
9 files changed, 101 insertions, 74 deletions
@@ -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 Binary files differindex 5f087ac5..fff134e3 100644 --- a/crypto++.mcp +++ b/crypto++.mcp @@ -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<ECP>; +CRYPTOPP_DLL_TEMPLATE_CLASS DL_GroupParameters_EC<EC2N>; +CRYPTOPP_DLL_TEMPLATE_CLASS DL_FixedBasePrecomputationImpl<Integer>; +CRYPTOPP_STATIC_TEMPLATE_CLASS IteratedHashBase<word64, HashTransformation>; +CRYPTOPP_DLL_TEMPLATE_CLASS IteratedHashBase<word32, HashTransformation>; +CRYPTOPP_STATIC_TEMPLATE_CLASS IteratedHashBase<word32, MessageAuthenticationCode>; +CRYPTOPP_DLL_TEMPLATE_CLASS CFB_CipherTemplate<AbstractPolicyHolder<CFB_CipherAbstractPolicy, CFB_ModePolicy> >; +CRYPTOPP_DLL_TEMPLATE_CLASS CFB_EncryptionTemplate<AbstractPolicyHolder<CFB_CipherAbstractPolicy, CFB_ModePolicy> >; +CRYPTOPP_DLL_TEMPLATE_CLASS CFB_DecryptionTemplate<AbstractPolicyHolder<CFB_CipherAbstractPolicy, CFB_ModePolicy> >; +CRYPTOPP_DLL_TEMPLATE_CLASS AdditiveCipherTemplate<>; +CRYPTOPP_DLL_TEMPLATE_CLASS AdditiveCipherTemplate<AbstractPolicyHolder<AdditiveCipherAbstractPolicy, OFB_ModePolicy> >; +CRYPTOPP_DLL_TEMPLATE_CLASS AdditiveCipherTemplate<AbstractPolicyHolder<AdditiveCipherAbstractPolicy, CTR_ModePolicy> >; +CRYPTOPP_DLL_TEMPLATE_CLASS AbstractEuclideanDomain<Integer>; +#endif + template<> const byte PKCS_DigestDecoration<SHA>::decoration[] = {0x30,0x21,0x30,0x09,0x06,0x05,0x2B,0x0E,0x03,0x02,0x1A,0x05,0x00,0x04,0x14}; template<> const unsigned int PKCS_DigestDecoration<SHA>::length = sizeof(PKCS_DigestDecoration<SHA>::decoration); @@ -212,9 +212,6 @@ struct DL_Keys_EC template <class EC, class H = SHA> struct ECDSA; -CRYPTOPP_DLL_TEMPLATE_CLASS DL_PrivateKey_WithSignaturePairwiseConsistencyTest<DL_PrivateKey_EC<ECP>, ECDSA<ECP> >; -CRYPTOPP_DLL_TEMPLATE_CLASS DL_PrivateKey_WithSignaturePairwiseConsistencyTest<DL_PrivateKey_EC<EC2N>, ECDSA<EC2N> >; - //! . template <class EC> struct DL_Keys_ECDSA @@ -248,6 +245,9 @@ struct ECDSA : public DL_SS<DL_Keys_ECDSA<EC>, DL_Algorithm_ECDSA<EC>, DL_Signat { }; +CRYPTOPP_DLL_TEMPLATE_CLASS DL_PrivateKey_WithSignaturePairwiseConsistencyTest<DL_PrivateKey_EC<ECP>, ECDSA<ECP> >; +CRYPTOPP_DLL_TEMPLATE_CLASS DL_PrivateKey_WithSignaturePairwiseConsistencyTest<DL_PrivateKey_EC<EC2N>, ECDSA<EC2N> >; + //! ECNR template <class EC, class H = SHA> struct ECNR : public DL_SS<DL_Keys_EC<EC>, DL_Algorithm_ECNR<EC>, DL_SignatureMessageEncodingMethod_NR, H> @@ -236,12 +236,6 @@ private: SecWordBlock reg; }; -CRYPTOPP_DLL_TEMPLATE_CLASS AbstractGroup<PolynomialMod2>; -CRYPTOPP_DLL_TEMPLATE_CLASS AbstractRing<PolynomialMod2>; -CRYPTOPP_DLL_TEMPLATE_CLASS AbstractEuclideanDomain<PolynomialMod2>; -CRYPTOPP_DLL_TEMPLATE_CLASS EuclideanDomainOf<PolynomialMod2>; -CRYPTOPP_DLL_TEMPLATE_CLASS QuotientRing<EuclideanDomainOf<PolynomialMod2> >; - //! GF(2^n) with Polynomial Basis class CRYPTOPP_DLL GF2NP : public QuotientRing<EuclideanDomainOf<PolynomialMod2> > { @@ -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<PolynomialMod2>; +CRYPTOPP_DLL_TEMPLATE_CLASS AbstractRing<PolynomialMod2>; +CRYPTOPP_DLL_TEMPLATE_CLASS AbstractEuclideanDomain<PolynomialMod2>; +CRYPTOPP_DLL_TEMPLATE_CLASS EuclideanDomainOf<PolynomialMod2>; +CRYPTOPP_DLL_TEMPLATE_CLASS QuotientRing<EuclideanDomainOf<PolynomialMod2> >; + NAMESPACE_END NAMESPACE_BEGIN(std) @@ -372,10 +372,6 @@ public: struct DSA; -CRYPTOPP_DLL_TEMPLATE_CLASS DL_PublicKey_GFP<DL_GroupParameters_DSA>; -CRYPTOPP_DLL_TEMPLATE_CLASS DL_PrivateKey_GFP<DL_GroupParameters_DSA>; -CRYPTOPP_DLL_TEMPLATE_CLASS DL_PrivateKey_WithSignaturePairwiseConsistencyTest<DL_PrivateKey_GFP<DL_GroupParameters_DSA>, 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<DL_GroupParameters_DSA>; +CRYPTOPP_DLL_TEMPLATE_CLASS DL_PrivateKey_GFP<DL_GroupParameters_DSA>; +CRYPTOPP_DLL_TEMPLATE_CLASS DL_PrivateKey_WithSignaturePairwiseConsistencyTest<DL_PrivateKey_GFP<DL_GroupParameters_DSA>, DSA>; + //! . template <class MAC, bool DHAES_MODE> 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 <stddef.h> // for NULL - -#ifdef HIGHRES_TIMER_AVAILABLE +#include <time.h> #if defined(CRYPTOPP_WIN32_AVAILABLE) #include <windows.h> @@ -19,33 +18,38 @@ NAMESPACE_BEGIN(CryptoPP) -word64 Timer::GetCurrentTimerValue() +double TimerBase::ConvertTo(word64 t, Unit unit) { -#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 + static unsigned long unitsPerSecondTable[] = {1, 1000, 1000*1000, 1000*1000*1000}; + + assert(unit < sizeof(unitsPerSecondTable) / sizeof(unitsPerSecondTable[0])); + return (double)t * unitsPerSecondTable[unit] / TicksPerSecond(); } -word64 Timer::TicksPerSecond() +void TimerBase::StartTimer() { -#if defined(CRYPTOPP_WIN32_AVAILABLE) - static LARGE_INTEGER freq = {0}; - if (freq.QuadPart == 0) + m_start = GetCurrentTimerValue(); + m_started = true; +} + +double TimerBase::ElapsedTimeAsDouble() +{ + if (m_stuckAtZero) + return 0; + else if (m_started) + return ConvertTo(GetCurrentTimerValue() - m_start, m_timerUnit); + else { - if (!QueryPerformanceFrequency(&freq)) - throw Exception(Exception::OTHER_ERROR, "Timer: QueryPerformanceFrequency failed with error " + IntToString(GetLastError())); + StartTimer(); + return 0; } - return freq.QuadPart; -#elif defined(CRYPTOPP_UNIX_AVAILABLE) - return 1000000; -#endif +} + +unsigned long TimerBase::ElapsedTime() +{ + double elapsed = ElapsedTimeAsDouble(); + assert(elapsed <= ULONG_MAX); + return (unsigned long)elapsed; } word64 ThreadUserTimer::GetCurrentTimerValue() @@ -73,6 +77,8 @@ GetCurrentThreadNotImplemented: tms now; times(&now); return now.tms_utime; +#else + return clock(); #endif } @@ -83,43 +89,42 @@ word64 ThreadUserTimer::TicksPerSecond() #elif defined(CRYPTOPP_UNIX_AVAILABLE) static const long ticksPerSecond = sysconf(_SC_CLK_TCK); return ticksPerSecond; +#else + return CLOCKS_PER_SEC; #endif } -double TimerBase::ConvertTo(word64 t, Unit unit) -{ - static unsigned long unitsPerSecondTable[] = {1, 1000, 1000*1000, 1000*1000*1000}; - - assert(unit < sizeof(unitsPerSecondTable) / sizeof(unitsPerSecondTable[0])); - return (double)t * unitsPerSecondTable[unit] / TicksPerSecond(); -} +#ifdef HIGHRES_TIMER_AVAILABLE -void TimerBase::StartTimer() +word64 Timer::GetCurrentTimerValue() { - m_start = GetCurrentTimerValue(); - m_started = true; +#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 } -double TimerBase::ElapsedTimeAsDouble() +word64 Timer::TicksPerSecond() { - if (m_stuckAtZero) - return 0; - else if (m_started) - return ConvertTo(GetCurrentTimerValue() - m_start, m_timerUnit); - else +#if defined(CRYPTOPP_WIN32_AVAILABLE) + static LARGE_INTEGER freq = {0}; + if (freq.QuadPart == 0) { - StartTimer(); - return 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 } -unsigned long TimerBase::ElapsedTime() -{ - double elapsed = ElapsedTimeAsDouble(); - assert(elapsed <= ULONG_MAX); - return (unsigned long)elapsed; -} +#endif NAMESPACE_END - -#endif @@ -5,8 +5,6 @@ NAMESPACE_BEGIN(CryptoPP) -#ifdef HIGHRES_TIMER_AVAILABLE - class TimerBase { public: @@ -28,22 +26,24 @@ private: word64 m_start; }; -//! high resolution timer -class Timer : public TimerBase +//! 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 others wall clock time. +*/ +class ThreadUserTimer : public TimerBase { public: - Timer(Unit unit = TimerBase::SECONDS, bool stuckAtZero = false) : TimerBase(unit, stuckAtZero) {} + ThreadUserTimer(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. -*/ -class ThreadUserTimer : public TimerBase +#ifdef HIGHRES_TIMER_AVAILABLE + +//! high resolution timer +class Timer : public TimerBase { public: - ThreadUserTimer(Unit unit = TimerBase::SECONDS, bool stuckAtZero = false) : TimerBase(unit, stuckAtZero) {} + Timer(Unit unit = TimerBase::SECONDS, bool stuckAtZero = false) : TimerBase(unit, stuckAtZero) {} word64 GetCurrentTimerValue(); word64 TicksPerSecond(); }; @@ -24,7 +24,7 @@ #include <windows.h> #endif -#ifdef USE_BERKELEY_STYLE_SOCKETS +#if defined(USE_BERKELEY_STYLE_SOCKETS) && !defined(macintosh) #include <netinet/in.h> #include <netinet/tcp.h> #endif |