Skip to content

Commit

Permalink
port to Borland C++Builder 2006
Browse files Browse the repository at this point in the history
  • Loading branch information
weidai11 committed Dec 14, 2006
1 parent 0f5ff1a commit 4afd858
Show file tree
Hide file tree
Showing 37 changed files with 158 additions and 117 deletions.
15 changes: 8 additions & 7 deletions Readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 ***

Expand Down Expand Up @@ -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 ***
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion adler32.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 0 additions & 7 deletions algebra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,7 @@ template <class T> const T& AbstractEuclideanDomain<T>::Gcd(const Element &a, co
template <class T> const typename QuotientRing<T>::Element& QuotientRing<T>::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;

Expand Down
25 changes: 21 additions & 4 deletions config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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 ********************

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion crc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions datatest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,9 @@ void TestSymmetricCipher(TestData &v)
if (test == "Encrypt")
{
std::auto_ptr<SymmetricCipher> encryptor(ObjectFactoryRegistry<SymmetricCipher, ENCRYPTION>::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)
Expand All @@ -276,6 +279,9 @@ void TestSymmetricCipher(TestData &v)
else if (test == "Decrypt")
{
std::auto_ptr<SymmetricCipher> decryptor(ObjectFactoryRegistry<SymmetricCipher, DECRYPTION>::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)
Expand Down
2 changes: 1 addition & 1 deletion dmac.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class CRYPTOPP_NO_VTABLE DMAC_Base : public SameKeyLengthAs<T>, public MessageAu
public:
static std::string StaticAlgorithmName() {return std::string("DMAC(") + T::StaticAlgorithmName() + ")";}

enum {DIGESTSIZE=T::BLOCKSIZE};
CRYPTOPP_CONSTANT(DIGESTSIZE=T::BLOCKSIZE)

DMAC_Base() {}

Expand Down
5 changes: 3 additions & 2 deletions eccrypto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -535,10 +535,11 @@ bool DL_GroupParameters_EC<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;
}
Expand Down
4 changes: 3 additions & 1 deletion factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,10 @@ template <class AbstractClass, class ConcreteClass, int instance = 0>
struct RegisterDefaultFactoryFor {
RegisterDefaultFactoryFor(const char *name=NULL)
{
// BCB2006 workaround
std::string n = name ? std::string(name) : std::string(ConcreteClass::StaticAlgorithmName());
ObjectFactoryRegistry<AbstractClass, instance>::Registry().
RegisterFactory(name ? name : ConcreteClass::StaticAlgorithmName(), new DefaultObjectFactory<AbstractClass, ConcreteClass>);
RegisterFactory(n, new DefaultObjectFactory<AbstractClass, ConcreteClass>);
}};

template <class SchemeClass>
Expand Down
1 change: 0 additions & 1 deletion files.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion filters.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class CRYPTOPP_DLL MeterFilter : public Bufferless<Filter>

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;
};
Expand Down
7 changes: 5 additions & 2 deletions gfpcrypt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
3 changes: 2 additions & 1 deletion haval.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ NAMESPACE_BEGIN(CryptoPP)
class HAVAL : public IteratedHash<word32, LittleEndian, 128>
{
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)<br>
/// pass can be 3, 4 or 5 (Default=3)
Expand Down
6 changes: 4 additions & 2 deletions hmac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -33,8 +35,8 @@ void HMAC_Base::UncheckedSetKey(const byte *userKey, unsigned int keylength, con

for (unsigned int i=0; i<blockSize; i++)
{
AccessOpad()[i] = AccessIpad()[i] ^ OPAD;
AccessIpad()[i] ^= IPAD;
AccessOpad()[i] = AccessIpad()[i] ^ 0x5c;
AccessIpad()[i] ^= 0x36;
}
}

Expand Down
19 changes: 7 additions & 12 deletions hmac.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
NAMESPACE_BEGIN(CryptoPP)

//! _
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE HMAC_Base : public VariableKeyLength<16, 0, UINT_MAX>, public MessageAuthenticationCode
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE HMAC_Base : public VariableKeyLength<16, 0, INT_MAX>, public MessageAuthenticationCode
{
public:
HMAC_Base() : m_innerHashKeyed(false) {}
Expand All @@ -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;
};

Expand All @@ -41,7 +40,8 @@ template <class T>
class HMAC : public MessageAuthenticationCodeImpl<HMAC_Base, HMAC<T> >
{
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)
Expand All @@ -52,12 +52,7 @@ class HMAC : public MessageAuthenticationCodeImpl<HMAC_Base, HMAC<T> >

private:
HashTransformation & AccessHash() {return m_hash;}
byte * AccessIpad() {return m_ipad;}
byte * AccessOpad() {return m_opad;}
byte * AccessInnerHash() {return m_innerHash;}

FixedSizeSecBlock<byte, BLOCKSIZE> m_ipad, m_opad;
FixedSizeSecBlock<byte, DIGESTSIZE> m_innerHash;
T m_hash;
};

Expand Down
9 changes: 5 additions & 4 deletions iterhash.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ class CRYPTOPP_NO_VTABLE IteratedHash : public IteratedHashBase<T_HashWordType,
typedef T_Endianness ByteOrderClass;
typedef T_HashWordType HashWordType;

enum {BLOCKSIZE = T_BlockSize};
CRYPTOPP_COMPILE_ASSERT((BLOCKSIZE & (BLOCKSIZE - 1)) == 0); // blockSize is a power of 2
CRYPTOPP_CONSTANT(BLOCKSIZE = T_BlockSize)
// BCB2006 workaround: can't use BLOCKSIZE here
CRYPTOPP_COMPILE_ASSERT((T_BlockSize & (T_BlockSize - 1)) == 0); // blockSize is a power of 2

ByteOrder GetByteOrder() const {return T_Endianness::ToEnum();}

Expand All @@ -77,12 +78,12 @@ class CRYPTOPP_NO_VTABLE IteratedHash : public IteratedHashBase<T_HashWordType,
};

//! _
template <class T_HashWordType, class T_Endianness, unsigned int T_BlockSize, unsigned int T_StateSize, class T_Transform, unsigned int T_DigestSize = T_StateSize>
template <class T_HashWordType, class T_Endianness, unsigned int T_BlockSize, unsigned int T_StateSize, class T_Transform, unsigned int T_DigestSize = 0>
class CRYPTOPP_NO_VTABLE IteratedHashWithStaticTransform
: public ClonableImpl<T_Transform, AlgorithmImpl<IteratedHash<T_HashWordType, T_Endianness, T_BlockSize>, T_Transform> >
{
public:
enum {DIGESTSIZE = T_DigestSize};
CRYPTOPP_CONSTANT(DIGESTSIZE = T_DigestSize ? T_DigestSize : T_StateSize)
unsigned int DigestSize() const {return DIGESTSIZE;};

protected:
Expand Down
9 changes: 6 additions & 3 deletions lubyrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@

NAMESPACE_BEGIN(CryptoPP)

template <class T> struct DigestSizeDoubleWorkaround {enum {RESULT = 2*T::DIGESTSIZE};}; // VC60 workaround
template <class T> struct DigestSizeDoubleWorkaround // VC60 workaround
{
CRYPTOPP_CONSTANT(RESULT = 2*T::DIGESTSIZE)
};

//! algorithm info
template <class T>
struct LR_Info : public VariableKeyLength<16, 0, 2*(UINT_MAX/2), 2>, public FixedBlockSize<DigestSizeDoubleWorkaround<T>::RESULT>
struct LR_Info : public VariableKeyLength<16, 0, 2*(INT_MAX/2), 2>, public FixedBlockSize<DigestSizeDoubleWorkaround<T>::RESULT>
{
static std::string StaticAlgorithmName() {return std::string("LR/")+T::StaticAlgorithmName();}
};
Expand All @@ -38,7 +41,7 @@ class LR : public LR_Info<T>, public BlockCipherDocumentation
}

protected:
enum {S=T::DIGESTSIZE};
CRYPTOPP_CONSTANT(S=T::DIGESTSIZE)
unsigned int L; // key length / 2
SecByteBlock key;

Expand Down
3 changes: 2 additions & 1 deletion md2.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion md5mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);}

Expand Down
Loading

0 comments on commit 4afd858

Please sign in to comment.