summaryrefslogtreecommitdiff
path: root/extra/yassl/taocrypt
diff options
context:
space:
mode:
authorsvoj@mysql.com <>2005-05-25 00:15:06 +0500
committersvoj@mysql.com <>2005-05-25 00:15:06 +0500
commit1dabee5aad6d4942c57014c9d9b548a0bb060c1d (patch)
tree816e402c0c60c638984277fb64ba0d6f7a4c35c1 /extra/yassl/taocrypt
parenta49ccfe6f061912fd256960d4d69cb3802f0acd1 (diff)
downloadmariadb-git-1dabee5aad6d4942c57014c9d9b548a0bb060c1d.tar.gz
Upgrade yaSSL to 0.9.9.
Diffstat (limited to 'extra/yassl/taocrypt')
-rw-r--r--extra/yassl/taocrypt/include/aes.hpp5
-rw-r--r--extra/yassl/taocrypt/include/algebra.hpp126
-rw-r--r--extra/yassl/taocrypt/include/block.hpp20
-rw-r--r--extra/yassl/taocrypt/include/des.hpp5
-rw-r--r--extra/yassl/taocrypt/include/error.hpp3
-rw-r--r--extra/yassl/taocrypt/include/hash.hpp2
-rw-r--r--extra/yassl/taocrypt/include/integer.hpp10
-rw-r--r--extra/yassl/taocrypt/include/misc.hpp11
-rw-r--r--extra/yassl/taocrypt/include/modarith.hpp13
-rw-r--r--extra/yassl/taocrypt/include/modes.hpp55
-rw-r--r--extra/yassl/taocrypt/src/algebra.cpp99
-rw-r--r--extra/yassl/taocrypt/src/asn.cpp20
-rw-r--r--extra/yassl/taocrypt/src/dh.cpp1
-rw-r--r--extra/yassl/taocrypt/src/dsa.cpp2
-rw-r--r--extra/yassl/taocrypt/src/integer.cpp243
-rw-r--r--extra/yassl/taocrypt/src/misc.cpp27
-rw-r--r--extra/yassl/taocrypt/src/random.cpp1
-rw-r--r--extra/yassl/taocrypt/src/rsa.cpp7
18 files changed, 127 insertions, 523 deletions
diff --git a/extra/yassl/taocrypt/include/aes.hpp b/extra/yassl/taocrypt/include/aes.hpp
index b2c93eff9fe..b8436d35c5f 100644
--- a/extra/yassl/taocrypt/include/aes.hpp
+++ b/extra/yassl/taocrypt/include/aes.hpp
@@ -37,11 +37,12 @@ enum { AES_BLOCK_SIZE = 16 };
// AES encryption and decryption, see FIPS-197
-class AES : public Mode_BASE<AES_BLOCK_SIZE> {
+class AES : public Mode_BASE {
public:
enum { BLOCK_SIZE = AES_BLOCK_SIZE };
- AES(CipherDir DIR, Mode MODE) : dir_(DIR), mode_(MODE) {}
+ AES(CipherDir DIR, Mode MODE)
+ : Mode_BASE(BLOCK_SIZE), dir_(DIR), mode_(MODE) {}
void Process(byte*, const byte*, word32);
void SetKey(const byte* iv, word32 sz, CipherDir fake = ENCRYPTION);
diff --git a/extra/yassl/taocrypt/include/algebra.hpp b/extra/yassl/taocrypt/include/algebra.hpp
index 74f244507f6..92cac607d97 100644
--- a/extra/yassl/taocrypt/include/algebra.hpp
+++ b/extra/yassl/taocrypt/include/algebra.hpp
@@ -24,11 +24,10 @@
#ifndef TAO_CRYPT_ALGEBRA_HPP
#define TAO_CRYPT_ALGEBRA_HPP
-#include "misc.hpp"
+#include "integer.hpp"
namespace TaoCrypt {
-class Integer;
// "const Element&" returned by member functions are references
// to internal data members. Since each object may have only
@@ -38,11 +37,11 @@ class Integer;
// But this should be fine:
// abcd = group.Add(a, group.Add(b, group.Add(c,d));
-//! Abstract Group
-template <class T> class TAOCRYPT_NO_VTABLE AbstractGroup
+// Abstract Group
+class TAOCRYPT_NO_VTABLE AbstractGroup
{
public:
- typedef T Element;
+ typedef Integer Element;
virtual ~AbstractGroup() {}
@@ -65,15 +64,14 @@ public:
const Integer *exponents, unsigned int exponentsCount) const;
};
-//! Abstract Ring
-template <class T> class TAOCRYPT_NO_VTABLE AbstractRing
- : public AbstractGroup<T>
+// Abstract Ring
+class TAOCRYPT_NO_VTABLE AbstractRing : public AbstractGroup
{
public:
- typedef T Element;
+ typedef Integer Element;
AbstractRing() {m_mg.m_pRing = this;}
- AbstractRing(const AbstractRing &source) {m_mg.m_pRing = this;}
+ AbstractRing(const AbstractRing &source) : AbstractGroup() {m_mg.m_pRing = this;}
AbstractRing& operator=(const AbstractRing &source) {return *this;}
virtual bool IsUnit(const Element &a) const =0;
@@ -91,14 +89,14 @@ public:
virtual void SimultaneousExponentiate(Element *results, const Element&,
const Integer *exponents, unsigned int exponentsCount) const;
- virtual const AbstractGroup<T>& MultiplicativeGroup() const
+ virtual const AbstractGroup& MultiplicativeGroup() const
{return m_mg;}
private:
- class MultiplicativeGroupT : public AbstractGroup<T>
+ class MultiplicativeGroupT : public AbstractGroup
{
public:
- const AbstractRing<T>& GetRing() const
+ const AbstractRing& GetRing() const
{return *m_pRing;}
bool Equal(const Element &a, const Element &b) const
@@ -137,44 +135,19 @@ private:
{GetRing().SimultaneousExponentiate(results, base, exponents,
exponentsCount);}
- const AbstractRing<T> *m_pRing;
+ const AbstractRing* m_pRing;
};
MultiplicativeGroupT m_mg;
};
-// ********************************************************
-//! Base and Exponent
-template <class T, class E = Integer>
-struct BaseAndExponent
+// Abstract Euclidean Domain
+class TAOCRYPT_NO_VTABLE AbstractEuclideanDomain
+ : public AbstractRing
{
public:
- BaseAndExponent() {}
- BaseAndExponent(const T &base, const E &exponent) : base(base),
- exponent(exponent) {}
- bool operator<(const BaseAndExponent<T, E> &rhs) const
- {return exponent < rhs.exponent;}
- T base;
- E exponent;
-};
-
-// VC60 workaround: incomplete member template support
-template <class Element, class Iterator>
- Element GeneralCascadeMultiplication(const AbstractGroup<Element> &group,
- Iterator begin, Iterator end);
-template <class Element, class Iterator>
- Element GeneralCascadeExponentiation(const AbstractRing<Element> &ring,
- Iterator begin, Iterator end);
-
-// ********************************************************
-
-//! Abstract Euclidean Domain
-template <class T> class TAOCRYPT_NO_VTABLE AbstractEuclideanDomain
- : public AbstractRing<T>
-{
-public:
- typedef T Element;
+ typedef Integer Element;
virtual void DivisionAlgorithm(Element &r, Element &q, const Element &a,
const Element &d) const =0;
@@ -186,13 +159,12 @@ protected:
mutable Element result;
};
-// ********************************************************
-//! EuclideanDomainOf
-template <class T> class EuclideanDomainOf : public AbstractEuclideanDomain<T>
+// EuclideanDomainOf
+class EuclideanDomainOf : public AbstractEuclideanDomain
{
public:
- typedef T Element;
+ typedef Integer Element;
EuclideanDomainOf() {}
@@ -249,68 +221,8 @@ private:
mutable Element result;
};
-//! Quotient Ring
-template<class T> class QuotientRing : public AbstractRing<typename T::Element>
-{
-public:
- typedef T EuclideanDomain;
- typedef typename T::Element Element;
-
- QuotientRing(const EuclideanDomain &domain, const Element &modulus)
- : m_domain(domain), m_modulus(modulus) {}
-
- const EuclideanDomain & GetDomain() const
- {return m_domain;}
-
- const Element& GetModulus() const
- {return m_modulus;}
-
- bool Equal(const Element &a, const Element &b) const
- {return m_domain.Equal(m_domain.Mod(m_domain.Subtract(a, b),
- m_modulus), m_domain.Identity());}
-
- const Element& Identity() const
- {return m_domain.Identity();}
-
- const Element& Add(const Element &a, const Element &b) const
- {return m_domain.Add(a, b);}
-
- Element& Accumulate(Element &a, const Element &b) const
- {return m_domain.Accumulate(a, b);}
-
- const Element& Inverse(const Element &a) const
- {return m_domain.Inverse(a);}
-
- const Element& Subtract(const Element &a, const Element &b) const
- {return m_domain.Subtract(a, b);}
-
- Element& Reduce(Element &a, const Element &b) const
- {return m_domain.Reduce(a, b);}
-
- const Element& Double(const Element &a) const
- {return m_domain.Double(a);}
-
- bool IsUnit(const Element &a) const
- {return m_domain.IsUnit(m_domain.Gcd(a, m_modulus));}
-
- const Element& MultiplicativeIdentity() const
- {return m_domain.MultiplicativeIdentity();}
-
- const Element& Multiply(const Element &a, const Element &b) const
- {return m_domain.Mod(m_domain.Multiply(a, b), m_modulus);}
-
- const Element& Square(const Element &a) const
- {return m_domain.Mod(m_domain.Square(a), m_modulus);}
-
- const Element& MultiplicativeInverse(const Element &a) const;
-
-protected:
- EuclideanDomain m_domain;
- Element m_modulus;
-};
} // namespace
-
#endif // TAO_CRYPT_ALGEBRA_HPP
diff --git a/extra/yassl/taocrypt/include/block.hpp b/extra/yassl/taocrypt/include/block.hpp
index f490fb0b6e7..f3c4415682d 100644
--- a/extra/yassl/taocrypt/include/block.hpp
+++ b/extra/yassl/taocrypt/include/block.hpp
@@ -34,10 +34,6 @@
#include <stddef.h> // ptrdiff_t
-#if defined(_MSC_VER) && defined(_CRTAPI1)
-#define TAOCRYPT_MSVCRT6
-#endif
-
namespace TaoCrypt {
@@ -47,13 +43,13 @@ template<class T>
class AllocatorBase
{
public:
- typedef T value_type;
- typedef size_t size_type;
- typedef ptrdiff_t difference_type;
- typedef T* pointer;
- typedef const T* const_pointer;
- typedef T& reference;
- typedef const T& const_reference;
+ typedef T value_type;
+ typedef size_t size_type;
+ typedef ptrdiff_t difference_type;
+ typedef T* pointer;
+ typedef const T* const_pointer;
+ typedef T& reference;
+ typedef const T& const_reference;
pointer address(reference r) const {return (&r);}
const_pointer address(const_reference r) const {return (&r); }
@@ -104,7 +100,7 @@ public:
CheckSize(n);
if (n == 0)
return 0;
- return new (tc) T[n];
+ return new T[n];
}
void deallocate(void* p, size_type n)
diff --git a/extra/yassl/taocrypt/include/des.hpp b/extra/yassl/taocrypt/include/des.hpp
index e8100b4e198..127b8ddc6d5 100644
--- a/extra/yassl/taocrypt/include/des.hpp
+++ b/extra/yassl/taocrypt/include/des.hpp
@@ -36,12 +36,13 @@ namespace TaoCrypt {
enum { DES_BLOCK_SIZE = 8 };
// Base for all DES types
-class DES_BASE : public Mode_BASE<DES_BLOCK_SIZE> {
+class DES_BASE : public Mode_BASE {
public:
enum { BLOCK_SIZE = DES_BLOCK_SIZE, KEY_SIZE = 32, BOXES = 8,
BOX_SIZE = 64 };
- DES_BASE(CipherDir DIR, Mode MODE) : dir_(DIR), mode_(MODE) {}
+ DES_BASE(CipherDir DIR, Mode MODE)
+ : Mode_BASE(BLOCK_SIZE), dir_(DIR), mode_(MODE) {}
void Process(byte*, const byte*, word32);
protected:
diff --git a/extra/yassl/taocrypt/include/error.hpp b/extra/yassl/taocrypt/include/error.hpp
index 6170d0349b5..55ab39313f5 100644
--- a/extra/yassl/taocrypt/include/error.hpp
+++ b/extra/yassl/taocrypt/include/error.hpp
@@ -65,7 +65,8 @@ UNKOWN_HASH_E = 1034, // "unknown hash OID"
DSA_SZ_E = 1035, // "bad DSA r or s size"
BEFORE_DATE_E = 1036, // "before date in the future"
AFTER_DATE_E = 1037, // "after date in the past"
-SIG_CONFIRM_E = 1038 // "bad signature confirmation"
+SIG_CONFIRM_E = 1038, // "bad self signature confirmation"
+SIG_OTHER_E = 1039 // "bad other signature confirmation"
};
diff --git a/extra/yassl/taocrypt/include/hash.hpp b/extra/yassl/taocrypt/include/hash.hpp
index 1703de23713..f01f343c2d1 100644
--- a/extra/yassl/taocrypt/include/hash.hpp
+++ b/extra/yassl/taocrypt/include/hash.hpp
@@ -50,7 +50,7 @@ public:
class HASHwithTransform : public HASH {
public:
HASHwithTransform(word32 digSz, word32 buffSz)
- : digest_(new (tc) word32[digSz]), buffer_(new (tc) byte[buffSz]) {}
+ : digest_(new word32[digSz]), buffer_(new byte[buffSz]) {}
virtual ~HASHwithTransform() { delete[] buffer_; delete[] digest_; }
virtual ByteOrder getByteOrder() const = 0;
diff --git a/extra/yassl/taocrypt/include/integer.hpp b/extra/yassl/taocrypt/include/integer.hpp
index 3713d09d9f9..6b1984e46ed 100644
--- a/extra/yassl/taocrypt/include/integer.hpp
+++ b/extra/yassl/taocrypt/include/integer.hpp
@@ -29,8 +29,8 @@
#include "block.hpp"
#include "random.hpp"
#include "file.hpp"
-#include <string.h>
#include "algorithm.hpp" // mySTL::swap
+#include <string.h>
#ifdef TAOCRYPT_X86ASM_AVAILABLE
@@ -128,9 +128,6 @@ public:
Integer(signed long value);
Integer(Sign s, word highWord, word lowWord);
- explicit Integer(const char* str);
- explicit Integer(const wchar_t* str);
-
// BER Decode Source
explicit Integer(Source&);
@@ -254,15 +251,13 @@ public:
private:
friend class ModularArithmetic;
friend class MontgomeryRepresentation;
- friend class HalfMontgomeryRepresentation;
-
Integer(word value, unsigned int length);
static const Integer zero;
static const Integer one;
static const Integer two;
-
int PositiveCompare(const Integer& t) const;
+
friend void PositiveAdd(Integer& sum, const Integer& a, const Integer& b);
friend void PositiveSubtract(Integer& diff, const Integer& a,
const Integer& b);
@@ -308,6 +303,7 @@ inline void swap(Integer &a, Integer &b)
Integer CRT(const Integer& xp, const Integer& p, const Integer& xq,
const Integer& q, const Integer& u);
+
inline Integer ModularExponentiation(const Integer& a, const Integer& e,
const Integer& m)
{
diff --git a/extra/yassl/taocrypt/include/misc.hpp b/extra/yassl/taocrypt/include/misc.hpp
index b5b0a4575fc..de8cbb30fcb 100644
--- a/extra/yassl/taocrypt/include/misc.hpp
+++ b/extra/yassl/taocrypt/include/misc.hpp
@@ -28,17 +28,6 @@
#include <assert.h>
#include <string.h>
-namespace TaoCrypt {
-
-// library allocation
-struct new_t {}; // TaoCrypt New type
-extern new_t tc; // pass in parameter
-
-} // namespace TaoCrypt
-
-void* operator new (size_t, TaoCrypt::new_t);
-void* operator new[](size_t, TaoCrypt::new_t);
-
namespace TaoCrypt {
diff --git a/extra/yassl/taocrypt/include/modarith.hpp b/extra/yassl/taocrypt/include/modarith.hpp
index 88a2cc95c7c..66a841b05c3 100644
--- a/extra/yassl/taocrypt/include/modarith.hpp
+++ b/extra/yassl/taocrypt/include/modarith.hpp
@@ -27,14 +27,13 @@
#define TAO_CRYPT_MODARITH_HPP
#include "misc.hpp"
-#include "integer.hpp"
#include "algebra.hpp"
namespace TaoCrypt {
-//! ModularArithmetic
-class ModularArithmetic : public AbstractRing<Integer>
+// ModularArithmetic
+class ModularArithmetic : public AbstractRing
{
public:
@@ -45,7 +44,7 @@ public:
: modulus(modulus), result((word)0, modulus.reg_.size()) {}
ModularArithmetic(const ModularArithmetic &ma)
- : AbstractRing<Integer>(),
+ : AbstractRing(),
modulus(ma.modulus), result((word)0, modulus.reg_.size()) {}
const Integer& GetModulus() const {return modulus;}
@@ -149,12 +148,12 @@ public:
Integer CascadeExponentiate(const Integer &x, const Integer &e1,
const Integer &y, const Integer &e2) const
- {return AbstractRing<Integer>::CascadeExponentiate(x, e1, y, e2);}
+ {return AbstractRing::CascadeExponentiate(x, e1, y, e2);}
void SimultaneousExponentiate(Element *results, const Element &base,
const Integer *exponents, unsigned int exponentsCount) const
- {AbstractRing<Integer>::SimultaneousExponentiate(results, base,
- exponents, exponentsCount);}
+ {AbstractRing::SimultaneousExponentiate(results, base,
+ exponents, exponentsCount);}
private:
Integer u;
diff --git a/extra/yassl/taocrypt/include/modes.hpp b/extra/yassl/taocrypt/include/modes.hpp
index 2a21ad46b76..3f9878a9e62 100644
--- a/extra/yassl/taocrypt/include/modes.hpp
+++ b/extra/yassl/taocrypt/include/modes.hpp
@@ -56,10 +56,11 @@ private:
// Mode Base for block ciphers, static size
-template<int BLOCK_SIZE>
class Mode_BASE {
public:
- Mode_BASE() {}
+ enum { MaxBlockSz = 16 };
+
+ explicit Mode_BASE(int sz) : blockSz_(sz) { assert(sz <= MaxBlockSz); }
virtual ~Mode_BASE() {}
virtual void ProcessAndXorBlock(const byte*, const byte*, byte*) const = 0;
@@ -68,10 +69,11 @@ public:
void CBC_Encrypt(byte*, const byte*, word32);
void CBC_Decrypt(byte*, const byte*, word32);
- void SetIV(const byte* iv) { memcpy(reg_, iv, BLOCK_SIZE); }
+ void SetIV(const byte* iv) { memcpy(reg_, iv, blockSz_); }
private:
- byte reg_[BLOCK_SIZE];
- byte tmp_[BLOCK_SIZE];
+ byte reg_[MaxBlockSz];
+ byte tmp_[MaxBlockSz];
+ int blockSz_;
Mode_BASE(const Mode_BASE&); // hide copy
Mode_BASE& operator=(const Mode_BASE&); // and assign
@@ -79,51 +81,48 @@ private:
// ECB Process blocks
-template<int BLOCK_SIZE>
-void Mode_BASE<BLOCK_SIZE>::ECB_Process(byte* out, const byte* in, word32 sz)
+inline void Mode_BASE::ECB_Process(byte* out, const byte* in, word32 sz)
{
- word32 blocks = sz / BLOCK_SIZE;
+ word32 blocks = sz / blockSz_;
while (blocks--) {
ProcessAndXorBlock(in, 0, out);
- out += BLOCK_SIZE;
- in += BLOCK_SIZE;
+ out += blockSz_;
+ in += blockSz_;
}
}
// CBC Encrypt
-template<int BLOCK_SIZE>
-void Mode_BASE<BLOCK_SIZE>::CBC_Encrypt(byte* out, const byte* in, word32 sz)
+inline void Mode_BASE::CBC_Encrypt(byte* out, const byte* in, word32 sz)
{
- word32 blocks = sz / BLOCK_SIZE;
+ word32 blocks = sz / blockSz_;
while (blocks--) {
- xorbuf(reg_, in, BLOCK_SIZE);
+ xorbuf(reg_, in, blockSz_);
ProcessAndXorBlock(reg_, 0, reg_);
- memcpy(out, reg_, BLOCK_SIZE);
- out += BLOCK_SIZE;
- in += BLOCK_SIZE;
+ memcpy(out, reg_, blockSz_);
+ out += blockSz_;
+ in += blockSz_;
}
}
// CBC Decrypt
-template<int BLOCK_SIZE>
-void Mode_BASE<BLOCK_SIZE>::CBC_Decrypt(byte* out, const byte* in, word32 sz)
+inline void Mode_BASE::CBC_Decrypt(byte* out, const byte* in, word32 sz)
{
- word32 blocks = sz / BLOCK_SIZE;
- byte hold[BLOCK_SIZE];
+ word32 blocks = sz / blockSz_;
+ byte hold[MaxBlockSz];
while (blocks--) {
- memcpy(tmp_, in, BLOCK_SIZE);
+ memcpy(tmp_, in, blockSz_);
ProcessAndXorBlock(tmp_, 0, out);
- xorbuf(out, reg_, BLOCK_SIZE);
- memcpy(hold, reg_, BLOCK_SIZE); // swap reg_ and tmp_
- memcpy(reg_, tmp_, BLOCK_SIZE);
- memcpy(tmp_, hold, BLOCK_SIZE);
- out += BLOCK_SIZE;
- in += BLOCK_SIZE;
+ xorbuf(out, reg_, blockSz_);
+ memcpy(hold, reg_, blockSz_); // swap reg_ and tmp_
+ memcpy(reg_, tmp_, blockSz_);
+ memcpy(tmp_, hold, blockSz_);
+ out += blockSz_;
+ in += blockSz_;
}
}
diff --git a/extra/yassl/taocrypt/src/algebra.cpp b/extra/yassl/taocrypt/src/algebra.cpp
index 1924be9b618..d70f8dd5d72 100644
--- a/extra/yassl/taocrypt/src/algebra.cpp
+++ b/extra/yassl/taocrypt/src/algebra.cpp
@@ -23,60 +23,58 @@
#include "runtime.hpp"
#include "algebra.hpp"
-#include "integer.hpp"
#include "vector.hpp" // mySTL::vector (simple)
namespace TaoCrypt {
-template <class T> const T& AbstractGroup<T>::Double(const Element &a) const
+
+const Integer& AbstractGroup::Double(const Element &a) const
{
return Add(a, a);
}
-template <class T> const T& AbstractGroup<T>::Subtract(const Element &a,
- const Element &b) const
+const Integer& AbstractGroup::Subtract(const Element &a, const Element &b) const
{
// make copy of a in case Inverse() overwrites it
Element a1(a);
return Add(a1, Inverse(b));
}
-template <class T> T& AbstractGroup<T>::Accumulate(Element &a,
- const Element &b) const
+Integer& AbstractGroup::Accumulate(Element &a, const Element &b) const
{
return a = Add(a, b);
}
-template <class T> T& AbstractGroup<T>::Reduce(Element &a,
- const Element &b) const
+Integer& AbstractGroup::Reduce(Element &a, const Element &b) const
{
return a = Subtract(a, b);
}
-template <class T> const T& AbstractRing<T>::Square(const Element &a) const
+const Integer& AbstractRing::Square(const Element &a) const
{
return Multiply(a, a);
}
-template <class T> const T& AbstractRing<T>::Divide(const Element &a,
- const Element &b) const
+
+const Integer& AbstractRing::Divide(const Element &a, const Element &b) const
{
// make copy of a in case MultiplicativeInverse() overwrites it
Element a1(a);
return Multiply(a1, MultiplicativeInverse(b));
}
-template <class T> const T& AbstractEuclideanDomain<T>::Mod(const Element &a,
- const Element &b) const
+
+const Integer& AbstractEuclideanDomain::Mod(const Element &a,
+ const Element &b) const
{
Element q;
DivisionAlgorithm(result, q, a, b);
return result;
}
-template <class T> const T& AbstractEuclideanDomain<T>::Gcd(const Element &a,
- const Element &b) const
+const Integer& AbstractEuclideanDomain::Gcd(const Element &a,
+ const Element &b) const
{
Element g[3]={b, a};
unsigned int i0=0, i1=1, i2=2;
@@ -90,45 +88,17 @@ template <class T> const T& AbstractEuclideanDomain<T>::Gcd(const Element &a,
return result = g[i0];
}
-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;
- while (!Equal(g[i1], Identity()))
- {
- // y = g[i0] / g[i1];
- // g[i2] = g[i0] % g[i1];
- m_domain.DivisionAlgorithm(g[i2], y, g[i0], g[i1]);
- // v[i2] = v[i0] - (v[i1] * y);
- v[i2] = m_domain.Subtract(v[i0], m_domain.Multiply(v[i1], y));
- unsigned int t = i0; i0 = i1; i1 = i2; i2 = t;
- }
-
- return m_domain.IsUnit(g[i0]) ? m_domain.Divide(v[i0], g[i0]) :
- m_domain.Identity();
-}
-
-template <class T> T AbstractGroup<T>::ScalarMultiply(const Element &base,
- const Integer &exponent) const
+Integer AbstractGroup::ScalarMultiply(const Element &base,
+ const Integer &exponent) const
{
Element result;
SimultaneousMultiply(&result, base, &exponent, 1);
return result;
}
-template <class T> T AbstractGroup<T>::CascadeScalarMultiply(const Element &x,
+
+Integer AbstractGroup::CascadeScalarMultiply(const Element &x,
const Integer &e1, const Element &y, const Integer &e2) const
{
const unsigned expLen = max(e1.BitCount(), e2.BitCount());
@@ -258,8 +228,8 @@ struct WindowSlider
bool fastNegate, negateNext, firstTime, finished;
};
-template <class T>
-void AbstractGroup<T>::SimultaneousMultiply(T *results, const T &base,
+
+void AbstractGroup::SimultaneousMultiply(Integer *results, const Integer &base,
const Integer *expBegin, unsigned int expCount) const
{
mySTL::vector<mySTL::vector<Element> > buckets(expCount);
@@ -321,34 +291,39 @@ void AbstractGroup<T>::SimultaneousMultiply(T *results, const T &base,
}
}
-template <class T> T AbstractRing<T>::Exponentiate(const Element &base,
- const Integer &exponent) const
+Integer AbstractRing::Exponentiate(const Element &base,
+ const Integer &exponent) const
{
Element result;
SimultaneousExponentiate(&result, base, &exponent, 1);
return result;
}
-template <class T> T AbstractRing<T>::CascadeExponentiate(const Element &x,
+
+Integer AbstractRing::CascadeExponentiate(const Element &x,
const Integer &e1, const Element &y, const Integer &e2) const
{
- return MultiplicativeGroup().AbstractGroup<T>::CascadeScalarMultiply(
+ return MultiplicativeGroup().AbstractGroup::CascadeScalarMultiply(
x, e1, y, e2);
}
-template <class Element, class Iterator> Element GeneralCascadeExponentiation(
- const AbstractRing<Element> &ring, Iterator begin, Iterator end)
-{
- return GeneralCascadeMultiplication<Element>(ring.MultiplicativeGroup(),
- begin, end);
-}
-template <class T>
-void AbstractRing<T>::SimultaneousExponentiate(T *results, const T &base,
+void AbstractRing::SimultaneousExponentiate(Integer *results,
+ const Integer &base,
const Integer *exponents, unsigned int expCount) const
{
- MultiplicativeGroup().AbstractGroup<T>::SimultaneousMultiply(results, base,
+ MultiplicativeGroup().AbstractGroup::SimultaneousMultiply(results, base,
exponents, expCount);
}
+
} // namespace
+
+#ifdef __GNUC__
+namespace mySTL {
+template TaoCrypt::WindowSlider* uninit_copy<TaoCrypt::WindowSlider*, TaoCrypt::WindowSlider*>(TaoCrypt::WindowSlider*, TaoCrypt::WindowSlider*, TaoCrypt::WindowSlider*);
+template vector<TaoCrypt::Integer>* uninit_fill_n<vector<TaoCrypt::Integer>*, unsigned int, vector<TaoCrypt::Integer> >(vector<TaoCrypt::Integer>*, unsigned int, vector<TaoCrypt::Integer> const&);
+template void destroy<TaoCrypt::WindowSlider*>(TaoCrypt::WindowSlider*, TaoCrypt::WindowSlider*);
+template void destroy<vector<TaoCrypt::Integer>*>(vector<TaoCrypt::Integer>*, vector<TaoCrypt::Integer>*);
+}
+#endif
diff --git a/extra/yassl/taocrypt/src/asn.cpp b/extra/yassl/taocrypt/src/asn.cpp
index d0d22a6c61d..59c544bd633 100644
--- a/extra/yassl/taocrypt/src/asn.cpp
+++ b/extra/yassl/taocrypt/src/asn.cpp
@@ -187,7 +187,7 @@ PublicKey::PublicKey(const byte* k, word32 s) : key_(0), sz_(0)
void PublicKey::SetSize(word32 s)
{
sz_ = s;
- key_ = new (tc) byte[sz_];
+ key_ = new byte[sz_];
}
@@ -199,7 +199,7 @@ void PublicKey::SetKey(const byte* k)
void PublicKey::AddToEnd(const byte* data, word32 len)
{
- mySTL::auto_ptr<byte> tmp(new (tc) byte[sz_ + len]);
+ mySTL::auto_ptr<byte> tmp(new byte[sz_ + len]);
memcpy(tmp.get(), key_, sz_);
memcpy(tmp.get() + sz_, data, len);
@@ -218,7 +218,7 @@ Signer::Signer(const byte* k, word32 kSz, const char* n, const byte* h)
{
if (n) {
int sz = strlen(n);
- name_ = new (tc) char[sz + 1];
+ name_ = new char[sz + 1];
memcpy(name_, n, sz);
name_[sz] = 0;
}
@@ -480,7 +480,7 @@ void CertDecoder::Decode(SignerList* signers)
}
else
if (!ValidateSignature(signers))
- source_.SetError(SIG_CONFIRM_E);
+ source_.SetError(SIG_OTHER_E);
}
@@ -632,7 +632,7 @@ word32 CertDecoder::GetSignature()
}
sigLength_--;
- signature_ = new (tc) byte[sigLength_];
+ signature_ = new byte[sigLength_];
memcpy(signature_, source_.get_current(), sigLength_);
source_.advance(sigLength_);
@@ -653,7 +653,7 @@ word32 CertDecoder::GetDigest()
sigLength_ = GetLength(source_);
- signature_ = new (tc) byte[sigLength_];
+ signature_ = new byte[sigLength_];
memcpy(signature_, source_.get_current(), sigLength_);
source_.advance(sigLength_);
@@ -693,7 +693,7 @@ void CertDecoder::GetName(NameType nt)
if (id == COMMON_NAME) {
char*& ptr = (nt == ISSUER) ? issuer_ : subject_;
- ptr = new (tc) char[strLen + 1];
+ ptr = new char[strLen + 1];
memcpy(ptr, source_.get_current(), strLen);
ptr[strLen] = 0;
}
@@ -810,15 +810,15 @@ bool CertDecoder::ConfirmSignature(Source& pub)
mySTL::auto_ptr<HASH> hasher;
if (signatureOID_ == MD5wRSA) {
- hasher.reset(new (tc) MD5);
+ hasher.reset(new MD5);
ht = MD5h;
}
else if (signatureOID_ == MD2wRSA) {
- hasher.reset(new (tc) MD2);
+ hasher.reset(new MD2);
ht = MD2h;
}
else if (signatureOID_ == SHAwRSA || signatureOID_ == SHAwDSA) {
- hasher.reset(new (tc) SHA);
+ hasher.reset(new SHA);
ht = SHAh;
}
else {
diff --git a/extra/yassl/taocrypt/src/dh.cpp b/extra/yassl/taocrypt/src/dh.cpp
index af50d471b52..ea1b5846f7d 100644
--- a/extra/yassl/taocrypt/src/dh.cpp
+++ b/extra/yassl/taocrypt/src/dh.cpp
@@ -26,7 +26,6 @@
#include "runtime.hpp"
#include "dh.hpp"
#include "asn.hpp"
-#include <math.h>
namespace TaoCrypt {
diff --git a/extra/yassl/taocrypt/src/dsa.cpp b/extra/yassl/taocrypt/src/dsa.cpp
index 4716ebb22df..5cb3018a402 100644
--- a/extra/yassl/taocrypt/src/dsa.cpp
+++ b/extra/yassl/taocrypt/src/dsa.cpp
@@ -27,8 +27,6 @@
#include "modarith.hpp"
#include "stdexcept.hpp"
-#include "algebra.cpp" // for GCC 3.2 on aix ?
-
namespace TaoCrypt {
diff --git a/extra/yassl/taocrypt/src/integer.cpp b/extra/yassl/taocrypt/src/integer.cpp
index 9be0a25b363..37cfe374451 100644
--- a/extra/yassl/taocrypt/src/integer.cpp
+++ b/extra/yassl/taocrypt/src/integer.cpp
@@ -38,11 +38,10 @@
#include "asn.hpp"
#include "stdexcept.hpp"
-#include "algebra.cpp"
#ifdef __DECCXX
- #include <c_asm.h> // for asm multiply overflow
+ #include <c_asm.h> // for asm overflow assembly
#endif
@@ -63,7 +62,7 @@
#pragma message("You do not seem to have the Visual C++ Processor Pack ")
#pragma message("installed, so use of SSE2 intrinsics will be disabled.")
#elif defined(__GNUC__) && defined(__i386__)
-/* #warning You do not have GCC 3.3 or later, or did not specify the -msse2 \
+/* #warning You do not have GCC 3.3 or later, or did not specify the -msse2 \
compiler option. Use of SSE2 intrinsics will be disabled.
*/
#endif
@@ -109,7 +108,7 @@ CPP_TYPENAME AllocatorBase<T>::pointer AlignedAllocator<T>::allocate(
assert(IsAlignedOn(p, 16));
return (T*)p;
}
- return new (tc) T[n];
+ return new T[n];
}
@@ -178,7 +177,7 @@ DWord() {}
#elif defined(__DECCXX)
r.halfs_.high = asm("umulh %a0, %a1, %v0", a, b);
#else
- #error unsupported alpha compiler for asm multiply overflow
+ #error can not implement multiply overflow
#endif
#elif defined(__ia64__)
r.halfs_.low = a*b;
@@ -392,6 +391,7 @@ S DivideThreeWordsByTwo(S* A, S B0, S B1, D* dummy_VC6_WorkAround = 0)
return Q;
}
+
// do a 4 word by 2 word divide, returns 2 word quotient in Q0 and Q1
template <class S, class D>
inline D DivideFourWordsByTwo(S *T, const D &Al, const D &Ah, const D &B)
@@ -470,66 +470,6 @@ static inline unsigned int RoundupSize(unsigned int n)
}
-template <class T>
-static Integer StringToInteger(const T *str)
-{
- word radix;
-
- unsigned int length;
- for (length = 0; str[length] != 0; length++) {}
-
- Integer v;
-
- if (length == 0)
- return v;
-
- switch (str[length-1])
- {
- case 'h':
- case 'H':
- radix=16;
- break;
- case 'o':
- case 'O':
- radix=8;
- break;
- case 'b':
- case 'B':
- radix=2;
- break;
- default:
- radix=10;
- }
-
- if (length > 2 && str[0] == '0' && str[1] == 'x')
- radix = 16;
-
- for (unsigned i=0; i<length; i++)
- {
- word digit;
-
- if (str[i] >= '0' && str[i] <= '9')
- digit = str[i] - '0';
- else if (str[i] >= 'A' && str[i] <= 'F')
- digit = str[i] - 'A' + 10;
- else if (str[i] >= 'a' && str[i] <= 'f')
- digit = str[i] - 'a' + 10;
- else
- digit = radix;
-
- if (digit < radix)
- {
- v *= radix;
- v += digit;
- }
- }
-
- if (str[0] == '-')
- v.Negate();
-
- return v;
-}
-
static int Compare(const word *A, const word *B, unsigned int N)
{
while (N--)
@@ -2308,85 +2248,6 @@ void RecursiveMultiplyBottom(word *R, word *T, const word *A, const word *B,
}
}
-/*
-template <class P>
-void RecursiveMultiplyTop(word *R, word *T, const word *L, const word *A,
- const word *B, unsigned int N, const P *dummy=0)
-{
- assert(N>=2 && N%2==0);
-
- if (N==4)
- {
- P::Multiply4(T, A, B);
- ((dword *)R)[0] = ((dword *)T)[2];
- ((dword *)R)[1] = ((dword *)T)[3];
- }
- else if (N==2)
- {
- P::Multiply2(T, A, B);
- ((dword *)R)[0] = ((dword *)T)[1];
- }
- else
- {
- const unsigned int N2 = N/2;
- int carry;
-
- int aComp = Compare(A0, A1, N2);
- int bComp = Compare(B0, B1, N2);
-
- switch (2*aComp + aComp + bComp)
- {
- case -4:
- P::Subtract(R0, A1, A0, N2);
- P::Subtract(R1, B0, B1, N2);
- RecursiveMultiply<P>(T0, T2, R0, R1, N2);
- P::Subtract(T1, T1, R0, N2);
- carry = -1;
- break;
- case -2:
- P::Subtract(R0, A1, A0, N2);
- P::Subtract(R1, B0, B1, N2);
- RecursiveMultiply<P>(T0, T2, R0, R1, N2);
- carry = 0;
- break;
- case 2:
- P::Subtract(R0, A0, A1, N2);
- P::Subtract(R1, B1, B0, N2);
- RecursiveMultiply<P>(T0, T2, R0, R1, N2);
- carry = 0;
- break;
- case 4:
- P::Subtract(R0, A1, A0, N2);
- P::Subtract(R1, B0, B1, N2);
- RecursiveMultiply<P>(T0, T2, R0, R1, N2);
- P::Subtract(T1, T1, R1, N2);
- carry = -1;
- break;
- default:
- SetWords(T0, 0, N);
- carry = 0;
- }
-
- RecursiveMultiply<P>(T2, R0, A1, B1, N2);
-
- // now T[01] holds (A1-A0)*(B0-B1), T[23] holds A1*B1
-
- word c2 = P::Subtract(R0, L+N2, L, N2);
- c2 += P::Subtract(R0, R0, T0, N2);
- word t = (Compare(R0, T2, N2) == -1);
-
- carry += t;
- carry += Increment(R0, N2, c2+t);
- carry += P::Add(R0, R0, T1, N2);
- carry += P::Add(R0, R0, T3, N2);
- assert (carry >= 0 && carry <= 2);
-
- CopyWords(R1, T3, N2);
- Increment(R1, N2, carry);
- }
-}
-*/
-
void RecursiveMultiplyTop(word *R, word *T, const word *L, const word *A,
const word *B, unsigned int N)
@@ -2739,20 +2600,6 @@ Integer::Integer(word value, unsigned int length)
}
-Integer::Integer(const char *str)
- : reg_(2), sign_(POSITIVE)
-{
- *this = StringToInteger(str);
-}
-
-
-Integer::Integer(const wchar_t *str)
- : reg_(2), sign_(POSITIVE)
-{
- *this = StringToInteger(str);
-}
-
-
Integer::Integer(const byte *encodedInteger, unsigned int byteCount,
Signedness s)
{
@@ -3358,76 +3205,6 @@ Integer Integer::Times(const Integer &b) const
#undef R2
#undef R3
-/*
-// do a 3 word by 2 word divide, returns quotient and leaves remainder in A
-static word SubatomicDivide(word *A, word B0, word B1)
-{
- // assert {A[2],A[1]} < {B1,B0}, so quotient can fit in a word
- assert(A[2] < B1 || (A[2]==B1 && A[1] < B0));
-
- dword p, u;
- word Q;
-
- // estimate the quotient: do a 2 word by 1 word divide
- if (B1+1 == 0)
- Q = A[2];
- else
- Q = word(MAKE_DWORD(A[1], A[2]) / (B1+1));
-
- // now subtract Q*B from A
- p = (dword) B0*Q;
- u = (dword) A[0] - LOW_WORD(p);
- A[0] = LOW_WORD(u);
- u = (dword) A[1] - HIGH_WORD(p) - (word)(0-HIGH_WORD(u)) - (dword)B1*Q;
- A[1] = LOW_WORD(u);
- A[2] += HIGH_WORD(u);
-
- // Q <= actual quotient, so fix it
- while (A[2] || A[1] > B1 || (A[1]==B1 && A[0]>=B0))
- {
- u = (dword) A[0] - B0;
- A[0] = LOW_WORD(u);
- u = (dword) A[1] - B1 - (word)(0-HIGH_WORD(u));
- A[1] = LOW_WORD(u);
- A[2] += HIGH_WORD(u);
- Q++;
- assert(Q); // shouldn't overflow
- }
-
- return Q;
-}
-*/
-
-
-/*
-// do a 4 word by 2 word divide, returns 2 word quotient in Q0 and Q1
-static inline void AtomicDivide(word *Q, const word *A, const word *B)
-{
- if (!B[0] && !B[1]) // if divisor is 0, we assume divisor==2**(2*WORD_BITS)
- {
- Q[0] = A[2];
- Q[1] = A[3];
- }
- else
- {
- word T[4];
- T[0] = A[0]; T[1] = A[1]; T[2] = A[2]; T[3] = A[3];
- Q[1] = SubatomicDivide(T+1, B[0], B[1]);
- Q[0] = SubatomicDivide(T, B[0], B[1]);
-
-#ifndef NDEBUG
- // multiply quotient and divisor and add remainder
- // make sure it equals dividend
- assert(!T[2] && !T[3] && (T[1] < B[1] || (T[1]==B[1] && T[0]<B[0])));
- word P[4];
- LowLevel::Multiply2(P, Q, B);
- Add(P, P, T, 4);
- assert(memcmp(P, A, 4*WORD_SIZE)==0);
-#endif
- }
-}
-*/
-
static inline void AtomicDivide(word *Q, const word *A, const word *B)
{
@@ -3772,7 +3549,7 @@ Integer a_exp_b_mod_c(const Integer &x, const Integer& e, const Integer& m)
Integer Integer::Gcd(const Integer &a, const Integer &b)
{
- return EuclideanDomainOf<Integer>().Gcd(a, b);
+ return EuclideanDomainOf().Gcd(a, b);
}
Integer Integer::InverseMod(const Integer &m) const
@@ -3955,7 +3732,7 @@ Integer ModularArithmetic::CascadeExponentiate(const Integer &x,
dr.ConvertIn(y), e2));
}
else
- return AbstractRing<Integer>::CascadeExponentiate(x, e1, y, e2);
+ return AbstractRing::CascadeExponentiate(x, e1, y, e2);
}
void ModularArithmetic::SimultaneousExponentiate(Integer *results,
@@ -3971,7 +3748,7 @@ void ModularArithmetic::SimultaneousExponentiate(Integer *results,
results[i] = dr.ConvertOut(results[i]);
}
else
- AbstractRing<Integer>::SimultaneousExponentiate(results, base,
+ AbstractRing::SimultaneousExponentiate(results, base,
exponents, exponentsCount);
}
@@ -4170,10 +3947,6 @@ Integer CRT(const Integer &xp, const Integer &p, const Integer &xq,
}
#ifdef __GNUC__
-template Integer StringToInteger<char>(char const*);
-template Integer StringToInteger<wchar_t>(wchar_t const*);
-template class EuclideanDomainOf<Integer>;
-template class AbstractEuclideanDomain<Integer>;
template unsigned int DivideThreeWordsByTwo<unsigned int, DWord>(unsigned int*, unsigned int, unsigned int, DWord*);
#endif
diff --git a/extra/yassl/taocrypt/src/misc.cpp b/extra/yassl/taocrypt/src/misc.cpp
index e4573abac3f..37d1bd1b14d 100644
--- a/extra/yassl/taocrypt/src/misc.cpp
+++ b/extra/yassl/taocrypt/src/misc.cpp
@@ -27,36 +27,9 @@
#include <new> // for NewHandler
-void* operator new(size_t sz, TaoCrypt::new_t)
-{
- void* ptr = ::operator new(sz);
-
- if (!ptr) abort();
-
- return ptr;
-}
-
-void* operator new[](size_t sz, TaoCrypt::new_t tc)
-{
-#if defined(_MSC_VER) && (_MSC_VER < 1300)
- void* ptr = ::operator new(sz); // no ::operator new[]
-#else
- void* ptr = ::operator new[](sz);
-#endif
-
- if (!ptr) abort();
-
- return ptr;
-}
-
-
-
namespace TaoCrypt {
-new_t tc; // for library new
-
-
inline void XorWords(word* r, const word* a, unsigned int n)
{
for (unsigned int i=0; i<n; i++)
diff --git a/extra/yassl/taocrypt/src/random.cpp b/extra/yassl/taocrypt/src/random.cpp
index 5c9e3b0f02a..75dd03e8aa5 100644
--- a/extra/yassl/taocrypt/src/random.cpp
+++ b/extra/yassl/taocrypt/src/random.cpp
@@ -26,7 +26,6 @@
#include "runtime.hpp"
#include "random.hpp"
-#include "stdexcept.hpp"
#if defined(WIN32)
#define _WIN32_WINNT 0x0400
diff --git a/extra/yassl/taocrypt/src/rsa.cpp b/extra/yassl/taocrypt/src/rsa.cpp
index ecb2288f1c2..7051a83c563 100644
--- a/extra/yassl/taocrypt/src/rsa.cpp
+++ b/extra/yassl/taocrypt/src/rsa.cpp
@@ -27,7 +27,6 @@
#include "modarith.hpp"
#include "stdexcept.hpp"
-#include "algebra.cpp" // for GCC 3.2 on aix ?
namespace TaoCrypt {
@@ -214,8 +213,6 @@ word32 SSL_Decrypt(const RSA_PublicKey& key, const byte* sig, byte* plain)
#ifdef __GNUC__
template AllocatorWithCleanup<unsigned char>::pointer StdReallocate<unsigned char, AllocatorWithCleanup<unsigned char> >(AllocatorWithCleanup<unsigned char>&, unsigned char*, AllocatorWithCleanup<unsigned char>::size_type, AllocatorWithCleanup<unsigned char>::size_type, bool);
template AllocatorWithCleanup<unsigned int>::pointer StdReallocate<unsigned int, AllocatorWithCleanup<unsigned int> >(AllocatorWithCleanup<unsigned int>&, unsigned int*, AllocatorWithCleanup<unsigned int>::size_type, AllocatorWithCleanup<unsigned int>::size_type, bool);
-template class AbstractGroup<Integer>;
-template class AbstractRing<Integer>;
template class RSA_Decryptor<RSA_BlockType2>;
template class RSA_Encryptor<RSA_BlockType1>;
template class RSA_Encryptor<RSA_BlockType2>;
@@ -227,11 +224,7 @@ template class RSA_Encryptor<RSA_BlockType2>;
namespace mySTL {
template TaoCrypt::Integer* uninit_copy<TaoCrypt::Integer*, TaoCrypt::Integer*>(TaoCrypt::Integer*, TaoCrypt::Integer*, TaoCrypt::Integer*);
template TaoCrypt::Integer* uninit_fill_n<TaoCrypt::Integer*, unsigned int, TaoCrypt::Integer>(TaoCrypt::Integer*, unsigned int, TaoCrypt::Integer const&);
-template TaoCrypt::WindowSlider* uninit_copy<TaoCrypt::WindowSlider*, TaoCrypt::WindowSlider*>(TaoCrypt::WindowSlider*, TaoCrypt::WindowSlider*, TaoCrypt::WindowSlider*);
-template vector<TaoCrypt::Integer>* uninit_fill_n<vector<TaoCrypt::Integer>*, unsigned int, vector<TaoCrypt::Integer> >(vector<TaoCrypt::Integer>*, unsigned int, vector<TaoCrypt::Integer> const&);
template void destroy<TaoCrypt::Integer*>(TaoCrypt::Integer*, TaoCrypt::Integer*);
-template void destroy<TaoCrypt::WindowSlider*>(TaoCrypt::WindowSlider*, TaoCrypt::WindowSlider*);
-template void destroy<vector<TaoCrypt::Integer>*>(vector<TaoCrypt::Integer>*, vector<TaoCrypt::Integer>*);
}
#endif