Commit bac98672 authored by unknown's avatar unknown

Merge svojtovich@bk-internal.mysql.com:/home/bk/mysql-5.0

into mysql.com:/home/svoj/devel/mysql/yassl-mysql-5.0

parents 388d9df1 87459997
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#define yaSSL_BUFFER_HPP #define yaSSL_BUFFER_HPP
#include <assert.h> // assert #include <assert.h> // assert
#include "yassl_types.hpp" // ysDelete
#include "yassl_error.hpp" // Error #include "yassl_error.hpp" // Error
#include "memory.hpp" // mySTL::auto_ptr #include "memory.hpp" // mySTL::auto_ptr
#include "algorithm.hpp" // mySTL::swap #include "algorithm.hpp" // mySTL::swap
...@@ -183,7 +184,7 @@ inline void checked_delete(T* p) ...@@ -183,7 +184,7 @@ inline void checked_delete(T* p)
{ {
typedef char complete_type[sizeof(T) ? 1 : -1]; typedef char complete_type[sizeof(T) ? 1 : -1];
(void)sizeof(complete_type); (void)sizeof(complete_type);
delete p; ysDelete(p);
} }
......
...@@ -43,7 +43,7 @@ namespace yaSSL { ...@@ -43,7 +43,7 @@ namespace yaSSL {
// Digest policy should implement a get_digest, update, and get sizes for pad and // Digest policy should implement a get_digest, update, and get sizes for pad and
// digest // digest
struct Digest { struct Digest : public virtual_base {
virtual void get_digest(byte*) = 0; virtual void get_digest(byte*) = 0;
virtual void get_digest(byte*, const byte*, unsigned int) = 0; virtual void get_digest(byte*, const byte*, unsigned int) = 0;
virtual void update(const byte*, unsigned int) = 0; virtual void update(const byte*, unsigned int) = 0;
...@@ -178,7 +178,7 @@ private: ...@@ -178,7 +178,7 @@ private:
// BulkCipher policy should implement encrypt, decrypt, get block size, // BulkCipher policy should implement encrypt, decrypt, get block size,
// and set keys for encrypt and decrypt // and set keys for encrypt and decrypt
struct BulkCipher { struct BulkCipher : public virtual_base {
virtual void encrypt(byte*, const byte*, unsigned int) = 0; virtual void encrypt(byte*, const byte*, unsigned int) = 0;
virtual void decrypt(byte*, const byte*, unsigned int) = 0; virtual void decrypt(byte*, const byte*, unsigned int) = 0;
virtual void set_encryptKey(const byte*, const byte* = 0) = 0; virtual void set_encryptKey(const byte*, const byte* = 0) = 0;
...@@ -308,7 +308,7 @@ private: ...@@ -308,7 +308,7 @@ private:
// Authentication policy should implement sign, and verify // Authentication policy should implement sign, and verify
struct Auth { struct Auth : public virtual_base {
virtual void sign(byte*, const byte*, unsigned int, const RandomPool&) = 0; virtual void sign(byte*, const byte*, unsigned int, const RandomPool&) = 0;
virtual bool verify(const byte*, unsigned int, const byte*, virtual bool verify(const byte*, unsigned int, const byte*,
unsigned int) = 0; unsigned int) = 0;
......
...@@ -68,7 +68,7 @@ class Socket { ...@@ -68,7 +68,7 @@ class Socket {
socket_t socket_; // underlying socket descriptor socket_t socket_; // underlying socket descriptor
public: public:
explicit Socket(socket_t s = INVALID_SOCKET); explicit Socket(socket_t s = INVALID_SOCKET);
virtual ~Socket(); ~Socket();
void set_fd(socket_t s); void set_fd(socket_t s);
uint get_ready() const; uint get_ready() const;
......
...@@ -63,7 +63,7 @@ struct RecordLayerHeader { ...@@ -63,7 +63,7 @@ struct RecordLayerHeader {
// base for all messages // base for all messages
struct Message { struct Message : public virtual_base {
virtual input_buffer& set(input_buffer&) =0; virtual input_buffer& set(input_buffer&) =0;
virtual output_buffer& get(output_buffer&) const =0; virtual output_buffer& get(output_buffer&) const =0;
...@@ -175,7 +175,7 @@ private: ...@@ -175,7 +175,7 @@ private:
// Base Class for all handshake messages // Base Class for all handshake messages
class HandShakeBase { class HandShakeBase : public virtual_base {
int length_; int length_;
public: public:
int get_length() const; int get_length() const;
...@@ -327,7 +327,7 @@ private: ...@@ -327,7 +327,7 @@ private:
}; };
struct ServerKeyBase { struct ServerKeyBase : public virtual_base {
virtual ~ServerKeyBase() {} virtual ~ServerKeyBase() {}
virtual void build(SSL&) {} virtual void build(SSL&) {}
virtual void read(SSL&, input_buffer&) {} virtual void read(SSL&, input_buffer&) {}
...@@ -342,7 +342,7 @@ struct Fortezza_Server : public ServerKeyBase { ...@@ -342,7 +342,7 @@ struct Fortezza_Server : public ServerKeyBase {
}; };
struct SignatureBase { struct SignatureBase : public virtual_base {
virtual ~SignatureBase() {} virtual ~SignatureBase() {}
}; };
...@@ -461,7 +461,7 @@ struct PreMasterSecret { ...@@ -461,7 +461,7 @@ struct PreMasterSecret {
}; };
struct ClientKeyBase { struct ClientKeyBase : public virtual_base {
virtual ~ClientKeyBase() {} virtual ~ClientKeyBase() {}
virtual void build(SSL&) {} virtual void build(SSL&) {}
virtual void read(SSL&, input_buffer&) {} virtual void read(SSL&, input_buffer&) {}
......
...@@ -28,10 +28,55 @@ ...@@ -28,10 +28,55 @@
#define yaSSL_TYPES_HPP #define yaSSL_TYPES_HPP
#include <stddef.h> #include <stddef.h>
#include <assert.h>
#include "type_traits.hpp"
namespace yaSSL { 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);
void operator delete (void*, yaSSL::new_t);
void operator delete[](void*, yaSSL::new_t);
namespace yaSSL {
template<typename T>
void ysDelete(T* ptr)
{
if (ptr) ptr->~T();
::operator delete(ptr, yaSSL::ys);
}
template<typename T>
void ysArrayDelete(T* ptr)
{
// can't do array placement destruction since not tracking size in
// allocation, only allow builtins to use array placement since they
// don't need destructors called
typedef char builtin[TaoCrypt::IsFundamentalType<T>::Yes ? 1 : -1];
(void)sizeof(builtin);
::operator delete[](ptr, yaSSL::ys);
}
// to resolve compiler generated operator delete on base classes with
// virtual destructors, make sure doesn't get called
class virtual_base {
public:
static void operator delete(void*) { assert(0); }
};
typedef unsigned char uint8; typedef unsigned char uint8;
typedef unsigned short uint16; typedef unsigned short uint16;
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#define mySTL_HELPERS_HPP #define mySTL_HELPERS_HPP
#include <stdlib.h> #include <stdlib.h>
#include <new> // placement new
#ifdef __IBMCPP__ #ifdef __IBMCPP__
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
#include "helpers.hpp" #include "helpers.hpp"
#include <new> // ::operator new and delete, placement too #include <stdlib.h>
namespace mySTL { namespace mySTL {
...@@ -38,13 +38,15 @@ namespace mySTL { ...@@ -38,13 +38,15 @@ namespace mySTL {
template<typename T> template<typename T>
class list { class list {
#ifdef __SUNPRO_CC #ifdef __SUNPRO_CC
/* /*
Sun Forte 7 C++ v. 5.4 needs class 'node' be public to be visible to Sun Forte 7 C++ v. 5.4 needs class 'node' public to be visible to
the nested class 'iterator' (a non-standard behaviour). the nested class 'iterator' (a non-standard behaviour).
*/ */
public: public:
#endif #endif
struct node { struct node {
node(T t) : prev_(0), next_(0), value_(t) {} node(T t) : prev_(0), next_(0), value_(t) {}
...@@ -94,22 +96,22 @@ public: ...@@ -94,22 +96,22 @@ public:
return *this; return *this;
} }
iterator& operator++(int) iterator operator++(int)
{ {
iterator tmp = *this; iterator tmp = *this;
current_ = current_->next_; current_ = current_->next_;
return *this; return tmp;
} }
iterator& operator--(int) iterator operator--(int)
{ {
iterator tmp = *this; iterator tmp = *this;
current_ = current_->prev_; current_ = current_->prev_;
return *this; return tmp;
} }
bool operator==(const iterator& other) const bool operator==(const iterator& other) const
{ {
return current_ == other.current_; return current_ == other.current_;
} }
...@@ -152,7 +154,7 @@ list<T>::~list() ...@@ -152,7 +154,7 @@ list<T>::~list()
for (; start; start = next_) { for (; start; start = next_) {
next_ = start->next_; next_ = start->next_;
destroy(start); destroy(start);
::operator delete(start); free(start);
} }
} }
...@@ -160,7 +162,7 @@ list<T>::~list() ...@@ -160,7 +162,7 @@ list<T>::~list()
template<typename T> template<typename T>
void list<T>::push_front(T t) void list<T>::push_front(T t)
{ {
void* mem = ::operator new(sizeof(node)); void* mem = malloc(sizeof(node));
if (!mem) abort(); if (!mem) abort();
node* add = new (mem) node(t); node* add = new (mem) node(t);
...@@ -190,7 +192,7 @@ void list<T>::pop_front() ...@@ -190,7 +192,7 @@ void list<T>::pop_front()
head_->prev_ = 0; head_->prev_ = 0;
} }
destroy(front); destroy(front);
::operator delete(front); free(front);
--sz_; --sz_;
} }
...@@ -206,7 +208,7 @@ T list<T>::front() const ...@@ -206,7 +208,7 @@ T list<T>::front() const
template<typename T> template<typename T>
void list<T>::push_back(T t) void list<T>::push_back(T t)
{ {
void* mem = ::operator new(sizeof(node)); void* mem = malloc(sizeof(node));
if (!mem) abort(); if (!mem) abort();
node* add = new (mem) node(t); node* add = new (mem) node(t);
...@@ -236,7 +238,7 @@ void list<T>::pop_back() ...@@ -236,7 +238,7 @@ void list<T>::pop_back()
tail_->next_ = 0; tail_->next_ = 0;
} }
destroy(rear); destroy(rear);
::operator delete(rear); free(rear);
--sz_; --sz_;
} }
...@@ -280,7 +282,7 @@ bool list<T>::remove(T t) ...@@ -280,7 +282,7 @@ bool list<T>::remove(T t)
del->next_->prev_ = del->prev_; del->next_->prev_ = del->prev_;
destroy(del); destroy(del);
::operator delete(del); free(del);
--sz_; --sz_;
} }
return true; return true;
...@@ -303,7 +305,7 @@ bool list<T>::erase(iterator iter) ...@@ -303,7 +305,7 @@ bool list<T>::erase(iterator iter)
del->next_->prev_ = del->prev_; del->next_->prev_ = del->prev_;
destroy(del); destroy(del);
::operator delete(del); free(del);
--sz_; --sz_;
} }
return true; return true;
......
...@@ -37,30 +37,42 @@ ...@@ -37,30 +37,42 @@
namespace mySTL { namespace mySTL {
template<typename T> template<typename T, typename Deletor = void (*) (T*)>
struct auto_ptr_ref { struct auto_ptr_ref {
T* ptr_; T* ptr_;
explicit auto_ptr_ref(T* p) : ptr_(p) {} Deletor del_;
auto_ptr_ref(T* p, Deletor d) : ptr_(p), del_(d) {}
}; };
template<typename T> template<typename T, typename Deletor = void (*) (T*)>
class auto_ptr { class auto_ptr {
T* ptr_; T* ptr_;
Deletor del_;
void Destroy()
{
del_(ptr_);
}
public: public:
explicit auto_ptr(T* p = 0) : ptr_(p) {} auto_ptr(T* p, Deletor d) : ptr_(p), del_(d) {}
explicit auto_ptr(Deletor d) : ptr_(0), del_(d) {}
~auto_ptr() ~auto_ptr()
{ {
delete ptr_; Destroy();
} }
auto_ptr(auto_ptr& other) : ptr_(other.release()) {} auto_ptr(auto_ptr& other) : ptr_(other.release()), del_(other.del_) {}
auto_ptr& operator=(auto_ptr& that) auto_ptr& operator=(auto_ptr& that)
{ {
if (this != &that) { if (this != &that) {
delete ptr_; Destroy();
ptr_ = that.release(); ptr_ = that.release();
del_ = that.del_;
} }
return *this; return *this;
} }
...@@ -91,19 +103,20 @@ public: ...@@ -91,19 +103,20 @@ public:
void reset(T* p = 0) void reset(T* p = 0)
{ {
if (ptr_ != p) { if (ptr_ != p) {
delete ptr_; Destroy();
ptr_ = p; ptr_ = p;
} }
} }
// auto_ptr_ref conversions // auto_ptr_ref conversions
auto_ptr(auto_ptr_ref<T> ref) : ptr_(ref.ptr_) {} auto_ptr(auto_ptr_ref<T> ref) : ptr_(ref.ptr_), del_(ref.del_) {}
auto_ptr& operator=(auto_ptr_ref<T> ref) auto_ptr& operator=(auto_ptr_ref<T> ref)
{ {
if (this->ptr_ != ref.ptr_) { if (this->ptr_ != ref.ptr_) {
delete ptr_; Destroy();
ptr_ = ref.ptr_; ptr_ = ref.ptr_;
del_ = ref.del_;
} }
return *this; return *this;
} }
...@@ -111,13 +124,13 @@ public: ...@@ -111,13 +124,13 @@ public:
template<typename T2> template<typename T2>
operator auto_ptr<T2>() operator auto_ptr<T2>()
{ {
return auto_ptr<T2>(this->release()); return auto_ptr<T2>(this->release(), this->del_);
} }
template<typename T2> template<typename T2>
operator auto_ptr_ref<T2>() operator auto_ptr_ref<T2>()
{ {
return auto_ptr_ref<T2>(this->release()); return auto_ptr_ref<T2>(this->release(), this->del_);
} }
}; };
......
...@@ -27,11 +27,10 @@ ...@@ -27,11 +27,10 @@
#ifndef mySTL_VECTOR_HPP #ifndef mySTL_VECTOR_HPP
#define mySTL_VECTOR_HPP #define mySTL_VECTOR_HPP
#include "helpers.hpp" // construct, destory, fill, etc. #include "helpers.hpp" // construct, destory, fill, etc.
#include "algorithm.hpp" // swap #include "algorithm.hpp" // swap
#include <new> // ::operator new and delete, placement too
#include <assert.h> // assert #include <assert.h> // assert
#include <stdlib.h> // malloc
namespace mySTL { namespace mySTL {
...@@ -46,13 +45,13 @@ struct vector_base { ...@@ -46,13 +45,13 @@ struct vector_base {
vector_base() : start_(0), finish_(0), end_of_storage_(0) {} vector_base() : start_(0), finish_(0), end_of_storage_(0) {}
vector_base(size_t n) vector_base(size_t n)
{ {
start_ = static_cast<T*>(::operator new(n * sizeof(T))); start_ = static_cast<T*>(malloc(n * sizeof(T)));
if (!start_) abort(); if (!start_) abort();
finish_ = start_; finish_ = start_;
end_of_storage_ = start_ + n; end_of_storage_ = start_ + n;
} }
~vector_base() { ::operator delete(start_); } ~vector_base() { if (start_) free(start_); }
void Swap(vector_base& that) void Swap(vector_base& that)
{ {
......
...@@ -3,5 +3,5 @@ INCLUDES = -I../include -I../taocrypt/include -I../mySTL ...@@ -3,5 +3,5 @@ INCLUDES = -I../include -I../taocrypt/include -I../mySTL
noinst_LIBRARIES = libyassl.a noinst_LIBRARIES = libyassl.a
libyassl_a_SOURCES = buffer.cpp cert_wrapper.cpp crypto_wrapper.cpp \ libyassl_a_SOURCES = buffer.cpp cert_wrapper.cpp crypto_wrapper.cpp \
handshake.cpp lock.cpp log.cpp socket_wrapper.cpp ssl.cpp \ handshake.cpp lock.cpp log.cpp socket_wrapper.cpp ssl.cpp \
timer.cpp yassl_imp.cpp yassl_error.cpp yassl_int.cpp template_instnt.cpp timer.cpp yassl_imp.cpp yassl_error.cpp yassl_int.cpp
EXTRA_DIST = ../include/*.hpp ../include/openssl/*.h EXTRA_DIST = ../include/*.hpp ../include/openssl/*.h
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
* with SSL types and sockets * with SSL types and sockets
*/ */
#include "runtime.hpp"
#include "buffer.hpp" #include "buffer.hpp"
#include "yassl_types.hpp" #include "yassl_types.hpp"
...@@ -62,13 +61,13 @@ input_buffer::input_buffer() ...@@ -62,13 +61,13 @@ input_buffer::input_buffer()
input_buffer::input_buffer(uint s) input_buffer::input_buffer(uint s)
: size_(0), current_(0), buffer_(new byte[s]), end_(buffer_ + s) : size_(0), current_(0), buffer_(new (ys) 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 byte[s]), end_(buffer_ + s) : size_(0), current_(0), buffer_(new (ys) byte[s]), end_(buffer_ + s)
{ {
assign(t, len); assign(t, len);
} }
...@@ -76,7 +75,7 @@ input_buffer::input_buffer(uint s, const byte* t, uint len) ...@@ -76,7 +75,7 @@ input_buffer::input_buffer(uint s, const byte* t, uint len)
input_buffer::~input_buffer() input_buffer::~input_buffer()
{ {
delete [] buffer_; ysArrayDelete(buffer_);
} }
...@@ -84,7 +83,7 @@ input_buffer::~input_buffer() ...@@ -84,7 +83,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 byte[s]; buffer_ = new (ys) byte[s];
end_ = buffer_ + s; end_ = buffer_ + s;
} }
...@@ -96,7 +95,7 @@ byte* input_buffer::get_buffer() const ...@@ -96,7 +95,7 @@ byte* input_buffer::get_buffer() const
} }
// after a raw write user can set new size // after a raw write user can set new (ys) size
// if you know the size before the write use assign() // if you know the size before the write use assign()
void input_buffer::add_size(uint i) void input_buffer::add_size(uint i)
{ {
...@@ -198,13 +197,13 @@ output_buffer::output_buffer() ...@@ -198,13 +197,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 byte[s]), end_(buffer_ + s) : current_(0), buffer_(new (ys) 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 byte[s]), end_(buffer_+ s) : current_(0), buffer_(new (ys) byte[s]), end_(buffer_+ s)
{ {
write(t, len); write(t, len);
} }
...@@ -212,7 +211,7 @@ output_buffer::output_buffer(uint s, const byte* t, uint len) ...@@ -212,7 +211,7 @@ output_buffer::output_buffer(uint s, const byte* t, uint len)
output_buffer::~output_buffer() output_buffer::~output_buffer()
{ {
delete [] buffer_; ysArrayDelete(buffer_);
} }
...@@ -239,7 +238,7 @@ void output_buffer::set_current(uint c) ...@@ -239,7 +238,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 byte[s]; end_ = buffer_ + s; buffer_ = new (ys) byte[s]; end_ = buffer_ + s;
} }
......
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
* *
*/ */
#include "runtime.hpp"
#include "cert_wrapper.hpp" #include "cert_wrapper.hpp"
#include "yassl_int.hpp" #include "yassl_int.hpp"
...@@ -39,19 +38,19 @@ ...@@ -39,19 +38,19 @@
namespace yaSSL { namespace yaSSL {
x509::x509(uint sz) : length_(sz), buffer_(new opaque[sz]) x509::x509(uint sz) : length_(sz), buffer_(new (ys) opaque[sz])
{ {
} }
x509::~x509() x509::~x509()
{ {
delete [] buffer_; ysArrayDelete(buffer_);
} }
x509::x509(const x509& that) : length_(that.length_), x509::x509(const x509& that) : length_(that.length_),
buffer_(new opaque[length_]) buffer_(new (ys) opaque[length_])
{ {
memcpy(buffer_, that.buffer_, length_); memcpy(buffer_, that.buffer_, length_);
} }
...@@ -98,7 +97,7 @@ CertManager::CertManager() ...@@ -98,7 +97,7 @@ CertManager::CertManager()
CertManager::~CertManager() CertManager::~CertManager()
{ {
delete peerX509_; ysDelete(peerX509_);
mySTL::for_each(signers_.begin(), signers_.end(), del_ptr_zero()) ; mySTL::for_each(signers_.begin(), signers_.end(), del_ptr_zero()) ;
...@@ -153,7 +152,7 @@ void CertManager::AddPeerCert(x509* x) ...@@ -153,7 +152,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 x509(*x)); list_.push_back(new (ys) x509(*x));
} }
...@@ -165,7 +164,7 @@ int CertManager::CopyCaCert(const x509* x) ...@@ -165,7 +164,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 TaoCrypt::Signer(key.GetKey(), key.size(), signers_.push_back(new (ys) TaoCrypt::Signer(key.GetKey(), key.size(),
cert.GetCommonName(), cert.GetHash())); cert.GetCommonName(), cert.GetHash()));
} }
return cert.GetError().What(); return cert.GetError().What();
...@@ -234,7 +233,7 @@ int CertManager::Validate() ...@@ -234,7 +233,7 @@ int CertManager::Validate()
return err; return err;
const TaoCrypt::PublicKey& key = cert.GetPublicKey(); const TaoCrypt::PublicKey& key = cert.GetPublicKey();
signers_.push_back(new TaoCrypt::Signer(key.GetKey(), key.size(), signers_.push_back(new (ys) TaoCrypt::Signer(key.GetKey(), key.size(),
cert.GetCommonName(), cert.GetHash())); cert.GetCommonName(), cert.GetHash()));
--last; --last;
--count; --count;
...@@ -259,7 +258,7 @@ int CertManager::Validate() ...@@ -259,7 +258,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 X509(cert.GetIssuer(), iSz, cert.GetCommonName(), peerX509_ = new (ys) X509(cert.GetIssuer(), iSz, cert.GetCommonName(),
sSz); sSz);
} }
return 0; return 0;
......
...@@ -58,13 +58,13 @@ struct MD5::MD5Impl { ...@@ -58,13 +58,13 @@ struct MD5::MD5Impl {
}; };
MD5::MD5() : pimpl_(new MD5Impl) {} MD5::MD5() : pimpl_(new (ys) MD5Impl) {}
MD5::~MD5() { delete pimpl_; } MD5::~MD5() { ysDelete(pimpl_); }
MD5::MD5(const MD5& that) : Digest(), pimpl_(new MD5::MD5(const MD5& that) : Digest(), pimpl_(new (ys)
MD5Impl(that.pimpl_->md5_)) {} MD5Impl(that.pimpl_->md5_)) {}
...@@ -116,13 +116,13 @@ struct SHA::SHAImpl { ...@@ -116,13 +116,13 @@ struct SHA::SHAImpl {
}; };
SHA::SHA() : pimpl_(new SHAImpl) {} SHA::SHA() : pimpl_(new (ys) SHAImpl) {}
SHA::~SHA() { delete pimpl_; } SHA::~SHA() { ysDelete(pimpl_); }
SHA::SHA(const SHA& that) : Digest(), pimpl_(new SHAImpl(that.pimpl_->sha_)) {} SHA::SHA(const SHA& that) : Digest(), pimpl_(new (ys) SHAImpl(that.pimpl_->sha_)) {}
SHA& SHA::operator=(const SHA& that) SHA& SHA::operator=(const SHA& that)
{ {
...@@ -173,13 +173,13 @@ struct RMD::RMDImpl { ...@@ -173,13 +173,13 @@ struct RMD::RMDImpl {
}; };
RMD::RMD() : pimpl_(new RMDImpl) {} RMD::RMD() : pimpl_(new (ys) RMDImpl) {}
RMD::~RMD() { delete pimpl_; } RMD::~RMD() { ysDelete(pimpl_); }
RMD::RMD(const RMD& that) : Digest(), pimpl_(new RMDImpl(that.pimpl_->rmd_)) {} RMD::RMD(const RMD& that) : Digest(), pimpl_(new (ys) RMDImpl(that.pimpl_->rmd_)) {}
RMD& RMD::operator=(const RMD& that) RMD& RMD::operator=(const RMD& that)
{ {
...@@ -230,13 +230,13 @@ struct HMAC_MD5::HMAC_MD5Impl { ...@@ -230,13 +230,13 @@ 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 HMAC_MD5Impl) : pimpl_(new (ys) HMAC_MD5Impl)
{ {
pimpl_->mac_.SetKey(secret, len); pimpl_->mac_.SetKey(secret, len);
} }
HMAC_MD5::~HMAC_MD5() { delete pimpl_; } HMAC_MD5::~HMAC_MD5() { ysDelete(pimpl_); }
uint HMAC_MD5::get_digestSize() const uint HMAC_MD5::get_digestSize() const
...@@ -280,13 +280,13 @@ struct HMAC_SHA::HMAC_SHAImpl { ...@@ -280,13 +280,13 @@ 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 HMAC_SHAImpl) : pimpl_(new (ys) HMAC_SHAImpl)
{ {
pimpl_->mac_.SetKey(secret, len); pimpl_->mac_.SetKey(secret, len);
} }
HMAC_SHA::~HMAC_SHA() { delete pimpl_; } HMAC_SHA::~HMAC_SHA() { ysDelete(pimpl_); }
uint HMAC_SHA::get_digestSize() const uint HMAC_SHA::get_digestSize() const
...@@ -331,13 +331,13 @@ struct HMAC_RMD::HMAC_RMDImpl { ...@@ -331,13 +331,13 @@ 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 HMAC_RMDImpl) : pimpl_(new (ys) HMAC_RMDImpl)
{ {
pimpl_->mac_.SetKey(secret, len); pimpl_->mac_.SetKey(secret, len);
} }
HMAC_RMD::~HMAC_RMD() { delete pimpl_; } HMAC_RMD::~HMAC_RMD() { ysDelete(pimpl_); }
uint HMAC_RMD::get_digestSize() const uint HMAC_RMD::get_digestSize() const
...@@ -379,9 +379,9 @@ struct DES::DESImpl { ...@@ -379,9 +379,9 @@ struct DES::DESImpl {
}; };
DES::DES() : pimpl_(new DESImpl) {} DES::DES() : pimpl_(new (ys) DESImpl) {}
DES::~DES() { delete pimpl_; } DES::~DES() { ysDelete(pimpl_); }
void DES::set_encryptKey(const byte* k, const byte* iv) void DES::set_encryptKey(const byte* k, const byte* iv)
...@@ -415,9 +415,9 @@ struct DES_EDE::DES_EDEImpl { ...@@ -415,9 +415,9 @@ struct DES_EDE::DES_EDEImpl {
}; };
DES_EDE::DES_EDE() : pimpl_(new DES_EDEImpl) {} DES_EDE::DES_EDE() : pimpl_(new (ys) DES_EDEImpl) {}
DES_EDE::~DES_EDE() { delete pimpl_; } DES_EDE::~DES_EDE() { ysDelete(pimpl_); }
void DES_EDE::set_encryptKey(const byte* k, const byte* iv) void DES_EDE::set_encryptKey(const byte* k, const byte* iv)
...@@ -453,9 +453,9 @@ struct RC4::RC4Impl { ...@@ -453,9 +453,9 @@ struct RC4::RC4Impl {
}; };
RC4::RC4() : pimpl_(new RC4Impl) {} RC4::RC4() : pimpl_(new (ys) RC4Impl) {}
RC4::~RC4() { delete pimpl_; } RC4::~RC4() { ysDelete(pimpl_); }
void RC4::set_encryptKey(const byte* k, const byte*) void RC4::set_encryptKey(const byte* k, const byte*)
...@@ -495,9 +495,9 @@ struct AES::AESImpl { ...@@ -495,9 +495,9 @@ struct AES::AESImpl {
}; };
AES::AES(unsigned int ks) : pimpl_(new AESImpl(ks)) {} AES::AES(unsigned int ks) : pimpl_(new (ys) AESImpl(ks)) {}
AES::~AES() { delete pimpl_; } AES::~AES() { ysDelete(pimpl_); }
int AES::get_keySize() const int AES::get_keySize() const
...@@ -536,9 +536,9 @@ struct RandomPool::RandomImpl { ...@@ -536,9 +536,9 @@ struct RandomPool::RandomImpl {
TaoCrypt::RandomNumberGenerator RNG_; TaoCrypt::RandomNumberGenerator RNG_;
}; };
RandomPool::RandomPool() : pimpl_(new RandomImpl) {} RandomPool::RandomPool() : pimpl_(new (ys) RandomImpl) {}
RandomPool::~RandomPool() { delete pimpl_; } RandomPool::~RandomPool() { ysDelete(pimpl_); }
int RandomPool::GetError() const int RandomPool::GetError() const
{ {
...@@ -580,7 +580,7 @@ void DSS::DSSImpl::SetPrivate(const byte* key, unsigned int sz) ...@@ -580,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 DSSImpl) : pimpl_(new (ys) DSSImpl)
{ {
if (publicKey) if (publicKey)
pimpl_->SetPublic(key, sz); pimpl_->SetPublic(key, sz);
...@@ -591,7 +591,7 @@ DSS::DSS(const byte* key, unsigned int sz, bool publicKey) ...@@ -591,7 +591,7 @@ DSS::DSS(const byte* key, unsigned int sz, bool publicKey)
DSS::~DSS() DSS::~DSS()
{ {
delete pimpl_; ysDelete(pimpl_);
} }
...@@ -651,7 +651,7 @@ void RSA::RSAImpl::SetPrivate(const byte* key, unsigned int sz) ...@@ -651,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 RSAImpl) : pimpl_(new (ys) RSAImpl)
{ {
if (publicKey) if (publicKey)
pimpl_->SetPublic(key, sz); pimpl_->SetPublic(key, sz);
...@@ -661,7 +661,7 @@ RSA::RSA(const byte* key, unsigned int sz, bool publicKey) ...@@ -661,7 +661,7 @@ RSA::RSA(const byte* key, unsigned int sz, bool publicKey)
RSA::~RSA() RSA::~RSA()
{ {
delete pimpl_; ysDelete(pimpl_);
} }
...@@ -723,13 +723,13 @@ struct Integer::IntegerImpl { ...@@ -723,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 IntegerImpl) {} Integer::Integer() : pimpl_(new (ys) IntegerImpl) {}
Integer::~Integer() { delete pimpl_; } Integer::~Integer() { ysDelete(pimpl_); }
Integer::Integer(const Integer& other) : pimpl_(new Integer::Integer(const Integer& other) : pimpl_(new (ys)
IntegerImpl(other.pimpl_->int_)) IntegerImpl(other.pimpl_->int_))
{} {}
...@@ -757,7 +757,12 @@ struct DiffieHellman::DHImpl { ...@@ -757,7 +757,12 @@ struct DiffieHellman::DHImpl {
DHImpl(TaoCrypt::RandomNumberGenerator& r) : ranPool_(r), publicKey_(0), DHImpl(TaoCrypt::RandomNumberGenerator& r) : ranPool_(r), publicKey_(0),
privateKey_(0), agreedKey_(0) {} privateKey_(0), agreedKey_(0) {}
~DHImpl() {delete[] agreedKey_; delete[] privateKey_; delete[] publicKey_;} ~DHImpl()
{
ysArrayDelete(agreedKey_);
ysArrayDelete(privateKey_);
ysArrayDelete(publicKey_);
}
DHImpl(const DHImpl& that) : dh_(that.dh_), ranPool_(that.ranPool_), DHImpl(const DHImpl& that) : dh_(that.dh_), ranPool_(that.ranPool_),
publicKey_(0), privateKey_(0), agreedKey_(0) publicKey_(0), privateKey_(0), agreedKey_(0)
...@@ -768,9 +773,9 @@ struct DiffieHellman::DHImpl { ...@@ -768,9 +773,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 byte[pubSz]; publicKey_ = new (ys) byte[pubSz];
privateKey_ = new byte[privSz]; privateKey_ = new (ys) byte[privSz];
agreedKey_ = new byte[agrSz]; agreedKey_ = new (ys) byte[agrSz];
} }
}; };
...@@ -779,7 +784,7 @@ struct DiffieHellman::DHImpl { ...@@ -779,7 +784,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 DHImpl(random.pimpl_->RNG_)) : pimpl_(new (ys) DHImpl(random.pimpl_->RNG_))
{ {
using namespace TaoCrypt; using namespace TaoCrypt;
Source source; Source source;
...@@ -803,12 +808,12 @@ DiffieHellman::DiffieHellman(const char* file, const RandomPool& random) ...@@ -803,12 +808,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 DHImpl(random.pimpl_->RNG_)) : pimpl_(new (ys) 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 opaque[pubSz]; pimpl_->publicKey_ = new (ys) opaque[pubSz];
memcpy(pimpl_->publicKey_, pub, pubSz); memcpy(pimpl_->publicKey_, pub, pubSz);
} }
...@@ -816,7 +821,7 @@ DiffieHellman::DiffieHellman(const byte* p, unsigned int pSz, const byte* g, ...@@ -816,7 +821,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 DHImpl(random.pimpl_->RNG_)) : pimpl_(new (ys) DHImpl(random.pimpl_->RNG_))
{ {
using TaoCrypt::Integer; using TaoCrypt::Integer;
...@@ -829,12 +834,12 @@ DiffieHellman::DiffieHellman(const Integer& p, const Integer& g, ...@@ -829,12 +834,12 @@ DiffieHellman::DiffieHellman(const Integer& p, const Integer& g,
pimpl_->publicKey_); pimpl_->publicKey_);
} }
DiffieHellman::~DiffieHellman() { delete pimpl_; } DiffieHellman::~DiffieHellman() { ysDelete(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 DHImpl(*that.pimpl_)) : pimpl_(new (ys) DHImpl(*that.pimpl_))
{ {
pimpl_->dh_.GenerateKeyPair(pimpl_->ranPool_, pimpl_->privateKey_, pimpl_->dh_.GenerateKeyPair(pimpl_->ranPool_, pimpl_->privateKey_,
pimpl_->publicKey_); pimpl_->publicKey_);
...@@ -955,7 +960,7 @@ x509* PemToDer(const char* fname, CertType type) ...@@ -955,7 +960,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 x509(sz)); mySTL::auto_ptr<x509> x(new (ys) x509(sz), ysDelete);
memcpy(x->use_buffer(), der.get_buffer(), sz); memcpy(x->use_buffer(), der.get_buffer(), sz);
fclose(file); fclose(file);
...@@ -965,10 +970,25 @@ x509* PemToDer(const char* fname, CertType type) ...@@ -965,10 +970,25 @@ x509* PemToDer(const char* fname, CertType type)
} // namespace } // namespace
#ifdef __GNUC__ #ifdef __GNUC__
template class TaoCrypt::HMAC<TaoCrypt::MD5>; namespace yaSSL {
template class TaoCrypt::HMAC<TaoCrypt::SHA>; template void ysDelete<DiffieHellman::DHImpl>(DiffieHellman::DHImpl*);
template class TaoCrypt::HMAC<TaoCrypt::RIPEMD160>; template void ysDelete<Integer::IntegerImpl>(Integer::IntegerImpl*);
#endif template void ysDelete<RSA::RSAImpl>(RSA::RSAImpl*);
template void ysDelete<DSS::DSSImpl>(DSS::DSSImpl*);
template void ysDelete<RandomPool::RandomImpl>(RandomPool::RandomImpl*);
template void ysDelete<AES::AESImpl>(AES::AESImpl*);
template void ysDelete<RC4::RC4Impl>(RC4::RC4Impl*);
template void ysDelete<DES_EDE::DES_EDEImpl>(DES_EDE::DES_EDEImpl*);
template void ysDelete<DES::DESImpl>(DES::DESImpl*);
template void ysDelete<HMAC_RMD::HMAC_RMDImpl>(HMAC_RMD::HMAC_RMDImpl*);
template void ysDelete<HMAC_SHA::HMAC_SHAImpl>(HMAC_SHA::HMAC_SHAImpl*);
template void ysDelete<HMAC_MD5::HMAC_MD5Impl>(HMAC_MD5::HMAC_MD5Impl*);
template void ysDelete<RMD::RMDImpl>(RMD::RMDImpl*);
template void ysDelete<SHA::SHAImpl>(SHA::SHAImpl*);
template void ysDelete<MD5::MD5Impl>(MD5::MD5Impl*);
}
#endif // __GNUC__
#endif // !USE_CRYPTOPP_LIB #endif // !USE_CRYPTOPP_LIB
...@@ -357,14 +357,14 @@ void p_hash(output_buffer& result, const output_buffer& secret, ...@@ -357,14 +357,14 @@ void p_hash(output_buffer& result, const output_buffer& secret,
uint lastLen = result.get_capacity() % len; uint lastLen = result.get_capacity() % len;
opaque previous[SHA_LEN]; // max size opaque previous[SHA_LEN]; // max size
opaque current[SHA_LEN]; // max size opaque current[SHA_LEN]; // max size
mySTL::auto_ptr<Digest> hmac; mySTL::auto_ptr<Digest> hmac(ysDelete);
if (lastLen) times += 1; if (lastLen) times += 1;
if (hash == md5) if (hash == md5)
hmac.reset(new HMAC_MD5(secret.get_buffer(), secret.get_size())); hmac.reset(new (ys) HMAC_MD5(secret.get_buffer(), secret.get_size()));
else else
hmac.reset(new HMAC_SHA(secret.get_buffer(), secret.get_size())); hmac.reset(new (ys) 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;
...@@ -571,7 +571,7 @@ void hmac(SSL& ssl, byte* digest, const byte* buffer, uint sz, ...@@ -571,7 +571,7 @@ void hmac(SSL& ssl, byte* digest, const byte* buffer, uint sz,
void TLS_hmac(SSL& ssl, byte* digest, const byte* buffer, uint sz, void TLS_hmac(SSL& ssl, byte* digest, const byte* buffer, uint sz,
ContentType content, bool verify) ContentType content, bool verify)
{ {
mySTL::auto_ptr<Digest> hmac; mySTL::auto_ptr<Digest> hmac(ysDelete);
opaque seq[SEQ_SZ] = { 0x00, 0x00, 0x00, 0x00 }; opaque seq[SEQ_SZ] = { 0x00, 0x00, 0x00, 0x00 };
opaque length[LENGTH_SZ]; opaque length[LENGTH_SZ];
opaque inner[SIZEOF_ENUM + VERSION_SZ + LENGTH_SZ]; // type + version + len opaque inner[SIZEOF_ENUM + VERSION_SZ + LENGTH_SZ]; // type + version + len
...@@ -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 HMAC_SHA(ssl.get_macSecret(verify), SHA_LEN)); hmac.reset(new (ys) HMAC_SHA(ssl.get_macSecret(verify), SHA_LEN));
else if (algo == rmd) else if (algo == rmd)
hmac.reset(new HMAC_RMD(ssl.get_macSecret(verify), RMD_LEN)); hmac.reset(new (ys) HMAC_RMD(ssl.get_macSecret(verify), RMD_LEN));
else else
hmac.reset(new HMAC_MD5(ssl.get_macSecret(verify), MD5_LEN)); hmac.reset(new (ys) 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
...@@ -648,7 +648,7 @@ void build_certHashes(SSL& ssl, Hashes& hashes) ...@@ -648,7 +648,7 @@ void build_certHashes(SSL& ssl, Hashes& hashes)
} }
mySTL::auto_ptr<input_buffer> null_buffer; mySTL::auto_ptr<input_buffer> null_buffer(ysDelete);
// do process input requests // do process input requests
mySTL::auto_ptr<input_buffer> mySTL::auto_ptr<input_buffer>
...@@ -666,7 +666,7 @@ DoProcessReply(SSL& ssl, mySTL::auto_ptr<input_buffer> buffered) ...@@ -666,7 +666,7 @@ DoProcessReply(SSL& ssl, mySTL::auto_ptr<input_buffer> buffered)
buffered = null_buffer; buffered = null_buffer;
} }
// add new data // add new (ys) data
uint read = ssl.getSocket().receive(buffer.get_buffer() + buffSz, ready); uint read = ssl.getSocket().receive(buffer.get_buffer() + buffSz, ready);
buffer.add_size(read); buffer.add_size(read);
uint offset = 0; uint offset = 0;
...@@ -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 input_buffer(sz, buffer.get_buffer() + buffered.reset(new (ys) input_buffer(sz, buffer.get_buffer() +
buffer.get_current() - RECORD_HEADER, sz)); buffer.get_current() - RECORD_HEADER, sz));
break; break;
} }
...@@ -696,7 +696,7 @@ DoProcessReply(SSL& ssl, mySTL::auto_ptr<input_buffer> buffered) ...@@ -696,7 +696,7 @@ DoProcessReply(SSL& ssl, mySTL::auto_ptr<input_buffer> buffered)
// each message in record // each message in record
if (ssl.getSecurity().get_parms().pending_ == false) // cipher on if (ssl.getSecurity().get_parms().pending_ == false) // cipher on
decrypt_message(ssl, buffer, hdr.length_); decrypt_message(ssl, buffer, hdr.length_);
mySTL::auto_ptr<Message> msg(mf.CreateObject(hdr.type_)); mySTL::auto_ptr<Message> msg(mf.CreateObject(hdr.type_), ysDelete);
if (!msg.get()) { if (!msg.get()) {
ssl.SetError(factory_error); ssl.SetError(factory_error);
return buffered = null_buffer; return buffered = null_buffer;
...@@ -715,7 +715,7 @@ DoProcessReply(SSL& ssl, mySTL::auto_ptr<input_buffer> buffered) ...@@ -715,7 +715,7 @@ DoProcessReply(SSL& ssl, mySTL::auto_ptr<input_buffer> buffered)
void processReply(SSL& ssl) void processReply(SSL& ssl)
{ {
if (ssl.GetError()) return; if (ssl.GetError()) return;
mySTL::auto_ptr<input_buffer> buffered; mySTL::auto_ptr<input_buffer> buffered(ysDelete);
for (;;) { for (;;) {
mySTL::auto_ptr<input_buffer> tmp = DoProcessReply(ssl, buffered); mySTL::auto_ptr<input_buffer> tmp = DoProcessReply(ssl, buffered);
...@@ -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 output_buffer); mySTL::auto_ptr<output_buffer> out(new (ys) output_buffer, ysDelete);
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 output_buffer); mySTL::auto_ptr<output_buffer> out(new (ys) output_buffer, ysDelete);
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 output_buffer); mySTL::auto_ptr<output_buffer> out(new (ys) output_buffer, ysDelete);
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 output_buffer); mySTL::auto_ptr<output_buffer> out(new (ys) output_buffer, ysDelete);
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 output_buffer); mySTL::auto_ptr<output_buffer> out(new (ys) output_buffer, ysDelete);
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 output_buffer); mySTL::auto_ptr<output_buffer> out(new (ys) output_buffer, ysDelete);
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 output_buffer); mySTL::auto_ptr<output_buffer> out(new (ys) output_buffer, ysDelete);
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 output_buffer); mySTL::auto_ptr<output_buffer> out(new (ys) output_buffer, ysDelete);
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 output_buffer); mySTL::auto_ptr<output_buffer> out(new (ys) output_buffer, ysDelete);
buildHeaders(ssl, hsHeader, rlHeader, verify); buildHeaders(ssl, hsHeader, rlHeader, verify);
buildOutput(*out.get(), rlHeader, hsHeader, verify); buildOutput(*out.get(), rlHeader, hsHeader, verify);
......
...@@ -22,7 +22,6 @@ ...@@ -22,7 +22,6 @@
/* Locking functions /* Locking functions
*/ */
#include "runtime.hpp"
#include "lock.hpp" #include "lock.hpp"
......
...@@ -22,7 +22,6 @@ ...@@ -22,7 +22,6 @@
/* Debug logging functions /* Debug logging functions
*/ */
#include "runtime.hpp"
#include "log.hpp" #include "log.hpp"
#ifdef YASSL_LOG #ifdef YASSL_LOG
......
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
*/ */
#include "runtime.hpp"
#include "socket_wrapper.hpp" #include "socket_wrapper.hpp"
#include "yassl_error.hpp" #include "yassl_error.hpp"
......
...@@ -32,7 +32,6 @@ ...@@ -32,7 +32,6 @@
/* see man pages for function descriptions */ /* see man pages for function descriptions */
#include "runtime.hpp"
#include "openssl/ssl.h" #include "openssl/ssl.h"
#include "handshake.hpp" #include "handshake.hpp"
#include "yassl_int.hpp" #include "yassl_int.hpp"
...@@ -52,25 +51,25 @@ SSL_METHOD* SSLv3_method() ...@@ -52,25 +51,25 @@ SSL_METHOD* SSLv3_method()
SSL_METHOD* SSLv3_server_method() SSL_METHOD* SSLv3_server_method()
{ {
return new SSL_METHOD(server_end, ProtocolVersion(3,0)); return new (ys) SSL_METHOD(server_end, ProtocolVersion(3,0));
} }
SSL_METHOD* SSLv3_client_method() SSL_METHOD* SSLv3_client_method()
{ {
return new SSL_METHOD(client_end, ProtocolVersion(3,0)); return new (ys) SSL_METHOD(client_end, ProtocolVersion(3,0));
} }
SSL_METHOD* TLSv1_server_method() SSL_METHOD* TLSv1_server_method()
{ {
return new SSL_METHOD(server_end, ProtocolVersion(3,1)); return new (ys) SSL_METHOD(server_end, ProtocolVersion(3,1));
} }
SSL_METHOD* TLSv1_client_method() SSL_METHOD* TLSv1_client_method()
{ {
return new SSL_METHOD(client_end, ProtocolVersion(3,1)); return new (ys) SSL_METHOD(client_end, ProtocolVersion(3,1));
} }
...@@ -83,25 +82,25 @@ SSL_METHOD* SSLv23_server_method() ...@@ -83,25 +82,25 @@ SSL_METHOD* SSLv23_server_method()
SSL_CTX* SSL_CTX_new(SSL_METHOD* method) SSL_CTX* SSL_CTX_new(SSL_METHOD* method)
{ {
return new SSL_CTX(method); return new (ys) SSL_CTX(method);
} }
void SSL_CTX_free(SSL_CTX* ctx) void SSL_CTX_free(SSL_CTX* ctx)
{ {
delete ctx; ysDelete(ctx);
} }
SSL* SSL_new(SSL_CTX* ctx) SSL* SSL_new(SSL_CTX* ctx)
{ {
return new SSL(ctx); return new (ys) SSL(ctx);
} }
void SSL_free(SSL* ssl) void SSL_free(SSL* ssl)
{ {
delete ssl; ysDelete(ssl);
} }
...@@ -443,7 +442,7 @@ int read_file(SSL_CTX* ctx, const char* file, int format, CertType type) ...@@ -443,7 +442,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 x509(sz); // takes ownership x = new (ys) 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);
...@@ -638,7 +637,7 @@ void OpenSSL_add_all_algorithms() // compatibility only ...@@ -638,7 +637,7 @@ void OpenSSL_add_all_algorithms() // compatibility only
DH* DH_new(void) DH* DH_new(void)
{ {
DH* dh = new DH; DH* dh = new (ys) DH;
if (dh) if (dh)
dh->p = dh->g = 0; dh->p = dh->g = 0;
return dh; return dh;
...@@ -647,9 +646,9 @@ DH* DH_new(void) ...@@ -647,9 +646,9 @@ DH* DH_new(void)
void DH_free(DH* dh) void DH_free(DH* dh)
{ {
delete dh->g; ysDelete(dh->g);
delete dh->p; ysDelete(dh->p);
delete dh; ysDelete(dh);
} }
...@@ -659,11 +658,11 @@ BIGNUM* BN_bin2bn(const unsigned char* num, int sz, BIGNUM* retVal) ...@@ -659,11 +658,11 @@ BIGNUM* BN_bin2bn(const unsigned char* num, int sz, BIGNUM* retVal)
{ {
using mySTL::auto_ptr; using mySTL::auto_ptr;
bool created = false; bool created = false;
auto_ptr<BIGNUM> bn; auto_ptr<BIGNUM> bn(ysDelete);
if (!retVal) { if (!retVal) {
created = true; created = true;
bn.reset(new BIGNUM); bn.reset(new (ys) BIGNUM);
retVal = bn.get(); retVal = bn.get();
} }
...@@ -712,14 +711,14 @@ const char* X509_verify_cert_error_string(long /* error */) ...@@ -712,14 +711,14 @@ const char* X509_verify_cert_error_string(long /* error */)
const EVP_MD* EVP_md5(void) const EVP_MD* EVP_md5(void)
{ {
// TODO: FIX add to some list for destruction // TODO: FIX add to some list for destruction
return new MD5; return new (ys) MD5;
} }
const EVP_CIPHER* EVP_des_ede3_cbc(void) const EVP_CIPHER* EVP_des_ede3_cbc(void)
{ {
// TODO: FIX add to some list for destruction // TODO: FIX add to some list for destruction
return new DES_EDE; return new (ys) DES_EDE;
} }
......
#include "runtime.hpp"
#include "handshake.hpp"
#include "yassl_int.hpp"
#include "crypto_wrapper.hpp"
#include "hmac.hpp"
#include "md5.hpp"
#include "sha.hpp"
#include "ripemd.hpp"
#include "openssl/ssl.h"
#ifdef __GNUC__
#if !defined(USE_CRYPTOPP_LIB)
namespace TaoCrypt {
template class HMAC<MD5>;
template class HMAC<SHA>;
template class HMAC<RIPEMD160>;
}
#endif
namespace mySTL {
template class mySTL::list<unsigned char*>;
template yaSSL::del_ptr_zero mySTL::for_each(mySTL::list<unsigned char*>::iterator, mySTL::list<unsigned char*>::iterator, yaSSL::del_ptr_zero);
template mySTL::pair<int, yaSSL::Message* (*)()>* mySTL::uninit_copy<mySTL::pair<int, yaSSL::Message* (*)()>*, mySTL::pair<int, yaSSL::Message* (*)()>*>(mySTL::pair<int, yaSSL::Message* (*)()>*, mySTL::pair<int, yaSSL::Message* (*)()>*, mySTL::pair<int, yaSSL::Message* (*)()>*);
template mySTL::pair<int, yaSSL::HandShakeBase* (*)()>* mySTL::uninit_copy<mySTL::pair<int, yaSSL::HandShakeBase* (*)()>*, mySTL::pair<int, yaSSL::HandShakeBase* (*)()>*>(mySTL::pair<int, yaSSL::HandShakeBase* (*)()>*, mySTL::pair<int, yaSSL::HandShakeBase* (*)()>*, mySTL::pair<int, yaSSL::HandShakeBase* (*)()>*);
template void mySTL::destroy<mySTL::pair<int, yaSSL::Message* (*)()>*>(mySTL::pair<int, yaSSL::Message* (*)()>*, mySTL::pair<int, yaSSL::Message* (*)()>*);
template void mySTL::destroy<mySTL::pair<int, yaSSL::HandShakeBase* (*)()>*>(mySTL::pair<int, yaSSL::HandShakeBase* (*)()>*, mySTL::pair<int, yaSSL::HandShakeBase* (*)()>*);
template mySTL::pair<int, yaSSL::ServerKeyBase* (*)()>* mySTL::uninit_copy<mySTL::pair<int, yaSSL::ServerKeyBase* (*)()>*, mySTL::pair<int, yaSSL::ServerKeyBase* (*)()>*>(mySTL::pair<int, yaSSL::ServerKeyBase* (*)()>*, mySTL::pair<int, yaSSL::ServerKeyBase* (*)()>*, mySTL::pair<int, yaSSL::ServerKeyBase* (*)()>*);
template void mySTL::destroy<mySTL::pair<int, yaSSL::ServerKeyBase* (*)()>*>(mySTL::pair<int, yaSSL::ServerKeyBase* (*)()>*, mySTL::pair<int, yaSSL::ServerKeyBase* (*)()>*);
template mySTL::pair<int, yaSSL::ClientKeyBase* (*)()>* mySTL::uninit_copy<mySTL::pair<int, yaSSL::ClientKeyBase* (*)()>*, mySTL::pair<int, yaSSL::ClientKeyBase* (*)()>*>(mySTL::pair<int, yaSSL::ClientKeyBase* (*)()>*, mySTL::pair<int, yaSSL::ClientKeyBase* (*)()>*, mySTL::pair<int, yaSSL::ClientKeyBase* (*)()>*);
template class mySTL::list<TaoCrypt::Signer*>;
template class mySTL::list<yaSSL::SSL_SESSION*>;
template class mySTL::list<yaSSL::input_buffer*>;
template class mySTL::list<yaSSL::output_buffer*>;
template class mySTL::list<yaSSL::x509*>;
template void mySTL::destroy<mySTL::pair<int, yaSSL::ClientKeyBase* (*)()>*>(mySTL::pair<int, yaSSL::ClientKeyBase* (*)()>*, mySTL::pair<int, yaSSL::ClientKeyBase* (*)()>*);
template yaSSL::del_ptr_zero mySTL::for_each<mySTL::list<TaoCrypt::Signer*>::iterator, yaSSL::del_ptr_zero>(mySTL::list<TaoCrypt::Signer*>::iterator, mySTL::list<TaoCrypt::Signer*>::iterator, yaSSL::del_ptr_zero);
template yaSSL::del_ptr_zero mySTL::for_each<mySTL::list<yaSSL::SSL_SESSION*>::iterator, yaSSL::del_ptr_zero>(mySTL::list<yaSSL::SSL_SESSION*>::iterator, mySTL::list<yaSSL::SSL_SESSION*>::iterator, yaSSL::del_ptr_zero);
template yaSSL::del_ptr_zero mySTL::for_each<mySTL::list<yaSSL::input_buffer*>::iterator, yaSSL::del_ptr_zero>(mySTL::list<yaSSL::input_buffer*>::iterator, mySTL::list<yaSSL::input_buffer*>::iterator, yaSSL::del_ptr_zero);
template yaSSL::del_ptr_zero mySTL::for_each<mySTL::list<yaSSL::output_buffer*>::iterator, yaSSL::del_ptr_zero>(mySTL::list<yaSSL::output_buffer*>::iterator, mySTL::list<yaSSL::output_buffer*>::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);
}
namespace yaSSL {
template void ysDelete<SSL_CTX>(yaSSL::SSL_CTX*);
template void ysDelete<SSL>(yaSSL::SSL*);
template void ysDelete<BIGNUM>(yaSSL::BIGNUM*);
template void ysDelete<unsigned char>(unsigned char*);
template void ysDelete<DH>(yaSSL::DH*);
template void ysDelete<TaoCrypt::Signer>(TaoCrypt::Signer*);
template void ysDelete<SSL_SESSION>(yaSSL::SSL_SESSION*);
template void ysDelete<input_buffer>(input_buffer*);
template void ysDelete<output_buffer>(output_buffer*);
template void ysDelete<x509>(x509*);
template void ysDelete<Auth>(Auth*);
template void ysDelete<HandShakeBase>(HandShakeBase*);
template void ysDelete<ServerKeyBase>(ServerKeyBase*);
template void ysDelete<ClientKeyBase>(ClientKeyBase*);
template void ysDelete<SSL_METHOD>(SSL_METHOD*);
template void ysDelete<DiffieHellman>(DiffieHellman*);
template void ysDelete<BulkCipher>(BulkCipher*);
template void ysDelete<Digest>(Digest*);
template void ysDelete<X509>(X509*);
template void ysDelete<Message>(Message*);
template void ysArrayDelete<unsigned char>(unsigned char*);
template void ysArrayDelete<char>(char*);
}
#endif
...@@ -23,7 +23,6 @@ ...@@ -23,7 +23,6 @@
* *
*/ */
#include "runtime.hpp"
#include "timer.hpp" #include "timer.hpp"
namespace yaSSL { namespace yaSSL {
......
...@@ -23,7 +23,6 @@ ...@@ -23,7 +23,6 @@
/* yaSSL error implements and an exception class /* yaSSL error implements and an exception class
*/ */
#include "runtime.hpp"
#include "yassl_error.hpp" #include "yassl_error.hpp"
namespace yaSSL { namespace yaSSL {
......
This diff is collapsed.
This diff is collapsed.
...@@ -38,7 +38,7 @@ namespace TaoCrypt { ...@@ -38,7 +38,7 @@ namespace TaoCrypt {
// 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
class TAOCRYPT_NO_VTABLE AbstractGroup class TAOCRYPT_NO_VTABLE AbstractGroup : public virtual_base
{ {
public: public:
typedef Integer Element; typedef Integer Element;
...@@ -70,8 +70,8 @@ class TAOCRYPT_NO_VTABLE AbstractRing : public AbstractGroup ...@@ -70,8 +70,8 @@ class TAOCRYPT_NO_VTABLE AbstractRing : public AbstractGroup
public: public:
typedef Integer Element; typedef Integer Element;
AbstractRing() {m_mg.m_pRing = this;} AbstractRing() : AbstractGroup() {m_mg.m_pRing = this;}
AbstractRing(const AbstractRing &source) : AbstractGroup() {m_mg.m_pRing = this;} AbstractRing(const AbstractRing &source) {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;
......
...@@ -106,7 +106,7 @@ class DH; ...@@ -106,7 +106,7 @@ class DH;
// General BER decoding // General BER decoding
class BER_Decoder { class BER_Decoder : public virtual_base {
protected: protected:
Source& source_; Source& source_;
public: public:
...@@ -184,7 +184,7 @@ class PublicKey { ...@@ -184,7 +184,7 @@ class PublicKey {
word32 sz_; word32 sz_;
public: public:
explicit PublicKey(const byte* k = 0, word32 s = 0); explicit PublicKey(const byte* k = 0, word32 s = 0);
~PublicKey() { delete[] key_; } ~PublicKey() { tcArrayDelete(key_); }
const byte* GetKey() const { return key_; } const byte* GetKey() const { return key_; }
word32 size() const { return sz_; } word32 size() const { return sz_; }
...@@ -287,7 +287,7 @@ word32 DecodeDSA_Signature(byte* decoded, const byte* encoded, word32 sz); ...@@ -287,7 +287,7 @@ word32 DecodeDSA_Signature(byte* decoded, const byte* encoded, word32 sz);
// General DER encoding // General DER encoding
class DER_Encoder { class DER_Encoder : public virtual_base {
public: public:
DER_Encoder() {} DER_Encoder() {}
virtual ~DER_Encoder() {} virtual ~DER_Encoder() {}
......
...@@ -100,13 +100,13 @@ public: ...@@ -100,13 +100,13 @@ public:
CheckSize(n); CheckSize(n);
if (n == 0) if (n == 0)
return 0; return 0;
return new T[n]; return new (tc) T[n];
} }
void deallocate(void* p, size_type n) void deallocate(void* p, size_type n)
{ {
memset(p, 0, n * sizeof(T)); memset(p, 0, n * sizeof(T));
delete [] (T*)p; tcArrayDelete((T*)p);
} }
pointer reallocate(T* p, size_type oldSize, size_type newSize, pointer reallocate(T* p, size_type oldSize, size_type newSize,
......
...@@ -32,7 +32,7 @@ namespace TaoCrypt { ...@@ -32,7 +32,7 @@ namespace TaoCrypt {
// HASH // HASH
class HASH { class HASH : public virtual_base {
public: public:
virtual ~HASH() {} virtual ~HASH() {}
...@@ -50,9 +50,9 @@ public: ...@@ -50,9 +50,9 @@ public:
class HASHwithTransform : public HASH { class HASHwithTransform : public HASH {
public: public:
HASHwithTransform(word32 digSz, word32 buffSz) HASHwithTransform(word32 digSz, word32 buffSz)
: digest_(new word32[digSz]), buffer_(new byte[buffSz]) {} : digest_(new (tc) word32[digSz]), buffer_(new (tc) byte[buffSz]) {}
virtual ~HASHwithTransform() { delete[] buffer_; delete[] digest_; } virtual ~HASHwithTransform() { tcArrayDelete(buffer_);
tcArrayDelete(digest_); }
virtual ByteOrder getByteOrder() const = 0; virtual ByteOrder getByteOrder() const = 0;
virtual word32 getPadSize() const = 0; virtual word32 getPadSize() const = 0;
......
...@@ -136,9 +136,8 @@ public: ...@@ -136,9 +136,8 @@ public:
~Integer() {} ~Integer() {}
static const Integer &Zero(); static const Integer& Zero();
static const Integer &One(); static const Integer& One();
static const Integer &Two();
Integer& Ref() { return *this; } Integer& Ref() { return *this; }
...@@ -252,9 +251,6 @@ private: ...@@ -252,9 +251,6 @@ private:
friend class ModularArithmetic; friend class ModularArithmetic;
friend class MontgomeryRepresentation; friend class MontgomeryRepresentation;
static const Integer zero;
static const Integer one;
static const Integer two;
Integer(word value, unsigned int length); Integer(word value, unsigned int length);
int PositiveCompare(const Integer& t) const; int PositiveCompare(const Integer& t) const;
...@@ -267,6 +263,9 @@ private: ...@@ -267,6 +263,9 @@ private:
Integer& dividend, const Integer& divisor); Integer& dividend, const Integer& divisor);
AlignedWordBlock reg_; AlignedWordBlock reg_;
Sign sign_; Sign sign_;
static const Integer zero_;
static const Integer one_;
}; };
inline bool operator==(const Integer& a, const Integer& b) inline bool operator==(const Integer& a, const Integer& b)
......
...@@ -27,75 +27,59 @@ ...@@ -27,75 +27,59 @@
#include <stdlib.h> #include <stdlib.h>
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
#include "types.hpp"
#include "type_traits.hpp"
/*
namespace GCC_ABI {
extern "C" int __cxa_pure_virtual();
} */
namespace TaoCrypt { namespace TaoCrypt {
// using GCC_ABI::__cxa_pure_virtual;
// define this if running on a big-endian CPU // library allocation
#if !defined(LITTLE_ENDIAN_ORDER) && (defined(__BIG_ENDIAN__) || \ struct new_t {}; // TaoCrypt New type
defined(__sparc) || defined(__sparc__) || defined(__hppa__) || \ extern new_t tc; // pass in parameter
defined(__mips__) || (defined(__MWERKS__) && !defined(__INTEL__)))
#define BIG_ENDIAN_ORDER
#endif
#ifndef BIG_ENDIAN_ORDER } // namespace TaoCrypt
#define LITTLE_ENDIAN_ORDER
#endif
void* operator new (size_t, TaoCrypt::new_t);
void* operator new[](size_t, TaoCrypt::new_t);
typedef unsigned char byte; void operator delete (void*, TaoCrypt::new_t);
typedef unsigned short word16; void operator delete[](void*, TaoCrypt::new_t);
typedef unsigned int word32;
#if defined(__GNUC__) || defined(__MWERKS__) || defined(_LONGLONG_TYPE)
#define WORD64_AVAILABLE
typedef unsigned long long word64;
#define W64LIT(x) x##LL
#elif defined(_MSC_VER) || defined(__BCPLUSPLUS__)
#define WORD64_AVAILABLE
typedef unsigned __int64 word64;
#define W64LIT(x) x##ui64
#elif defined(__DECCXX)
#define WORD64_AVAILABLE
typedef unsigned long word64;
#endif
// define largest word type
#ifdef WORD64_AVAILABLE
typedef word64 lword;
#else
typedef word32 lword;
#endif
// FIXME the !defined(__sun) is a temporarely solution until asm for namespace TaoCrypt {
// __x86_64__ and Solaris is written
#if defined(__alpha__) || defined(__ia64__) || defined(_ARCH_PPC64) || \
defined(__mips64) || (defined(__x86_64__) && !defined(__sun))
// These platforms have 64-bit CPU registers. Unfortunately most C++ compilers
// don't allow any way to access the 64-bit by 64-bit multiply instruction
// without using assembly, so in order to use word64 as word, the assembly
// instruction must be defined in Dword::Multiply().
typedef word32 hword;
typedef word64 word;
#else
#define TAOCRYPT_NATIVE_DWORD_AVAILABLE
#ifdef WORD64_AVAILABLE
#define TAOCRYPT_SLOW_WORD64
// define this if your CPU is not64-bit to use alternative code
// that avoids word64
typedef word16 hword;
typedef word32 word;
typedef word64 dword;
#else
typedef byte hword;
typedef word16 word;
typedef word32 dword;
#endif
#endif
const word32 WORD_SIZE = sizeof(word); template<typename T>
const word32 WORD_BITS = WORD_SIZE * 8; void tcDelete(T* ptr)
{
if (ptr) ptr->~T();
::operator delete(ptr, TaoCrypt::tc);
}
template<typename T>
void tcArrayDelete(T* ptr)
{
// can't do array placement destruction since not tracking size in
// allocation, only allow builtins to use array placement since they
// don't need destructors called
typedef char builtin[IsFundamentalType<T>::Yes ? 1 : -1];
(void)sizeof(builtin);
::operator delete[](ptr, TaoCrypt::tc);
}
// to resolve compiler generated operator delete on base classes with
// virtual destructors, make sure doesn't get called
class virtual_base {
public:
static void operator delete(void*) { assert(0); }
};
#if defined(_MSC_VER) || defined(__BCPLUSPLUS__) #if defined(_MSC_VER) || defined(__BCPLUSPLUS__)
......
...@@ -56,7 +56,7 @@ private: ...@@ -56,7 +56,7 @@ private:
// Mode Base for block ciphers, static size // Mode Base for block ciphers, static size
class Mode_BASE { class Mode_BASE : public virtual_base {
public: public:
enum { MaxBlockSz = 16 }; enum { MaxBlockSz = 16 };
......
...@@ -31,30 +31,6 @@ ...@@ -31,30 +31,6 @@
#if __GNUC__ > 2 #if __GNUC__ > 2
#include <stdlib.h>
static void* operator new (size_t sz)
{
return malloc (sz ? sz : 1);
}
static void* operator new[](size_t sz)
{
return malloc (sz ? sz : 1);
}
static void operator delete (void* ptr)
{
if (ptr) free(ptr);
}
static void operator delete[] (void* ptr)
{
if (ptr) free(ptr);
}
extern "C" { extern "C" {
#include <assert.h> #include <assert.h>
......
/* type_traits.hpp
*
* Copyright (C) 2003 Sawtooth Consulting Ltd.
*
* This file is part of yaSSL.
*
* yaSSL is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* yaSSL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
/* type_traits defines fundamental types
* see discussion in C++ Templates, $19.1
*/
#ifndef TAO_CRYPT_TYPE_TRAITS_HPP
#define TAO_CRYPT_TYPE_TRAITS_HPP
#include "types.hpp"
namespace TaoCrypt {
// primary template: in general T is not a fundamental type
template <typename T>
class IsFundamentalType {
public:
enum { Yes = 0, No = 1 };
};
// macro to specialize for fundamental types
#define MK_FUNDAMENTAL_TYPE(T) \
template<> class IsFundamentalType<T> { \
public: \
enum { Yes = 1, No = 0 }; \
};
MK_FUNDAMENTAL_TYPE(void)
MK_FUNDAMENTAL_TYPE(bool)
MK_FUNDAMENTAL_TYPE( char)
MK_FUNDAMENTAL_TYPE(signed char)
MK_FUNDAMENTAL_TYPE(unsigned char)
MK_FUNDAMENTAL_TYPE(signed short)
MK_FUNDAMENTAL_TYPE(unsigned short)
MK_FUNDAMENTAL_TYPE(signed int)
MK_FUNDAMENTAL_TYPE(unsigned int)
MK_FUNDAMENTAL_TYPE(signed long)
MK_FUNDAMENTAL_TYPE(unsigned long)
MK_FUNDAMENTAL_TYPE(float)
MK_FUNDAMENTAL_TYPE( double)
MK_FUNDAMENTAL_TYPE(long double)
#ifdef WORD64_AVAILABLE
MK_FUNDAMENTAL_TYPE(word64)
#endif
#undef MK_FUNDAMENTAL_TYPE
} // namespace
#endif // TAO_CRYPT_TYPE_TRAITS_HPP
/* types.hpp
*
* Copyright (C) 2003 Sawtooth Consulting Ltd.
*
* This file is part of yaSSL.
*
* yaSSL is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* yaSSL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
/* based on Wei Dai's misc.h from CryptoPP, basic crypt types */
#ifndef TAO_CRYPT_TYPES_HPP
#define TAO_CRYPT_TYPES_HPP
namespace TaoCrypt {
// define this if running on a big-endian CPU
#if !defined(LITTLE_ENDIAN_ORDER) && (defined(__BIG_ENDIAN__) || \
defined(__sparc) || defined(__sparc__) || defined(__hppa__) || \
defined(__mips__) || (defined(__MWERKS__) && !defined(__INTEL__)))
#define BIG_ENDIAN_ORDER
#endif
#ifndef BIG_ENDIAN_ORDER
#define LITTLE_ENDIAN_ORDER
#endif
typedef unsigned char byte;
typedef unsigned short word16;
typedef unsigned int word32;
#if defined(__GNUC__) || defined(__MWERKS__) || defined(_LONGLONG_TYPE)
#define WORD64_AVAILABLE
typedef unsigned long long word64;
#define W64LIT(x) x##LL
#elif defined(_MSC_VER) || defined(__BCPLUSPLUS__)
#define WORD64_AVAILABLE
typedef unsigned __int64 word64;
#define W64LIT(x) x##ui64
#elif defined(__DECCXX)
#define WORD64_AVAILABLE
typedef unsigned long word64;
#endif
// define largest word type
#ifdef WORD64_AVAILABLE
typedef word64 lword;
#else
typedef word32 lword;
#endif
// TODO: FIXME, add asm multiply for x86_64 on Solaris and remove !__sun
#if defined(__alpha__) || defined(__ia64__) || defined(_ARCH_PPC64) || \
defined(__mips64) || (defined(__x86_64__) && !defined(__sun))
// These platforms have 64-bit CPU registers. Unfortunately most C++ compilers
// don't allow any way to access the 64-bit by 64-bit multiply instruction
// without using assembly, so in order to use word64 as word, the assembly
// instruction must be defined in Dword::Multiply().
typedef word32 hword;
typedef word64 word;
#else
#define TAOCRYPT_NATIVE_DWORD_AVAILABLE
#ifdef WORD64_AVAILABLE
#define TAOCRYPT_SLOW_WORD64
// define this if your CPU is not64-bit to use alternative code
// that avoids word64
typedef word16 hword;
typedef word32 word;
typedef word64 dword;
#else
typedef byte hword;
typedef word16 word;
typedef word32 dword;
#endif
#endif
const word32 WORD_SIZE = sizeof(word);
const word32 WORD_BITS = WORD_SIZE * 8;
} // namespace
#endif // TAO_CRYPT_TYPES_HPP
...@@ -3,5 +3,6 @@ INCLUDES = -I../include -I../../mySTL ...@@ -3,5 +3,6 @@ INCLUDES = -I../include -I../../mySTL
noinst_LIBRARIES = libtaocrypt.a noinst_LIBRARIES = libtaocrypt.a
libtaocrypt_a_SOURCES = aes.cpp aestables.cpp algebra.cpp arc4.cpp asn.cpp \ libtaocrypt_a_SOURCES = aes.cpp aestables.cpp algebra.cpp arc4.cpp asn.cpp \
coding.cpp dh.cpp des.cpp dsa.cpp file.cpp hash.cpp integer.cpp \ coding.cpp dh.cpp des.cpp dsa.cpp file.cpp hash.cpp integer.cpp \
md2.cpp md5.cpp misc.cpp random.cpp ripemd.cpp rsa.cpp sha.cpp md2.cpp md5.cpp misc.cpp random.cpp ripemd.cpp rsa.cpp sha.cpp \
template_instnt.cpp
EXTRA_DIST = ../include/*.hpp EXTRA_DIST = ../include/*.hpp
...@@ -21,7 +21,6 @@ ...@@ -21,7 +21,6 @@
/* based on Wei Dai's aestables.cpp from CryptoPP */ /* based on Wei Dai's aestables.cpp from CryptoPP */
#include "runtime.hpp"
#include "aes.hpp" #include "aes.hpp"
......
...@@ -322,8 +322,6 @@ void AbstractRing::SimultaneousExponentiate(Integer *results, ...@@ -322,8 +322,6 @@ void AbstractRing::SimultaneousExponentiate(Integer *results,
#ifdef __GNUC__ #ifdef __GNUC__
namespace mySTL { namespace mySTL {
template TaoCrypt::WindowSlider* uninit_copy<TaoCrypt::WindowSlider*, TaoCrypt::WindowSlider*>(TaoCrypt::WindowSlider*, TaoCrypt::WindowSlider*, TaoCrypt::WindowSlider*); 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<TaoCrypt::WindowSlider*>(TaoCrypt::WindowSlider*, TaoCrypt::WindowSlider*);
template void destroy<vector<TaoCrypt::Integer>*>(vector<TaoCrypt::Integer>*, vector<TaoCrypt::Integer>*);
} }
#endif #endif
...@@ -21,7 +21,6 @@ ...@@ -21,7 +21,6 @@
/* based on Wei Dai's arc4.cpp from CryptoPP */ /* based on Wei Dai's arc4.cpp from CryptoPP */
#include "runtime.hpp"
#include "arc4.hpp" #include "arc4.hpp"
......
...@@ -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 byte[sz_]; key_ = new (tc) byte[sz_];
} }
...@@ -199,14 +199,14 @@ void PublicKey::SetKey(const byte* k) ...@@ -199,14 +199,14 @@ 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 byte[sz_ + len]); mySTL::auto_ptr<byte> tmp(new (tc) byte[sz_ + len], tcArrayDelete);
memcpy(tmp.get(), key_, sz_); memcpy(tmp.get(), key_, sz_);
memcpy(tmp.get() + sz_, data, len); memcpy(tmp.get() + sz_, data, len);
byte* del = 0; byte* del = 0;
mySTL::swap(del, key_); mySTL::swap(del, key_);
delete[] del; tcArrayDelete(del);
key_ = tmp.release(); key_ = tmp.release();
sz_ += len; sz_ += 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 char[sz + 1]; name_ = new (tc) char[sz + 1];
memcpy(name_, n, sz); memcpy(name_, n, sz);
name_[sz] = 0; name_[sz] = 0;
} }
...@@ -228,7 +228,7 @@ Signer::Signer(const byte* k, word32 kSz, const char* n, const byte* h) ...@@ -228,7 +228,7 @@ Signer::Signer(const byte* k, word32 kSz, const char* n, const byte* h)
Signer::~Signer() Signer::~Signer()
{ {
delete[] name_; tcArrayDelete(name_);
} }
...@@ -433,9 +433,9 @@ CertDecoder::CertDecoder(Source& s, bool decode, SignerList* signers) ...@@ -433,9 +433,9 @@ CertDecoder::CertDecoder(Source& s, bool decode, SignerList* signers)
CertDecoder::~CertDecoder() CertDecoder::~CertDecoder()
{ {
delete[] subject_; tcArrayDelete(subject_);
delete[] issuer_; tcArrayDelete(issuer_);
delete[] signature_; tcArrayDelete(signature_);
} }
...@@ -632,7 +632,7 @@ word32 CertDecoder::GetSignature() ...@@ -632,7 +632,7 @@ word32 CertDecoder::GetSignature()
} }
sigLength_--; sigLength_--;
signature_ = new byte[sigLength_]; signature_ = new (tc) 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 byte[sigLength_]; signature_ = new (tc) 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 char[strLen + 1]; ptr = new (tc) char[strLen + 1];
memcpy(ptr, source_.get_current(), strLen); memcpy(ptr, source_.get_current(), strLen);
ptr[strLen] = 0; ptr[strLen] = 0;
} }
...@@ -807,18 +807,18 @@ bool CertDecoder::ValidateSignature(SignerList* signers) ...@@ -807,18 +807,18 @@ bool CertDecoder::ValidateSignature(SignerList* signers)
bool CertDecoder::ConfirmSignature(Source& pub) bool CertDecoder::ConfirmSignature(Source& pub)
{ {
HashType ht; HashType ht;
mySTL::auto_ptr<HASH> hasher; mySTL::auto_ptr<HASH> hasher(tcDelete);
if (signatureOID_ == MD5wRSA) { if (signatureOID_ == MD5wRSA) {
hasher.reset(new MD5); hasher.reset(new (tc) MD5);
ht = MD5h; ht = MD5h;
} }
else if (signatureOID_ == MD2wRSA) { else if (signatureOID_ == MD2wRSA) {
hasher.reset(new MD2); hasher.reset(new (tc) MD2);
ht = MD2h; ht = MD2h;
} }
else if (signatureOID_ == SHAwRSA || signatureOID_ == SHAwDSA) { else if (signatureOID_ == SHAwRSA || signatureOID_ == SHAwDSA) {
hasher.reset(new SHA); hasher.reset(new (tc) SHA);
ht = SHAh; ht = SHAh;
} }
else { else {
......
...@@ -22,7 +22,6 @@ ...@@ -22,7 +22,6 @@
/* coding.cpp implements hex and base64 encoding/decoing /* coding.cpp implements hex and base64 encoding/decoing
*/ */
#include "runtime.hpp"
#include "coding.hpp" #include "coding.hpp"
#include "file.hpp" #include "file.hpp"
......
...@@ -23,7 +23,6 @@ ...@@ -23,7 +23,6 @@
/* dh.cpp implements Diffie-Hellman support /* dh.cpp implements Diffie-Hellman support
*/ */
#include "runtime.hpp"
#include "dh.hpp" #include "dh.hpp"
#include "asn.hpp" #include "asn.hpp"
......
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
*/ */
#include "runtime.hpp"
#include "dsa.hpp" #include "dsa.hpp"
#include "sha.hpp" #include "sha.hpp"
#include "asn.hpp" #include "asn.hpp"
......
...@@ -22,7 +22,6 @@ ...@@ -22,7 +22,6 @@
/* file.cpp implements File Sources and Sinks /* file.cpp implements File Sources and Sinks
*/ */
#include "runtime.hpp"
#include "file.hpp" #include "file.hpp"
......
...@@ -32,7 +32,6 @@ ...@@ -32,7 +32,6 @@
# pragma warning(disable: 4250 4660 4661 4786 4355) # pragma warning(disable: 4250 4660 4661 4786 4355)
#endif #endif
#include "runtime.hpp"
#include "integer.hpp" #include "integer.hpp"
#include "modarith.hpp" #include "modarith.hpp"
#include "asn.hpp" #include "asn.hpp"
...@@ -108,7 +107,7 @@ CPP_TYPENAME AllocatorBase<T>::pointer AlignedAllocator<T>::allocate( ...@@ -108,7 +107,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 T[n]; return new (tc) T[n];
} }
...@@ -129,7 +128,7 @@ void AlignedAllocator<T>::deallocate(void* p, size_type n) ...@@ -129,7 +128,7 @@ void AlignedAllocator<T>::deallocate(void* p, size_type n)
#endif #endif
} }
else else
delete [] (T *)p; tcArrayDelete((T *)p);
} }
#endif // SSE2 #endif // SSE2
...@@ -2691,25 +2690,19 @@ unsigned int Integer::Encode(byte* output, unsigned int outputLen, ...@@ -2691,25 +2690,19 @@ unsigned int Integer::Encode(byte* output, unsigned int outputLen,
} }
const Integer Integer::zero(1,2); const Integer Integer::zero_;
const Integer &Integer::Zero() const Integer &Integer::Zero()
{ {
return zero; return zero_;
} }
const Integer Integer::one(1,2);
const Integer &Integer::One() const Integer Integer::one_(1,2);
{
return one;
}
const Integer Integer::two(1,2); const Integer &Integer::One()
const Integer &Integer::Two()
{ {
return two; return one_;
} }
...@@ -3948,9 +3941,6 @@ Integer CRT(const Integer &xp, const Integer &p, const Integer &xq, ...@@ -3948,9 +3941,6 @@ Integer CRT(const Integer &xp, const Integer &p, const Integer &xq,
#ifdef __GNUC__ #ifdef __GNUC__
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*);
#if defined(SSE2_INTRINSICS_AVAILABLE)
template AlignedAllocator<unsigned int>::pointer StdReallocate<unsigned int, AlignedAllocator<unsigned int> >(AlignedAllocator<unsigned int>&, unsigned int*, AlignedAllocator<unsigned int>::size_type, AlignedAllocator<unsigned int>::size_type, bool);
#endif
#endif #endif
} // namespace } // namespace
......
...@@ -22,14 +22,73 @@ ...@@ -22,14 +22,73 @@
/* based on Wei Dai's misc.cpp from CryptoPP */ /* based on Wei Dai's misc.cpp from CryptoPP */
#include "runtime.hpp"
#include "misc.hpp" #include "misc.hpp"
#include <new> // for NewHandler #include <new> // for NewHandler
void* operator new(size_t sz, TaoCrypt::new_t)
{
void* ptr = malloc(sz ? sz : 1);
if (!ptr) abort();
return ptr;
}
void* operator new[](size_t sz, TaoCrypt::new_t)
{
void* ptr = malloc(sz ? sz : 1);
if (!ptr) abort();
return ptr;
}
void operator delete(void* ptr, TaoCrypt::new_t)
{
if (ptr) free(ptr);
}
void operator delete[](void* ptr, TaoCrypt::new_t)
{
if (ptr) free(ptr);
}
/* uncomment to test
// make sure not using globals anywhere by forgetting to use overloaded
void* operator new(size_t sz)
{
assert(0);
return malloc(sz);
}
void operator delete(void* ptr)
{
assert(0);
}
void* operator new[](size_t sz)
{
assert(0);
return malloc(sz);
}
void operator delete[](void* ptr)
{
assert(0);
}
*/
/* namespace GCC_ABI {
extern "C" int __cxa_pure_virtual() { assert(0); return 0; }
} */
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++)
......
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
specific seed, switch to /dev/random for more security but may block specific seed, switch to /dev/random for more security but may block
*/ */
#include "runtime.hpp"
#include "random.hpp" #include "random.hpp"
#if defined(WIN32) #if defined(WIN32)
......
...@@ -21,7 +21,6 @@ ...@@ -21,7 +21,6 @@
/* based on Wei Dai's rsa.cpp from CryptoPP */ /* based on Wei Dai's rsa.cpp from CryptoPP */
#include "runtime.hpp"
#include "rsa.hpp" #include "rsa.hpp"
#include "asn.hpp" #include "asn.hpp"
#include "modarith.hpp" #include "modarith.hpp"
...@@ -210,22 +209,5 @@ word32 SSL_Decrypt(const RSA_PublicKey& key, const byte* sig, byte* plain) ...@@ -210,22 +209,5 @@ word32 SSL_Decrypt(const RSA_PublicKey& key, const byte* sig, byte* plain)
lengths.PaddedBlockBitLength(), plain); lengths.PaddedBlockBitLength(), plain);
} }
#ifdef __GNUC__
template AllocatorWithCleanup<unsigned char>::pointer StdReallocate<unsigned char, AllocatorWithCleanup<unsigned char> >(AllocatorWithCleanup<unsigned char>&, unsigned char*, AllocatorWithCleanup<unsigned char>::size_type, AllocatorWithCleanup<unsigned char>::size_type, bool);
template AllocatorWithCleanup<unsigned int>::pointer StdReallocate<unsigned int, AllocatorWithCleanup<unsigned int> >(AllocatorWithCleanup<unsigned int>&, unsigned int*, AllocatorWithCleanup<unsigned int>::size_type, AllocatorWithCleanup<unsigned int>::size_type, bool);
template class RSA_Decryptor<RSA_BlockType2>;
template class RSA_Encryptor<RSA_BlockType1>;
template class RSA_Encryptor<RSA_BlockType2>;
#endif
} // namespace } // namespace
#ifdef __GNUC__
namespace mySTL {
template TaoCrypt::Integer* uninit_copy<TaoCrypt::Integer*, TaoCrypt::Integer*>(TaoCrypt::Integer*, TaoCrypt::Integer*, TaoCrypt::Integer*);
template TaoCrypt::Integer* uninit_fill_n<TaoCrypt::Integer*, unsigned int, TaoCrypt::Integer>(TaoCrypt::Integer*, unsigned int, TaoCrypt::Integer const&);
template void destroy<TaoCrypt::Integer*>(TaoCrypt::Integer*, TaoCrypt::Integer*);
}
#endif
#include "integer.hpp"
#include "rsa.hpp"
#include "algebra.hpp"
#include "vector.hpp"
#include "hash.hpp"
#ifdef __GNUC__
namespace TaoCrypt {
#if defined(SSE2_INTRINSICS_AVAILABLE)
template AlignedAllocator<unsigned int>::pointer StdReallocate<unsigned int, AlignedAllocator<unsigned int> >(AlignedAllocator<unsigned int>&, unsigned int*, AlignedAllocator<unsigned int>::size_type, AlignedAllocator<unsigned int>::size_type, bool);
#endif
template AllocatorWithCleanup<unsigned char>::pointer StdReallocate<unsigned char, AllocatorWithCleanup<unsigned char> >(AllocatorWithCleanup<unsigned char>&, unsigned char*, AllocatorWithCleanup<unsigned char>::size_type, AllocatorWithCleanup<unsigned char>::size_type, bool);
template AllocatorWithCleanup<unsigned int>::pointer StdReallocate<unsigned int, AllocatorWithCleanup<unsigned int> >(AllocatorWithCleanup<unsigned int>&, unsigned int*, AllocatorWithCleanup<unsigned int>::size_type, AllocatorWithCleanup<unsigned int>::size_type, bool);
template class RSA_Decryptor<RSA_BlockType2>;
template class RSA_Encryptor<RSA_BlockType1>;
template class RSA_Encryptor<RSA_BlockType2>;
}
namespace mySTL {
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<vector<TaoCrypt::Integer>*>(vector<TaoCrypt::Integer>*, vector<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 void destroy<TaoCrypt::Integer*>(TaoCrypt::Integer*, TaoCrypt::Integer*);
}
template void TaoCrypt::tcDelete<TaoCrypt::HASH>(TaoCrypt::HASH*);
template void TaoCrypt::tcArrayDelete<unsigned>(unsigned*);
template void TaoCrypt::tcArrayDelete<unsigned char>(unsigned char*);
template void TaoCrypt::tcArrayDelete<char>(char*);
#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