Skip to content

Commit

Permalink
port to GCC 4
Browse files Browse the repository at this point in the history
  • Loading branch information
weidai11 committed Sep 5, 2005
1 parent 946eb7f commit 09bb1aa
Show file tree
Hide file tree
Showing 21 changed files with 117 additions and 103 deletions.
4 changes: 4 additions & 0 deletions algebra.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,4 +278,8 @@ template <class T> class QuotientRing : public AbstractRing<typename T::Element>

NAMESPACE_END

#ifdef CRYPTOPP_MANUALLY_INSTANTIATE_TEMPLATES
#include "algebra.cpp"
#endif

#endif
2 changes: 1 addition & 1 deletion base32.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Base32Decoder : public BaseN_Decoder
void IsolatedInitialize(const NameValuePairs &parameters);

private:
static const int *GetDefaultDecodingLookupArray();
static const int * CRYPTOPP_API GetDefaultDecodingLookupArray();
};

NAMESPACE_END
Expand Down
2 changes: 1 addition & 1 deletion base64.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Base64Decoder : public BaseN_Decoder
void IsolatedInitialize(const NameValuePairs &parameters) {}

private:
static const int *GetDecodingLookupArray();
static const int * CRYPTOPP_API GetDecodingLookupArray();
};

NAMESPACE_END
Expand Down
2 changes: 1 addition & 1 deletion basecode.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class CRYPTOPP_DLL BaseN_Decoder : public Unflushable<Filter>
void IsolatedInitialize(const NameValuePairs &parameters);
size_t Put2(const byte *begin, size_t length, int messageEnd, bool blocking);

static void InitializeDecodingLookupArray(int *lookup, const byte *alphabet, unsigned int base, bool caseInsensitive);
static void CRYPTOPP_API InitializeDecodingLookupArray(int *lookup, const byte *alphabet, unsigned int base, bool caseInsensitive);

private:
const int *m_lookup;
Expand Down
20 changes: 14 additions & 6 deletions config.h
Original file line number Diff line number Diff line change
Expand Up @@ -284,20 +284,28 @@ NAMESPACE_END

#endif // CRYPTOPP_WIN32_AVAILABLE

#if defined(__MWERKS__)
#define CRYPTOPP_EXTERN_DLL_TEMPLATE_CLASS extern class CRYPTOPP_DLL
#else
#define CRYPTOPP_EXTERN_DLL_TEMPLATE_CLASS extern template class CRYPTOPP_DLL
#endif

#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
#define CRYPTOPP_DLL_TEMPLATE_CLASS CRYPTOPP_EXTERN_DLL_TEMPLATE_CLASS
#endif

#if defined(__MWERKS__)
#define CRYPTOPP_EXTERN_STATIC_TEMPLATE_CLASS extern class
#else
#define CRYPTOPP_EXTERN_STATIC_TEMPLATE_CLASS extern template class
#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
#define CRYPTOPP_STATIC_TEMPLATE_CLASS CRYPTOPP_EXTERN_STATIC_TEMPLATE_CLASS
#endif

#endif
2 changes: 1 addition & 1 deletion dh.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class DH_Domain : public DL_SimpleKeyAgreementDomainBase<typename GROUP_PARAMETE
}
}

static std::string StaticAlgorithmName()
static std::string CRYPTOPP_API StaticAlgorithmName()
{return GroupParameters::StaticAlgorithmNamePrefix() + DH_Algorithm::StaticAlgorithmName();}
std::string AlgorithmName() const {return StaticAlgorithmName();}

Expand Down
25 changes: 1 addition & 24 deletions dll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,14 @@
#include "dll.h"
#pragma warning(default: 4660)

#ifdef CRYPTOPP_WIN32_AVAILABLE
#if defined(CRYPTOPP_EXPORTS) && defined(CRYPTOPP_WIN32_AVAILABLE)
#include <windows.h>
#endif

#include "iterhash.cpp"
#include "strciphr.cpp"
#include "algebra.cpp"
#include "eprecomp.cpp"
#include "eccrypto.cpp"

#ifndef CRYPTOPP_IMPORTS

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<SHA1>::decoration[] = {0x30,0x21,0x30,0x09,0x06,0x05,0x2B,0x0E,0x03,0x02,0x1A,0x05,0x00,0x04,0x14};
template<> const unsigned int PKCS_DigestDecoration<SHA1>::length = sizeof(PKCS_DigestDecoration<SHA1>::decoration);

Expand Down
2 changes: 1 addition & 1 deletion eccrypto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

NAMESPACE_BEGIN(CryptoPP)

#ifndef NDEBUG
#if 0
static void ECDSA_TestInstantiations()
{
ECDSA<EC2N>::Signer t1;
Expand Down
52 changes: 28 additions & 24 deletions eccrypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class DL_GroupParameters_EC : public DL_GroupParametersImpl<EcPrecomputation<EC>
Integer GetMaxExponent() const {return GetSubgroupOrder()-1;}
bool IsIdentity(const Element &element) const {return element.identity;}
void SimultaneousExponentiate(Element *results, const Element &base, const Integer *exponents, unsigned int exponentsCount) const;
static std::string StaticAlgorithmNamePrefix() {return "EC";}
static std::string CRYPTOPP_API StaticAlgorithmNamePrefix() {return "EC";}

// ASN1Key
OID GetAlgorithmID() const;
Expand All @@ -105,7 +105,7 @@ class DL_GroupParameters_EC : public DL_GroupParametersImpl<EcPrecomputation<EC>
// non-inherited

// enumerate OIDs for recommended parameters, use OID() to get first one
static OID GetNextRecommendedParametersOID(const OID &oid);
static OID CRYPTOPP_API GetNextRecommendedParametersOID(const OID &oid);

void BERDecode(BufferedTransformation &bt);
void DEREncode(BufferedTransformation &bt) const;
Expand Down Expand Up @@ -137,11 +137,6 @@ class DL_GroupParameters_EC : public DL_GroupParametersImpl<EcPrecomputation<EC>
mutable Integer m_k; // cofactor
};

CRYPTOPP_DLL_TEMPLATE_CLASS DL_GroupParameters_EC<ECP>;
CRYPTOPP_DLL_TEMPLATE_CLASS DL_GroupParameters_EC<EC2N>;
CRYPTOPP_DLL_TEMPLATE_CLASS DL_PublicKeyImpl<DL_GroupParameters_EC<ECP> >;
CRYPTOPP_DLL_TEMPLATE_CLASS DL_PublicKeyImpl<DL_GroupParameters_EC<EC2N> >;

//! EC public key
template <class EC>
class DL_PublicKey_EC : public DL_PublicKeyImpl<DL_GroupParameters_EC<EC> >
Expand All @@ -159,11 +154,6 @@ class DL_PublicKey_EC : public DL_PublicKeyImpl<DL_GroupParameters_EC<EC> >
void DEREncodeKey(BufferedTransformation &bt) const;
};

CRYPTOPP_DLL_TEMPLATE_CLASS DL_PublicKey_EC<ECP>;
CRYPTOPP_DLL_TEMPLATE_CLASS DL_PublicKey_EC<EC2N>;
CRYPTOPP_DLL_TEMPLATE_CLASS DL_PrivateKeyImpl<DL_GroupParameters_EC<ECP> >;
CRYPTOPP_DLL_TEMPLATE_CLASS DL_PrivateKeyImpl<DL_GroupParameters_EC<EC2N> >;

//! EC private key
template <class EC>
class DL_PrivateKey_EC : public DL_PrivateKeyImpl<DL_GroupParameters_EC<EC> >
Expand All @@ -185,9 +175,6 @@ class DL_PrivateKey_EC : public DL_PrivateKeyImpl<DL_GroupParameters_EC<EC> >
void DEREncodeKey(BufferedTransformation &bt) const;
};

CRYPTOPP_DLL_TEMPLATE_CLASS DL_PrivateKey_EC<ECP>;
CRYPTOPP_DLL_TEMPLATE_CLASS DL_PrivateKey_EC<EC2N>;

//! Elliptic Curve Diffie-Hellman, AKA <a href="http://www.weidai.com/scan-mirror/ka.html#ECDH">ECDH</a>
template <class EC, class COFACTOR_OPTION = CPP_TYPENAME DL_GroupParameters_EC<EC>::DefaultCofactorOption>
struct ECDH
Expand Down Expand Up @@ -221,23 +208,20 @@ struct DL_Keys_ECDSA
typedef DL_PrivateKey_WithSignaturePairwiseConsistencyTest<DL_PrivateKey_EC<EC>, ECDSA<EC> > PrivateKey;
};

CRYPTOPP_DLL_TEMPLATE_CLASS DL_Algorithm_GDSA<ECP::Point>;
CRYPTOPP_DLL_TEMPLATE_CLASS DL_Algorithm_GDSA<EC2N::Point>;

//! ECDSA algorithm
template <class EC>
class DL_Algorithm_ECDSA : public DL_Algorithm_GDSA<typename EC::Point>
{
public:
static const char * StaticAlgorithmName() {return "ECDSA";}
static const char * CRYPTOPP_API StaticAlgorithmName() {return "ECDSA";}
};

//! ECNR algorithm
template <class EC>
class DL_Algorithm_ECNR : public DL_Algorithm_NR<typename EC::Point>
{
public:
static const char * StaticAlgorithmName() {return "ECNR";}
static const char * CRYPTOPP_API StaticAlgorithmName() {return "ECNR";}
};

//! <a href="http://www.weidai.com/scan-mirror/sig.html#ECDSA">ECDSA</a>
Expand All @@ -246,9 +230,6 @@ 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>
Expand All @@ -268,9 +249,32 @@ struct ECIES
DL_EncryptionAlgorithm_Xor<HMAC<SHA1>, DHAES_MODE>,
ECIES<EC> >
{
static std::string StaticAlgorithmName() {return "ECIES";} // TODO: fix this after name is standardized
static std::string CRYPTOPP_API StaticAlgorithmName() {return "ECIES";} // TODO: fix this after name is standardized
};

NAMESPACE_END

#ifdef CRYPTOPP_MANUALLY_INSTANTIATE_TEMPLATES
#include "eccrypto.cpp"
#endif

NAMESPACE_BEGIN(CryptoPP)

CRYPTOPP_DLL_TEMPLATE_CLASS DL_GroupParameters_EC<ECP>;
CRYPTOPP_DLL_TEMPLATE_CLASS DL_GroupParameters_EC<EC2N>;
CRYPTOPP_DLL_TEMPLATE_CLASS DL_PublicKeyImpl<DL_GroupParameters_EC<ECP> >;
CRYPTOPP_DLL_TEMPLATE_CLASS DL_PublicKeyImpl<DL_GroupParameters_EC<EC2N> >;
CRYPTOPP_DLL_TEMPLATE_CLASS DL_PublicKey_EC<ECP>;
CRYPTOPP_DLL_TEMPLATE_CLASS DL_PublicKey_EC<EC2N>;
CRYPTOPP_DLL_TEMPLATE_CLASS DL_PrivateKeyImpl<DL_GroupParameters_EC<ECP> >;
CRYPTOPP_DLL_TEMPLATE_CLASS DL_PrivateKeyImpl<DL_GroupParameters_EC<EC2N> >;
CRYPTOPP_DLL_TEMPLATE_CLASS DL_PrivateKey_EC<ECP>;
CRYPTOPP_DLL_TEMPLATE_CLASS DL_PrivateKey_EC<EC2N>;
CRYPTOPP_DLL_TEMPLATE_CLASS DL_Algorithm_GDSA<ECP::Point>;
CRYPTOPP_DLL_TEMPLATE_CLASS DL_Algorithm_GDSA<EC2N::Point>;
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> >;

NAMESPACE_END

#endif
4 changes: 4 additions & 0 deletions eprecomp.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,8 @@ class DL_FixedBasePrecomputationImpl : public DL_FixedBasePrecomputation<T>

NAMESPACE_END

#ifdef CRYPTOPP_MANUALLY_INSTANTIATE_TEMPLATES
#include "eprecomp.cpp"
#endif

#endif
16 changes: 8 additions & 8 deletions gf2n.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,18 @@ class CRYPTOPP_DLL PolynomialMod2
{Randomize(rng, bitcount);}

//! return x^i
static PolynomialMod2 Monomial(size_t i);
static PolynomialMod2 CRYPTOPP_API Monomial(size_t i);
//! return x^t0 + x^t1 + x^t2
static PolynomialMod2 Trinomial(size_t t0, size_t t1, size_t t2);
static PolynomialMod2 CRYPTOPP_API Trinomial(size_t t0, size_t t1, size_t t2);
//! return x^t0 + x^t1 + x^t2 + x^t3 + x^t4
static PolynomialMod2 Pentanomial(size_t t0, size_t t1, size_t t2, size_t t3, size_t t4);
static PolynomialMod2 CRYPTOPP_API Pentanomial(size_t t0, size_t t1, size_t t2, size_t t3, size_t t4);
//! return x^(n-1) + ... + x + 1
static PolynomialMod2 AllOnes(size_t n);
static PolynomialMod2 CRYPTOPP_API AllOnes(size_t n);

//!
static const PolynomialMod2 &Zero();
static const PolynomialMod2 & CRYPTOPP_API Zero();
//!
static const PolynomialMod2 &One();
static const PolynomialMod2 & CRYPTOPP_API One();
//@}

//! \name ENCODE/DECODE
Expand Down Expand Up @@ -216,12 +216,12 @@ class CRYPTOPP_DLL PolynomialMod2
PolynomialMod2 MultiplicativeInverse() const {return IsUnit() ? One() : Zero();}

//! greatest common divisor
static PolynomialMod2 Gcd(const PolynomialMod2 &a, const PolynomialMod2 &n);
static PolynomialMod2 CRYPTOPP_API Gcd(const PolynomialMod2 &a, const PolynomialMod2 &n);
//! calculate multiplicative inverse of *this mod n
PolynomialMod2 InverseMod(const PolynomialMod2 &) const;

//! calculate r and q such that (a == d*q + r) && (deg(r) < deg(d))
static void Divide(PolynomialMod2 &r, PolynomialMod2 &q, const PolynomialMod2 &a, const PolynomialMod2 &d);
static void CRYPTOPP_API Divide(PolynomialMod2 &r, PolynomialMod2 &q, const PolynomialMod2 &a, const PolynomialMod2 &d);
//@}

//! \name INPUT/OUTPUT
Expand Down
2 changes: 1 addition & 1 deletion hex.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class CRYPTOPP_DLL HexDecoder : public BaseN_Decoder
void IsolatedInitialize(const NameValuePairs &parameters);

private:
static const int *GetDefaultDecodingLookupArray();
static const int * CRYPTOPP_API GetDefaultDecodingLookupArray();
};

NAMESPACE_END
Expand Down
2 changes: 2 additions & 0 deletions integer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ void AlignedAllocator<T>::deallocate(void *p, size_type n)
else
delete [] (T *)p;
}

template class CRYPTOPP_DLL AlignedAllocator<word>;
#endif

static int Compare(const word *A, const word *B, size_t N)
Expand Down
7 changes: 5 additions & 2 deletions integer.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#endif

// SSE2 intrinsics work in GCC 3.3 or later
#if defined(__SSE2__) && (__GNUC_MAJOR__ > 3 || __GNUC_MINOR__ > 2)
#if defined(__SSE2__) && (__GNUC__ > 3 || __GNUC_MINOR__ > 2)
#define SSE2_INTRINSICS_AVAILABLE
#endif

Expand Down Expand Up @@ -56,7 +56,10 @@ NAMESPACE_BEGIN(CryptoPP)
#endif
};

template class CRYPTOPP_DLL AlignedAllocator<word>;
#ifdef CRYPTOPP_IMPORTS
CRYPTOPP_DLL_TEMPLATE_CLASS AlignedAllocator<word>;
#endif

typedef SecBlock<word, AlignedAllocator<word> > SecAlignedWordBlock;
#else
typedef SecWordBlock SecAlignedWordBlock;
Expand Down
24 changes: 16 additions & 8 deletions iterhash.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,6 @@ class CRYPTOPP_NO_VTABLE IteratedHashBase : public BASE
T m_countLo, m_countHi;
};

#ifdef WORD64_AVAILABLE
CRYPTOPP_DLL_TEMPLATE_CLASS IteratedHashBase<word64, HashTransformation>;
CRYPTOPP_STATIC_TEMPLATE_CLASS IteratedHashBase<word64, MessageAuthenticationCode>;
#endif

CRYPTOPP_DLL_TEMPLATE_CLASS IteratedHashBase<word32, HashTransformation>;
CRYPTOPP_STATIC_TEMPLATE_CLASS IteratedHashBase<word32, MessageAuthenticationCode>;

//! _
template <class T_HashWordType, class T_Endianness, unsigned int T_BlockSize, class T_Base = HashTransformation>
class CRYPTOPP_NO_VTABLE IteratedHash : public IteratedHashBase<T_HashWordType, T_Base>
Expand Down Expand Up @@ -105,4 +97,20 @@ class CRYPTOPP_NO_VTABLE IteratedHashWithStaticTransform

NAMESPACE_END

#ifdef CRYPTOPP_MANUALLY_INSTANTIATE_TEMPLATES
#include "iterhash.cpp"
#endif

NAMESPACE_BEGIN(CryptoPP)

#ifdef WORD64_AVAILABLE
CRYPTOPP_DLL_TEMPLATE_CLASS IteratedHashBase<word64, HashTransformation>;
CRYPTOPP_STATIC_TEMPLATE_CLASS IteratedHashBase<word64, MessageAuthenticationCode>;
#endif

CRYPTOPP_DLL_TEMPLATE_CLASS IteratedHashBase<word32, HashTransformation>;
CRYPTOPP_STATIC_TEMPLATE_CLASS IteratedHashBase<word32, MessageAuthenticationCode>;

NAMESPACE_END

#endif
4 changes: 2 additions & 2 deletions osrng.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ void BlockingRng::GenerateBlock(byte *output, size_t size)
{
// on some systems /dev/random will block until all bytes
// are available, on others it will returns immediately
int len = read(m_fd, output, STDMIN(size, (unsigned int)INT_MAX));
if (len == -1)
ssize_t len = read(m_fd, output, size);
if (len < 0)
throw OS_RNG_Err("read /dev/random");
size -= len;
output += len;
Expand Down
Loading

0 comments on commit 09bb1aa

Please sign in to comment.