Commit 1dabee5a authored by svoj@mysql.com's avatar svoj@mysql.com

Upgrade yaSSL to 0.9.9.

parent a49ccfe6
...@@ -67,7 +67,7 @@ public: ...@@ -67,7 +67,7 @@ public:
init(*this); init(*this);
} }
// reservce place in vector before registering, used by init funcion // reserve place in vector before registering, used by init funcion
void Reserve(size_t sz) void Reserve(size_t sz)
{ {
callbacks_.reserve(sz); callbacks_.reserve(sz);
......
...@@ -31,8 +31,8 @@ ...@@ -31,8 +31,8 @@
#include "yassl_imp.hpp" #include "yassl_imp.hpp"
#include "crypto_wrapper.hpp" #include "crypto_wrapper.hpp"
#include "cert_wrapper.hpp" #include "cert_wrapper.hpp"
#include "lock.hpp"
#include "log.hpp" #include "log.hpp"
#include "lock.hpp"
namespace yaSSL { namespace yaSSL {
......
...@@ -29,16 +29,6 @@ ...@@ -29,16 +29,6 @@
#include <stddef.h> #include <stddef.h>
namespace yaSSL {
// library allocation
struct new_t {}; // yaSSL New type
extern new_t ys; // pass in parameter
} // namespace yaSSL
void* operator new (size_t, yaSSL::new_t);
void* operator new[](size_t, yaSSL::new_t);
namespace yaSSL { namespace yaSSL {
......
...@@ -62,13 +62,13 @@ input_buffer::input_buffer() ...@@ -62,13 +62,13 @@ input_buffer::input_buffer()
input_buffer::input_buffer(uint s) input_buffer::input_buffer(uint s)
: size_(0), current_(0), buffer_(new (ys) byte[s]), end_(buffer_ + s) : size_(0), current_(0), buffer_(new byte[s]), end_(buffer_ + s)
{} {}
// with assign // with assign
input_buffer::input_buffer(uint s, const byte* t, uint len) input_buffer::input_buffer(uint s, const byte* t, uint len)
: size_(0), current_(0), buffer_(new (ys) byte[s]), end_(buffer_ + s) : size_(0), current_(0), buffer_(new byte[s]), end_(buffer_ + s)
{ {
assign(t, len); assign(t, len);
} }
...@@ -84,7 +84,7 @@ input_buffer::~input_buffer() ...@@ -84,7 +84,7 @@ input_buffer::~input_buffer()
void input_buffer::allocate(uint s) void input_buffer::allocate(uint s)
{ {
assert(!buffer_); // find realloc error assert(!buffer_); // find realloc error
buffer_ = new (ys) byte[s]; buffer_ = new byte[s];
end_ = buffer_ + s; end_ = buffer_ + s;
} }
...@@ -198,13 +198,13 @@ output_buffer::output_buffer() ...@@ -198,13 +198,13 @@ output_buffer::output_buffer()
// with allocate // with allocate
output_buffer::output_buffer(uint s) output_buffer::output_buffer(uint s)
: current_(0), buffer_(new (ys) byte[s]), end_(buffer_ + s) : current_(0), buffer_(new byte[s]), end_(buffer_ + s)
{} {}
// with assign // with assign
output_buffer::output_buffer(uint s, const byte* t, uint len) output_buffer::output_buffer(uint s, const byte* t, uint len)
: current_(0), buffer_(new (ys) byte[s]), end_(buffer_+ s) : current_(0), buffer_(new byte[s]), end_(buffer_+ s)
{ {
write(t, len); write(t, len);
} }
...@@ -239,7 +239,7 @@ void output_buffer::set_current(uint c) ...@@ -239,7 +239,7 @@ void output_buffer::set_current(uint c)
void output_buffer::allocate(uint s) void output_buffer::allocate(uint s)
{ {
assert(!buffer_); // find realloc error assert(!buffer_); // find realloc error
buffer_ = new (ys) byte[s]; end_ = buffer_ + s; buffer_ = new byte[s]; end_ = buffer_ + s;
} }
......
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
namespace yaSSL { namespace yaSSL {
x509::x509(uint sz) : length_(sz), buffer_(new (ys) opaque[sz]) x509::x509(uint sz) : length_(sz), buffer_(new opaque[sz])
{ {
} }
...@@ -51,7 +51,7 @@ x509::~x509() ...@@ -51,7 +51,7 @@ x509::~x509()
x509::x509(const x509& that) : length_(that.length_), x509::x509(const x509& that) : length_(that.length_),
buffer_(new (ys) opaque[length_]) buffer_(new opaque[length_])
{ {
memcpy(buffer_, that.buffer_, length_); memcpy(buffer_, that.buffer_, length_);
} }
...@@ -153,7 +153,7 @@ void CertManager::AddPeerCert(x509* x) ...@@ -153,7 +153,7 @@ void CertManager::AddPeerCert(x509* x)
void CertManager::CopySelfCert(const x509* x) void CertManager::CopySelfCert(const x509* x)
{ {
if (x) if (x)
list_.push_back(new (ys) x509(*x)); list_.push_back(new x509(*x));
} }
...@@ -165,7 +165,7 @@ int CertManager::CopyCaCert(const x509* x) ...@@ -165,7 +165,7 @@ int CertManager::CopyCaCert(const x509* x)
if (!cert.GetError().What()) { if (!cert.GetError().What()) {
const TaoCrypt::PublicKey& key = cert.GetPublicKey(); const TaoCrypt::PublicKey& key = cert.GetPublicKey();
signers_.push_back(new (ys) TaoCrypt::Signer(key.GetKey(), key.size(), signers_.push_back(new TaoCrypt::Signer(key.GetKey(), key.size(),
cert.GetCommonName(), cert.GetHash())); cert.GetCommonName(), cert.GetHash()));
} }
return cert.GetError().What(); return cert.GetError().What();
...@@ -234,7 +234,7 @@ int CertManager::Validate() ...@@ -234,7 +234,7 @@ int CertManager::Validate()
return err; return err;
const TaoCrypt::PublicKey& key = cert.GetPublicKey(); const TaoCrypt::PublicKey& key = cert.GetPublicKey();
signers_.push_back(new (ys) TaoCrypt::Signer(key.GetKey(), key.size(), signers_.push_back(new TaoCrypt::Signer(key.GetKey(), key.size(),
cert.GetCommonName(), cert.GetHash())); cert.GetCommonName(), cert.GetHash()));
--last; --last;
--count; --count;
...@@ -259,7 +259,7 @@ int CertManager::Validate() ...@@ -259,7 +259,7 @@ int CertManager::Validate()
int iSz = cert.GetIssuer() ? strlen(cert.GetIssuer()) + 1 : 0; int iSz = cert.GetIssuer() ? strlen(cert.GetIssuer()) + 1 : 0;
int sSz = cert.GetCommonName() ? strlen(cert.GetCommonName()) + 1 : 0; int sSz = cert.GetCommonName() ? strlen(cert.GetCommonName()) + 1 : 0;
peerX509_ = new (ys) X509(cert.GetIssuer(), iSz, cert.GetCommonName(), peerX509_ = new X509(cert.GetIssuer(), iSz, cert.GetCommonName(),
sSz); sSz);
} }
return 0; return 0;
...@@ -273,13 +273,13 @@ int CertManager::SetPrivateKey(const x509& key) ...@@ -273,13 +273,13 @@ int CertManager::SetPrivateKey(const x509& key)
privateKey_.assign(key.get_buffer(), key.get_length()); privateKey_.assign(key.get_buffer(), key.get_length());
// set key type // set key type
if (x509* cert509 = list_.front()) { if (x509* cert = list_.front()) {
TaoCrypt::Source source(cert509->get_buffer(), cert509->get_length()); TaoCrypt::Source source(cert->get_buffer(), cert->get_length());
TaoCrypt::CertDecoder cert(source, false); TaoCrypt::CertDecoder cd(source, false);
cert.DecodeToKey(); cd.DecodeToKey();
if (int err = cert.GetError().What()) if (int err = cd.GetError().What())
return err; return err;
if (cert.GetKeyType() == TaoCrypt::RSAk) if (cd.GetKeyType() == TaoCrypt::RSAk)
keyType_ = rsa_sa_algo; keyType_ = rsa_sa_algo;
else else
keyType_ = dsa_sa_algo; keyType_ = dsa_sa_algo;
......
...@@ -58,13 +58,13 @@ struct MD5::MD5Impl { ...@@ -58,13 +58,13 @@ struct MD5::MD5Impl {
}; };
MD5::MD5() : pimpl_(new (ys) MD5Impl) {} MD5::MD5() : pimpl_(new MD5Impl) {}
MD5::~MD5() { delete pimpl_; } MD5::~MD5() { delete pimpl_; }
MD5::MD5(const MD5& that) : Digest(), pimpl_(new (ys) MD5::MD5(const MD5& that) : Digest(), pimpl_(new
MD5Impl(that.pimpl_->md5_)) {} MD5Impl(that.pimpl_->md5_)) {}
...@@ -116,14 +116,13 @@ struct SHA::SHAImpl { ...@@ -116,14 +116,13 @@ struct SHA::SHAImpl {
}; };
SHA::SHA() : pimpl_(new (ys) SHAImpl) {} SHA::SHA() : pimpl_(new SHAImpl) {}
SHA::~SHA() { delete pimpl_; } SHA::~SHA() { delete pimpl_; }
SHA::SHA(const SHA& that) : Digest(), pimpl_(new (ys) SHA::SHA(const SHA& that) : Digest(), pimpl_(new SHAImpl(that.pimpl_->sha_)) {}
SHAImpl(that.pimpl_->sha_)) {}
SHA& SHA::operator=(const SHA& that) SHA& SHA::operator=(const SHA& that)
{ {
...@@ -174,14 +173,13 @@ struct RMD::RMDImpl { ...@@ -174,14 +173,13 @@ struct RMD::RMDImpl {
}; };
RMD::RMD() : pimpl_(new (ys) RMDImpl) {} RMD::RMD() : pimpl_(new RMDImpl) {}
RMD::~RMD() { delete pimpl_; } RMD::~RMD() { delete pimpl_; }
RMD::RMD(const RMD& that) : Digest(), pimpl_(new (ys) RMD::RMD(const RMD& that) : Digest(), pimpl_(new RMDImpl(that.pimpl_->rmd_)) {}
RMDImpl(that.pimpl_->rmd_)) {}
RMD& RMD::operator=(const RMD& that) RMD& RMD::operator=(const RMD& that)
{ {
...@@ -232,7 +230,7 @@ struct HMAC_MD5::HMAC_MD5Impl { ...@@ -232,7 +230,7 @@ struct HMAC_MD5::HMAC_MD5Impl {
HMAC_MD5::HMAC_MD5(const byte* secret, unsigned int len) HMAC_MD5::HMAC_MD5(const byte* secret, unsigned int len)
: pimpl_(new (ys) HMAC_MD5Impl) : pimpl_(new HMAC_MD5Impl)
{ {
pimpl_->mac_.SetKey(secret, len); pimpl_->mac_.SetKey(secret, len);
} }
...@@ -282,7 +280,7 @@ struct HMAC_SHA::HMAC_SHAImpl { ...@@ -282,7 +280,7 @@ struct HMAC_SHA::HMAC_SHAImpl {
HMAC_SHA::HMAC_SHA(const byte* secret, unsigned int len) HMAC_SHA::HMAC_SHA(const byte* secret, unsigned int len)
: pimpl_(new (ys) HMAC_SHAImpl) : pimpl_(new HMAC_SHAImpl)
{ {
pimpl_->mac_.SetKey(secret, len); pimpl_->mac_.SetKey(secret, len);
} }
...@@ -333,7 +331,7 @@ struct HMAC_RMD::HMAC_RMDImpl { ...@@ -333,7 +331,7 @@ struct HMAC_RMD::HMAC_RMDImpl {
HMAC_RMD::HMAC_RMD(const byte* secret, unsigned int len) HMAC_RMD::HMAC_RMD(const byte* secret, unsigned int len)
: pimpl_(new (ys) HMAC_RMDImpl) : pimpl_(new HMAC_RMDImpl)
{ {
pimpl_->mac_.SetKey(secret, len); pimpl_->mac_.SetKey(secret, len);
} }
...@@ -381,7 +379,7 @@ struct DES::DESImpl { ...@@ -381,7 +379,7 @@ struct DES::DESImpl {
}; };
DES::DES() : pimpl_(new (ys) DESImpl) {} DES::DES() : pimpl_(new DESImpl) {}
DES::~DES() { delete pimpl_; } DES::~DES() { delete pimpl_; }
...@@ -417,7 +415,7 @@ struct DES_EDE::DES_EDEImpl { ...@@ -417,7 +415,7 @@ struct DES_EDE::DES_EDEImpl {
}; };
DES_EDE::DES_EDE() : pimpl_(new (ys) DES_EDEImpl) {} DES_EDE::DES_EDE() : pimpl_(new DES_EDEImpl) {}
DES_EDE::~DES_EDE() { delete pimpl_; } DES_EDE::~DES_EDE() { delete pimpl_; }
...@@ -455,7 +453,7 @@ struct RC4::RC4Impl { ...@@ -455,7 +453,7 @@ struct RC4::RC4Impl {
}; };
RC4::RC4() : pimpl_(new (ys) RC4Impl) {} RC4::RC4() : pimpl_(new RC4Impl) {}
RC4::~RC4() { delete pimpl_; } RC4::~RC4() { delete pimpl_; }
...@@ -497,7 +495,7 @@ struct AES::AESImpl { ...@@ -497,7 +495,7 @@ struct AES::AESImpl {
}; };
AES::AES(unsigned int ks) : pimpl_(new (ys) AESImpl(ks)) {} AES::AES(unsigned int ks) : pimpl_(new AESImpl(ks)) {}
AES::~AES() { delete pimpl_; } AES::~AES() { delete pimpl_; }
...@@ -538,7 +536,7 @@ struct RandomPool::RandomImpl { ...@@ -538,7 +536,7 @@ struct RandomPool::RandomImpl {
TaoCrypt::RandomNumberGenerator RNG_; TaoCrypt::RandomNumberGenerator RNG_;
}; };
RandomPool::RandomPool() : pimpl_(new (ys) RandomImpl) {} RandomPool::RandomPool() : pimpl_(new RandomImpl) {}
RandomPool::~RandomPool() { delete pimpl_; } RandomPool::~RandomPool() { delete pimpl_; }
...@@ -582,7 +580,7 @@ void DSS::DSSImpl::SetPrivate(const byte* key, unsigned int sz) ...@@ -582,7 +580,7 @@ void DSS::DSSImpl::SetPrivate(const byte* key, unsigned int sz)
// Set public or private key // Set public or private key
DSS::DSS(const byte* key, unsigned int sz, bool publicKey) DSS::DSS(const byte* key, unsigned int sz, bool publicKey)
: pimpl_(new (ys) DSSImpl) : pimpl_(new DSSImpl)
{ {
if (publicKey) if (publicKey)
pimpl_->SetPublic(key, sz); pimpl_->SetPublic(key, sz);
...@@ -653,7 +651,7 @@ void RSA::RSAImpl::SetPrivate(const byte* key, unsigned int sz) ...@@ -653,7 +651,7 @@ void RSA::RSAImpl::SetPrivate(const byte* key, unsigned int sz)
// Set public or private key // Set public or private key
RSA::RSA(const byte* key, unsigned int sz, bool publicKey) RSA::RSA(const byte* key, unsigned int sz, bool publicKey)
: pimpl_(new (ys) RSAImpl) : pimpl_(new RSAImpl)
{ {
if (publicKey) if (publicKey)
pimpl_->SetPublic(key, sz); pimpl_->SetPublic(key, sz);
...@@ -725,13 +723,13 @@ struct Integer::IntegerImpl { ...@@ -725,13 +723,13 @@ struct Integer::IntegerImpl {
explicit IntegerImpl(const TaoCrypt::Integer& i) : int_(i) {} explicit IntegerImpl(const TaoCrypt::Integer& i) : int_(i) {}
}; };
Integer::Integer() : pimpl_(new (ys) IntegerImpl) {} Integer::Integer() : pimpl_(new IntegerImpl) {}
Integer::~Integer() { delete pimpl_; } Integer::~Integer() { delete pimpl_; }
Integer::Integer(const Integer& other) : pimpl_(new (ys) Integer::Integer(const Integer& other) : pimpl_(new
IntegerImpl(other.pimpl_->int_)) IntegerImpl(other.pimpl_->int_))
{} {}
...@@ -770,9 +768,9 @@ struct DiffieHellman::DHImpl { ...@@ -770,9 +768,9 @@ struct DiffieHellman::DHImpl {
void AllocKeys(unsigned int pubSz, unsigned int privSz, unsigned int agrSz) void AllocKeys(unsigned int pubSz, unsigned int privSz, unsigned int agrSz)
{ {
publicKey_ = new (ys) byte[pubSz]; publicKey_ = new byte[pubSz];
privateKey_ = new (ys) byte[privSz]; privateKey_ = new byte[privSz];
agreedKey_ = new (ys) byte[agrSz]; agreedKey_ = new byte[agrSz];
} }
}; };
...@@ -781,7 +779,7 @@ struct DiffieHellman::DHImpl { ...@@ -781,7 +779,7 @@ struct DiffieHellman::DHImpl {
/* /*
// server Side DH, server's view // server Side DH, server's view
DiffieHellman::DiffieHellman(const char* file, const RandomPool& random) DiffieHellman::DiffieHellman(const char* file, const RandomPool& random)
: pimpl_(new (ys) DHImpl(random.pimpl_->RNG_)) : pimpl_(new DHImpl(random.pimpl_->RNG_))
{ {
using namespace TaoCrypt; using namespace TaoCrypt;
Source source; Source source;
...@@ -805,12 +803,12 @@ DiffieHellman::DiffieHellman(const char* file, const RandomPool& random) ...@@ -805,12 +803,12 @@ DiffieHellman::DiffieHellman(const char* file, const RandomPool& random)
DiffieHellman::DiffieHellman(const byte* p, unsigned int pSz, const byte* g, DiffieHellman::DiffieHellman(const byte* p, unsigned int pSz, const byte* g,
unsigned int gSz, const byte* pub, unsigned int gSz, const byte* pub,
unsigned int pubSz, const RandomPool& random) unsigned int pubSz, const RandomPool& random)
: pimpl_(new (ys) DHImpl(random.pimpl_->RNG_)) : pimpl_(new DHImpl(random.pimpl_->RNG_))
{ {
using TaoCrypt::Integer; using TaoCrypt::Integer;
pimpl_->dh_.Initialize(Integer(p, pSz).Ref(), Integer(g, gSz).Ref()); pimpl_->dh_.Initialize(Integer(p, pSz).Ref(), Integer(g, gSz).Ref());
pimpl_->publicKey_ = new (ys) opaque[pubSz]; pimpl_->publicKey_ = new opaque[pubSz];
memcpy(pimpl_->publicKey_, pub, pubSz); memcpy(pimpl_->publicKey_, pub, pubSz);
} }
...@@ -818,7 +816,7 @@ DiffieHellman::DiffieHellman(const byte* p, unsigned int pSz, const byte* g, ...@@ -818,7 +816,7 @@ DiffieHellman::DiffieHellman(const byte* p, unsigned int pSz, const byte* g,
// Server Side DH, server's view // Server Side DH, server's view
DiffieHellman::DiffieHellman(const Integer& p, const Integer& g, DiffieHellman::DiffieHellman(const Integer& p, const Integer& g,
const RandomPool& random) const RandomPool& random)
: pimpl_(new (ys) DHImpl(random.pimpl_->RNG_)) : pimpl_(new DHImpl(random.pimpl_->RNG_))
{ {
using TaoCrypt::Integer; using TaoCrypt::Integer;
...@@ -836,7 +834,7 @@ DiffieHellman::~DiffieHellman() { delete pimpl_; } ...@@ -836,7 +834,7 @@ DiffieHellman::~DiffieHellman() { delete pimpl_; }
// Client side and view, use server that for p and g // Client side and view, use server that for p and g
DiffieHellman::DiffieHellman(const DiffieHellman& that) DiffieHellman::DiffieHellman(const DiffieHellman& that)
: pimpl_(new (ys) DHImpl(*that.pimpl_)) : pimpl_(new DHImpl(*that.pimpl_))
{ {
pimpl_->dh_.GenerateKeyPair(pimpl_->ranPool_, pimpl_->privateKey_, pimpl_->dh_.GenerateKeyPair(pimpl_->ranPool_, pimpl_->privateKey_,
pimpl_->publicKey_); pimpl_->publicKey_);
...@@ -957,7 +955,7 @@ x509* PemToDer(const char* fname, CertType type) ...@@ -957,7 +955,7 @@ x509* PemToDer(const char* fname, CertType type)
Base64Decoder b64Dec(der); Base64Decoder b64Dec(der);
uint sz = der.size(); uint sz = der.size();
mySTL::auto_ptr<x509> x(new (ys) x509(sz)); mySTL::auto_ptr<x509> x(new x509(sz));
memcpy(x->use_buffer(), der.get_buffer(), sz); memcpy(x->use_buffer(), der.get_buffer(), sz);
fclose(file); fclose(file);
...@@ -971,8 +969,6 @@ x509* PemToDer(const char* fname, CertType type) ...@@ -971,8 +969,6 @@ x509* PemToDer(const char* fname, CertType type)
template class TaoCrypt::HMAC<TaoCrypt::MD5>; template class TaoCrypt::HMAC<TaoCrypt::MD5>;
template class TaoCrypt::HMAC<TaoCrypt::SHA>; template class TaoCrypt::HMAC<TaoCrypt::SHA>;
template class TaoCrypt::HMAC<TaoCrypt::RIPEMD160>; template class TaoCrypt::HMAC<TaoCrypt::RIPEMD160>;
template class TaoCrypt::Mode_BASE<16>;
template class TaoCrypt::Mode_BASE<8>;
#endif #endif
#endif // !USE_CRYPTOPP_LIB #endif // !USE_CRYPTOPP_LIB
...@@ -362,9 +362,9 @@ void p_hash(output_buffer& result, const output_buffer& secret, ...@@ -362,9 +362,9 @@ void p_hash(output_buffer& result, const output_buffer& secret,
if (lastLen) times += 1; if (lastLen) times += 1;
if (hash == md5) if (hash == md5)
hmac.reset(new (ys) HMAC_MD5(secret.get_buffer(), secret.get_size())); hmac.reset(new HMAC_MD5(secret.get_buffer(), secret.get_size()));
else else
hmac.reset(new (ys) HMAC_SHA(secret.get_buffer(), secret.get_size())); hmac.reset(new HMAC_SHA(secret.get_buffer(), secret.get_size()));
// A0 = seed // A0 = seed
hmac->get_digest(previous, seed.get_buffer(), seed.get_size());// A1 hmac->get_digest(previous, seed.get_buffer(), seed.get_size());// A1
uint lastTime = times - 1; uint lastTime = times - 1;
...@@ -582,11 +582,11 @@ void TLS_hmac(SSL& ssl, byte* digest, const byte* buffer, uint sz, ...@@ -582,11 +582,11 @@ void TLS_hmac(SSL& ssl, byte* digest, const byte* buffer, uint sz,
MACAlgorithm algo = ssl.getSecurity().get_parms().mac_algorithm_; MACAlgorithm algo = ssl.getSecurity().get_parms().mac_algorithm_;
if (algo == sha) if (algo == sha)
hmac.reset(new (ys) HMAC_SHA(ssl.get_macSecret(verify), SHA_LEN)); hmac.reset(new HMAC_SHA(ssl.get_macSecret(verify), SHA_LEN));
else if (algo == rmd) else if (algo == rmd)
hmac.reset(new (ys) HMAC_RMD(ssl.get_macSecret(verify), RMD_LEN)); hmac.reset(new HMAC_RMD(ssl.get_macSecret(verify), RMD_LEN));
else else
hmac.reset(new (ys) HMAC_MD5(ssl.get_macSecret(verify), MD5_LEN)); hmac.reset(new HMAC_MD5(ssl.get_macSecret(verify), MD5_LEN));
hmac->update(seq, SEQ_SZ); // seq_num hmac->update(seq, SEQ_SZ); // seq_num
inner[0] = content; // type inner[0] = content; // type
...@@ -687,7 +687,7 @@ DoProcessReply(SSL& ssl, mySTL::auto_ptr<input_buffer> buffered) ...@@ -687,7 +687,7 @@ DoProcessReply(SSL& ssl, mySTL::auto_ptr<input_buffer> buffered)
// make sure we have enough input in buffer to process this record // make sure we have enough input in buffer to process this record
if (hdr.length_ > buffer.get_remaining()) { if (hdr.length_ > buffer.get_remaining()) {
uint sz = buffer.get_remaining() + RECORD_HEADER; uint sz = buffer.get_remaining() + RECORD_HEADER;
buffered.reset(new (ys) input_buffer(sz, buffer.get_buffer() + buffered.reset(new input_buffer(sz, buffer.get_buffer() +
buffer.get_current() - RECORD_HEADER, sz)); buffer.get_current() - RECORD_HEADER, sz));
break; break;
} }
...@@ -760,7 +760,7 @@ void sendClientKeyExchange(SSL& ssl, BufferOutput buffer) ...@@ -760,7 +760,7 @@ void sendClientKeyExchange(SSL& ssl, BufferOutput buffer)
RecordLayerHeader rlHeader; RecordLayerHeader rlHeader;
HandShakeHeader hsHeader; HandShakeHeader hsHeader;
mySTL::auto_ptr<output_buffer> out(new (ys) output_buffer); mySTL::auto_ptr<output_buffer> out(new output_buffer);
buildHeaders(ssl, hsHeader, rlHeader, ck); buildHeaders(ssl, hsHeader, rlHeader, ck);
buildOutput(*out.get(), rlHeader, hsHeader, ck); buildOutput(*out.get(), rlHeader, hsHeader, ck);
hashHandShake(ssl, *out.get()); hashHandShake(ssl, *out.get());
...@@ -781,7 +781,7 @@ void sendServerKeyExchange(SSL& ssl, BufferOutput buffer) ...@@ -781,7 +781,7 @@ void sendServerKeyExchange(SSL& ssl, BufferOutput buffer)
RecordLayerHeader rlHeader; RecordLayerHeader rlHeader;
HandShakeHeader hsHeader; HandShakeHeader hsHeader;
mySTL::auto_ptr<output_buffer> out(new (ys) output_buffer); mySTL::auto_ptr<output_buffer> out(new output_buffer);
buildHeaders(ssl, hsHeader, rlHeader, sk); buildHeaders(ssl, hsHeader, rlHeader, sk);
buildOutput(*out.get(), rlHeader, hsHeader, sk); buildOutput(*out.get(), rlHeader, hsHeader, sk);
hashHandShake(ssl, *out.get()); hashHandShake(ssl, *out.get());
...@@ -806,7 +806,7 @@ void sendChangeCipher(SSL& ssl, BufferOutput buffer) ...@@ -806,7 +806,7 @@ void sendChangeCipher(SSL& ssl, BufferOutput buffer)
ChangeCipherSpec ccs; ChangeCipherSpec ccs;
RecordLayerHeader rlHeader; RecordLayerHeader rlHeader;
buildHeader(ssl, rlHeader, ccs); buildHeader(ssl, rlHeader, ccs);
mySTL::auto_ptr<output_buffer> out(new (ys) output_buffer); mySTL::auto_ptr<output_buffer> out(new output_buffer);
buildOutput(*out.get(), rlHeader, ccs); buildOutput(*out.get(), rlHeader, ccs);
if (buffer == buffered) if (buffer == buffered)
...@@ -823,7 +823,7 @@ void sendFinished(SSL& ssl, ConnectionEnd side, BufferOutput buffer) ...@@ -823,7 +823,7 @@ void sendFinished(SSL& ssl, ConnectionEnd side, BufferOutput buffer)
Finished fin; Finished fin;
buildFinished(ssl, fin, side == client_end ? client : server); buildFinished(ssl, fin, side == client_end ? client : server);
mySTL::auto_ptr<output_buffer> out(new (ys) output_buffer); mySTL::auto_ptr<output_buffer> out(new output_buffer);
cipherFinished(ssl, fin, *out.get()); // hashes handshake cipherFinished(ssl, fin, *out.get()); // hashes handshake
if (ssl.getSecurity().get_resuming()) { if (ssl.getSecurity().get_resuming()) {
...@@ -907,7 +907,7 @@ void sendServerHello(SSL& ssl, BufferOutput buffer) ...@@ -907,7 +907,7 @@ void sendServerHello(SSL& ssl, BufferOutput buffer)
ServerHello sh(ssl.getSecurity().get_connection().version_); ServerHello sh(ssl.getSecurity().get_connection().version_);
RecordLayerHeader rlHeader; RecordLayerHeader rlHeader;
HandShakeHeader hsHeader; HandShakeHeader hsHeader;
mySTL::auto_ptr<output_buffer> out(new (ys) output_buffer); mySTL::auto_ptr<output_buffer> out(new output_buffer);
buildServerHello(ssl, sh); buildServerHello(ssl, sh);
ssl.set_random(sh.get_random(), server_end); ssl.set_random(sh.get_random(), server_end);
...@@ -930,7 +930,7 @@ void sendServerHelloDone(SSL& ssl, BufferOutput buffer) ...@@ -930,7 +930,7 @@ void sendServerHelloDone(SSL& ssl, BufferOutput buffer)
ServerHelloDone shd; ServerHelloDone shd;
RecordLayerHeader rlHeader; RecordLayerHeader rlHeader;
HandShakeHeader hsHeader; HandShakeHeader hsHeader;
mySTL::auto_ptr<output_buffer> out(new (ys) output_buffer); mySTL::auto_ptr<output_buffer> out(new output_buffer);
buildHeaders(ssl, hsHeader, rlHeader, shd); buildHeaders(ssl, hsHeader, rlHeader, shd);
buildOutput(*out.get(), rlHeader, hsHeader, shd); buildOutput(*out.get(), rlHeader, hsHeader, shd);
...@@ -951,7 +951,7 @@ void sendCertificate(SSL& ssl, BufferOutput buffer) ...@@ -951,7 +951,7 @@ void sendCertificate(SSL& ssl, BufferOutput buffer)
Certificate cert(ssl.getCrypto().get_certManager().get_cert()); Certificate cert(ssl.getCrypto().get_certManager().get_cert());
RecordLayerHeader rlHeader; RecordLayerHeader rlHeader;
HandShakeHeader hsHeader; HandShakeHeader hsHeader;
mySTL::auto_ptr<output_buffer> out(new (ys) output_buffer); mySTL::auto_ptr<output_buffer> out(new output_buffer);
buildHeaders(ssl, hsHeader, rlHeader, cert); buildHeaders(ssl, hsHeader, rlHeader, cert);
buildOutput(*out.get(), rlHeader, hsHeader, cert); buildOutput(*out.get(), rlHeader, hsHeader, cert);
...@@ -973,7 +973,7 @@ void sendCertificateRequest(SSL& ssl, BufferOutput buffer) ...@@ -973,7 +973,7 @@ void sendCertificateRequest(SSL& ssl, BufferOutput buffer)
request.Build(); request.Build();
RecordLayerHeader rlHeader; RecordLayerHeader rlHeader;
HandShakeHeader hsHeader; HandShakeHeader hsHeader;
mySTL::auto_ptr<output_buffer> out(new (ys) output_buffer); mySTL::auto_ptr<output_buffer> out(new output_buffer);
buildHeaders(ssl, hsHeader, rlHeader, request); buildHeaders(ssl, hsHeader, rlHeader, request);
buildOutput(*out.get(), rlHeader, hsHeader, request); buildOutput(*out.get(), rlHeader, hsHeader, request);
...@@ -995,7 +995,7 @@ void sendCertificateVerify(SSL& ssl, BufferOutput buffer) ...@@ -995,7 +995,7 @@ void sendCertificateVerify(SSL& ssl, BufferOutput buffer)
verify.Build(ssl); verify.Build(ssl);
RecordLayerHeader rlHeader; RecordLayerHeader rlHeader;
HandShakeHeader hsHeader; HandShakeHeader hsHeader;
mySTL::auto_ptr<output_buffer> out(new (ys) output_buffer); mySTL::auto_ptr<output_buffer> out(new output_buffer);
buildHeaders(ssl, hsHeader, rlHeader, verify); buildHeaders(ssl, hsHeader, rlHeader, verify);
buildOutput(*out.get(), rlHeader, hsHeader, verify); buildOutput(*out.get(), rlHeader, hsHeader, verify);
......
...@@ -443,7 +443,7 @@ int read_file(SSL_CTX* ctx, const char* file, int format, CertType type) ...@@ -443,7 +443,7 @@ int read_file(SSL_CTX* ctx, const char* file, int format, CertType type)
fseek(input, 0, SEEK_END); fseek(input, 0, SEEK_END);
long sz = ftell(input); long sz = ftell(input);
rewind(input); rewind(input);
x = new (ys) x509(sz); // takes ownership x = new x509(sz); // takes ownership
size_t bytes = fread(x->use_buffer(), sz, 1, input); size_t bytes = fread(x->use_buffer(), sz, 1, input);
if (bytes != 1) { if (bytes != 1) {
fclose(input); fclose(input);
...@@ -663,7 +663,7 @@ BIGNUM* BN_bin2bn(const unsigned char* num, int sz, BIGNUM* retVal) ...@@ -663,7 +663,7 @@ BIGNUM* BN_bin2bn(const unsigned char* num, int sz, BIGNUM* retVal)
if (!retVal) { if (!retVal) {
created = true; created = true;
bn.reset(new (ys) BIGNUM); bn.reset(new BIGNUM);
retVal = bn.get(); retVal = bn.get();
} }
......
...@@ -134,10 +134,10 @@ void DH_Server::build(SSL& ssl) ...@@ -134,10 +134,10 @@ void DH_Server::build(SSL& ssl)
const CertManager& cert = ssl.getCrypto().get_certManager(); const CertManager& cert = ssl.getCrypto().get_certManager();
if (ssl.getSecurity().get_parms().sig_algo_ == rsa_sa_algo) if (ssl.getSecurity().get_parms().sig_algo_ == rsa_sa_algo)
auth.reset(new (ys) RSA(cert.get_privateKey(), auth.reset(new RSA(cert.get_privateKey(),
cert.get_privateKeyLength(), false)); cert.get_privateKeyLength(), false));
else { else {
auth.reset(new (ys) DSS(cert.get_privateKey(), auth.reset(new DSS(cert.get_privateKey(),
cert.get_privateKeyLength(), false)); cert.get_privateKeyLength(), false));
sigSz += DSS_ENCODED_EXTRA; sigSz += DSS_ENCODED_EXTRA;
} }
...@@ -168,7 +168,7 @@ void DH_Server::build(SSL& ssl) ...@@ -168,7 +168,7 @@ void DH_Server::build(SSL& ssl)
byte hash[FINISHED_SZ]; byte hash[FINISHED_SZ];
MD5 md5; MD5 md5;
SHA sha; SHA sha;
signature_ = new (ys) byte[sigSz]; signature_ = new byte[sigSz];
const Connection& conn = ssl.getSecurity().get_connection(); const Connection& conn = ssl.getSecurity().get_connection();
// md5 // md5
...@@ -199,7 +199,7 @@ void DH_Server::build(SSL& ssl) ...@@ -199,7 +199,7 @@ void DH_Server::build(SSL& ssl)
tmp.write(signature_, sigSz); tmp.write(signature_, sigSz);
// key message // key message
keyMessage_ = new (ys) opaque[length_]; keyMessage_ = new opaque[length_];
memcpy(keyMessage_, tmp.get_buffer(), tmp.get_size()); memcpy(keyMessage_, tmp.get_buffer(), tmp.get_size());
} }
...@@ -253,7 +253,7 @@ opaque* EncryptedPreMasterSecret::get_clientKey() const ...@@ -253,7 +253,7 @@ opaque* EncryptedPreMasterSecret::get_clientKey() const
void EncryptedPreMasterSecret::alloc(int sz) void EncryptedPreMasterSecret::alloc(int sz)
{ {
length_ = sz; length_ = sz;
secret_ = new (ys) opaque[sz]; secret_ = new opaque[sz];
} }
...@@ -303,7 +303,7 @@ opaque* ClientDiffieHellmanPublic::get_clientKey() const ...@@ -303,7 +303,7 @@ opaque* ClientDiffieHellmanPublic::get_clientKey() const
void ClientDiffieHellmanPublic::alloc(int sz, bool offset) void ClientDiffieHellmanPublic::alloc(int sz, bool offset)
{ {
length_ = sz + (offset ? KEY_OFFSET : 0); length_ = sz + (offset ? KEY_OFFSET : 0);
Yc_ = new (ys) opaque[length_]; Yc_ = new opaque[length_];
} }
...@@ -348,7 +348,7 @@ void DH_Server::read(SSL& ssl, input_buffer& input) ...@@ -348,7 +348,7 @@ void DH_Server::read(SSL& ssl, input_buffer& input)
tmp[1] = input[AUTO]; tmp[1] = input[AUTO];
ato16(tmp, length); ato16(tmp, length);
signature_ = new (ys) byte[length]; signature_ = new byte[length];
input.read(signature_, length); input.read(signature_, length);
// verify signature // verify signature
...@@ -386,7 +386,7 @@ void DH_Server::read(SSL& ssl, input_buffer& input) ...@@ -386,7 +386,7 @@ void DH_Server::read(SSL& ssl, input_buffer& input)
} }
// save input // save input
ssl.useCrypto().SetDH(new (ys) DiffieHellman(parms_.get_p(), ssl.useCrypto().SetDH(new DiffieHellman(parms_.get_p(),
parms_.get_pSize(), parms_.get_g(), parms_.get_gSize(), parms_.get_pSize(), parms_.get_g(), parms_.get_gSize(),
parms_.get_pub(), parms_.get_pubSize(), parms_.get_pub(), parms_.get_pubSize(),
ssl.getCrypto().get_random())); ssl.getCrypto().get_random()));
...@@ -928,7 +928,7 @@ void Data::Process(input_buffer& input, SSL& ssl) ...@@ -928,7 +928,7 @@ void Data::Process(input_buffer& input, SSL& ssl)
// read data // read data
if (dataSz) { if (dataSz) {
input_buffer* data; input_buffer* data;
ssl.addData(data = new (ys) input_buffer(dataSz)); ssl.addData(data = new input_buffer(dataSz));
input.read(data->get_buffer(), dataSz); input.read(data->get_buffer(), dataSz);
data->add_size(dataSz); data->add_size(dataSz);
...@@ -1025,7 +1025,7 @@ void Certificate::Process(input_buffer& input, SSL& ssl) ...@@ -1025,7 +1025,7 @@ void Certificate::Process(input_buffer& input, SSL& ssl)
c24to32(tmp, cert_sz); c24to32(tmp, cert_sz);
x509* myCert; x509* myCert;
cm.AddPeerCert(myCert = new (ys) x509(cert_sz)); cm.AddPeerCert(myCert = new x509(cert_sz));
input.read(myCert->use_buffer(), myCert->get_length()); input.read(myCert->use_buffer(), myCert->get_length());
list_sz -= cert_sz + CERT_HEADER; list_sz -= cert_sz + CERT_HEADER;
...@@ -1111,21 +1111,21 @@ const opaque* ServerDHParams::get_pub() const ...@@ -1111,21 +1111,21 @@ const opaque* ServerDHParams::get_pub() const
opaque* ServerDHParams::alloc_p(int sz) opaque* ServerDHParams::alloc_p(int sz)
{ {
p_ = new (ys) opaque[pSz_ = sz]; p_ = new opaque[pSz_ = sz];
return p_; return p_;
} }
opaque* ServerDHParams::alloc_g(int sz) opaque* ServerDHParams::alloc_g(int sz)
{ {
g_ = new (ys) opaque[gSz_ = sz]; g_ = new opaque[gSz_ = sz];
return g_; return g_;
} }
opaque* ServerDHParams::alloc_pub(int sz) opaque* ServerDHParams::alloc_pub(int sz)
{ {
Ys_ = new (ys) opaque[pubSz_ = sz]; Ys_ = new opaque[pubSz_ = sz];
return Ys_; return Ys_;
} }
...@@ -1537,7 +1537,7 @@ void CertificateRequest::Build() ...@@ -1537,7 +1537,7 @@ void CertificateRequest::Build()
for (int j = 0; j < authCount; j++) { for (int j = 0; j < authCount; j++) {
int sz = REQUEST_HEADER + MIN_DIS_SIZE; int sz = REQUEST_HEADER + MIN_DIS_SIZE;
DistinguishedName dn; DistinguishedName dn;
certificate_authorities_.push_back(dn = new (ys) byte[sz]); certificate_authorities_.push_back(dn = new byte[sz]);
opaque tmp[REQUEST_HEADER]; opaque tmp[REQUEST_HEADER];
c16toa(MIN_DIS_SIZE, tmp); c16toa(MIN_DIS_SIZE, tmp);
...@@ -1584,7 +1584,7 @@ input_buffer& operator>>(input_buffer& input, CertificateRequest& request) ...@@ -1584,7 +1584,7 @@ input_buffer& operator>>(input_buffer& input, CertificateRequest& request)
ato16(tmp, dnSz); ato16(tmp, dnSz);
DistinguishedName dn; DistinguishedName dn;
request.certificate_authorities_.push_back(dn = new (ys) request.certificate_authorities_.push_back(dn = new
byte[REQUEST_HEADER + dnSz]); byte[REQUEST_HEADER + dnSz]);
memcpy(dn, tmp, REQUEST_HEADER); memcpy(dn, tmp, REQUEST_HEADER);
input.read(&dn[REQUEST_HEADER], dnSz); input.read(&dn[REQUEST_HEADER], dnSz);
...@@ -1665,7 +1665,7 @@ void CertificateVerify::Build(SSL& ssl) ...@@ -1665,7 +1665,7 @@ void CertificateVerify::Build(SSL& ssl)
RSA rsa(cert.get_privateKey(), cert.get_privateKeyLength(), false); RSA rsa(cert.get_privateKey(), cert.get_privateKeyLength(), false);
sz = rsa.get_cipherLength() + VERIFY_HEADER; sz = rsa.get_cipherLength() + VERIFY_HEADER;
sig.reset(new (ys) byte[sz]); sig.reset(new byte[sz]);
c16toa(sz - VERIFY_HEADER, len); c16toa(sz - VERIFY_HEADER, len);
memcpy(sig.get(), len, VERIFY_HEADER); memcpy(sig.get(), len, VERIFY_HEADER);
...@@ -1676,7 +1676,7 @@ void CertificateVerify::Build(SSL& ssl) ...@@ -1676,7 +1676,7 @@ void CertificateVerify::Build(SSL& ssl)
DSS dss(cert.get_privateKey(), cert.get_privateKeyLength(), false); DSS dss(cert.get_privateKey(), cert.get_privateKeyLength(), false);
sz = DSS_SIG_SZ + DSS_ENCODED_EXTRA + VERIFY_HEADER; sz = DSS_SIG_SZ + DSS_ENCODED_EXTRA + VERIFY_HEADER;
sig.reset(new (ys) byte[sz]); sig.reset(new byte[sz]);
c16toa(sz - VERIFY_HEADER, len); c16toa(sz - VERIFY_HEADER, len);
memcpy(sig.get(), len, VERIFY_HEADER); memcpy(sig.get(), len, VERIFY_HEADER);
...@@ -1714,7 +1714,7 @@ input_buffer& operator>>(input_buffer& input, CertificateVerify& request) ...@@ -1714,7 +1714,7 @@ input_buffer& operator>>(input_buffer& input, CertificateVerify& request)
ato16(tmp, sz); ato16(tmp, sz);
request.set_length(sz); request.set_length(sz);
request.signature_ = new (ys) byte[sz]; request.signature_ = new byte[sz];
input.read(request.signature_, sz); input.read(request.signature_, sz);
return input; return input;
...@@ -1975,7 +1975,7 @@ Connection::~Connection() ...@@ -1975,7 +1975,7 @@ Connection::~Connection()
void Connection::AllocPreSecret(uint sz) void Connection::AllocPreSecret(uint sz)
{ {
pre_master_secret_ = new (ys) opaque[pre_secret_len_ = sz]; pre_master_secret_ = new opaque[pre_secret_len_ = sz];
} }
...@@ -2011,35 +2011,35 @@ void Connection::CleanPreMaster() ...@@ -2011,35 +2011,35 @@ void Connection::CleanPreMaster()
// Create functions for message factory // Create functions for message factory
Message* CreateCipherSpec() { return new (ys) ChangeCipherSpec; } Message* CreateCipherSpec() { return new ChangeCipherSpec; }
Message* CreateAlert() { return new (ys) Alert; } Message* CreateAlert() { return new Alert; }
Message* CreateHandShake() { return new (ys) HandShakeHeader; } Message* CreateHandShake() { return new HandShakeHeader; }
Message* CreateData() { return new (ys) Data; } Message* CreateData() { return new Data; }
// Create functions for handshake factory // Create functions for handshake factory
HandShakeBase* CreateHelloRequest() { return new (ys) HelloRequest; } HandShakeBase* CreateHelloRequest() { return new HelloRequest; }
HandShakeBase* CreateClientHello() { return new (ys) ClientHello; } HandShakeBase* CreateClientHello() { return new ClientHello; }
HandShakeBase* CreateServerHello() { return new (ys) ServerHello; } HandShakeBase* CreateServerHello() { return new ServerHello; }
HandShakeBase* CreateCertificate() { return new (ys) Certificate; } HandShakeBase* CreateCertificate() { return new Certificate; }
HandShakeBase* CreateServerKeyExchange() { return new (ys) ServerKeyExchange;} HandShakeBase* CreateServerKeyExchange() { return new ServerKeyExchange;}
HandShakeBase* CreateCertificateRequest() { return new (ys) HandShakeBase* CreateCertificateRequest() { return new
CertificateRequest; } CertificateRequest; }
HandShakeBase* CreateServerHelloDone() { return new (ys) ServerHelloDone; } HandShakeBase* CreateServerHelloDone() { return new ServerHelloDone; }
HandShakeBase* CreateCertificateVerify() { return new (ys) CertificateVerify;} HandShakeBase* CreateCertificateVerify() { return new CertificateVerify;}
HandShakeBase* CreateClientKeyExchange() { return new (ys) ClientKeyExchange;} HandShakeBase* CreateClientKeyExchange() { return new ClientKeyExchange;}
HandShakeBase* CreateFinished() { return new (ys) Finished; } HandShakeBase* CreateFinished() { return new Finished; }
// Create functions for server key exchange factory // Create functions for server key exchange factory
ServerKeyBase* CreateRSAServerKEA() { return new (ys) RSA_Server; } ServerKeyBase* CreateRSAServerKEA() { return new RSA_Server; }
ServerKeyBase* CreateDHServerKEA() { return new (ys) DH_Server; } ServerKeyBase* CreateDHServerKEA() { return new DH_Server; }
ServerKeyBase* CreateFortezzaServerKEA() { return new (ys) Fortezza_Server; } ServerKeyBase* CreateFortezzaServerKEA() { return new Fortezza_Server; }
// Create functions for client key exchange factory // Create functions for client key exchange factory
ClientKeyBase* CreateRSAClient() { return new (ys) ClientKeyBase* CreateRSAClient() { return new
EncryptedPreMasterSecret; } EncryptedPreMasterSecret; }
ClientKeyBase* CreateDHClient() { return new (ys) ClientKeyBase* CreateDHClient() { return new
ClientDiffieHellmanPublic; } ClientDiffieHellmanPublic; }
ClientKeyBase* CreateFortezzaClient() { return new (ys) FortezzaKeys; } ClientKeyBase* CreateFortezzaClient() { return new FortezzaKeys; }
// Constructor calls this to Register compile time callbacks // Constructor calls this to Register compile time callbacks
...@@ -2115,4 +2115,3 @@ template yaSSL::del_ptr_zero mySTL::for_each<mySTL::list<yaSSL::output_buffer*>: ...@@ -2115,4 +2115,3 @@ template yaSSL::del_ptr_zero mySTL::for_each<mySTL::list<yaSSL::output_buffer*>:
template yaSSL::del_ptr_zero mySTL::for_each<mySTL::list<yaSSL::x509*>::iterator, yaSSL::del_ptr_zero>(mySTL::list<yaSSL::x509*>::iterator, mySTL::list<yaSSL::x509*>::iterator, yaSSL::del_ptr_zero); template yaSSL::del_ptr_zero mySTL::for_each<mySTL::list<yaSSL::x509*>::iterator, yaSSL::del_ptr_zero>(mySTL::list<yaSSL::x509*>::iterator, mySTL::list<yaSSL::x509*>::iterator, yaSSL::del_ptr_zero);
} }
#endif #endif
...@@ -31,28 +31,6 @@ ...@@ -31,28 +31,6 @@
#include "openssl/ssl.h" // for DH #include "openssl/ssl.h" // for DH
void* operator new(size_t sz, yaSSL::new_t)
{
void* ptr = ::operator new(sz);
if (!ptr) abort();
return ptr;
}
void* operator new[](size_t sz, yaSSL::new_t n)
{
#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 yaSSL { namespace yaSSL {
...@@ -60,8 +38,6 @@ namespace yaSSL { ...@@ -60,8 +38,6 @@ namespace yaSSL {
using mySTL::min; using mySTL::min;
new_t ys; // for library new
// convert a 32 bit integer into a 24 bit one // convert a 32 bit integer into a 24 bit one
void c32to24(uint32 u32, uint24& u24) void c32to24(uint32 u32, uint24& u24)
...@@ -308,8 +284,8 @@ void SSL::set_pending(Cipher suite) ...@@ -308,8 +284,8 @@ void SSL::set_pending(Cipher suite)
parms.key_size_ = AES_256_KEY_SZ; parms.key_size_ = AES_256_KEY_SZ;
parms.iv_size_ = AES_BLOCK_SZ; parms.iv_size_ = AES_BLOCK_SZ;
parms.cipher_type_ = block; parms.cipher_type_ = block;
crypto_.setDigest(new (ys) SHA); crypto_.setDigest(new SHA);
crypto_.setCipher(new (ys) AES(AES_256_KEY_SZ)); crypto_.setCipher(new AES(AES_256_KEY_SZ));
strncpy(parms.cipher_name_, cipher_names[TLS_RSA_WITH_AES_256_CBC_SHA], strncpy(parms.cipher_name_, cipher_names[TLS_RSA_WITH_AES_256_CBC_SHA],
MAX_SUITE_NAME); MAX_SUITE_NAME);
break; break;
...@@ -322,8 +298,8 @@ void SSL::set_pending(Cipher suite) ...@@ -322,8 +298,8 @@ void SSL::set_pending(Cipher suite)
parms.key_size_ = AES_128_KEY_SZ; parms.key_size_ = AES_128_KEY_SZ;
parms.iv_size_ = AES_BLOCK_SZ; parms.iv_size_ = AES_BLOCK_SZ;
parms.cipher_type_ = block; parms.cipher_type_ = block;
crypto_.setDigest(new (ys) SHA); crypto_.setDigest(new SHA);
crypto_.setCipher(new (ys) AES); crypto_.setCipher(new AES);
strncpy(parms.cipher_name_, cipher_names[TLS_RSA_WITH_AES_128_CBC_SHA], strncpy(parms.cipher_name_, cipher_names[TLS_RSA_WITH_AES_128_CBC_SHA],
MAX_SUITE_NAME); MAX_SUITE_NAME);
break; break;
...@@ -336,8 +312,8 @@ void SSL::set_pending(Cipher suite) ...@@ -336,8 +312,8 @@ void SSL::set_pending(Cipher suite)
parms.key_size_ = DES_EDE_KEY_SZ; parms.key_size_ = DES_EDE_KEY_SZ;
parms.iv_size_ = DES_IV_SZ; parms.iv_size_ = DES_IV_SZ;
parms.cipher_type_ = block; parms.cipher_type_ = block;
crypto_.setDigest(new (ys) SHA); crypto_.setDigest(new SHA);
crypto_.setCipher(new (ys) DES_EDE); crypto_.setCipher(new DES_EDE);
strncpy(parms.cipher_name_, cipher_names[SSL_RSA_WITH_3DES_EDE_CBC_SHA] strncpy(parms.cipher_name_, cipher_names[SSL_RSA_WITH_3DES_EDE_CBC_SHA]
, MAX_SUITE_NAME); , MAX_SUITE_NAME);
break; break;
...@@ -350,8 +326,8 @@ void SSL::set_pending(Cipher suite) ...@@ -350,8 +326,8 @@ void SSL::set_pending(Cipher suite)
parms.key_size_ = DES_KEY_SZ; parms.key_size_ = DES_KEY_SZ;
parms.iv_size_ = DES_IV_SZ; parms.iv_size_ = DES_IV_SZ;
parms.cipher_type_ = block; parms.cipher_type_ = block;
crypto_.setDigest(new (ys) SHA); crypto_.setDigest(new SHA);
crypto_.setCipher(new (ys) DES); crypto_.setCipher(new DES);
strncpy(parms.cipher_name_, cipher_names[SSL_RSA_WITH_DES_CBC_SHA], strncpy(parms.cipher_name_, cipher_names[SSL_RSA_WITH_DES_CBC_SHA],
MAX_SUITE_NAME); MAX_SUITE_NAME);
break; break;
...@@ -364,8 +340,8 @@ void SSL::set_pending(Cipher suite) ...@@ -364,8 +340,8 @@ void SSL::set_pending(Cipher suite)
parms.key_size_ = RC4_KEY_SZ; parms.key_size_ = RC4_KEY_SZ;
parms.iv_size_ = 0; parms.iv_size_ = 0;
parms.cipher_type_ = stream; parms.cipher_type_ = stream;
crypto_.setDigest(new (ys) SHA); crypto_.setDigest(new SHA);
crypto_.setCipher(new (ys) RC4); crypto_.setCipher(new RC4);
strncpy(parms.cipher_name_, cipher_names[SSL_RSA_WITH_RC4_128_SHA], strncpy(parms.cipher_name_, cipher_names[SSL_RSA_WITH_RC4_128_SHA],
MAX_SUITE_NAME); MAX_SUITE_NAME);
break; break;
...@@ -378,8 +354,8 @@ void SSL::set_pending(Cipher suite) ...@@ -378,8 +354,8 @@ void SSL::set_pending(Cipher suite)
parms.key_size_ = RC4_KEY_SZ; parms.key_size_ = RC4_KEY_SZ;
parms.iv_size_ = 0; parms.iv_size_ = 0;
parms.cipher_type_ = stream; parms.cipher_type_ = stream;
crypto_.setDigest(new (ys) MD5); crypto_.setDigest(new MD5);
crypto_.setCipher(new (ys) RC4); crypto_.setCipher(new RC4);
strncpy(parms.cipher_name_, cipher_names[SSL_RSA_WITH_RC4_128_MD5], strncpy(parms.cipher_name_, cipher_names[SSL_RSA_WITH_RC4_128_MD5],
MAX_SUITE_NAME); MAX_SUITE_NAME);
break; break;
...@@ -394,8 +370,8 @@ void SSL::set_pending(Cipher suite) ...@@ -394,8 +370,8 @@ void SSL::set_pending(Cipher suite)
parms.iv_size_ = DES_IV_SZ; parms.iv_size_ = DES_IV_SZ;
parms.cipher_type_ = block; parms.cipher_type_ = block;
secure_.use_connection().send_server_key_ = true; // eph secure_.use_connection().send_server_key_ = true; // eph
crypto_.setDigest(new (ys) SHA); crypto_.setDigest(new SHA);
crypto_.setCipher(new (ys) DES); crypto_.setCipher(new DES);
strncpy(parms.cipher_name_, cipher_names[SSL_DHE_RSA_WITH_DES_CBC_SHA], strncpy(parms.cipher_name_, cipher_names[SSL_DHE_RSA_WITH_DES_CBC_SHA],
MAX_SUITE_NAME); MAX_SUITE_NAME);
break; break;
...@@ -410,8 +386,8 @@ void SSL::set_pending(Cipher suite) ...@@ -410,8 +386,8 @@ void SSL::set_pending(Cipher suite)
parms.iv_size_ = DES_IV_SZ; parms.iv_size_ = DES_IV_SZ;
parms.cipher_type_ = block; parms.cipher_type_ = block;
secure_.use_connection().send_server_key_ = true; // eph secure_.use_connection().send_server_key_ = true; // eph
crypto_.setDigest(new (ys) SHA); crypto_.setDigest(new SHA);
crypto_.setCipher(new (ys) DES_EDE); crypto_.setCipher(new DES_EDE);
strncpy(parms.cipher_name_, strncpy(parms.cipher_name_,
cipher_names[SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA], MAX_SUITE_NAME); cipher_names[SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA], MAX_SUITE_NAME);
break; break;
...@@ -426,8 +402,8 @@ void SSL::set_pending(Cipher suite) ...@@ -426,8 +402,8 @@ void SSL::set_pending(Cipher suite)
parms.iv_size_ = AES_BLOCK_SZ; parms.iv_size_ = AES_BLOCK_SZ;
parms.cipher_type_ = block; parms.cipher_type_ = block;
secure_.use_connection().send_server_key_ = true; // eph secure_.use_connection().send_server_key_ = true; // eph
crypto_.setDigest(new (ys) SHA); crypto_.setDigest(new SHA);
crypto_.setCipher(new (ys) AES(AES_256_KEY_SZ)); crypto_.setCipher(new AES(AES_256_KEY_SZ));
strncpy(parms.cipher_name_, strncpy(parms.cipher_name_,
cipher_names[TLS_DHE_RSA_WITH_AES_256_CBC_SHA], MAX_SUITE_NAME); cipher_names[TLS_DHE_RSA_WITH_AES_256_CBC_SHA], MAX_SUITE_NAME);
break; break;
...@@ -442,8 +418,8 @@ void SSL::set_pending(Cipher suite) ...@@ -442,8 +418,8 @@ void SSL::set_pending(Cipher suite)
parms.iv_size_ = AES_BLOCK_SZ; parms.iv_size_ = AES_BLOCK_SZ;
parms.cipher_type_ = block; parms.cipher_type_ = block;
secure_.use_connection().send_server_key_ = true; // eph secure_.use_connection().send_server_key_ = true; // eph
crypto_.setDigest(new (ys) SHA); crypto_.setDigest(new SHA);
crypto_.setCipher(new (ys) AES); crypto_.setCipher(new AES);
strncpy(parms.cipher_name_, strncpy(parms.cipher_name_,
cipher_names[TLS_DHE_RSA_WITH_AES_128_CBC_SHA], MAX_SUITE_NAME); cipher_names[TLS_DHE_RSA_WITH_AES_128_CBC_SHA], MAX_SUITE_NAME);
break; break;
...@@ -458,8 +434,8 @@ void SSL::set_pending(Cipher suite) ...@@ -458,8 +434,8 @@ void SSL::set_pending(Cipher suite)
parms.iv_size_ = DES_IV_SZ; parms.iv_size_ = DES_IV_SZ;
parms.cipher_type_ = block; parms.cipher_type_ = block;
secure_.use_connection().send_server_key_ = true; // eph secure_.use_connection().send_server_key_ = true; // eph
crypto_.setDigest(new (ys) SHA); crypto_.setDigest(new SHA);
crypto_.setCipher(new (ys) DES); crypto_.setCipher(new DES);
strncpy(parms.cipher_name_, cipher_names[SSL_DHE_DSS_WITH_DES_CBC_SHA], strncpy(parms.cipher_name_, cipher_names[SSL_DHE_DSS_WITH_DES_CBC_SHA],
MAX_SUITE_NAME); MAX_SUITE_NAME);
break; break;
...@@ -474,8 +450,8 @@ void SSL::set_pending(Cipher suite) ...@@ -474,8 +450,8 @@ void SSL::set_pending(Cipher suite)
parms.iv_size_ = DES_IV_SZ; parms.iv_size_ = DES_IV_SZ;
parms.cipher_type_ = block; parms.cipher_type_ = block;
secure_.use_connection().send_server_key_ = true; // eph secure_.use_connection().send_server_key_ = true; // eph
crypto_.setDigest(new (ys) SHA); crypto_.setDigest(new SHA);
crypto_.setCipher(new (ys) DES_EDE); crypto_.setCipher(new DES_EDE);
strncpy(parms.cipher_name_, strncpy(parms.cipher_name_,
cipher_names[SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA], MAX_SUITE_NAME); cipher_names[SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA], MAX_SUITE_NAME);
break; break;
...@@ -490,8 +466,8 @@ void SSL::set_pending(Cipher suite) ...@@ -490,8 +466,8 @@ void SSL::set_pending(Cipher suite)
parms.iv_size_ = AES_BLOCK_SZ; parms.iv_size_ = AES_BLOCK_SZ;
parms.cipher_type_ = block; parms.cipher_type_ = block;
secure_.use_connection().send_server_key_ = true; // eph secure_.use_connection().send_server_key_ = true; // eph
crypto_.setDigest(new (ys) SHA); crypto_.setDigest(new SHA);
crypto_.setCipher(new (ys) AES(AES_256_KEY_SZ)); crypto_.setCipher(new AES(AES_256_KEY_SZ));
strncpy(parms.cipher_name_, strncpy(parms.cipher_name_,
cipher_names[TLS_DHE_DSS_WITH_AES_256_CBC_SHA], MAX_SUITE_NAME); cipher_names[TLS_DHE_DSS_WITH_AES_256_CBC_SHA], MAX_SUITE_NAME);
break; break;
...@@ -506,8 +482,8 @@ void SSL::set_pending(Cipher suite) ...@@ -506,8 +482,8 @@ void SSL::set_pending(Cipher suite)
parms.iv_size_ = AES_BLOCK_SZ; parms.iv_size_ = AES_BLOCK_SZ;
parms.cipher_type_ = block; parms.cipher_type_ = block;
secure_.use_connection().send_server_key_ = true; // eph secure_.use_connection().send_server_key_ = true; // eph
crypto_.setDigest(new (ys) SHA); crypto_.setDigest(new SHA);
crypto_.setCipher(new (ys) AES); crypto_.setCipher(new AES);
strncpy(parms.cipher_name_, strncpy(parms.cipher_name_,
cipher_names[TLS_DHE_DSS_WITH_AES_128_CBC_SHA], MAX_SUITE_NAME); cipher_names[TLS_DHE_DSS_WITH_AES_128_CBC_SHA], MAX_SUITE_NAME);
break; break;
...@@ -520,8 +496,8 @@ void SSL::set_pending(Cipher suite) ...@@ -520,8 +496,8 @@ void SSL::set_pending(Cipher suite)
parms.key_size_ = AES_256_KEY_SZ; parms.key_size_ = AES_256_KEY_SZ;
parms.iv_size_ = AES_BLOCK_SZ; parms.iv_size_ = AES_BLOCK_SZ;
parms.cipher_type_ = block; parms.cipher_type_ = block;
crypto_.setDigest(new (ys) RMD); crypto_.setDigest(new RMD);
crypto_.setCipher(new (ys) AES(AES_256_KEY_SZ)); crypto_.setCipher(new AES(AES_256_KEY_SZ));
strncpy(parms.cipher_name_, strncpy(parms.cipher_name_,
cipher_names[TLS_RSA_WITH_AES_256_CBC_RMD160], MAX_SUITE_NAME); cipher_names[TLS_RSA_WITH_AES_256_CBC_RMD160], MAX_SUITE_NAME);
break; break;
...@@ -534,8 +510,8 @@ void SSL::set_pending(Cipher suite) ...@@ -534,8 +510,8 @@ void SSL::set_pending(Cipher suite)
parms.key_size_ = AES_128_KEY_SZ; parms.key_size_ = AES_128_KEY_SZ;
parms.iv_size_ = AES_BLOCK_SZ; parms.iv_size_ = AES_BLOCK_SZ;
parms.cipher_type_ = block; parms.cipher_type_ = block;
crypto_.setDigest(new (ys) RMD); crypto_.setDigest(new RMD);
crypto_.setCipher(new (ys) AES); crypto_.setCipher(new AES);
strncpy(parms.cipher_name_, strncpy(parms.cipher_name_,
cipher_names[TLS_RSA_WITH_AES_128_CBC_RMD160], MAX_SUITE_NAME); cipher_names[TLS_RSA_WITH_AES_128_CBC_RMD160], MAX_SUITE_NAME);
break; break;
...@@ -548,8 +524,8 @@ void SSL::set_pending(Cipher suite) ...@@ -548,8 +524,8 @@ void SSL::set_pending(Cipher suite)
parms.key_size_ = DES_EDE_KEY_SZ; parms.key_size_ = DES_EDE_KEY_SZ;
parms.iv_size_ = DES_IV_SZ; parms.iv_size_ = DES_IV_SZ;
parms.cipher_type_ = block; parms.cipher_type_ = block;
crypto_.setDigest(new (ys) RMD); crypto_.setDigest(new RMD);
crypto_.setCipher(new (ys) DES_EDE); crypto_.setCipher(new DES_EDE);
strncpy(parms.cipher_name_, strncpy(parms.cipher_name_,
cipher_names[TLS_RSA_WITH_3DES_EDE_CBC_RMD160], MAX_SUITE_NAME); cipher_names[TLS_RSA_WITH_3DES_EDE_CBC_RMD160], MAX_SUITE_NAME);
break; break;
...@@ -564,8 +540,8 @@ void SSL::set_pending(Cipher suite) ...@@ -564,8 +540,8 @@ void SSL::set_pending(Cipher suite)
parms.iv_size_ = DES_IV_SZ; parms.iv_size_ = DES_IV_SZ;
parms.cipher_type_ = block; parms.cipher_type_ = block;
secure_.use_connection().send_server_key_ = true; // eph secure_.use_connection().send_server_key_ = true; // eph
crypto_.setDigest(new (ys) RMD); crypto_.setDigest(new RMD);
crypto_.setCipher(new (ys) DES_EDE); crypto_.setCipher(new DES_EDE);
strncpy(parms.cipher_name_, strncpy(parms.cipher_name_,
cipher_names[TLS_DHE_RSA_WITH_3DES_EDE_CBC_RMD160], cipher_names[TLS_DHE_RSA_WITH_3DES_EDE_CBC_RMD160],
MAX_SUITE_NAME); MAX_SUITE_NAME);
...@@ -581,8 +557,8 @@ void SSL::set_pending(Cipher suite) ...@@ -581,8 +557,8 @@ void SSL::set_pending(Cipher suite)
parms.iv_size_ = AES_BLOCK_SZ; parms.iv_size_ = AES_BLOCK_SZ;
parms.cipher_type_ = block; parms.cipher_type_ = block;
secure_.use_connection().send_server_key_ = true; // eph secure_.use_connection().send_server_key_ = true; // eph
crypto_.setDigest(new (ys) RMD); crypto_.setDigest(new RMD);
crypto_.setCipher(new (ys) AES(AES_256_KEY_SZ)); crypto_.setCipher(new AES(AES_256_KEY_SZ));
strncpy(parms.cipher_name_, strncpy(parms.cipher_name_,
cipher_names[TLS_DHE_RSA_WITH_AES_256_CBC_RMD160], cipher_names[TLS_DHE_RSA_WITH_AES_256_CBC_RMD160],
MAX_SUITE_NAME); MAX_SUITE_NAME);
...@@ -598,8 +574,8 @@ void SSL::set_pending(Cipher suite) ...@@ -598,8 +574,8 @@ void SSL::set_pending(Cipher suite)
parms.iv_size_ = AES_BLOCK_SZ; parms.iv_size_ = AES_BLOCK_SZ;
parms.cipher_type_ = block; parms.cipher_type_ = block;
secure_.use_connection().send_server_key_ = true; // eph secure_.use_connection().send_server_key_ = true; // eph
crypto_.setDigest(new (ys) RMD); crypto_.setDigest(new RMD);
crypto_.setCipher(new (ys) AES); crypto_.setCipher(new AES);
strncpy(parms.cipher_name_, strncpy(parms.cipher_name_,
cipher_names[TLS_DHE_RSA_WITH_AES_128_CBC_RMD160], cipher_names[TLS_DHE_RSA_WITH_AES_128_CBC_RMD160],
MAX_SUITE_NAME); MAX_SUITE_NAME);
...@@ -615,8 +591,8 @@ void SSL::set_pending(Cipher suite) ...@@ -615,8 +591,8 @@ void SSL::set_pending(Cipher suite)
parms.iv_size_ = DES_IV_SZ; parms.iv_size_ = DES_IV_SZ;
parms.cipher_type_ = block; parms.cipher_type_ = block;
secure_.use_connection().send_server_key_ = true; // eph secure_.use_connection().send_server_key_ = true; // eph
crypto_.setDigest(new (ys) RMD); crypto_.setDigest(new RMD);
crypto_.setCipher(new (ys) DES_EDE); crypto_.setCipher(new DES_EDE);
strncpy(parms.cipher_name_, strncpy(parms.cipher_name_,
cipher_names[TLS_DHE_DSS_WITH_3DES_EDE_CBC_RMD160], cipher_names[TLS_DHE_DSS_WITH_3DES_EDE_CBC_RMD160],
MAX_SUITE_NAME); MAX_SUITE_NAME);
...@@ -632,8 +608,8 @@ void SSL::set_pending(Cipher suite) ...@@ -632,8 +608,8 @@ void SSL::set_pending(Cipher suite)
parms.iv_size_ = AES_BLOCK_SZ; parms.iv_size_ = AES_BLOCK_SZ;
parms.cipher_type_ = block; parms.cipher_type_ = block;
secure_.use_connection().send_server_key_ = true; // eph secure_.use_connection().send_server_key_ = true; // eph
crypto_.setDigest(new (ys) RMD); crypto_.setDigest(new RMD);
crypto_.setCipher(new (ys) AES(AES_256_KEY_SZ)); crypto_.setCipher(new AES(AES_256_KEY_SZ));
strncpy(parms.cipher_name_, strncpy(parms.cipher_name_,
cipher_names[TLS_DHE_DSS_WITH_AES_256_CBC_RMD160], cipher_names[TLS_DHE_DSS_WITH_AES_256_CBC_RMD160],
MAX_SUITE_NAME); MAX_SUITE_NAME);
...@@ -649,8 +625,8 @@ void SSL::set_pending(Cipher suite) ...@@ -649,8 +625,8 @@ void SSL::set_pending(Cipher suite)
parms.iv_size_ = AES_BLOCK_SZ; parms.iv_size_ = AES_BLOCK_SZ;
parms.cipher_type_ = block; parms.cipher_type_ = block;
secure_.use_connection().send_server_key_ = true; // eph secure_.use_connection().send_server_key_ = true; // eph
crypto_.setDigest(new (ys) RMD); crypto_.setDigest(new RMD);
crypto_.setCipher(new (ys) AES); crypto_.setCipher(new AES);
strncpy(parms.cipher_name_, strncpy(parms.cipher_name_,
cipher_names[TLS_DHE_DSS_WITH_AES_128_CBC_RMD160], cipher_names[TLS_DHE_DSS_WITH_AES_128_CBC_RMD160],
MAX_SUITE_NAME); MAX_SUITE_NAME);
...@@ -936,12 +912,14 @@ struct SumBuffer { ...@@ -936,12 +912,14 @@ struct SumBuffer {
} // namespace for locals } // namespace for locals
using namespace yassl_int_cpp_local1; using namespace yassl_int_cpp_local1;
uint SSL::bufferedData() uint SSL::bufferedData()
{ {
return mySTL::for_each(buffers_.getData().begin(),buffers_.getData().end(), return mySTL::for_each(buffers_.getData().begin(),buffers_.getData().end(),
SumData()).total_; SumData()).total_;
} }
// use input buffer to fill data // use input buffer to fill data
void SSL::fillData(Data& data) void SSL::fillData(Data& data)
{ {
...@@ -1367,7 +1345,7 @@ typedef Mutex::Lock Lock; ...@@ -1367,7 +1345,7 @@ typedef Mutex::Lock Lock;
void Sessions::add(const SSL& ssl) void Sessions::add(const SSL& ssl)
{ {
Lock guard(mutex_); Lock guard(mutex_);
list_.push_back(new (ys) SSL_SESSION(ssl, random_)); list_.push_back(new SSL_SESSION(ssl, random_));
} }
...@@ -1397,6 +1375,7 @@ struct sess_match { ...@@ -1397,6 +1375,7 @@ struct sess_match {
} // local namespace } // local namespace
using namespace yassl_int_cpp_local2; using namespace yassl_int_cpp_local2;
// lookup session by id, return a copy if space provided // lookup session by id, return a copy if space provided
SSL_SESSION* Sessions::lookup(const opaque* id, SSL_SESSION* copy) SSL_SESSION* Sessions::lookup(const opaque* id, SSL_SESSION* copy)
{ {
...@@ -1764,7 +1743,7 @@ void Crypto::SetDH(DiffieHellman* dh) ...@@ -1764,7 +1743,7 @@ void Crypto::SetDH(DiffieHellman* dh)
void Crypto::SetDH(const DH_Parms& dh) void Crypto::SetDH(const DH_Parms& dh)
{ {
if (dh.set_) if (dh.set_)
dh_ = new (ys) DiffieHellman(dh.p_, dh.g_, random_); dh_ = new DiffieHellman(dh.p_, dh.g_, random_);
} }
...@@ -1931,7 +1910,7 @@ X509_NAME::X509_NAME(const char* n, size_t sz) ...@@ -1931,7 +1910,7 @@ X509_NAME::X509_NAME(const char* n, size_t sz)
: name_(0) : name_(0)
{ {
if (sz) { if (sz) {
name_ = new (ys) char[sz]; name_ = new char[sz];
memcpy(name_, n, sz); memcpy(name_, n, sz);
} }
} }
...@@ -1952,7 +1931,7 @@ char* X509_NAME::GetName() ...@@ -1952,7 +1931,7 @@ char* X509_NAME::GetName()
X509::X509(const char* i, size_t iSz, const char* s, size_t sSz) X509::X509(const char* i, size_t iSz, const char* s, size_t sSz)
: issuer_(i, iSz), subject_(s, sSz) : issuer_(i, iSz), subject_(s, sSz)
{} {}
X509_NAME* X509::GetIssuer() X509_NAME* X509::GetIssuer()
{ {
......
...@@ -37,11 +37,12 @@ enum { AES_BLOCK_SIZE = 16 }; ...@@ -37,11 +37,12 @@ enum { AES_BLOCK_SIZE = 16 };
// AES encryption and decryption, see FIPS-197 // AES encryption and decryption, see FIPS-197
class AES : public Mode_BASE<AES_BLOCK_SIZE> { class AES : public Mode_BASE {
public: public:
enum { BLOCK_SIZE = AES_BLOCK_SIZE }; 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 Process(byte*, const byte*, word32);
void SetKey(const byte* iv, word32 sz, CipherDir fake = ENCRYPTION); void SetKey(const byte* iv, word32 sz, CipherDir fake = ENCRYPTION);
......
...@@ -24,11 +24,10 @@ ...@@ -24,11 +24,10 @@
#ifndef TAO_CRYPT_ALGEBRA_HPP #ifndef TAO_CRYPT_ALGEBRA_HPP
#define TAO_CRYPT_ALGEBRA_HPP #define TAO_CRYPT_ALGEBRA_HPP
#include "misc.hpp" #include "integer.hpp"
namespace TaoCrypt { namespace TaoCrypt {
class Integer;
// "const Element&" returned by member functions are references // "const Element&" returned by member functions are references
// to internal data members. Since each object may have only // to internal data members. Since each object may have only
...@@ -38,11 +37,11 @@ class Integer; ...@@ -38,11 +37,11 @@ class Integer;
// But this should be fine: // But this should be fine:
// abcd = group.Add(a, group.Add(b, group.Add(c,d)); // abcd = group.Add(a, group.Add(b, group.Add(c,d));
//! Abstract Group // Abstract Group
template <class T> class TAOCRYPT_NO_VTABLE AbstractGroup class TAOCRYPT_NO_VTABLE AbstractGroup
{ {
public: public:
typedef T Element; typedef Integer Element;
virtual ~AbstractGroup() {} virtual ~AbstractGroup() {}
...@@ -65,15 +64,14 @@ public: ...@@ -65,15 +64,14 @@ public:
const Integer *exponents, unsigned int exponentsCount) const; const Integer *exponents, unsigned int exponentsCount) const;
}; };
//! Abstract Ring // Abstract Ring
template <class T> class TAOCRYPT_NO_VTABLE AbstractRing class TAOCRYPT_NO_VTABLE AbstractRing : public AbstractGroup
: public AbstractGroup<T>
{ {
public: public:
typedef T Element; typedef Integer Element;
AbstractRing() {m_mg.m_pRing = this;} 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;} AbstractRing& operator=(const AbstractRing &source) {return *this;}
virtual bool IsUnit(const Element &a) const =0; virtual bool IsUnit(const Element &a) const =0;
...@@ -91,14 +89,14 @@ public: ...@@ -91,14 +89,14 @@ public:
virtual void SimultaneousExponentiate(Element *results, const Element&, virtual void SimultaneousExponentiate(Element *results, const Element&,
const Integer *exponents, unsigned int exponentsCount) const; const Integer *exponents, unsigned int exponentsCount) const;
virtual const AbstractGroup<T>& MultiplicativeGroup() const virtual const AbstractGroup& MultiplicativeGroup() const
{return m_mg;} {return m_mg;}
private: private:
class MultiplicativeGroupT : public AbstractGroup<T> class MultiplicativeGroupT : public AbstractGroup
{ {
public: public:
const AbstractRing<T>& GetRing() const const AbstractRing& GetRing() const
{return *m_pRing;} {return *m_pRing;}
bool Equal(const Element &a, const Element &b) const bool Equal(const Element &a, const Element &b) const
...@@ -137,44 +135,19 @@ private: ...@@ -137,44 +135,19 @@ private:
{GetRing().SimultaneousExponentiate(results, base, exponents, {GetRing().SimultaneousExponentiate(results, base, exponents,
exponentsCount);} exponentsCount);}
const AbstractRing<T> *m_pRing; const AbstractRing* m_pRing;
}; };
MultiplicativeGroupT m_mg; MultiplicativeGroupT m_mg;
}; };
// ********************************************************
//! Base and Exponent // Abstract Euclidean Domain
template <class T, class E = Integer> class TAOCRYPT_NO_VTABLE AbstractEuclideanDomain
struct BaseAndExponent : public AbstractRing
{ {
public: public:
BaseAndExponent() {} typedef Integer Element;
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;
virtual void DivisionAlgorithm(Element &r, Element &q, const Element &a, virtual void DivisionAlgorithm(Element &r, Element &q, const Element &a,
const Element &d) const =0; const Element &d) const =0;
...@@ -186,13 +159,12 @@ protected: ...@@ -186,13 +159,12 @@ protected:
mutable Element result; mutable Element result;
}; };
// ********************************************************
//! EuclideanDomainOf // EuclideanDomainOf
template <class T> class EuclideanDomainOf : public AbstractEuclideanDomain<T> class EuclideanDomainOf : public AbstractEuclideanDomain
{ {
public: public:
typedef T Element; typedef Integer Element;
EuclideanDomainOf() {} EuclideanDomainOf() {}
...@@ -249,68 +221,8 @@ private: ...@@ -249,68 +221,8 @@ private:
mutable Element result; 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 } // namespace
#endif // TAO_CRYPT_ALGEBRA_HPP #endif // TAO_CRYPT_ALGEBRA_HPP
...@@ -34,10 +34,6 @@ ...@@ -34,10 +34,6 @@
#include <stddef.h> // ptrdiff_t #include <stddef.h> // ptrdiff_t
#if defined(_MSC_VER) && defined(_CRTAPI1)
#define TAOCRYPT_MSVCRT6
#endif
namespace TaoCrypt { namespace TaoCrypt {
...@@ -47,13 +43,13 @@ template<class T> ...@@ -47,13 +43,13 @@ template<class T>
class AllocatorBase class AllocatorBase
{ {
public: public:
typedef T value_type; typedef T value_type;
typedef size_t size_type; typedef size_t size_type;
typedef ptrdiff_t difference_type; typedef ptrdiff_t difference_type;
typedef T* pointer; typedef T* pointer;
typedef const T* const_pointer; typedef const T* const_pointer;
typedef T& reference; typedef T& reference;
typedef const T& const_reference; typedef const T& const_reference;
pointer address(reference r) const {return (&r);} pointer address(reference r) const {return (&r);}
const_pointer address(const_reference r) const {return (&r); } const_pointer address(const_reference r) const {return (&r); }
...@@ -104,7 +100,7 @@ public: ...@@ -104,7 +100,7 @@ public:
CheckSize(n); CheckSize(n);
if (n == 0) if (n == 0)
return 0; return 0;
return new (tc) T[n]; return new T[n];
} }
void deallocate(void* p, size_type n) void deallocate(void* p, size_type n)
......
...@@ -36,12 +36,13 @@ namespace TaoCrypt { ...@@ -36,12 +36,13 @@ namespace TaoCrypt {
enum { DES_BLOCK_SIZE = 8 }; enum { DES_BLOCK_SIZE = 8 };
// Base for all DES types // Base for all DES types
class DES_BASE : public Mode_BASE<DES_BLOCK_SIZE> { class DES_BASE : public Mode_BASE {
public: public:
enum { BLOCK_SIZE = DES_BLOCK_SIZE, KEY_SIZE = 32, BOXES = 8, enum { BLOCK_SIZE = DES_BLOCK_SIZE, KEY_SIZE = 32, BOXES = 8,
BOX_SIZE = 64 }; 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); void Process(byte*, const byte*, word32);
protected: protected:
......
...@@ -65,7 +65,8 @@ UNKOWN_HASH_E = 1034, // "unknown hash OID" ...@@ -65,7 +65,8 @@ UNKOWN_HASH_E = 1034, // "unknown hash OID"
DSA_SZ_E = 1035, // "bad DSA r or s size" DSA_SZ_E = 1035, // "bad DSA r or s size"
BEFORE_DATE_E = 1036, // "before date in the future" BEFORE_DATE_E = 1036, // "before date in the future"
AFTER_DATE_E = 1037, // "after date in the past" 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"
}; };
......
...@@ -50,7 +50,7 @@ public: ...@@ -50,7 +50,7 @@ public:
class HASHwithTransform : public HASH { class HASHwithTransform : public HASH {
public: public:
HASHwithTransform(word32 digSz, word32 buffSz) 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 ~HASHwithTransform() { delete[] buffer_; delete[] digest_; }
virtual ByteOrder getByteOrder() const = 0; virtual ByteOrder getByteOrder() const = 0;
......
...@@ -29,8 +29,8 @@ ...@@ -29,8 +29,8 @@
#include "block.hpp" #include "block.hpp"
#include "random.hpp" #include "random.hpp"
#include "file.hpp" #include "file.hpp"
#include <string.h>
#include "algorithm.hpp" // mySTL::swap #include "algorithm.hpp" // mySTL::swap
#include <string.h>
#ifdef TAOCRYPT_X86ASM_AVAILABLE #ifdef TAOCRYPT_X86ASM_AVAILABLE
...@@ -128,9 +128,6 @@ public: ...@@ -128,9 +128,6 @@ public:
Integer(signed long value); Integer(signed long value);
Integer(Sign s, word highWord, word lowWord); Integer(Sign s, word highWord, word lowWord);
explicit Integer(const char* str);
explicit Integer(const wchar_t* str);
// BER Decode Source // BER Decode Source
explicit Integer(Source&); explicit Integer(Source&);
...@@ -254,15 +251,13 @@ public: ...@@ -254,15 +251,13 @@ public:
private: private:
friend class ModularArithmetic; friend class ModularArithmetic;
friend class MontgomeryRepresentation; friend class MontgomeryRepresentation;
friend class HalfMontgomeryRepresentation;
Integer(word value, unsigned int length); Integer(word value, unsigned int length);
static const Integer zero; static const Integer zero;
static const Integer one; static const Integer one;
static const Integer two; static const Integer two;
int PositiveCompare(const Integer& t) const; int PositiveCompare(const Integer& t) const;
friend void PositiveAdd(Integer& sum, const Integer& a, const Integer& b); friend void PositiveAdd(Integer& sum, const Integer& a, const Integer& b);
friend void PositiveSubtract(Integer& diff, const Integer& a, friend void PositiveSubtract(Integer& diff, const Integer& a,
const Integer& b); const Integer& b);
...@@ -308,6 +303,7 @@ inline void swap(Integer &a, Integer &b) ...@@ -308,6 +303,7 @@ inline void swap(Integer &a, Integer &b)
Integer CRT(const Integer& xp, const Integer& p, const Integer& xq, Integer CRT(const Integer& xp, const Integer& p, const Integer& xq,
const Integer& q, const Integer& u); const Integer& q, const Integer& u);
inline Integer ModularExponentiation(const Integer& a, const Integer& e, inline Integer ModularExponentiation(const Integer& a, const Integer& e,
const Integer& m) const Integer& m)
{ {
......
...@@ -28,17 +28,6 @@ ...@@ -28,17 +28,6 @@
#include <assert.h> #include <assert.h>
#include <string.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 { namespace TaoCrypt {
......
...@@ -27,14 +27,13 @@ ...@@ -27,14 +27,13 @@
#define TAO_CRYPT_MODARITH_HPP #define TAO_CRYPT_MODARITH_HPP
#include "misc.hpp" #include "misc.hpp"
#include "integer.hpp"
#include "algebra.hpp" #include "algebra.hpp"
namespace TaoCrypt { namespace TaoCrypt {
//! ModularArithmetic // ModularArithmetic
class ModularArithmetic : public AbstractRing<Integer> class ModularArithmetic : public AbstractRing
{ {
public: public:
...@@ -45,7 +44,7 @@ public: ...@@ -45,7 +44,7 @@ public:
: modulus(modulus), result((word)0, modulus.reg_.size()) {} : modulus(modulus), result((word)0, modulus.reg_.size()) {}
ModularArithmetic(const ModularArithmetic &ma) ModularArithmetic(const ModularArithmetic &ma)
: AbstractRing<Integer>(), : AbstractRing(),
modulus(ma.modulus), result((word)0, modulus.reg_.size()) {} modulus(ma.modulus), result((word)0, modulus.reg_.size()) {}
const Integer& GetModulus() const {return modulus;} const Integer& GetModulus() const {return modulus;}
...@@ -149,12 +148,12 @@ public: ...@@ -149,12 +148,12 @@ public:
Integer CascadeExponentiate(const Integer &x, const Integer &e1, Integer CascadeExponentiate(const Integer &x, const Integer &e1,
const Integer &y, const Integer &e2) const 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, void SimultaneousExponentiate(Element *results, const Element &base,
const Integer *exponents, unsigned int exponentsCount) const const Integer *exponents, unsigned int exponentsCount) const
{AbstractRing<Integer>::SimultaneousExponentiate(results, base, {AbstractRing::SimultaneousExponentiate(results, base,
exponents, exponentsCount);} exponents, exponentsCount);}
private: private:
Integer u; Integer u;
......
...@@ -56,10 +56,11 @@ private: ...@@ -56,10 +56,11 @@ private:
// Mode Base for block ciphers, static size // Mode Base for block ciphers, static size
template<int BLOCK_SIZE>
class Mode_BASE { class Mode_BASE {
public: public:
Mode_BASE() {} enum { MaxBlockSz = 16 };
explicit Mode_BASE(int sz) : blockSz_(sz) { assert(sz <= MaxBlockSz); }
virtual ~Mode_BASE() {} virtual ~Mode_BASE() {}
virtual void ProcessAndXorBlock(const byte*, const byte*, byte*) const = 0; virtual void ProcessAndXorBlock(const byte*, const byte*, byte*) const = 0;
...@@ -68,10 +69,11 @@ public: ...@@ -68,10 +69,11 @@ public:
void CBC_Encrypt(byte*, const byte*, word32); void CBC_Encrypt(byte*, const byte*, word32);
void CBC_Decrypt(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: private:
byte reg_[BLOCK_SIZE]; byte reg_[MaxBlockSz];
byte tmp_[BLOCK_SIZE]; byte tmp_[MaxBlockSz];
int blockSz_;
Mode_BASE(const Mode_BASE&); // hide copy Mode_BASE(const Mode_BASE&); // hide copy
Mode_BASE& operator=(const Mode_BASE&); // and assign Mode_BASE& operator=(const Mode_BASE&); // and assign
...@@ -79,51 +81,48 @@ private: ...@@ -79,51 +81,48 @@ private:
// ECB Process blocks // ECB Process blocks
template<int BLOCK_SIZE> inline void Mode_BASE::ECB_Process(byte* out, const byte* in, word32 sz)
void Mode_BASE<BLOCK_SIZE>::ECB_Process(byte* out, const byte* in, word32 sz)
{ {
word32 blocks = sz / BLOCK_SIZE; word32 blocks = sz / blockSz_;
while (blocks--) { while (blocks--) {
ProcessAndXorBlock(in, 0, out); ProcessAndXorBlock(in, 0, out);
out += BLOCK_SIZE; out += blockSz_;
in += BLOCK_SIZE; in += blockSz_;
} }
} }
// CBC Encrypt // CBC Encrypt
template<int BLOCK_SIZE> inline void Mode_BASE::CBC_Encrypt(byte* out, const byte* in, word32 sz)
void Mode_BASE<BLOCK_SIZE>::CBC_Encrypt(byte* out, const byte* in, word32 sz)
{ {
word32 blocks = sz / BLOCK_SIZE; word32 blocks = sz / blockSz_;
while (blocks--) { while (blocks--) {
xorbuf(reg_, in, BLOCK_SIZE); xorbuf(reg_, in, blockSz_);
ProcessAndXorBlock(reg_, 0, reg_); ProcessAndXorBlock(reg_, 0, reg_);
memcpy(out, reg_, BLOCK_SIZE); memcpy(out, reg_, blockSz_);
out += BLOCK_SIZE; out += blockSz_;
in += BLOCK_SIZE; in += blockSz_;
} }
} }
// CBC Decrypt // CBC Decrypt
template<int BLOCK_SIZE> inline void Mode_BASE::CBC_Decrypt(byte* out, const byte* in, word32 sz)
void Mode_BASE<BLOCK_SIZE>::CBC_Decrypt(byte* out, const byte* in, word32 sz)
{ {
word32 blocks = sz / BLOCK_SIZE; word32 blocks = sz / blockSz_;
byte hold[BLOCK_SIZE]; byte hold[MaxBlockSz];
while (blocks--) { while (blocks--) {
memcpy(tmp_, in, BLOCK_SIZE); memcpy(tmp_, in, blockSz_);
ProcessAndXorBlock(tmp_, 0, out); ProcessAndXorBlock(tmp_, 0, out);
xorbuf(out, reg_, BLOCK_SIZE); xorbuf(out, reg_, blockSz_);
memcpy(hold, reg_, BLOCK_SIZE); // swap reg_ and tmp_ memcpy(hold, reg_, blockSz_); // swap reg_ and tmp_
memcpy(reg_, tmp_, BLOCK_SIZE); memcpy(reg_, tmp_, blockSz_);
memcpy(tmp_, hold, BLOCK_SIZE); memcpy(tmp_, hold, blockSz_);
out += BLOCK_SIZE; out += blockSz_;
in += BLOCK_SIZE; in += blockSz_;
} }
} }
......
...@@ -23,60 +23,58 @@ ...@@ -23,60 +23,58 @@
#include "runtime.hpp" #include "runtime.hpp"
#include "algebra.hpp" #include "algebra.hpp"
#include "integer.hpp"
#include "vector.hpp" // mySTL::vector (simple) #include "vector.hpp" // mySTL::vector (simple)
namespace TaoCrypt { 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); return Add(a, a);
} }
template <class T> const T& AbstractGroup<T>::Subtract(const Element &a, const Integer& AbstractGroup::Subtract(const Element &a, const Element &b) const
const Element &b) const
{ {
// make copy of a in case Inverse() overwrites it // make copy of a in case Inverse() overwrites it
Element a1(a); Element a1(a);
return Add(a1, Inverse(b)); return Add(a1, Inverse(b));
} }
template <class T> T& AbstractGroup<T>::Accumulate(Element &a, Integer& AbstractGroup::Accumulate(Element &a, const Element &b) const
const Element &b) const
{ {
return a = Add(a, b); return a = Add(a, b);
} }
template <class T> T& AbstractGroup<T>::Reduce(Element &a, Integer& AbstractGroup::Reduce(Element &a, const Element &b) const
const Element &b) const
{ {
return a = Subtract(a, b); 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); 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 // make copy of a in case MultiplicativeInverse() overwrites it
Element a1(a); Element a1(a);
return Multiply(a1, MultiplicativeInverse(b)); 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; Element q;
DivisionAlgorithm(result, q, a, b); DivisionAlgorithm(result, q, a, b);
return result; return result;
} }
template <class T> const T& AbstractEuclideanDomain<T>::Gcd(const Element &a, const Integer& AbstractEuclideanDomain::Gcd(const Element &a,
const Element &b) const const Element &b) const
{ {
Element g[3]={b, a}; Element g[3]={b, a};
unsigned int i0=0, i1=1, i2=2; unsigned int i0=0, i1=1, i2=2;
...@@ -90,45 +88,17 @@ template <class T> const T& AbstractEuclideanDomain<T>::Gcd(const Element &a, ...@@ -90,45 +88,17 @@ template <class T> const T& AbstractEuclideanDomain<T>::Gcd(const Element &a,
return result = g[i0]; 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())) Integer AbstractGroup::ScalarMultiply(const Element &base,
{ const Integer &exponent) const
// 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
{ {
Element result; Element result;
SimultaneousMultiply(&result, base, &exponent, 1); SimultaneousMultiply(&result, base, &exponent, 1);
return result; 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 Integer &e1, const Element &y, const Integer &e2) const
{ {
const unsigned expLen = max(e1.BitCount(), e2.BitCount()); const unsigned expLen = max(e1.BitCount(), e2.BitCount());
...@@ -258,8 +228,8 @@ struct WindowSlider ...@@ -258,8 +228,8 @@ struct WindowSlider
bool fastNegate, negateNext, firstTime, finished; 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 const Integer *expBegin, unsigned int expCount) const
{ {
mySTL::vector<mySTL::vector<Element> > buckets(expCount); mySTL::vector<mySTL::vector<Element> > buckets(expCount);
...@@ -321,34 +291,39 @@ void AbstractGroup<T>::SimultaneousMultiply(T *results, const T &base, ...@@ -321,34 +291,39 @@ void AbstractGroup<T>::SimultaneousMultiply(T *results, const T &base,
} }
} }
template <class T> T AbstractRing<T>::Exponentiate(const Element &base, Integer AbstractRing::Exponentiate(const Element &base,
const Integer &exponent) const const Integer &exponent) const
{ {
Element result; Element result;
SimultaneousExponentiate(&result, base, &exponent, 1); SimultaneousExponentiate(&result, base, &exponent, 1);
return result; 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 const Integer &e1, const Element &y, const Integer &e2) const
{ {
return MultiplicativeGroup().AbstractGroup<T>::CascadeScalarMultiply( return MultiplicativeGroup().AbstractGroup::CascadeScalarMultiply(
x, e1, y, e2); 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::SimultaneousExponentiate(Integer *results,
void AbstractRing<T>::SimultaneousExponentiate(T *results, const T &base, const Integer &base,
const Integer *exponents, unsigned int expCount) const const Integer *exponents, unsigned int expCount) const
{ {
MultiplicativeGroup().AbstractGroup<T>::SimultaneousMultiply(results, base, MultiplicativeGroup().AbstractGroup::SimultaneousMultiply(results, base,
exponents, expCount); exponents, expCount);
} }
} // namespace } // 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
...@@ -187,7 +187,7 @@ PublicKey::PublicKey(const byte* k, word32 s) : key_(0), sz_(0) ...@@ -187,7 +187,7 @@ PublicKey::PublicKey(const byte* k, word32 s) : key_(0), sz_(0)
void PublicKey::SetSize(word32 s) void PublicKey::SetSize(word32 s)
{ {
sz_ = s; sz_ = s;
key_ = new (tc) byte[sz_]; key_ = new byte[sz_];
} }
...@@ -199,7 +199,7 @@ void PublicKey::SetKey(const byte* k) ...@@ -199,7 +199,7 @@ void PublicKey::SetKey(const byte* k)
void PublicKey::AddToEnd(const byte* data, word32 len) 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(), key_, sz_);
memcpy(tmp.get() + sz_, data, len); memcpy(tmp.get() + sz_, data, len);
...@@ -218,7 +218,7 @@ Signer::Signer(const byte* k, word32 kSz, const char* n, const byte* h) ...@@ -218,7 +218,7 @@ Signer::Signer(const byte* k, word32 kSz, const char* n, const byte* h)
{ {
if (n) { if (n) {
int sz = strlen(n); int sz = strlen(n);
name_ = new (tc) char[sz + 1]; name_ = new char[sz + 1];
memcpy(name_, n, sz); memcpy(name_, n, sz);
name_[sz] = 0; name_[sz] = 0;
} }
...@@ -480,7 +480,7 @@ void CertDecoder::Decode(SignerList* signers) ...@@ -480,7 +480,7 @@ void CertDecoder::Decode(SignerList* signers)
} }
else else
if (!ValidateSignature(signers)) if (!ValidateSignature(signers))
source_.SetError(SIG_CONFIRM_E); source_.SetError(SIG_OTHER_E);
} }
...@@ -632,7 +632,7 @@ word32 CertDecoder::GetSignature() ...@@ -632,7 +632,7 @@ word32 CertDecoder::GetSignature()
} }
sigLength_--; sigLength_--;
signature_ = new (tc) byte[sigLength_]; signature_ = new byte[sigLength_];
memcpy(signature_, source_.get_current(), sigLength_); memcpy(signature_, source_.get_current(), sigLength_);
source_.advance(sigLength_); source_.advance(sigLength_);
...@@ -653,7 +653,7 @@ word32 CertDecoder::GetDigest() ...@@ -653,7 +653,7 @@ word32 CertDecoder::GetDigest()
sigLength_ = GetLength(source_); sigLength_ = GetLength(source_);
signature_ = new (tc) byte[sigLength_]; signature_ = new byte[sigLength_];
memcpy(signature_, source_.get_current(), sigLength_); memcpy(signature_, source_.get_current(), sigLength_);
source_.advance(sigLength_); source_.advance(sigLength_);
...@@ -693,7 +693,7 @@ void CertDecoder::GetName(NameType nt) ...@@ -693,7 +693,7 @@ void CertDecoder::GetName(NameType nt)
if (id == COMMON_NAME) { if (id == COMMON_NAME) {
char*& ptr = (nt == ISSUER) ? issuer_ : subject_; char*& ptr = (nt == ISSUER) ? issuer_ : subject_;
ptr = new (tc) char[strLen + 1]; ptr = new char[strLen + 1];
memcpy(ptr, source_.get_current(), strLen); memcpy(ptr, source_.get_current(), strLen);
ptr[strLen] = 0; ptr[strLen] = 0;
} }
...@@ -810,15 +810,15 @@ bool CertDecoder::ConfirmSignature(Source& pub) ...@@ -810,15 +810,15 @@ bool CertDecoder::ConfirmSignature(Source& pub)
mySTL::auto_ptr<HASH> hasher; mySTL::auto_ptr<HASH> hasher;
if (signatureOID_ == MD5wRSA) { if (signatureOID_ == MD5wRSA) {
hasher.reset(new (tc) MD5); hasher.reset(new MD5);
ht = MD5h; ht = MD5h;
} }
else if (signatureOID_ == MD2wRSA) { else if (signatureOID_ == MD2wRSA) {
hasher.reset(new (tc) MD2); hasher.reset(new MD2);
ht = MD2h; ht = MD2h;
} }
else if (signatureOID_ == SHAwRSA || signatureOID_ == SHAwDSA) { else if (signatureOID_ == SHAwRSA || signatureOID_ == SHAwDSA) {
hasher.reset(new (tc) SHA); hasher.reset(new SHA);
ht = SHAh; ht = SHAh;
} }
else { else {
......
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
#include "runtime.hpp" #include "runtime.hpp"
#include "dh.hpp" #include "dh.hpp"
#include "asn.hpp" #include "asn.hpp"
#include <math.h>
namespace TaoCrypt { namespace TaoCrypt {
......
...@@ -27,8 +27,6 @@ ...@@ -27,8 +27,6 @@
#include "modarith.hpp" #include "modarith.hpp"
#include "stdexcept.hpp" #include "stdexcept.hpp"
#include "algebra.cpp" // for GCC 3.2 on aix ?
namespace TaoCrypt { namespace TaoCrypt {
......
...@@ -38,11 +38,10 @@ ...@@ -38,11 +38,10 @@
#include "asn.hpp" #include "asn.hpp"
#include "stdexcept.hpp" #include "stdexcept.hpp"
#include "algebra.cpp"
#ifdef __DECCXX #ifdef __DECCXX
#include <c_asm.h> // for asm multiply overflow #include <c_asm.h> // for asm overflow assembly
#endif #endif
...@@ -63,7 +62,7 @@ ...@@ -63,7 +62,7 @@
#pragma message("You do not seem to have the Visual C++ Processor Pack ") #pragma message("You do not seem to have the Visual C++ Processor Pack ")
#pragma message("installed, so use of SSE2 intrinsics will be disabled.") #pragma message("installed, so use of SSE2 intrinsics will be disabled.")
#elif defined(__GNUC__) && defined(__i386__) #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. compiler option. Use of SSE2 intrinsics will be disabled.
*/ */
#endif #endif
...@@ -109,7 +108,7 @@ CPP_TYPENAME AllocatorBase<T>::pointer AlignedAllocator<T>::allocate( ...@@ -109,7 +108,7 @@ CPP_TYPENAME AllocatorBase<T>::pointer AlignedAllocator<T>::allocate(
assert(IsAlignedOn(p, 16)); assert(IsAlignedOn(p, 16));
return (T*)p; return (T*)p;
} }
return new (tc) T[n]; return new T[n];
} }
...@@ -178,7 +177,7 @@ DWord() {} ...@@ -178,7 +177,7 @@ DWord() {}
#elif defined(__DECCXX) #elif defined(__DECCXX)
r.halfs_.high = asm("umulh %a0, %a1, %v0", a, b); r.halfs_.high = asm("umulh %a0, %a1, %v0", a, b);
#else #else
#error unsupported alpha compiler for asm multiply overflow #error can not implement multiply overflow
#endif #endif
#elif defined(__ia64__) #elif defined(__ia64__)
r.halfs_.low = a*b; r.halfs_.low = a*b;
...@@ -392,6 +391,7 @@ S DivideThreeWordsByTwo(S* A, S B0, S B1, D* dummy_VC6_WorkAround = 0) ...@@ -392,6 +391,7 @@ S DivideThreeWordsByTwo(S* A, S B0, S B1, D* dummy_VC6_WorkAround = 0)
return Q; return Q;
} }
// do a 4 word by 2 word divide, returns 2 word quotient in Q0 and Q1 // do a 4 word by 2 word divide, returns 2 word quotient in Q0 and Q1
template <class S, class D> template <class S, class D>
inline D DivideFourWordsByTwo(S *T, const D &Al, const D &Ah, const D &B) 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) ...@@ -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) static int Compare(const word *A, const word *B, unsigned int N)
{ {
while (N--) while (N--)
...@@ -2308,85 +2248,6 @@ void RecursiveMultiplyBottom(word *R, word *T, const word *A, const word *B, ...@@ -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, void RecursiveMultiplyTop(word *R, word *T, const word *L, const word *A,
const word *B, unsigned int N) const word *B, unsigned int N)
...@@ -2739,20 +2600,6 @@ Integer::Integer(word value, unsigned int length) ...@@ -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, Integer::Integer(const byte *encodedInteger, unsigned int byteCount,
Signedness s) Signedness s)
{ {
...@@ -3358,76 +3205,6 @@ Integer Integer::Times(const Integer &b) const ...@@ -3358,76 +3205,6 @@ Integer Integer::Times(const Integer &b) const
#undef R2 #undef R2
#undef R3 #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) 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) ...@@ -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) 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 Integer Integer::InverseMod(const Integer &m) const
...@@ -3955,7 +3732,7 @@ Integer ModularArithmetic::CascadeExponentiate(const Integer &x, ...@@ -3955,7 +3732,7 @@ Integer ModularArithmetic::CascadeExponentiate(const Integer &x,
dr.ConvertIn(y), e2)); dr.ConvertIn(y), e2));
} }
else else
return AbstractRing<Integer>::CascadeExponentiate(x, e1, y, e2); return AbstractRing::CascadeExponentiate(x, e1, y, e2);
} }
void ModularArithmetic::SimultaneousExponentiate(Integer *results, void ModularArithmetic::SimultaneousExponentiate(Integer *results,
...@@ -3971,7 +3748,7 @@ void ModularArithmetic::SimultaneousExponentiate(Integer *results, ...@@ -3971,7 +3748,7 @@ void ModularArithmetic::SimultaneousExponentiate(Integer *results,
results[i] = dr.ConvertOut(results[i]); results[i] = dr.ConvertOut(results[i]);
} }
else else
AbstractRing<Integer>::SimultaneousExponentiate(results, base, AbstractRing::SimultaneousExponentiate(results, base,
exponents, exponentsCount); exponents, exponentsCount);
} }
...@@ -4170,10 +3947,6 @@ Integer CRT(const Integer &xp, const Integer &p, const Integer &xq, ...@@ -4170,10 +3947,6 @@ Integer CRT(const Integer &xp, const Integer &p, const Integer &xq,
} }
#ifdef __GNUC__ #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*); template unsigned int DivideThreeWordsByTwo<unsigned int, DWord>(unsigned int*, unsigned int, unsigned int, DWord*);
#endif #endif
......
...@@ -27,36 +27,9 @@ ...@@ -27,36 +27,9 @@
#include <new> // for NewHandler #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 { namespace TaoCrypt {
new_t tc; // for library new
inline void XorWords(word* r, const word* a, unsigned int n) inline void XorWords(word* r, const word* a, unsigned int n)
{ {
for (unsigned int i=0; i<n; i++) for (unsigned int i=0; i<n; i++)
......
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
#include "runtime.hpp" #include "runtime.hpp"
#include "random.hpp" #include "random.hpp"
#include "stdexcept.hpp"
#if defined(WIN32) #if defined(WIN32)
#define _WIN32_WINNT 0x0400 #define _WIN32_WINNT 0x0400
......
...@@ -27,7 +27,6 @@ ...@@ -27,7 +27,6 @@
#include "modarith.hpp" #include "modarith.hpp"
#include "stdexcept.hpp" #include "stdexcept.hpp"
#include "algebra.cpp" // for GCC 3.2 on aix ?
namespace TaoCrypt { namespace TaoCrypt {
...@@ -214,8 +213,6 @@ word32 SSL_Decrypt(const RSA_PublicKey& key, const byte* sig, byte* plain) ...@@ -214,8 +213,6 @@ word32 SSL_Decrypt(const RSA_PublicKey& key, const byte* sig, byte* plain)
#ifdef __GNUC__ #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 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 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_Decryptor<RSA_BlockType2>;
template class RSA_Encryptor<RSA_BlockType1>; template class RSA_Encryptor<RSA_BlockType1>;
template class RSA_Encryptor<RSA_BlockType2>; template class RSA_Encryptor<RSA_BlockType2>;
...@@ -227,11 +224,7 @@ template class RSA_Encryptor<RSA_BlockType2>; ...@@ -227,11 +224,7 @@ template class RSA_Encryptor<RSA_BlockType2>;
namespace mySTL { namespace mySTL {
template TaoCrypt::Integer* uninit_copy<TaoCrypt::Integer*, TaoCrypt::Integer*>(TaoCrypt::Integer*, TaoCrypt::Integer*, TaoCrypt::Integer*); 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::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::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 #endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment