Import from yaSSL upstream

parent 1c4e31d5
/* rsa.h for openSSL */
#ifndef ysSSL_rsa_h__
#ifndef yaSSL_rsa_h__
#define yaSSL_rsa_h__
enum { RSA_F4 = 1 };
......
......@@ -25,7 +25,7 @@
#ifndef ysSSL_openssl_h__
#ifndef yaSSL_openssl_h__
#define yaSSL_openssl_h__
#include <stdio.h> /* ERR_print fp */
......@@ -345,6 +345,7 @@ long SSL_CTX_sess_set_cache_size(SSL_CTX*, long);
long SSL_CTX_set_tmp_dh(SSL_CTX*, DH*);
void OpenSSL_add_all_algorithms(void);
void SSL_library_init();
void SSLeay_add_ssl_algorithms(void);
......
......@@ -121,8 +121,6 @@ public:
friend sslFactory& GetSSL_Factory(); // singleton creator
private:
static sslFactory instance_;
sslFactory(const sslFactory&); // hide copy
sslFactory& operator=(const sslFactory&); // and assign
};
......@@ -214,8 +212,6 @@ public:
friend Sessions& GetSessions(); // singleton creator
private:
static Sessions instance_;
Sessions(const Sessions&); // hide copy
Sessions& operator=(const Sessions&); // and assign
};
......
......@@ -34,6 +34,11 @@
namespace yaSSL {
// Delete static singleton memory holders
void CleanUp();
#ifdef YASSL_PURE_C
// library allocation
......
......@@ -28,14 +28,14 @@
#define mySTL_HELPERS_HPP
#include <stdlib.h>
#include <new> // placement new
#ifdef _MSC_VER
#include <new>
#endif
#ifdef __IBMCPP__
/*
Workaround for the lack of operator new(size_t, void*)
in IBM VA C++ 6.0
Also used as a workaround to avoid including <new>
*/
struct Dummy {};
......@@ -45,10 +45,6 @@
}
typedef Dummy* yassl_pointer;
#else
typedef void* yassl_pointer;
#endif
namespace mySTL {
......
......@@ -164,7 +164,7 @@ void list<T>::push_front(T t)
{
void* mem = malloc(sizeof(node));
if (!mem) abort();
node* add = new (mem) node(t);
node* add = new (reinterpret_cast<yassl_pointer>(mem)) node(t);
if (head_) {
add->next_ = head_;
......@@ -210,7 +210,7 @@ void list<T>::push_back(T t)
{
void* mem = malloc(sizeof(node));
if (!mem) abort();
node* add = new (mem) node(t);
node* add = new (reinterpret_cast<yassl_pointer>(mem)) node(t);
if (tail_) {
tail_->next_ = add;
......
......@@ -45,7 +45,8 @@ struct vector_base {
vector_base() : start_(0), finish_(0), end_of_storage_(0) {}
vector_base(size_t n)
{
start_ = static_cast<T*>(malloc(n * sizeof(T)));
// Don't allow malloc(0), if n is 0 use 1
start_ = static_cast<T*>(malloc((n ? n : 1) * sizeof(T)));
if (!start_) abort();
finish_ = start_;
end_of_storage_ = start_ + n;
......
......@@ -650,7 +650,6 @@ void build_certHashes(SSL& ssl, Hashes& hashes)
}
mySTL::auto_ptr<input_buffer> null_buffer(ysDelete);
// do process input requests
mySTL::auto_ptr<input_buffer>
......@@ -659,7 +658,8 @@ DoProcessReply(SSL& ssl, mySTL::auto_ptr<input_buffer> buffered)
// wait for input if blocking
if (!ssl.getSocket().wait()) {
ssl.SetError(receive_error);
return buffered = null_buffer;
buffered.reset(0);
return buffered;
}
uint ready = ssl.getSocket().get_ready();
if (!ready) return buffered;
......@@ -669,10 +669,10 @@ DoProcessReply(SSL& ssl, mySTL::auto_ptr<input_buffer> buffered)
input_buffer buffer(buffSz + ready);
if (buffSz) {
buffer.assign(buffered.get()->get_buffer(), buffSz);
buffered = null_buffer;
buffered.reset(0);
}
// add NEW_YS data
// add new data
uint read = ssl.getSocket().receive(buffer.get_buffer() + buffSz, ready);
buffer.add_size(read);
uint offset = 0;
......@@ -705,11 +705,15 @@ DoProcessReply(SSL& ssl, mySTL::auto_ptr<input_buffer> buffered)
mySTL::auto_ptr<Message> msg(mf.CreateObject(hdr.type_), ysDelete);
if (!msg.get()) {
ssl.SetError(factory_error);
return buffered = null_buffer;
buffered.reset(0);
return buffered;
}
buffer >> *msg;
msg->Process(buffer, ssl);
if (ssl.GetError()) return buffered = null_buffer;
if (ssl.GetError()) {
buffered.reset(0);
return buffered;
}
}
offset += hdr.length_ + RECORD_HEADER;
}
......
......@@ -39,7 +39,7 @@
#include <string.h>
#endif // _WIN32
#ifdef __sun
#if defined(__sun) || defined(__SCO_VERSION__)
#include <sys/filio.h>
#endif
......@@ -95,11 +95,15 @@ void Socket::closeSocket()
uint Socket::get_ready() const
{
unsigned long ready = 0;
#ifdef _WIN32
unsigned long ready = 0;
ioctlsocket(socket_, FIONREAD, &ready);
#else
/*
64-bit Solaris requires the variable passed to
FIONREAD be a 32-bit value.
*/
unsigned int ready = 0;
ioctl(socket_, FIONREAD, &ready);
#endif
......
......@@ -723,6 +723,10 @@ void OpenSSL_add_all_algorithms() // compatibility only
{}
void SSL_library_init() // compatiblity only
{}
DH* DH_new(void)
{
DH* dh = NEW_YS DH;
......
......@@ -1329,6 +1329,7 @@ input_buffer& operator>>(input_buffer& input, ClientHello& hello)
// Compression
hello.comp_len_ = input[AUTO];
while (hello.comp_len_--) // ignore for now
hello.compression_methods_ = CompressionMethod(input[AUTO]);
return input;
......
......@@ -1363,19 +1363,31 @@ SSL_SESSION::~SSL_SESSION()
}
Sessions Sessions::instance_; // simple singleton
static Sessions* sessionsInstance = 0;
Sessions& GetSessions()
{
return Sessions::instance_;
if (!sessionsInstance)
sessionsInstance = NEW_YS Sessions;
return *sessionsInstance;
}
sslFactory sslFactory::instance_; // simple singleton
static sslFactory* sslFactoryInstance = 0;
sslFactory& GetSSL_Factory()
{
return sslFactory::instance_;
if (!sslFactoryInstance)
sslFactoryInstance = NEW_YS sslFactory;
return *sslFactoryInstance;
}
void CleanUp()
{
TaoCrypt::CleanUp();
ysDelete(sslFactoryInstance);
ysDelete(sessionsInstance);
}
......
......@@ -284,7 +284,7 @@ void bench_rsa()
double each = total / times; // per second
double milliEach = each * 1000; // milliseconds
printf("RSA 1024 encryption took %3.2f milliseconds, avg over %d"
printf("RSA 1024 encryption took %6.2f milliseconds, avg over %d"
" iterations\n", milliEach, times);
RSAES_Decryptor dec(priv);
......@@ -298,7 +298,7 @@ void bench_rsa()
each = total / times; // per second
milliEach = each * 1000; // milliseconds
printf("RSA 1024 decryption took %3.2f milliseconds, avg over %d"
printf("RSA 1024 decryption took %6.2f milliseconds, avg over %d"
" iterations\n", milliEach, times);
}
......@@ -329,7 +329,7 @@ void bench_dh()
double each = total / times; // per second
double milliEach = each * 1000; // milliseconds
printf("DH 1024 key generation %3.2f milliseconds, avg over %d"
printf("DH 1024 key generation %6.2f milliseconds, avg over %d"
" iterations\n", milliEach, times);
DH dh2(dh);
......@@ -347,7 +347,7 @@ void bench_dh()
each = total / times; // per second
milliEach = each * 1000; // in milliseconds
printf("DH 1024 key agreement %3.2f milliseconds, avg over %d"
printf("DH 1024 key agreement %6.2f milliseconds, avg over %d"
" iterations\n", milliEach, times);
}
......@@ -383,7 +383,7 @@ void bench_dsa()
double each = total / times; // per second
double milliEach = each * 1000; // milliseconds
printf("DSA 1024 sign took %3.2f milliseconds, avg over %d"
printf("DSA 1024 sign took %6.2f milliseconds, avg over %d"
" iterations\n", milliEach, times);
DSA_Verifier verifier(key);
......@@ -397,7 +397,7 @@ void bench_dsa()
each = total / times; // per second
milliEach = each * 1000; // in milliseconds
printf("DSA 1024 verify took %3.2f milliseconds, avg over %d"
printf("DSA 1024 verify took %6.2f milliseconds, avg over %d"
" iterations\n", milliEach, times);
}
......
......@@ -274,9 +274,6 @@ private:
Integer& dividend, const Integer& divisor);
AlignedWordBlock reg_;
Sign sign_;
static const Integer zero_;
static const Integer one_;
};
inline bool operator==(const Integer& a, const Integer& b)
......
......@@ -40,6 +40,11 @@
namespace TaoCrypt {
// Delete static singleton holders
void CleanUp();
#ifdef YASSL_PURE_C
// library allocation
......@@ -123,7 +128,12 @@ namespace TaoCrypt {
// no gas on these systems ?, disable for now
#if defined(__sun__) || defined (__QNX__)
#if defined(__sun__) || defined (__QNX__) || defined (__APPLE__)
#define TAOCRYPT_DISABLE_X86ASM
#endif
// icc problem with -03 and integer, disable for now
#if defined(__INTEL_COMPILER)
#define TAOCRYPT_DISABLE_X86ASM
#endif
......
......@@ -25,10 +25,27 @@
#if !defined(yaSSL_NEW_HPP) && defined(__GNUC__) && !defined(__ICC)
#ifndef yaSSL_NEW_HPP
#define yaSSL_NEW_HPP
#ifdef __sun
#include <assert.h>
// Handler for pure virtual functions
namespace __Crun {
static void pure_error(void)
{
assert("Pure virtual method called." == "Aborted");
}
} // namespace __Crun
#endif // __sun
#if defined(__GNUC__) && !(defined(__ICC) || defined(__INTEL_COMPILER))
#if __GNUC__ > 2
extern "C" {
......@@ -50,5 +67,6 @@ static int __cxa_pure_virtual()
} // extern "C"
#endif // __GNUC__ > 2
#endif // yaSSL_NEW_HPP && __GNUC__
#endif // compiler check
#endif // yaSSL_NEW_HPP
......@@ -61,7 +61,9 @@ typedef unsigned int word32;
// compilers we've found 64-bit multiply insructions for
#if defined(__GNUC__) || defined(_MSC_VER) || defined(__DECCXX)
#if !(defined(__ICC) || defined(__INTEL_COMPILER))
#define HAVE_64_MULTIPLY
#endif
#endif
......
......@@ -78,7 +78,9 @@ const Integer& AbstractEuclideanDomain::Mod(const Element &a,
const Integer& AbstractEuclideanDomain::Gcd(const Element &a,
const Element &b) const
{
Element g[3]={b, a};
mySTL::vector<Element> g(3);
g[0]= b;
g[1]= a;
unsigned int i0=0, i1=1, i2=2;
while (!Equal(g[i1], this->Identity()))
......
......@@ -2709,22 +2709,34 @@ unsigned int Integer::Encode(byte* output, unsigned int outputLen,
}
const Integer Integer::zero_;
static Integer* zero = 0;
const Integer &Integer::Zero()
{
return zero_;
if (!zero)
zero = NEW_TC Integer;
return *zero;
}
const Integer Integer::one_(1,2);
static Integer* one = 0;
const Integer &Integer::One()
{
return one_;
if (!one)
one = NEW_TC Integer(1,2);
return *one;
}
// Clean up static singleton holders, not a leak, but helpful to have gone
// when checking for leaks
void CleanUp()
{
tcDelete(one);
tcDelete(zero);
}
Integer::Integer(RandomNumberGenerator& rng, const Integer& min,
const Integer& max)
{
......
......@@ -24,7 +24,6 @@
#include "runtime.hpp"
#include "misc.hpp"
#include <new> // for NewHandler
#ifdef YASSL_PURE_C
......
......@@ -97,8 +97,11 @@ void OS_Seed::GenerateSeed(byte* output, word32 sz)
OS_Seed::OS_Seed()
{
fd_ = open("/dev/urandom",O_RDONLY);
if (fd_ == -1) {
fd_ = open("/dev/random",O_RDONLY);
if (fd_ == -1)
error_.SetError(OPEN_RAN_E);
}
}
......
......@@ -24,8 +24,13 @@
*/
#include "runtime.hpp"
#include "integer.hpp"
#include "rsa.hpp"
#include "sha.hpp"
#include "md5.hpp"
#include "hmac.hpp"
#include "pwdbased.hpp"
#include "algebra.hpp"
#include "vector.hpp"
#include "hash.hpp"
......@@ -52,6 +57,10 @@ template AllocatorWithCleanup<word32>::pointer StdReallocate<word32, AllocatorWi
#endif
template void tcArrayDelete<char>(char*);
template class PBKDF2_HMAC<SHA>;
template class HMAC<MD5>;
template class HMAC<SHA>;
}
namespace mySTL {
......
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