diff options
author | unknown <svoj@mysql.com> | 2005-05-31 20:56:32 +0500 |
---|---|---|
committer | unknown <svoj@mysql.com> | 2005-05-31 20:56:32 +0500 |
commit | b3d646e6f8b3b53f43ecb4f1cfefd2863d689390 (patch) | |
tree | 039a0d9d6e565ecbf39c2c04fed0bdf039351125 /extra/yassl/taocrypt/include | |
parent | 1c7b61e3aef5227165a9957ead000e67935708b2 (diff) | |
download | mariadb-git-b3d646e6f8b3b53f43ecb4f1cfefd2863d689390.tar.gz |
WL#2286 - Compile MySQL w/YASSL support
merge with latest yaSSL, move templates instantiation into separate file where it is possible
extra/yassl/include/buffer.hpp:
merge with latest yaSSL
extra/yassl/include/crypto_wrapper.hpp:
merge with latest yaSSL
extra/yassl/include/socket_wrapper.hpp:
merge with latest yaSSL
extra/yassl/include/yassl_imp.hpp:
merge with latest yaSSL
extra/yassl/include/yassl_types.hpp:
merge with latest yaSSL
extra/yassl/mySTL/helpers.hpp:
merge with latest yaSSL
extra/yassl/mySTL/list.hpp:
merge with latest yaSSL
extra/yassl/mySTL/memory.hpp:
merge with latest yaSSL
extra/yassl/mySTL/vector.hpp:
merge with latest yaSSL
extra/yassl/src/Makefile.am:
Include template_instnt.cpp into libyassl_a_SOURCES.
extra/yassl/src/buffer.cpp:
merge with latest yaSSL
extra/yassl/src/cert_wrapper.cpp:
merge with latest yaSSL
extra/yassl/src/crypto_wrapper.cpp:
merge with latest yaSSL
extra/yassl/src/handshake.cpp:
merge with latest yaSSL
extra/yassl/src/lock.cpp:
merge with latest yaSSL
extra/yassl/src/log.cpp:
merge with latest yaSSL
extra/yassl/src/socket_wrapper.cpp:
merge with latest yaSSL
extra/yassl/src/ssl.cpp:
merge with latest yaSSL
extra/yassl/src/timer.cpp:
merge with latest yaSSL
extra/yassl/src/yassl_error.cpp:
merge with latest yaSSL
extra/yassl/src/yassl_imp.cpp:
merge with latest yaSSL
extra/yassl/src/yassl_int.cpp:
merge with latest yaSSL
extra/yassl/taocrypt/include/algebra.hpp:
merge with latest yaSSL
extra/yassl/taocrypt/include/asn.hpp:
merge with latest yaSSL
extra/yassl/taocrypt/include/block.hpp:
merge with latest yaSSL
extra/yassl/taocrypt/include/hash.hpp:
merge with latest yaSSL
extra/yassl/taocrypt/include/integer.hpp:
merge with latest yaSSL
extra/yassl/taocrypt/include/misc.hpp:
merge with latest yaSSL
extra/yassl/taocrypt/include/modes.hpp:
merge with latest yaSSL
extra/yassl/taocrypt/include/runtime.hpp:
merge with latest yaSSL
extra/yassl/taocrypt/src/Makefile.am:
Include template_instnt.cpp into libtaocrypt_a_SOURCES.
extra/yassl/taocrypt/src/aestables.cpp:
merge with latest yaSSL
extra/yassl/taocrypt/src/algebra.cpp:
merge with latest yaSSL
extra/yassl/taocrypt/src/arc4.cpp:
merge with latest yaSSL
extra/yassl/taocrypt/src/asn.cpp:
merge with latest yaSSL
extra/yassl/taocrypt/src/coding.cpp:
merge with latest yaSSL
extra/yassl/taocrypt/src/dh.cpp:
merge with latest yaSSL
extra/yassl/taocrypt/src/dsa.cpp:
merge with latest yaSSL
extra/yassl/taocrypt/src/file.cpp:
merge with latest yaSSL
extra/yassl/taocrypt/src/integer.cpp:
merge with latest yaSSL
extra/yassl/taocrypt/src/misc.cpp:
merge with latest yaSSL
extra/yassl/taocrypt/src/random.cpp:
merge with latest yaSSL
extra/yassl/taocrypt/src/rsa.cpp:
merge with latest yaSSL
Diffstat (limited to 'extra/yassl/taocrypt/include')
-rw-r--r-- | extra/yassl/taocrypt/include/algebra.hpp | 6 | ||||
-rw-r--r-- | extra/yassl/taocrypt/include/asn.hpp | 6 | ||||
-rw-r--r-- | extra/yassl/taocrypt/include/block.hpp | 4 | ||||
-rw-r--r-- | extra/yassl/taocrypt/include/hash.hpp | 8 | ||||
-rw-r--r-- | extra/yassl/taocrypt/include/integer.hpp | 11 | ||||
-rw-r--r-- | extra/yassl/taocrypt/include/misc.hpp | 100 | ||||
-rw-r--r-- | extra/yassl/taocrypt/include/modes.hpp | 2 | ||||
-rw-r--r-- | extra/yassl/taocrypt/include/runtime.hpp | 24 | ||||
-rw-r--r-- | extra/yassl/taocrypt/include/type_traits.hpp | 80 | ||||
-rw-r--r-- | extra/yassl/taocrypt/include/types.hpp | 99 |
10 files changed, 239 insertions, 101 deletions
diff --git a/extra/yassl/taocrypt/include/algebra.hpp b/extra/yassl/taocrypt/include/algebra.hpp index 92cac607d97..a09ac8dce16 100644 --- a/extra/yassl/taocrypt/include/algebra.hpp +++ b/extra/yassl/taocrypt/include/algebra.hpp @@ -38,7 +38,7 @@ namespace TaoCrypt { // abcd = group.Add(a, group.Add(b, group.Add(c,d)); // Abstract Group -class TAOCRYPT_NO_VTABLE AbstractGroup +class TAOCRYPT_NO_VTABLE AbstractGroup : public virtual_base { public: typedef Integer Element; @@ -70,8 +70,8 @@ class TAOCRYPT_NO_VTABLE AbstractRing : public AbstractGroup public: typedef Integer Element; - AbstractRing() {m_mg.m_pRing = this;} - AbstractRing(const AbstractRing &source) : AbstractGroup() {m_mg.m_pRing = this;} + AbstractRing() : AbstractGroup() {m_mg.m_pRing = this;} + AbstractRing(const AbstractRing &source) {m_mg.m_pRing = this;} AbstractRing& operator=(const AbstractRing &source) {return *this;} virtual bool IsUnit(const Element &a) const =0; diff --git a/extra/yassl/taocrypt/include/asn.hpp b/extra/yassl/taocrypt/include/asn.hpp index 974bbf4c86f..14fcf22d843 100644 --- a/extra/yassl/taocrypt/include/asn.hpp +++ b/extra/yassl/taocrypt/include/asn.hpp @@ -106,7 +106,7 @@ class DH; // General BER decoding -class BER_Decoder { +class BER_Decoder : public virtual_base { protected: Source& source_; public: @@ -184,7 +184,7 @@ class PublicKey { word32 sz_; public: explicit PublicKey(const byte* k = 0, word32 s = 0); - ~PublicKey() { delete[] key_; } + ~PublicKey() { tcArrayDelete(key_); } const byte* GetKey() const { return key_; } word32 size() const { return sz_; } @@ -287,7 +287,7 @@ word32 DecodeDSA_Signature(byte* decoded, const byte* encoded, word32 sz); // General DER encoding -class DER_Encoder { +class DER_Encoder : public virtual_base { public: DER_Encoder() {} virtual ~DER_Encoder() {} diff --git a/extra/yassl/taocrypt/include/block.hpp b/extra/yassl/taocrypt/include/block.hpp index f3c4415682d..c5eec55d37e 100644 --- a/extra/yassl/taocrypt/include/block.hpp +++ b/extra/yassl/taocrypt/include/block.hpp @@ -100,13 +100,13 @@ public: CheckSize(n); if (n == 0) return 0; - return new T[n]; + return new (tc) T[n]; } void deallocate(void* p, size_type n) { memset(p, 0, n * sizeof(T)); - delete [] (T*)p; + tcArrayDelete((T*)p); } pointer reallocate(T* p, size_type oldSize, size_type newSize, diff --git a/extra/yassl/taocrypt/include/hash.hpp b/extra/yassl/taocrypt/include/hash.hpp index f01f343c2d1..257aa1be419 100644 --- a/extra/yassl/taocrypt/include/hash.hpp +++ b/extra/yassl/taocrypt/include/hash.hpp @@ -32,7 +32,7 @@ namespace TaoCrypt { // HASH -class HASH { +class HASH : public virtual_base { public: virtual ~HASH() {} @@ -50,9 +50,9 @@ public: class HASHwithTransform : public HASH { public: HASHwithTransform(word32 digSz, word32 buffSz) - : digest_(new word32[digSz]), buffer_(new byte[buffSz]) {} - virtual ~HASHwithTransform() { delete[] buffer_; delete[] digest_; } - + : digest_(new (tc) word32[digSz]), buffer_(new (tc) byte[buffSz]) {} + virtual ~HASHwithTransform() { tcArrayDelete(buffer_); + tcArrayDelete(digest_); } virtual ByteOrder getByteOrder() const = 0; virtual word32 getPadSize() const = 0; diff --git a/extra/yassl/taocrypt/include/integer.hpp b/extra/yassl/taocrypt/include/integer.hpp index e9e4a7218bd..f9ef267ce4c 100644 --- a/extra/yassl/taocrypt/include/integer.hpp +++ b/extra/yassl/taocrypt/include/integer.hpp @@ -136,9 +136,8 @@ public: ~Integer() {} - static const Integer &Zero(); - static const Integer &One(); - static const Integer &Two(); + static const Integer& Zero(); + static const Integer& One(); Integer& Ref() { return *this; } @@ -252,9 +251,6 @@ private: friend class ModularArithmetic; friend class MontgomeryRepresentation; - static const Integer zero; - static const Integer one; - static const Integer two; Integer(word value, unsigned int length); int PositiveCompare(const Integer& t) const; @@ -267,6 +263,9 @@ 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) diff --git a/extra/yassl/taocrypt/include/misc.hpp b/extra/yassl/taocrypt/include/misc.hpp index de8cbb30fcb..812cdd93879 100644 --- a/extra/yassl/taocrypt/include/misc.hpp +++ b/extra/yassl/taocrypt/include/misc.hpp @@ -27,75 +27,59 @@ #include <stdlib.h> #include <assert.h> #include <string.h> +#include "types.hpp" +#include "type_traits.hpp" +/* +namespace GCC_ABI { + extern "C" int __cxa_pure_virtual(); +} */ namespace TaoCrypt { +// using GCC_ABI::__cxa_pure_virtual; -// 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 +// library allocation +struct new_t {}; // TaoCrypt New type +extern new_t tc; // pass in parameter -#ifndef BIG_ENDIAN_ORDER - #define LITTLE_ENDIAN_ORDER -#endif +} // namespace TaoCrypt +void* operator new (size_t, TaoCrypt::new_t); +void* operator new[](size_t, TaoCrypt::new_t); -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 +void operator delete (void*, TaoCrypt::new_t); +void operator delete[](void*, TaoCrypt::new_t); -// 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 -// __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 +namespace TaoCrypt { -const word32 WORD_SIZE = sizeof(word); -const word32 WORD_BITS = WORD_SIZE * 8; +template<typename T> +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__) diff --git a/extra/yassl/taocrypt/include/modes.hpp b/extra/yassl/taocrypt/include/modes.hpp index 3f9878a9e62..585231c9b9e 100644 --- a/extra/yassl/taocrypt/include/modes.hpp +++ b/extra/yassl/taocrypt/include/modes.hpp @@ -56,7 +56,7 @@ private: // Mode Base for block ciphers, static size -class Mode_BASE { +class Mode_BASE : public virtual_base { public: enum { MaxBlockSz = 16 }; diff --git a/extra/yassl/taocrypt/include/runtime.hpp b/extra/yassl/taocrypt/include/runtime.hpp index 43f1b72fd51..01106b6f960 100644 --- a/extra/yassl/taocrypt/include/runtime.hpp +++ b/extra/yassl/taocrypt/include/runtime.hpp @@ -31,30 +31,6 @@ #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" { #include <assert.h> diff --git a/extra/yassl/taocrypt/include/type_traits.hpp b/extra/yassl/taocrypt/include/type_traits.hpp new file mode 100644 index 00000000000..caf71f90e11 --- /dev/null +++ b/extra/yassl/taocrypt/include/type_traits.hpp @@ -0,0 +1,80 @@ +/* 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 diff --git a/extra/yassl/taocrypt/include/types.hpp b/extra/yassl/taocrypt/include/types.hpp new file mode 100644 index 00000000000..0d57022a2d0 --- /dev/null +++ b/extra/yassl/taocrypt/include/types.hpp @@ -0,0 +1,99 @@ +/* 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 |