diff -ur a/include/bigint.h b/include/bigint.h --- a/include/bigint.h 2007-03-24 11:51:37.000000000 -0700 +++ b/include/bigint.h 2007-06-26 11:31:40.000000000 -0700 @@ -6,7 +6,13 @@ #ifndef BOTAN_BIGINT_H__ #define BOTAN_BIGINT_H__ -#include +#ifdef BOTAN_MINIMAL_BIGINT +# include +# include +#else +# include +#endif + #include #include @@ -82,7 +88,9 @@ word operator[](u32bit index) const { return reg[index]; } void clear() { reg.clear(); } +#ifndef BOTAN_MINIMAL_BIGINT void randomize(u32bit = 0); +#endif void binary_encode(byte[]) const; void binary_decode(const byte[], u32bit); @@ -102,7 +110,9 @@ BigInt(const std::string&); BigInt(const byte[], u32bit, Base = Binary); BigInt(Sign, u32bit); +#ifndef BOTAN_MINIMAL_BIGINT BigInt(NumberType, u32bit); +#endif private: void grow_to(u32bit) const; SecureVector reg; @@ -140,15 +150,19 @@ /************************************************* * I/O Operators * *************************************************/ +#ifndef BOTAN_MINIMAL_BIGINT std::ostream& operator<<(std::ostream&, const BigInt&); std::istream& operator>>(std::istream&, BigInt&); +#endif } +#ifndef BOTAN_MINIMAL_BIGINT namespace std { inline void swap(Botan::BigInt& a, Botan::BigInt& b) { a.swap(b); } } +#endif #endif diff -ur a/include/charset.h b/include/charset.h --- a/include/charset.h 2007-03-24 11:51:37.000000000 -0700 +++ b/include/charset.h 2007-06-26 11:31:40.000000000 -0700 @@ -7,7 +7,9 @@ #define BOTAN_CHARSET_H__ #include +#ifndef BOTAN_TOOLS_ONLY #include +#endif #include namespace Botan { @@ -15,6 +17,7 @@ /************************************************* * Character Set Transcoder Interface * *************************************************/ +#ifndef BOTAN_TOOLS_ONLY class Charset_Transcoder { public: @@ -23,13 +26,16 @@ virtual ~Charset_Transcoder() {} }; +#endif namespace Charset { /************************************************* * Character Set Handling * *************************************************/ +#ifndef BOTAN_TOOLS_ONLY std::string transcode(const std::string&, Character_Set, Character_Set); +#endif bool is_digit(char); bool is_space(char); diff -ur a/include/libstate.h b/include/libstate.h --- a/include/libstate.h 2007-03-24 11:51:37.000000000 -0700 +++ b/include/libstate.h 2007-06-26 11:31:40.000000000 -0700 @@ -6,9 +6,13 @@ #ifndef BOTAN_LIB_STATE_H__ #define BOTAN_LIB_STATE_H__ +#ifdef BOTAN_TOOLS_ONLY +#include +#else #include #include #include +#endif #include #include #include @@ -21,6 +25,7 @@ class Library_State { public: +#ifndef BOTAN_TOOLS_ONLY class Engine_Iterator { public: @@ -38,11 +43,18 @@ virtual void pulse(Pulse_Type) {} virtual ~UI() {} }; +#endif + int prealloc_size; Allocator* get_allocator(const std::string& = "") const; void add_allocator(Allocator*); +#ifdef BOTAN_TOOLS_ONLY + void set_default_allocator(const std::string&); +#else void set_default_allocator(const std::string&) const; +#endif +#ifndef BOTAN_TOOLS_ONLY bool rng_is_seeded() const { return rng->is_seeded(); } void randomize(byte[], u32bit); @@ -51,19 +63,23 @@ void add_entropy(const byte[], u32bit); void add_entropy(EntropySource&, bool); u32bit seed_prng(bool, u32bit); +#endif void load(class Modules&); +#ifndef BOTAN_TOOLS_ONLY void set_timer(class Timer*); u64bit system_clock() const; class Config& config() const; void add_engine(class Engine*); +#endif class Mutex* get_mutex() const; class Mutex* get_named_mutex(const std::string&); +#ifndef BOTAN_TOOLS_ONLY void set_x509_state(class X509_GlobalState*); class X509_GlobalState& x509_state(); @@ -73,6 +89,7 @@ void set_transcoder(class Charset_Transcoder*); std::string transcode(const std::string, Character_Set, Character_Set) const; +#endif Library_State(class Mutex_Factory*); ~Library_State(); @@ -80,23 +97,34 @@ Library_State(const Library_State&) {} Library_State& operator=(const Library_State&) { return (*this); } +#ifndef BOTAN_TOOLS_ONLY class Engine* get_engine_n(u32bit) const; +#endif class Mutex_Factory* mutex_factory; +#ifndef BOTAN_TOOLS_ONLY class Timer* timer; class Config* config_obj; class X509_GlobalState* x509_state_obj; +#endif std::map locks; std::map alloc_factory; mutable Allocator* cached_default_allocator; +#ifdef BOTAN_TOOLS_ONLY + std::string default_allocator_type; +#endif +#ifndef BOTAN_TOOLS_ONLY UI* ui; class Charset_Transcoder* transcoder; RandomNumberGenerator* rng; +#endif std::vector allocators; +#ifndef BOTAN_TOOLS_ONLY std::vector entropy_sources; std::vector engines; +#endif }; /************************************************* diff -ur a/include/mem_ops.h b/include/mem_ops.h --- a/include/mem_ops.h 2007-03-24 11:51:37.000000000 -0700 +++ b/include/mem_ops.h 2007-06-26 11:31:40.000000000 -0700 @@ -8,6 +8,7 @@ #include #include +#include namespace Botan { @@ -15,16 +16,16 @@ * Memory Manipulation Functions * *************************************************/ template inline void copy_mem(T* out, const T* in, u32bit n) - { std::memmove(out, in, sizeof(T)*n); } + { memmove(out, in, sizeof(T)*n); } template inline void clear_mem(T* ptr, u32bit n) - { std::memset(ptr, 0, sizeof(T)*n); } + { memset(ptr, 0, sizeof(T)*n); } template inline void set_mem(T* ptr, u32bit n, byte val) - { std::memset(ptr, val, sizeof(T)*n); } + { memset(ptr, val, sizeof(T)*n); } template inline bool same_mem(const T* p1, const T* p2, u32bit n) - { return (std::memcmp(p1, p2, sizeof(T)*n) == 0); } + { return (memcmp(p1, p2, sizeof(T)*n) == 0); } } diff -ur a/include/mem_pool.h b/include/mem_pool.h --- a/include/mem_pool.h 2007-03-24 11:51:37.000000000 -0700 +++ b/include/mem_pool.h 2007-06-26 11:31:40.000000000 -0700 @@ -46,13 +46,17 @@ byte* alloc(u32bit) throw(); void free(void*, u32bit) throw(); - bool operator<(const void*) const; bool operator<(const Memory_Block& other) const - { return (buffer < other.buffer); } + { + if(buffer < other.buffer && other.buffer < buffer_end) + return false; + return (buffer < other.buffer); + } + private: typedef u64bit bitmap_type; - static const u32bit BITMAP_SIZE = 8 * sizeof(bitmap_type); - static const u32bit BLOCK_SIZE = 64; + static const u32bit BITMAP_SIZE; + static const u32bit BLOCK_SIZE; bitmap_type bitmap; byte* buffer, *buffer_end; Only in b/include: mmap_mem.h diff -ur a/include/modules.h b/include/modules.h --- a/include/modules.h 2007-03-24 11:51:37.000000000 -0700 +++ b/include/modules.h 2007-06-26 11:31:40.000000000 -0700 @@ -6,7 +6,9 @@ #ifndef BOTAN_MODULE_FACTORIES_H__ #define BOTAN_MODULE_FACTORIES_H__ +#ifndef BOTAN_TOOLS_ONLY #include +#endif #include #include @@ -19,14 +21,18 @@ { public: virtual class Mutex_Factory* mutex_factory() const = 0; +#ifndef BOTAN_TOOLS_ONLY virtual class Timer* timer() const = 0; virtual class Charset_Transcoder* transcoder() const = 0; +#endif virtual std::string default_allocator() const = 0; virtual std::vector allocators() const = 0; +#ifndef BOTAN_TOOLS_ONLY virtual std::vector entropy_sources() const = 0; virtual std::vector engines() const = 0; +#endif virtual ~Modules() {} }; @@ -38,18 +44,30 @@ { public: class Mutex_Factory* mutex_factory() const; +#ifndef BOTAN_TOOLS_ONLY class Timer* timer() const; class Charset_Transcoder* transcoder() const; +#endif std::string default_allocator() const; std::vector allocators() const; +#ifndef BOTAN_TOOLS_ONLY std::vector entropy_sources() const; std::vector engines() const; +#endif +#ifdef BOTAN_TOOLS_ONLY + Builtin_Modules(); +#else Builtin_Modules(const InitializerOptions&); +#endif private: +#ifdef BOTAN_TOOLS_ONLY + const bool should_lock; +#else const bool should_lock, use_engines; +#endif }; } diff -ur a/include/mutex.h b/include/mutex.h --- a/include/mutex.h 2007-03-24 11:51:37.000000000 -0700 +++ b/include/mutex.h 2007-06-26 11:31:40.000000000 -0700 @@ -55,6 +55,7 @@ /************************************************* * Named Mutex Holder * *************************************************/ +#ifndef BOTAN_NO_LIBSTATE class Named_Mutex_Holder { public: @@ -63,6 +64,7 @@ private: const std::string mutex_name; }; +#endif } Only in b/include: mux_qt.h diff -ur a/include/numthry.h b/include/numthry.h --- a/include/numthry.h 2007-03-24 11:51:37.000000000 -0700 +++ b/include/numthry.h 2007-06-26 11:31:40.000000000 -0700 @@ -7,11 +7,14 @@ #define BOTAN_NUMBTHRY_H__ #include +#ifndef BOTAN_MINIMAL_BIGINT #include #include +#endif namespace Botan { +#ifndef BOTAN_MINIMAL_BIGINT /************************************************* * Fused Arithmetic Operations * *************************************************/ @@ -22,9 +25,11 @@ * Number Theory Functions * *************************************************/ inline BigInt abs(const BigInt& n) { return n.abs(); } +#endif void divide(const BigInt&, const BigInt&, BigInt&, BigInt&); +#ifndef BOTAN_MINIMAL_BIGINT BigInt gcd(const BigInt&, const BigInt&); BigInt lcm(const BigInt&, const BigInt&); @@ -85,6 +90,7 @@ Fixed_Exponent_Power_Mod pow_mod; Modular_Reducer reducer; }; +#endif } diff -ur a/include/parsing.h b/include/parsing.h --- a/include/parsing.h 2007-03-24 11:51:37.000000000 -0700 +++ b/include/parsing.h 2007-06-26 11:31:40.000000000 -0700 @@ -15,17 +15,21 @@ /************************************************* * String Parsing Functions * *************************************************/ +#ifndef BOTAN_TOOLS_ONLY std::vector parse_algorithm_name(const std::string&); std::vector split_on(const std::string&, char); std::vector parse_asn1_oid(const std::string&); bool x500_name_cmp(const std::string&, const std::string&); u32bit parse_expr(const std::string&); +#endif /************************************************* * String/Integer Conversions * *************************************************/ std::string to_string(u64bit, u32bit = 0); +#ifndef BOTAN_TOOLS_ONLY u32bit to_u32bit(const std::string&); +#endif } diff -ur a/include/types.h b/include/types.h --- a/include/types.h 2007-03-24 11:51:37.000000000 -0700 +++ b/include/types.h 2007-06-26 11:31:40.000000000 -0700 @@ -6,10 +6,24 @@ #ifndef BOTAN_TYPES_H__ #define BOTAN_TYPES_H__ +#ifdef BOTAN_TYPES_QT +#include +#else #include +#endif namespace Botan { +#ifdef BOTAN_TYPES_QT + +typedef quint8 byte; +typedef quint16 u16bit; +typedef quint32 u32bit; +typedef qint32 s32bit; +typedef quint64 u64bit; + +#else + typedef unsigned char byte; typedef unsigned short u16bit; typedef unsigned int u32bit; @@ -26,6 +40,8 @@ typedef unsigned long long u64bit; #endif +#endif // BOTAN_TYPES_QT + } namespace Botan_types { diff -ur a/include/util.h b/include/util.h --- a/include/util.h 2007-03-24 11:51:37.000000000 -0700 +++ b/include/util.h 2007-06-26 11:31:40.000000000 -0700 @@ -13,8 +13,10 @@ /************************************************* * Timer Access Functions * *************************************************/ +#ifndef BOTAN_TOOLS_ONLY u64bit system_time(); u64bit system_clock(); +#endif /************************************************* * Memory Locking Functions * @@ -27,13 +29,17 @@ *************************************************/ u32bit round_up(u32bit, u32bit); u32bit round_down(u32bit, u32bit); +#ifndef BOTAN_TOOLS_ONLY u64bit combine_timers(u32bit, u32bit, u32bit); +#endif /************************************************* * Work Factor Estimates * *************************************************/ +#ifndef BOTAN_TOOLS_ONLY u32bit entropy_estimate(const byte[], u32bit); u32bit dl_work_factor(u32bit); +#endif } diff -ur a/modules/alloc_mmap/mmap_mem.cpp b/modules/alloc_mmap/mmap_mem.cpp --- a/modules/alloc_mmap/mmap_mem.cpp 2007-03-24 11:51:37.000000000 -0700 +++ b/modules/alloc_mmap/mmap_mem.cpp 2007-08-20 07:51:08.000000000 -0700 @@ -102,6 +102,11 @@ void MemoryMapping_Allocator::dealloc_block(void* ptr, u32bit n) { if(ptr == 0) return; +#ifdef MLOCK_NOT_VOID_PTR +# define MLOCK_TYPE_CAST (char *) +#else +# define MLOCK_TYPE_CAST +#endif const u32bit OVERWRITE_PASSES = 12; const byte PATTERNS[] = { 0x00, 0xFF, 0xAA, 0x55, 0x73, 0x8C, 0x5F, 0xA0, @@ -110,14 +115,14 @@ for(u32bit j = 0; j != OVERWRITE_PASSES; j++) { std::memset(ptr, PATTERNS[j % sizeof(PATTERNS)], n); - if(msync(ptr, n, MS_SYNC)) + if(msync(MLOCK_TYPE_CAST ptr, n, MS_SYNC)) throw MemoryMapping_Failed("Sync operation failed"); } std::memset(ptr, 0, n); - if(msync(ptr, n, MS_SYNC)) + if(msync(MLOCK_TYPE_CAST ptr, n, MS_SYNC)) throw MemoryMapping_Failed("Sync operation failed"); - if(munmap(ptr, n)) + if(munmap(MLOCK_TYPE_CAST ptr, n)) throw MemoryMapping_Failed("Could not unmap file"); } diff -ur a/modules/mux_qt/mux_qt.cpp b/modules/mux_qt/mux_qt.cpp --- a/modules/mux_qt/mux_qt.cpp 2007-03-24 11:51:37.000000000 -0700 +++ b/modules/mux_qt/mux_qt.cpp 2007-06-26 11:32:30.000000000 -0700 @@ -6,7 +6,7 @@ #include #include -#if !defined(QT_THREAD_SUPPORT) +#if QT_VERSION <= 0x040000 && !defined(QT_THREAD_SUPPORT) #error Your version of Qt does not support threads or mutexes #endif diff -ur a/src/big_code.cpp b/src/big_code.cpp --- a/src/big_code.cpp 2007-03-24 11:51:37.000000000 -0700 +++ b/src/big_code.cpp 2007-06-26 11:31:30.000000000 -0700 @@ -6,7 +6,9 @@ #include #include #include +#ifndef BOTAN_MINIMAL_BIGINT #include +#endif namespace Botan { @@ -17,6 +19,7 @@ { if(base == Binary) n.binary_encode(output); +#ifndef BOTAN_MINIMAL_BIGINT else if(base == Hexadecimal) { SecureVector binary(n.encoded_size(Binary)); @@ -24,6 +27,7 @@ for(u32bit j = 0; j != binary.size(); ++j) Hex_Encoder::encode(binary[j], output + 2*j); } +#endif else if(base == Octal) { BigInt copy = n; @@ -46,7 +50,15 @@ output[output_size - 1 - j] = Charset::digit2char(remainder.word_at(0)); if(copy.is_zero()) + { + if(j < output_size - 1) + { + int extra = output_size - 1 - j; + memmove(output, output + extra, output_size - extra); + memset(output + output_size - extra, 0, extra); + } break; + } } } else @@ -99,6 +111,7 @@ BigInt r; if(base == Binary) r.binary_decode(buf, length); +#ifndef BOTAN_MINIMAL_BIGINT else if(base == Hexadecimal) { SecureVector hex; @@ -119,6 +132,7 @@ binary[j] = Hex_Decoder::decode(hex+2*j-offset); r.binary_decode(binary, binary.size()); } +#endif else if(base == Decimal || base == Octal) { const u32bit RADIX = ((base == Decimal) ? 10 : 8); diff -ur a/src/big_io.cpp b/src/big_io.cpp --- a/src/big_io.cpp 2007-03-24 11:51:37.000000000 -0700 +++ b/src/big_io.cpp 2007-06-26 11:31:30.000000000 -0700 @@ -8,6 +8,8 @@ namespace Botan { +#ifndef BOTAN_MINIMAL_BIGINT + /************************************************* * Write the BigInt into a stream * *************************************************/ @@ -49,4 +51,6 @@ return stream; } +#endif + } diff -ur a/src/big_ops2.cpp b/src/big_ops2.cpp --- a/src/big_ops2.cpp 2007-03-24 11:51:37.000000000 -0700 +++ b/src/big_ops2.cpp 2007-06-26 11:31:30.000000000 -0700 @@ -19,7 +19,11 @@ { const u32bit x_sw = sig_words(), y_sw = y.sig_words(); +#ifdef BOTAN_TYPES_QT + const u32bit reg_size = qMax(x_sw, y_sw) + 1; +#else const u32bit reg_size = std::max(x_sw, y_sw) + 1; +#endif grow_to(reg_size); if((sign() == y.sign())) @@ -56,7 +60,11 @@ s32bit relative_size = bigint_cmp(data(), x_sw, y.data(), y_sw); +#ifdef BOTAN_TYPES_QT + const u32bit reg_size = qMax(x_sw, y_sw) + 1; +#else const u32bit reg_size = std::max(x_sw, y_sw) + 1; +#endif grow_to(reg_size); if(relative_size < 0) diff -ur a/src/big_ops3.cpp b/src/big_ops3.cpp --- a/src/big_ops3.cpp 2007-03-24 11:51:37.000000000 -0700 +++ b/src/big_ops3.cpp 2007-06-26 11:31:30.000000000 -0700 @@ -18,7 +18,11 @@ { const u32bit x_sw = x.sig_words(), y_sw = y.sig_words(); +#ifdef BOTAN_TYPES_QT + BigInt z(x.sign(), qMax(x_sw, y_sw) + 1); +#else BigInt z(x.sign(), std::max(x_sw, y_sw) + 1); +#endif if((x.sign() == y.sign())) bigint_add3(z.get_reg(), x.data(), x_sw, y.data(), y_sw); @@ -49,7 +53,11 @@ s32bit relative_size = bigint_cmp(x.data(), x_sw, y.data(), y_sw); +#ifdef BOTAN_TYPES_QT + BigInt z(BigInt::Positive, qMax(x_sw, y_sw) + 1); +#else BigInt z(BigInt::Positive, std::max(x_sw, y_sw) + 1); +#endif if(relative_size < 0) { diff -ur a/src/charset.cpp b/src/charset.cpp --- a/src/charset.cpp 2007-03-24 11:51:37.000000000 -0700 +++ b/src/charset.cpp 2007-06-26 11:31:30.000000000 -0700 @@ -4,10 +4,15 @@ *************************************************/ #include +#ifdef BOTAN_TOOLS_ONLY +#include +#else #include #include +#endif #include #include +#include namespace Botan { @@ -16,11 +21,13 @@ /************************************************* * Perform character set transcoding * *************************************************/ +#ifndef BOTAN_TOOLS_ONLY std::string transcode(const std::string& str, Character_Set to, Character_Set from) { return global_state().transcode(str, to, from); } +#endif /************************************************* * Check if a character represents a digit * @@ -92,11 +99,13 @@ *************************************************/ bool caseless_cmp(char a, char b) { - return (std::tolower((unsigned char)a) == std::tolower((unsigned char)b)); + return (tolower((unsigned char)a) == tolower((unsigned char)b)); } } +#ifndef BOTAN_TOOLS_ONLY + /************************************************* * Hex Encoder Lookup Tables * *************************************************/ @@ -168,4 +177,6 @@ 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80 }; +#endif + } diff -ur a/src/defalloc.cpp b/src/defalloc.cpp --- a/src/defalloc.cpp 2007-03-24 11:51:37.000000000 -0700 +++ b/src/defalloc.cpp 2007-06-26 11:31:30.000000000 -0700 @@ -8,6 +8,8 @@ #include #include #include +#include +#include namespace Botan { @@ -18,7 +20,7 @@ *************************************************/ void* do_malloc(u32bit n, bool do_lock) { - void* ptr = std::malloc(n); + void* ptr = malloc(n); if(!ptr) return 0; @@ -26,7 +28,7 @@ if(do_lock) lock_mem(ptr, n); - std::memset(ptr, 0, n); + memset(ptr, 0, n); return ptr; } @@ -38,11 +40,11 @@ if(!ptr) return; - std::memset(ptr, 0, n); + memset(ptr, 0, n); if(do_lock) unlock_mem(ptr, n); - std::free(ptr); + free(ptr); } } diff -ur a/src/libstate.cpp b/src/libstate.cpp --- a/src/libstate.cpp 2007-03-24 11:51:37.000000000 -0700 +++ b/src/libstate.cpp 2007-06-26 11:31:30.000000000 -0700 @@ -4,14 +4,20 @@ *************************************************/ #include +#ifndef BOTAN_TOOLS_ONLY #include +#endif #include +#ifndef BOTAN_TOOLS_ONLY #include #include +#endif #include #include +#ifndef BOTAN_TOOLS_ONLY #include #include +#endif #include namespace Botan { @@ -56,10 +62,12 @@ /************************************************* * Increment the Engine iterator * *************************************************/ +#ifndef BOTAN_TOOLS_ONLY Engine* Library_State::Engine_Iterator::next() { return lib.get_engine_n(n++); } +#endif /************************************************* * Get a new mutex object * @@ -92,8 +100,11 @@ if(!cached_default_allocator) { +#ifdef BOTAN_TOOLS_ONLY + std::string chosen = default_allocator_type; +#else std::string chosen = config().option("base/default_allocator"); - +#endif if(chosen == "") chosen = "malloc"; @@ -120,17 +131,26 @@ /************************************************* * Set the default allocator type * *************************************************/ +#ifdef BOTAN_TOOLS_ONLY +void Library_State::set_default_allocator(const std::string& type) +#else void Library_State::set_default_allocator(const std::string& type) const +#endif { Named_Mutex_Holder lock("allocator"); if(type == "") return; +#ifdef BOTAN_TOOLS_ONLY + default_allocator_type = type; +#else config().set("conf", "base/default_allocator", type); +#endif cached_default_allocator = 0; } +#ifndef BOTAN_TOOLS_ONLY /************************************************* * Set the high resolution clock implementation * *************************************************/ @@ -317,13 +337,17 @@ return (*config_obj); } +#endif + /************************************************* * Load modules * *************************************************/ void Library_State::load(Modules& modules) { +#ifndef BOTAN_TOOLS_ONLY set_timer(modules.timer()); set_transcoder(modules.transcoder()); +#endif std::vector mod_allocs = modules.allocators(); for(u32bit j = 0; j != mod_allocs.size(); j++) @@ -331,6 +355,7 @@ set_default_allocator(modules.default_allocator()); +#ifndef BOTAN_TOOLS_ONLY std::vector mod_engines = modules.engines(); for(u32bit j = 0; j != mod_engines.size(); ++j) { @@ -341,6 +366,7 @@ std::vector sources = modules.entropy_sources(); for(u32bit j = 0; j != sources.size(); ++j) add_entropy_source(sources[j]); +#endif } /************************************************* @@ -352,25 +378,39 @@ throw Exception("Library_State: no mutex found"); this->mutex_factory = mutex_factory; +#ifndef BOTAN_TOOLS_ONLY this->timer = new Timer(); this->transcoder = 0; this->config_obj = new Config(); +#endif +#ifndef BOTAN_TOOLS_ONLY locks["settings"] = get_mutex(); +#endif locks["allocator"] = get_mutex(); +#ifndef BOTAN_TOOLS_ONLY locks["rng"] = get_mutex(); locks["engine"] = get_mutex(); rng = 0; +#endif cached_default_allocator = 0; +#ifndef BOTAN_TOOLS_ONLY x509_state_obj = 0; ui = 0; +#endif } /************************************************* * Library_State Destructor * *************************************************/ +static void delete_lock(std::pair &pair) + { + delete pair.second; + } + Library_State::~Library_State() { +#ifndef BOTAN_TOOLS_ONLY delete x509_state_obj; delete transcoder; delete rng; @@ -381,6 +421,7 @@ std::for_each(entropy_sources.begin(), entropy_sources.end(), del_fun()); std::for_each(engines.begin(), engines.end(), del_fun()); +#endif cached_default_allocator = 0; @@ -390,8 +431,7 @@ delete allocators[j]; } - std::for_each(locks.begin(), locks.end(), - delete2nd::value_type>); + std::for_each(locks.begin(), locks.end(), delete_lock); delete mutex_factory; } diff -ur a/src/mem_pool.cpp b/src/mem_pool.cpp --- a/src/mem_pool.cpp 2007-03-24 11:51:37.000000000 -0700 +++ b/src/mem_pool.cpp 2007-06-26 11:31:30.000000000 -0700 @@ -5,8 +5,12 @@ #include #include +#ifdef BOTAN_TOOLS_ONLY +#include +#else #include #include +#endif #include #include @@ -22,7 +26,11 @@ if(provided) return provided; +#ifdef BOTAN_TOOLS_ONLY + u32bit result = (u32bit)global_state().prealloc_size; +#else u32bit result = global_config().option_as_u32bit("base/memory_chunk"); +#endif if(result) return result; @@ -42,16 +50,6 @@ } /************************************************* -* Compare a Memory_Block with a void pointer * -*************************************************/ -inline bool Pooling_Allocator::Memory_Block::operator<(const void* other) const - { - if(buffer <= other && other < buffer_end) - return false; - return (buffer < other); - } - -/************************************************* * See if ptr is contained by this block * *************************************************/ bool Pooling_Allocator::Memory_Block::contains(void* ptr, @@ -207,7 +205,7 @@ const u32bit block_no = round_up(n, BLOCK_SIZE) / BLOCK_SIZE; std::vector::iterator i = - std::lower_bound(blocks.begin(), blocks.end(), ptr); + std::lower_bound(blocks.begin(), blocks.end(), Memory_Block(ptr)); if(i == blocks.end() || !i->contains(ptr, block_no)) throw Invalid_State("Pointer released to the wrong allocator"); @@ -270,7 +268,10 @@ } std::sort(blocks.begin(), blocks.end()); - last_used = std::lower_bound(blocks.begin(), blocks.end(), ptr); + last_used = std::lower_bound(blocks.begin(), blocks.end(), Memory_Block(ptr)); } +const u32bit Pooling_Allocator::Memory_Block::BITMAP_SIZE = 8 * sizeof(Pooling_Allocator::Memory_Block::bitmap_type); +const u32bit Pooling_Allocator::Memory_Block::BLOCK_SIZE = 64; + } diff -ur a/src/modules.cpp b/src/modules.cpp --- a/src/modules.cpp 2007-03-24 11:51:37.000000000 -0700 +++ b/src/modules.cpp 2007-06-26 11:31:30.000000000 -0700 @@ -5,71 +5,77 @@ #include #include +#ifndef BOTAN_TOOLS_ONLY #include #include #include #include +#endif #if defined(BOTAN_EXT_MUTEX_PTHREAD) - #include +# include #elif defined(BOTAN_EXT_MUTEX_WIN32) - #include +# include #elif defined(BOTAN_EXT_MUTEX_QT) - #include +# include #endif #if defined(BOTAN_EXT_ALLOC_MMAP) - #include +# include #endif +#ifndef BOTAN_TOOLS_ONLY + #if defined(BOTAN_EXT_TIMER_HARDWARE) - #include +# include #elif defined(BOTAN_EXT_TIMER_POSIX) - #include +# include #elif defined(BOTAN_EXT_TIMER_UNIX) - #include +# include #elif defined(BOTAN_EXT_TIMER_WIN32) - #include +# include #endif #if defined(BOTAN_EXT_ENGINE_AEP) - #include +# include #endif #if defined(BOTAN_EXT_ENGINE_GNU_MP) - #include +# include #endif #if defined(BOTAN_EXT_ENGINE_OPENSSL) - #include +# include #endif #if defined(BOTAN_EXT_ENTROPY_SRC_AEP) - #include +# include #endif #if defined(BOTAN_EXT_ENTROPY_SRC_EGD) - #include +# include #endif #if defined(BOTAN_EXT_ENTROPY_SRC_UNIX) - #include +# include #endif #if defined(BOTAN_EXT_ENTROPY_SRC_BEOS) - #include +# include #endif #if defined(BOTAN_EXT_ENTROPY_SRC_CAPI) - #include +# include #endif #if defined(BOTAN_EXT_ENTROPY_SRC_WIN32) - #include +# include #endif #if defined(BOTAN_EXT_ENTROPY_SRC_FTW) - #include +# include +#endif + #endif namespace Botan { @@ -93,6 +99,7 @@ /************************************************* * Find a high resolution timer, if possible * *************************************************/ +#ifndef BOTAN_TOOLS_ONLY Timer* Builtin_Modules::timer() const { #if defined(BOTAN_EXT_TIMER_HARDWARE) @@ -107,6 +114,7 @@ return new Timer; #endif } +#endif /************************************************* * Find any usable allocators * @@ -142,6 +150,8 @@ return "malloc"; } +#ifndef BOTAN_TOOLS_ONLY + /************************************************* * Register any usable entropy sources * *************************************************/ @@ -217,13 +227,22 @@ return new Default_Charset_Transcoder; } +#endif + /************************************************* * Builtin_Modules Constructor * *************************************************/ +#ifdef BOTAN_TOOLS_ONLY +Builtin_Modules::Builtin_Modules() : + should_lock(true) + { + } +#else Builtin_Modules::Builtin_Modules(const InitializerOptions& args) : should_lock(args.secure_memory()), use_engines(args.use_engines()) { } +#endif } diff -ur a/src/mp_asm.cpp b/src/mp_asm.cpp --- a/src/mp_asm.cpp 2007-03-24 11:51:37.000000000 -0700 +++ b/src/mp_asm.cpp 2007-06-26 11:31:30.000000000 -0700 @@ -174,6 +174,7 @@ /************************************************* * Montgomery Reduction Algorithm * *************************************************/ +#ifndef BOTAN_MINIMAL_BIGINT void bigint_monty_redc(word z[], u32bit z_size, const word x[], u32bit x_size, word u) { @@ -199,6 +200,7 @@ if(bigint_cmp(z + x_size, x_size + 1, x, x_size) >= 0) bigint_sub2(z + x_size, x_size + 1, x, x_size); } +#endif } diff -ur a/src/mutex.cpp b/src/mutex.cpp --- a/src/mutex.cpp 2007-03-24 11:51:37.000000000 -0700 +++ b/src/mutex.cpp 2007-08-20 07:53:57.000000000 -0700 @@ -3,8 +3,11 @@ * (C) 1999-2007 The Botan Project * *************************************************/ +#include #include +#ifndef BOTAN_NO_LIBSTATE #include +#endif namespace Botan { @@ -26,6 +29,7 @@ mux->unlock(); } +#ifndef BOTAN_NO_LIBSTATE /************************************************* * Named_Mutex_Holder Constructor * *************************************************/ @@ -42,12 +46,17 @@ { global_state().get_named_mutex(mutex_name)->unlock(); } +#endif /************************************************* * Default Mutex Factory * *************************************************/ +#ifdef BOTAN_FIX_GDB +namespace { +#else Mutex* Default_Mutex_Factory::make() { +#endif class Default_Mutex : public Mutex { public: @@ -78,6 +87,12 @@ bool locked; }; +#ifdef BOTAN_FIX_GDB + } // end unnamed namespace +Mutex* Default_Mutex_Factory::make() + { +#endif + return new Default_Mutex; } diff -ur a/src/parsing.cpp b/src/parsing.cpp --- a/src/parsing.cpp 2007-03-24 11:51:37.000000000 -0700 +++ b/src/parsing.cpp 2007-06-26 11:31:30.000000000 -0700 @@ -12,6 +12,7 @@ /************************************************* * Convert a string into an integer * *************************************************/ +#ifndef BOTAN_TOOLS_ONLY u32bit to_u32bit(const std::string& number) { u32bit n = 0; @@ -29,7 +30,7 @@ } return n; } - +#endif /************************************************* * Convert an integer into a string * @@ -54,6 +55,7 @@ return lenstr; } +#ifndef BOTAN_TOOLS_ONLY /************************************************* * Parse a SCAN-style algorithm name * *************************************************/ @@ -237,5 +239,6 @@ else return to_u32bit(expr); } +#endif } diff -ur a/src/util.cpp b/src/util.cpp --- a/src/util.cpp 2007-03-24 11:51:37.000000000 -0700 +++ b/src/util.cpp 2007-06-26 11:31:30.000000000 -0700 @@ -4,7 +4,9 @@ *************************************************/ #include +#ifndef BOTAN_TOOLS_ONLY #include +#endif #include #include @@ -28,6 +30,7 @@ return (n - (n % align_to)); } +#ifndef BOTAN_TOOLS_ONLY /************************************************* * Return the work required for solving DL * *************************************************/ @@ -77,5 +80,6 @@ return (estimate / 2); } +#endif }