port to Sun Studio 12's 64-bit C++ Compiler 5.9 Patch 124864-09 2008/12/16

pull/2/head
weidai 2009-02-13 12:18:26 +00:00
parent eb5732337b
commit fa25129ac9
14 changed files with 73 additions and 71 deletions

View File

@ -1,4 +1,5 @@
CXXFLAGS = -DNDEBUG -g -O2 CXXFLAGS = -DNDEBUG -g -O2
#CXXFLAGS = -g
# -fPIC is supported. Please report any breakage of -fPIC as a bug. # -fPIC is supported. Please report any breakage of -fPIC as a bug.
# CXXFLAGS += -fPIC # CXXFLAGS += -fPIC
# the following options reduce code size, but breaks link or makes link very slow on some systems # the following options reduce code size, but breaks link or makes link very slow on some systems
@ -79,7 +80,7 @@ endif
ifeq ($(UNAME),SunOS) ifeq ($(UNAME),SunOS)
LDLIBS += -lnsl -lsocket LDLIBS += -lnsl -lsocket
ifeq ($(CXX),CC) # override flags for CC (Solaris native C++ compiler) ifeq ($(CXX),CC) # override flags for CC (Solaris native C++ compiler)
CXXFLAGS = -DNDEBUG -O -g -native CXXFLAGS = -DNDEBUG -O -g0 -native -template=no%extdef -m$(shell isainfo -b)
LDFLAGS = LDFLAGS =
ifeq ($(ISX86),1) ifeq ($(ISX86),1)
# SSE2 intrinsics should work in Sun Studio 12, but we're not using SSE2 intrinsics anymore # SSE2 intrinsics should work in Sun Studio 12, but we're not using SSE2 intrinsics anymore

View File

@ -23,7 +23,8 @@ bool AlgorithmParametersBase::GetVoidValue(const char *name, const std::type_inf
if (strcmp(name, "ValueNames") == 0) if (strcmp(name, "ValueNames") == 0)
{ {
ThrowIfTypeMismatch(name, typeid(std::string), valueType); ThrowIfTypeMismatch(name, typeid(std::string), valueType);
GetParent().GetVoidValue(name, valueType, pValue); if (m_next.get())
m_next->GetVoidValue(name, valueType, pValue);
(*reinterpret_cast<std::string *>(pValue) += m_name) += ";"; (*reinterpret_cast<std::string *>(pValue) += m_name) += ";";
return true; return true;
} }
@ -33,8 +34,15 @@ bool AlgorithmParametersBase::GetVoidValue(const char *name, const std::type_inf
m_used = true; m_used = true;
return true; return true;
} }
else if (m_next.get())
return m_next->GetVoidValue(name, valueType, pValue);
else else
return GetParent().GetVoidValue(name, valueType, pValue); return false;
}
bool AlgorithmParameters::GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const
{
return m_ptr->GetVoidValue(name, valueType, pValue);
} }
NAMESPACE_END NAMESPACE_END

View File

@ -278,19 +278,21 @@ public:
bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const; bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const;
protected: protected:
friend class AlgorithmParameters;
virtual void AssignValue(const char *name, const std::type_info &valueType, void *pValue) const =0; virtual void AssignValue(const char *name, const std::type_info &valueType, void *pValue) const =0;
virtual const NameValuePairs & GetParent() const =0;
const char *m_name; const char *m_name;
bool m_throwIfNotUsed; bool m_throwIfNotUsed;
mutable bool m_used; mutable bool m_used;
member_ptr<NameValuePairs> m_next;
}; };
template <class T> template <class T>
class AlgorithmParametersBase2 : public AlgorithmParametersBase class AlgorithmParametersTemplate : public AlgorithmParametersBase
{ {
public: public:
AlgorithmParametersBase2(const char *name, const T &value, bool throwIfNotUsed) : AlgorithmParametersBase(name, throwIfNotUsed), m_value(value) {} AlgorithmParametersTemplate(const char *name, const T &value, bool throwIfNotUsed) : AlgorithmParametersBase(name, throwIfNotUsed), m_value(value) {}
void AssignValue(const char *name, const std::type_info &valueType, void *pValue) const void AssignValue(const char *name, const std::type_info &valueType, void *pValue) const
{ {
@ -306,35 +308,35 @@ protected:
T m_value; T m_value;
}; };
template <class PARENT, class T> class AlgorithmParameters : public NameValuePairs
class AlgorithmParameters : public AlgorithmParametersBase2<T>
{ {
public: public:
AlgorithmParameters(const PARENT &parent, const char *name, const T &value, bool throwIfNotUsed) AlgorithmParameters(AlgorithmParameters &x) : m_ptr(x.m_ptr.release()) {}
: AlgorithmParametersBase2<T>(name, value, throwIfNotUsed), m_parent(parent)
{}
AlgorithmParameters(const AlgorithmParameters &copy) AlgorithmParameters(AlgorithmParametersBase *p) : m_ptr(p) {}
: AlgorithmParametersBase2<T>(copy), m_parent(copy.m_parent)
template <class T>
AlgorithmParameters & operator()(const char *name, const T &value, bool throwIfNotUsed)
{ {
copy.m_used = true; member_ptr<AlgorithmParametersBase> p(new AlgorithmParametersTemplate<T>(name, value, throwIfNotUsed));
p->m_next.reset(m_ptr.release());
m_ptr.reset(p.release());
return *this;
} }
template <class R> template <class T>
AlgorithmParameters<AlgorithmParameters<PARENT,T>, R> operator()(const char *name, const R &value) const AlgorithmParameters & operator()(const char *name, const T &value)
{ {
return AlgorithmParameters<AlgorithmParameters<PARENT,T>, R>(*this, name, value, this->m_throwIfNotUsed); member_ptr<AlgorithmParametersBase> p(new AlgorithmParametersTemplate<T>(name, value, m_ptr->m_throwIfNotUsed));
p->m_next.reset(m_ptr.release());
m_ptr.reset(p.release());
return *this;
} }
template <class R> bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const;
AlgorithmParameters<AlgorithmParameters<PARENT,T>, R> operator()(const char *name, const R &value, bool throwIfNotUsed) const
{
return AlgorithmParameters<AlgorithmParameters<PARENT,T>, R>(*this, name, value, throwIfNotUsed);
}
private: protected:
const NameValuePairs & GetParent() const {return m_parent;} member_ptr<AlgorithmParametersBase> m_ptr;
PARENT m_parent;
}; };
//! Create an object that implements NameValuePairs for passing parameters //! Create an object that implements NameValuePairs for passing parameters
@ -343,12 +345,12 @@ private:
such as MSVC 7.0 and earlier. such as MSVC 7.0 and earlier.
\note A NameValuePairs object containing an arbitrary number of name value pairs may be constructed by \note A NameValuePairs object containing an arbitrary number of name value pairs may be constructed by
repeatedly using operator() on the object returned by MakeParameters, for example: repeatedly using operator() on the object returned by MakeParameters, for example:
const NameValuePairs &parameters = MakeParameters(name1, value1)(name2, value2)(name3, value3); AlgorithmParameters parameters = MakeParameters(name1, value1)(name2, value2)(name3, value3);
*/ */
template <class T> template <class T>
AlgorithmParameters<NullNameValuePairs,T> MakeParameters(const char *name, const T &value, bool throwIfNotUsed = true) AlgorithmParameters MakeParameters(const char *name, const T &value, bool throwIfNotUsed = true)
{ {
return AlgorithmParameters<NullNameValuePairs,T>(g_nullNameValuePairs, name, value, throwIfNotUsed); return AlgorithmParameters(new AlgorithmParametersTemplate<T>(name, value, throwIfNotUsed));
} }
#define CRYPTOPP_GET_FUNCTION_ENTRY(name) (Name::name(), &ThisClass::Get##name) #define CRYPTOPP_GET_FUNCTION_ENTRY(name) (Name::name(), &ThisClass::Get##name)

View File

@ -104,14 +104,13 @@ NAMESPACE_BEGIN(CryptoPP)
typedef unsigned short word16; typedef unsigned short word16;
typedef unsigned int word32; typedef unsigned int word32;
#if defined(__GNUC__) || defined(__MWERKS__) || defined(__SUNPRO_CC)
#define WORD64_AVAILABLE
typedef unsigned long long word64;
#define W64LIT(x) x##LL
#elif defined(_MSC_VER) || defined(__BORLANDC__)
#define WORD64_AVAILABLE #define WORD64_AVAILABLE
#if defined(_MSC_VER) || defined(__BORLANDC__)
typedef unsigned __int64 word64; typedef unsigned __int64 word64;
#define W64LIT(x) x##ui64 #define W64LIT(x) x##ui64
#else
typedef unsigned long long word64;
#define W64LIT(x) x##ULL
#endif #endif
// define large word type, used for file offsets and such // define large word type, used for file offsets and such
@ -129,7 +128,7 @@ typedef unsigned int word32;
// define hword, word, and dword. these are used for multiprecision integer arithmetic // define hword, word, and dword. these are used for multiprecision integer arithmetic
// Intel compiler won't have _umul128 until version 10.0. See http://softwarecommunity.intel.com/isn/Community/en-US/forums/thread/30231625.aspx // Intel compiler won't have _umul128 until version 10.0. See http://softwarecommunity.intel.com/isn/Community/en-US/forums/thread/30231625.aspx
#if (defined(_MSC_VER) && (!defined(__INTEL_COMPILER) || __INTEL_COMPILER >= 1000) && (defined(_M_X64) || defined(_M_IA64))) || (defined(__DECCXX) && defined(__alpha__)) || (defined(__INTEL_COMPILER) && defined(__x86_64__)) #if (defined(_MSC_VER) && (!defined(__INTEL_COMPILER) || __INTEL_COMPILER >= 1000) && (defined(_M_X64) || defined(_M_IA64))) || (defined(__DECCXX) && defined(__alpha__)) || (defined(__INTEL_COMPILER) && defined(__x86_64__)) || (defined(__SUNPRO_CC) && defined(__x86_64__))
typedef word32 hword; typedef word32 hword;
typedef word64 word; typedef word64 word;
#else #else
@ -189,7 +188,7 @@ NAMESPACE_END
#ifndef CRYPTOPP_ALIGN_DATA #ifndef CRYPTOPP_ALIGN_DATA
#if defined(CRYPTOPP_MSVC6PP_OR_LATER) #if defined(CRYPTOPP_MSVC6PP_OR_LATER)
#define CRYPTOPP_ALIGN_DATA(x) __declspec(align(x)) #define CRYPTOPP_ALIGN_DATA(x) __declspec(align(x))
#elif defined(__GNUC__) || __SUNPRO_CC > 0x580 #elif defined(__GNUC__) || __SUNPRO_CC > 0x590
#define CRYPTOPP_ALIGN_DATA(x) __attribute__((aligned(x))) #define CRYPTOPP_ALIGN_DATA(x) __attribute__((aligned(x)))
#else #else
#define CRYPTOPP_ALIGN_DATA(x) #define CRYPTOPP_ALIGN_DATA(x)
@ -341,7 +340,7 @@ NAMESPACE_END
#define CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS #define CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS
#endif #endif
#define CRYPTOPP_VERSION 552 #define CRYPTOPP_VERSION 553
// ***************** determine availability of OS features ******************** // ***************** determine availability of OS features ********************

View File

@ -2,9 +2,6 @@
#include "pch.h" #include "pch.h"
// prevent Sun's CC compiler from including this file automatically
#if !defined(__SUNPRO_CC) || defined(CRYPTOPP_MANUALLY_INSTANTIATE_TEMPLATES)
#ifndef CRYPTOPP_IMPORTS #ifndef CRYPTOPP_IMPORTS
#include "eccrypto.h" #include "eccrypto.h"
@ -646,5 +643,3 @@ void DL_PrivateKey_EC<EC>::DEREncodePrivateKey(BufferedTransformation &bt) const
NAMESPACE_END NAMESPACE_END
#endif #endif
#endif

View File

@ -2,9 +2,6 @@
#include "pch.h" #include "pch.h"
// prevent Sun's CC compiler from including this file automatically
#if !defined(__SUNPRO_CC) || defined(CRYPTOPP_MANUALLY_INSTANTIATE_TEMPLATES)
#ifndef CRYPTOPP_IMPORTS #ifndef CRYPTOPP_IMPORTS
#include "eprecomp.h" #include "eprecomp.h"
@ -113,5 +110,3 @@ template <class T> T
NAMESPACE_END NAMESPACE_END
#endif #endif
#endif

View File

@ -94,7 +94,7 @@ void InvertibleESIGNFunction::GenerateRandom(RandomNumberGenerator &rng, const N
const Integer minP = Integer(204) << (modulusSize/3-8); const Integer minP = Integer(204) << (modulusSize/3-8);
const Integer maxP = Integer::Power2(modulusSize/3)-1; const Integer maxP = Integer::Power2(modulusSize/3)-1;
const NameValuePairs &primeParam = MakeParameters("Min", minP)("Max", maxP)("RandomNumberType", Integer::PRIME); AlgorithmParameters primeParam = MakeParameters("Min", minP)("Max", maxP)("RandomNumberType", Integer::PRIME);
if (param.GetValue("Seed", seedParam)) if (param.GetValue("Seed", seedParam))
{ {

View File

@ -108,20 +108,26 @@ static word AtomicInverseModPower2(word A)
#define LowWord(a) a##0 #define LowWord(a) a##0
#define HighWord(a) a##1 #define HighWord(a) a##1
#ifdef _MSC_VER #ifdef _MSC_VER
#define MultiplyWords(p, a, b) p##0 = _umul128(a, b, &p##1); #define MultiplyWordsLoHi(p0, p1, a, b) p0 = _umul128(a, b, &p1);
#ifndef __INTEL_COMPILER #ifndef __INTEL_COMPILER
#define Double3Words(c, d) d##1 = __shiftleft128(d##0, d##1, 1); d##0 = __shiftleft128(c, d##0, 1); c *= 2; #define Double3Words(c, d) d##1 = __shiftleft128(d##0, d##1, 1); d##0 = __shiftleft128(c, d##0, 1); c *= 2;
#endif #endif
#elif defined(__DECCXX) #elif defined(__DECCXX)
#define MultiplyWords(p, a, b) p##0 = a*b; p##1 = asm("umulh %a0, %a1, %v0", a, b); #define MultiplyWordsLoHi(p0, p1, a, b) p0 = a*b; p1 = asm("umulh %a0, %a1, %v0", a, b);
#elif defined(__x86_64__) #elif defined(__x86_64__)
#define MultiplyWords(p, a, b) asm ("mulq %3" : "=a"(p##0), "=d"(p##1) : "a"(a), "g"(b) : "cc"); #ifdef __SUNPRO_CC
// Sun Studio's gcc-style inline assembly is heavily bugged as of version 5.9 Patch 124864-09 2008/12/16, but this one works
#define MultiplyWordsLoHi(p0, p1, a, b) asm ("mulq %3" : "=a"(p0), "=d"(p1) : "a"(a), "r"(b) : "cc");
#else
#define MultiplyWordsLoHi(p0, p1, a, b) asm ("mulq %3" : "=a"(p0), "=d"(p1) : "a"(a), "g"(b) : "cc");
#define MulAcc(c, d, a, b) asm ("mulq %6; addq %3, %0; adcq %4, %1; adcq $0, %2;" : "+r"(c), "+r"(d##0), "+r"(d##1), "=a"(p0), "=d"(p1) : "a"(a), "g"(b) : "cc"); #define MulAcc(c, d, a, b) asm ("mulq %6; addq %3, %0; adcq %4, %1; adcq $0, %2;" : "+r"(c), "+r"(d##0), "+r"(d##1), "=a"(p0), "=d"(p1) : "a"(a), "g"(b) : "cc");
#define Double3Words(c, d) asm ("addq %0, %0; adcq %1, %1; adcq %2, %2;" : "+r"(c), "+r"(d##0), "+r"(d##1) : : "cc"); #define Double3Words(c, d) asm ("addq %0, %0; adcq %1, %1; adcq %2, %2;" : "+r"(c), "+r"(d##0), "+r"(d##1) : : "cc");
#define Acc2WordsBy1(a, b) asm ("addq %2, %0; adcq $0, %1;" : "+r"(a##0), "+r"(a##1) : "r"(b) : "cc"); #define Acc2WordsBy1(a, b) asm ("addq %2, %0; adcq $0, %1;" : "+r"(a##0), "+r"(a##1) : "r"(b) : "cc");
#define Acc2WordsBy2(a, b) asm ("addq %2, %0; adcq %3, %1;" : "+r"(a##0), "+r"(a##1) : "r"(b##0), "r"(b##1) : "cc"); #define Acc2WordsBy2(a, b) asm ("addq %2, %0; adcq %3, %1;" : "+r"(a##0), "+r"(a##1) : "r"(b##0), "r"(b##1) : "cc");
#define Acc3WordsBy2(c, d, e) asm ("addq %5, %0; adcq %6, %1; adcq $0, %2;" : "+r"(c), "=r"(e##0), "=r"(e##1) : "1"(d##0), "2"(d##1), "r"(e##0), "r"(e##1) : "cc"); #define Acc3WordsBy2(c, d, e) asm ("addq %5, %0; adcq %6, %1; adcq $0, %2;" : "+r"(c), "=r"(e##0), "=r"(e##1) : "1"(d##0), "2"(d##1), "r"(e##0), "r"(e##1) : "cc");
#endif #endif
#endif
#define MultiplyWords(p, a, b) MultiplyWordsLoHi(p##0, p##1, a, b)
#ifndef Double3Words #ifndef Double3Words
#define Double3Words(c, d) d##1 = 2*d##1 + (d##0>>(WORD_BITS-1)); d##0 = 2*d##0 + (c>>(WORD_BITS-1)); c *= 2; #define Double3Words(c, d) d##1 = 2*d##1 + (d##0>>(WORD_BITS-1)); d##0 = 2*d##0 + (c>>(WORD_BITS-1)); c *= 2;
#endif #endif
@ -189,10 +195,8 @@ public:
DWord r; DWord r;
#ifdef CRYPTOPP_NATIVE_DWORD_AVAILABLE #ifdef CRYPTOPP_NATIVE_DWORD_AVAILABLE
r.m_whole = (dword)a * b; r.m_whole = (dword)a * b;
#elif defined(__x86_64__) #elif defined(MultiplyWordsLoHi)
asm ("mulq %3" : "=a"(r.m_halfs.low), "=d"(r.m_halfs.high) : "a"(a), "g"(b) : "cc"); MultiplyWordsLoHi(r.m_halfs.low, r.m_halfs.high, a, b);
#else
r.m_halfs.low = _umul128(a, b, &r.m_halfs.high);
#endif #endif
return r; return r;
} }

View File

@ -118,7 +118,7 @@ void InvertibleLUCFunction::GenerateRandom(RandomNumberGenerator &rng, const Nam
throw InvalidArgument("InvertibleLUCFunction: invalid public exponent"); throw InvalidArgument("InvertibleLUCFunction: invalid public exponent");
LUCPrimeSelector selector(m_e); LUCPrimeSelector selector(m_e);
const NameValuePairs &primeParam = MakeParametersForTwoPrimesOfEqualSize(modulusSize) AlgorithmParameters primeParam = MakeParametersForTwoPrimesOfEqualSize(modulusSize)
("PointerToPrimeSelector", selector.GetSelectorPointer()); ("PointerToPrimeSelector", selector.GetSelectorPointer());
m_p.GenerateRandom(rng, primeParam); m_p.GenerateRandom(rng, primeParam);
m_q.GenerateRandom(rng, primeParam); m_q.GenerateRandom(rng, primeParam);

View File

@ -262,8 +262,7 @@ static inline bool FastProbablePrimeTest(const Integer &n)
return IsStrongProbablePrime(n,2); return IsStrongProbablePrime(n,2);
} }
AlgorithmParameters<AlgorithmParameters<AlgorithmParameters<NullNameValuePairs, Integer::RandomNumberType>, Integer>, Integer> AlgorithmParameters MakeParametersForTwoPrimesOfEqualSize(unsigned int productBitLength)
MakeParametersForTwoPrimesOfEqualSize(unsigned int productBitLength)
{ {
if (productBitLength < 16) if (productBitLength < 16)
throw InvalidArgument("invalid bit length"); throw InvalidArgument("invalid bit length");

View File

@ -56,8 +56,7 @@ CRYPTOPP_DLL bool CRYPTOPP_API FirstPrime(Integer &p, const Integer &max, const
CRYPTOPP_DLL unsigned int CRYPTOPP_API PrimeSearchInterval(const Integer &max); CRYPTOPP_DLL unsigned int CRYPTOPP_API PrimeSearchInterval(const Integer &max);
CRYPTOPP_DLL AlgorithmParameters<AlgorithmParameters<AlgorithmParameters<NullNameValuePairs, Integer::RandomNumberType>, Integer>, Integer> CRYPTOPP_DLL AlgorithmParameters CRYPTOPP_API MakeParametersForTwoPrimesOfEqualSize(unsigned int productBitLength);
CRYPTOPP_API MakeParametersForTwoPrimesOfEqualSize(unsigned int productBitLength);
// ********** other number theoretic functions ************ // ********** other number theoretic functions ************

View File

@ -84,7 +84,7 @@ void InvertibleRabinFunction::GenerateRandom(RandomNumberGenerator &rng, const N
bool rFound=false, sFound=false; bool rFound=false, sFound=false;
Integer t=2; Integer t=2;
const NameValuePairs &primeParam = MakeParametersForTwoPrimesOfEqualSize(modulusSize) AlgorithmParameters primeParam = MakeParametersForTwoPrimesOfEqualSize(modulusSize)
("EquivalentTo", 3)("Mod", 4); ("EquivalentTo", 3)("Mod", 4);
m_p.GenerateRandom(rng, primeParam); m_p.GenerateRandom(rng, primeParam);
m_q.GenerateRandom(rng, primeParam); m_q.GenerateRandom(rng, primeParam);

View File

@ -115,7 +115,7 @@ void InvertibleRSAFunction::GenerateRandom(RandomNumberGenerator &rng, const Nam
throw InvalidArgument("InvertibleRSAFunction: invalid public exponent"); throw InvalidArgument("InvertibleRSAFunction: invalid public exponent");
RSAPrimeSelector selector(m_e); RSAPrimeSelector selector(m_e);
const NameValuePairs &primeParam = MakeParametersForTwoPrimesOfEqualSize(modulusSize) AlgorithmParameters primeParam = MakeParametersForTwoPrimesOfEqualSize(modulusSize)
(Name::PointerToPrimeSelector(), selector.GetSelectorPointer()); (Name::PointerToPrimeSelector(), selector.GetSelectorPointer());
m_p.GenerateRandom(rng, primeParam); m_p.GenerateRandom(rng, primeParam);
m_q.GenerateRandom(rng, primeParam); m_q.GenerateRandom(rng, primeParam);

2
rw.cpp
View File

@ -93,7 +93,7 @@ void InvertibleRWFunction::GenerateRandom(RandomNumberGenerator &rng, const Name
if (modulusSize < 16) if (modulusSize < 16)
throw InvalidArgument("InvertibleRWFunction: specified modulus length is too small"); throw InvalidArgument("InvertibleRWFunction: specified modulus length is too small");
const NameValuePairs &primeParam = MakeParametersForTwoPrimesOfEqualSize(modulusSize); AlgorithmParameters primeParam = MakeParametersForTwoPrimesOfEqualSize(modulusSize);
m_p.GenerateRandom(rng, CombinedNameValuePairs(primeParam, MakeParameters("EquivalentTo", 3)("Mod", 8))); m_p.GenerateRandom(rng, CombinedNameValuePairs(primeParam, MakeParameters("EquivalentTo", 3)("Mod", 8)));
m_q.GenerateRandom(rng, CombinedNameValuePairs(primeParam, MakeParameters("EquivalentTo", 7)("Mod", 8))); m_q.GenerateRandom(rng, CombinedNameValuePairs(primeParam, MakeParameters("EquivalentTo", 7)("Mod", 8)));