Warning, /libraries/qca/src/botantools/botantools.diff is written in an unsupported language. File is not indexed.
0001 diff -ur a/include/bigint.h b/include/bigint.h
0002 --- a/include/bigint.h 2007-03-24 11:51:37.000000000 -0700
0003 +++ b/include/bigint.h 2007-06-26 11:31:40.000000000 -0700
0004 @@ -6,7 +6,13 @@
0005 #ifndef BOTAN_BIGINT_H__
0006 #define BOTAN_BIGINT_H__
0007
0008 -#include <botan/base.h>
0009 +#ifdef BOTAN_MINIMAL_BIGINT
0010 +# include <botan/secmem.h>
0011 +# include <botan/exceptn.h>
0012 +#else
0013 +# include <botan/base.h>
0014 +#endif
0015 +
0016 #include <botan/mp_types.h>
0017 #include <iosfwd>
0018
0019 @@ -82,7 +88,9 @@
0020 word operator[](u32bit index) const { return reg[index]; }
0021 void clear() { reg.clear(); }
0022
0023 +#ifndef BOTAN_MINIMAL_BIGINT
0024 void randomize(u32bit = 0);
0025 +#endif
0026
0027 void binary_encode(byte[]) const;
0028 void binary_decode(const byte[], u32bit);
0029 @@ -102,7 +110,9 @@
0030 BigInt(const std::string&);
0031 BigInt(const byte[], u32bit, Base = Binary);
0032 BigInt(Sign, u32bit);
0033 +#ifndef BOTAN_MINIMAL_BIGINT
0034 BigInt(NumberType, u32bit);
0035 +#endif
0036 private:
0037 void grow_to(u32bit) const;
0038 SecureVector<word> reg;
0039 @@ -140,15 +150,19 @@
0040 /*************************************************
0041 * I/O Operators *
0042 *************************************************/
0043 +#ifndef BOTAN_MINIMAL_BIGINT
0044 std::ostream& operator<<(std::ostream&, const BigInt&);
0045 std::istream& operator>>(std::istream&, BigInt&);
0046 +#endif
0047
0048 }
0049
0050 +#ifndef BOTAN_MINIMAL_BIGINT
0051 namespace std {
0052
0053 inline void swap(Botan::BigInt& a, Botan::BigInt& b) { a.swap(b); }
0054
0055 }
0056 +#endif
0057
0058 #endif
0059 diff -ur a/include/charset.h b/include/charset.h
0060 --- a/include/charset.h 2007-03-24 11:51:37.000000000 -0700
0061 +++ b/include/charset.h 2007-06-26 11:31:40.000000000 -0700
0062 @@ -7,7 +7,9 @@
0063 #define BOTAN_CHARSET_H__
0064
0065 #include <botan/types.h>
0066 +#ifndef BOTAN_TOOLS_ONLY
0067 #include <botan/enums.h>
0068 +#endif
0069 #include <string>
0070
0071 namespace Botan {
0072 @@ -15,6 +17,7 @@
0073 /*************************************************
0074 * Character Set Transcoder Interface *
0075 *************************************************/
0076 +#ifndef BOTAN_TOOLS_ONLY
0077 class Charset_Transcoder
0078 {
0079 public:
0080 @@ -23,13 +26,16 @@
0081
0082 virtual ~Charset_Transcoder() {}
0083 };
0084 +#endif
0085
0086 namespace Charset {
0087
0088 /*************************************************
0089 * Character Set Handling *
0090 *************************************************/
0091 +#ifndef BOTAN_TOOLS_ONLY
0092 std::string transcode(const std::string&, Character_Set, Character_Set);
0093 +#endif
0094
0095 bool is_digit(char);
0096 bool is_space(char);
0097 diff -ur a/include/libstate.h b/include/libstate.h
0098 --- a/include/libstate.h 2007-03-24 11:51:37.000000000 -0700
0099 +++ b/include/libstate.h 2007-06-26 11:31:40.000000000 -0700
0100 @@ -6,9 +6,13 @@
0101 #ifndef BOTAN_LIB_STATE_H__
0102 #define BOTAN_LIB_STATE_H__
0103
0104 +#ifdef BOTAN_TOOLS_ONLY
0105 +#include <botan/allocate.h>
0106 +#else
0107 #include <botan/base.h>
0108 #include <botan/enums.h>
0109 #include <botan/ui.h>
0110 +#endif
0111 #include <string>
0112 #include <vector>
0113 #include <map>
0114 @@ -21,6 +25,7 @@
0115 class Library_State
0116 {
0117 public:
0118 +#ifndef BOTAN_TOOLS_ONLY
0119 class Engine_Iterator
0120 {
0121 public:
0122 @@ -38,11 +43,18 @@
0123 virtual void pulse(Pulse_Type) {}
0124 virtual ~UI() {}
0125 };
0126 +#endif
0127
0128 + int prealloc_size;
0129 Allocator* get_allocator(const std::string& = "") const;
0130 void add_allocator(Allocator*);
0131 +#ifdef BOTAN_TOOLS_ONLY
0132 + void set_default_allocator(const std::string&);
0133 +#else
0134 void set_default_allocator(const std::string&) const;
0135 +#endif
0136
0137 +#ifndef BOTAN_TOOLS_ONLY
0138 bool rng_is_seeded() const { return rng->is_seeded(); }
0139 void randomize(byte[], u32bit);
0140
0141 @@ -51,19 +63,23 @@
0142 void add_entropy(const byte[], u32bit);
0143 void add_entropy(EntropySource&, bool);
0144 u32bit seed_prng(bool, u32bit);
0145 +#endif
0146
0147 void load(class Modules&);
0148
0149 +#ifndef BOTAN_TOOLS_ONLY
0150 void set_timer(class Timer*);
0151 u64bit system_clock() const;
0152
0153 class Config& config() const;
0154
0155 void add_engine(class Engine*);
0156 +#endif
0157
0158 class Mutex* get_mutex() const;
0159 class Mutex* get_named_mutex(const std::string&);
0160
0161 +#ifndef BOTAN_TOOLS_ONLY
0162 void set_x509_state(class X509_GlobalState*);
0163 class X509_GlobalState& x509_state();
0164
0165 @@ -73,6 +89,7 @@
0166 void set_transcoder(class Charset_Transcoder*);
0167 std::string transcode(const std::string,
0168 Character_Set, Character_Set) const;
0169 +#endif
0170
0171 Library_State(class Mutex_Factory*);
0172 ~Library_State();
0173 @@ -80,23 +97,34 @@
0174 Library_State(const Library_State&) {}
0175 Library_State& operator=(const Library_State&) { return (*this); }
0176
0177 +#ifndef BOTAN_TOOLS_ONLY
0178 class Engine* get_engine_n(u32bit) const;
0179 +#endif
0180
0181 class Mutex_Factory* mutex_factory;
0182 +#ifndef BOTAN_TOOLS_ONLY
0183 class Timer* timer;
0184 class Config* config_obj;
0185 class X509_GlobalState* x509_state_obj;
0186 +#endif
0187
0188 std::map<std::string, class Mutex*> locks;
0189 std::map<std::string, Allocator*> alloc_factory;
0190 mutable Allocator* cached_default_allocator;
0191 +#ifdef BOTAN_TOOLS_ONLY
0192 + std::string default_allocator_type;
0193 +#endif
0194
0195 +#ifndef BOTAN_TOOLS_ONLY
0196 UI* ui;
0197 class Charset_Transcoder* transcoder;
0198 RandomNumberGenerator* rng;
0199 +#endif
0200 std::vector<Allocator*> allocators;
0201 +#ifndef BOTAN_TOOLS_ONLY
0202 std::vector<EntropySource*> entropy_sources;
0203 std::vector<class Engine*> engines;
0204 +#endif
0205 };
0206
0207 /*************************************************
0208 diff -ur a/include/mem_ops.h b/include/mem_ops.h
0209 --- a/include/mem_ops.h 2007-03-24 11:51:37.000000000 -0700
0210 +++ b/include/mem_ops.h 2007-06-26 11:31:40.000000000 -0700
0211 @@ -8,6 +8,7 @@
0212
0213 #include <botan/types.h>
0214 #include <cstring>
0215 +#include <string.h>
0216
0217 namespace Botan {
0218
0219 @@ -15,16 +16,16 @@
0220 * Memory Manipulation Functions *
0221 *************************************************/
0222 template<typename T> inline void copy_mem(T* out, const T* in, u32bit n)
0223 - { std::memmove(out, in, sizeof(T)*n); }
0224 + { memmove(out, in, sizeof(T)*n); }
0225
0226 template<typename T> inline void clear_mem(T* ptr, u32bit n)
0227 - { std::memset(ptr, 0, sizeof(T)*n); }
0228 + { memset(ptr, 0, sizeof(T)*n); }
0229
0230 template<typename T> inline void set_mem(T* ptr, u32bit n, byte val)
0231 - { std::memset(ptr, val, sizeof(T)*n); }
0232 + { memset(ptr, val, sizeof(T)*n); }
0233
0234 template<typename T> inline bool same_mem(const T* p1, const T* p2, u32bit n)
0235 - { return (std::memcmp(p1, p2, sizeof(T)*n) == 0); }
0236 + { return (memcmp(p1, p2, sizeof(T)*n) == 0); }
0237
0238 }
0239
0240 diff -ur a/include/mem_pool.h b/include/mem_pool.h
0241 --- a/include/mem_pool.h 2007-03-24 11:51:37.000000000 -0700
0242 +++ b/include/mem_pool.h 2007-06-26 11:31:40.000000000 -0700
0243 @@ -46,13 +46,17 @@
0244 byte* alloc(u32bit) throw();
0245 void free(void*, u32bit) throw();
0246
0247 - bool operator<(const void*) const;
0248 bool operator<(const Memory_Block& other) const
0249 - { return (buffer < other.buffer); }
0250 + {
0251 + if(buffer < other.buffer && other.buffer < buffer_end)
0252 + return false;
0253 + return (buffer < other.buffer);
0254 + }
0255 +
0256 private:
0257 typedef u64bit bitmap_type;
0258 - static const u32bit BITMAP_SIZE = 8 * sizeof(bitmap_type);
0259 - static const u32bit BLOCK_SIZE = 64;
0260 + static const u32bit BITMAP_SIZE;
0261 + static const u32bit BLOCK_SIZE;
0262
0263 bitmap_type bitmap;
0264 byte* buffer, *buffer_end;
0265 Only in b/include: mmap_mem.h
0266 diff -ur a/include/modules.h b/include/modules.h
0267 --- a/include/modules.h 2007-03-24 11:51:37.000000000 -0700
0268 +++ b/include/modules.h 2007-06-26 11:31:40.000000000 -0700
0269 @@ -6,7 +6,9 @@
0270 #ifndef BOTAN_MODULE_FACTORIES_H__
0271 #define BOTAN_MODULE_FACTORIES_H__
0272
0273 +#ifndef BOTAN_TOOLS_ONLY
0274 #include <botan/init.h>
0275 +#endif
0276 #include <string>
0277 #include <vector>
0278
0279 @@ -19,14 +21,18 @@
0280 {
0281 public:
0282 virtual class Mutex_Factory* mutex_factory() const = 0;
0283 +#ifndef BOTAN_TOOLS_ONLY
0284 virtual class Timer* timer() const = 0;
0285 virtual class Charset_Transcoder* transcoder() const = 0;
0286 +#endif
0287
0288 virtual std::string default_allocator() const = 0;
0289
0290 virtual std::vector<class Allocator*> allocators() const = 0;
0291 +#ifndef BOTAN_TOOLS_ONLY
0292 virtual std::vector<class EntropySource*> entropy_sources() const = 0;
0293 virtual std::vector<class Engine*> engines() const = 0;
0294 +#endif
0295
0296 virtual ~Modules() {}
0297 };
0298 @@ -38,18 +44,30 @@
0299 {
0300 public:
0301 class Mutex_Factory* mutex_factory() const;
0302 +#ifndef BOTAN_TOOLS_ONLY
0303 class Timer* timer() const;
0304 class Charset_Transcoder* transcoder() const;
0305 +#endif
0306
0307 std::string default_allocator() const;
0308
0309 std::vector<class Allocator*> allocators() const;
0310 +#ifndef BOTAN_TOOLS_ONLY
0311 std::vector<class EntropySource*> entropy_sources() const;
0312 std::vector<class Engine*> engines() const;
0313 +#endif
0314
0315 +#ifdef BOTAN_TOOLS_ONLY
0316 + Builtin_Modules();
0317 +#else
0318 Builtin_Modules(const InitializerOptions&);
0319 +#endif
0320 private:
0321 +#ifdef BOTAN_TOOLS_ONLY
0322 + const bool should_lock;
0323 +#else
0324 const bool should_lock, use_engines;
0325 +#endif
0326 };
0327
0328 }
0329 diff -ur a/include/mutex.h b/include/mutex.h
0330 --- a/include/mutex.h 2007-03-24 11:51:37.000000000 -0700
0331 +++ b/include/mutex.h 2007-06-26 11:31:40.000000000 -0700
0332 @@ -55,6 +55,7 @@
0333 /*************************************************
0334 * Named Mutex Holder *
0335 *************************************************/
0336 +#ifndef BOTAN_NO_LIBSTATE
0337 class Named_Mutex_Holder
0338 {
0339 public:
0340 @@ -63,6 +64,7 @@
0341 private:
0342 const std::string mutex_name;
0343 };
0344 +#endif
0345
0346 }
0347
0348 Only in b/include: mux_qt.h
0349 diff -ur a/include/numthry.h b/include/numthry.h
0350 --- a/include/numthry.h 2007-03-24 11:51:37.000000000 -0700
0351 +++ b/include/numthry.h 2007-06-26 11:31:40.000000000 -0700
0352 @@ -7,11 +7,14 @@
0353 #define BOTAN_NUMBTHRY_H__
0354
0355 #include <botan/bigint.h>
0356 +#ifndef BOTAN_MINIMAL_BIGINT
0357 #include <botan/reducer.h>
0358 #include <botan/pow_mod.h>
0359 +#endif
0360
0361 namespace Botan {
0362
0363 +#ifndef BOTAN_MINIMAL_BIGINT
0364 /*************************************************
0365 * Fused Arithmetic Operations *
0366 *************************************************/
0367 @@ -22,9 +25,11 @@
0368 * Number Theory Functions *
0369 *************************************************/
0370 inline BigInt abs(const BigInt& n) { return n.abs(); }
0371 +#endif
0372
0373 void divide(const BigInt&, const BigInt&, BigInt&, BigInt&);
0374
0375 +#ifndef BOTAN_MINIMAL_BIGINT
0376 BigInt gcd(const BigInt&, const BigInt&);
0377 BigInt lcm(const BigInt&, const BigInt&);
0378
0379 @@ -85,6 +90,7 @@
0380 Fixed_Exponent_Power_Mod pow_mod;
0381 Modular_Reducer reducer;
0382 };
0383 +#endif
0384
0385 }
0386
0387 diff -ur a/include/parsing.h b/include/parsing.h
0388 --- a/include/parsing.h 2007-03-24 11:51:37.000000000 -0700
0389 +++ b/include/parsing.h 2007-06-26 11:31:40.000000000 -0700
0390 @@ -15,17 +15,21 @@
0391 /*************************************************
0392 * String Parsing Functions *
0393 *************************************************/
0394 +#ifndef BOTAN_TOOLS_ONLY
0395 std::vector<std::string> parse_algorithm_name(const std::string&);
0396 std::vector<std::string> split_on(const std::string&, char);
0397 std::vector<u32bit> parse_asn1_oid(const std::string&);
0398 bool x500_name_cmp(const std::string&, const std::string&);
0399 u32bit parse_expr(const std::string&);
0400 +#endif
0401
0402 /*************************************************
0403 * String/Integer Conversions *
0404 *************************************************/
0405 std::string to_string(u64bit, u32bit = 0);
0406 +#ifndef BOTAN_TOOLS_ONLY
0407 u32bit to_u32bit(const std::string&);
0408 +#endif
0409
0410 }
0411
0412 diff -ur a/include/types.h b/include/types.h
0413 --- a/include/types.h 2007-03-24 11:51:37.000000000 -0700
0414 +++ b/include/types.h 2007-06-26 11:31:40.000000000 -0700
0415 @@ -6,10 +6,24 @@
0416 #ifndef BOTAN_TYPES_H__
0417 #define BOTAN_TYPES_H__
0418
0419 +#ifdef BOTAN_TYPES_QT
0420 +#include <QtGlobal>
0421 +#else
0422 #include <botan/build.h>
0423 +#endif
0424
0425 namespace Botan {
0426
0427 +#ifdef BOTAN_TYPES_QT
0428 +
0429 +typedef quint8 byte;
0430 +typedef quint16 u16bit;
0431 +typedef quint32 u32bit;
0432 +typedef qint32 s32bit;
0433 +typedef quint64 u64bit;
0434 +
0435 +#else
0436 +
0437 typedef unsigned char byte;
0438 typedef unsigned short u16bit;
0439 typedef unsigned int u32bit;
0440 @@ -26,6 +40,8 @@
0441 typedef unsigned long long u64bit;
0442 #endif
0443
0444 +#endif // BOTAN_TYPES_QT
0445 +
0446 }
0447
0448 namespace Botan_types {
0449 diff -ur a/include/util.h b/include/util.h
0450 --- a/include/util.h 2007-03-24 11:51:37.000000000 -0700
0451 +++ b/include/util.h 2007-06-26 11:31:40.000000000 -0700
0452 @@ -13,8 +13,10 @@
0453 /*************************************************
0454 * Timer Access Functions *
0455 *************************************************/
0456 +#ifndef BOTAN_TOOLS_ONLY
0457 u64bit system_time();
0458 u64bit system_clock();
0459 +#endif
0460
0461 /*************************************************
0462 * Memory Locking Functions *
0463 @@ -27,13 +29,17 @@
0464 *************************************************/
0465 u32bit round_up(u32bit, u32bit);
0466 u32bit round_down(u32bit, u32bit);
0467 +#ifndef BOTAN_TOOLS_ONLY
0468 u64bit combine_timers(u32bit, u32bit, u32bit);
0469 +#endif
0470
0471 /*************************************************
0472 * Work Factor Estimates *
0473 *************************************************/
0474 +#ifndef BOTAN_TOOLS_ONLY
0475 u32bit entropy_estimate(const byte[], u32bit);
0476 u32bit dl_work_factor(u32bit);
0477 +#endif
0478
0479 }
0480
0481 diff -ur a/modules/alloc_mmap/mmap_mem.cpp b/modules/alloc_mmap/mmap_mem.cpp
0482 --- a/modules/alloc_mmap/mmap_mem.cpp 2007-03-24 11:51:37.000000000 -0700
0483 +++ b/modules/alloc_mmap/mmap_mem.cpp 2007-08-20 07:51:08.000000000 -0700
0484 @@ -102,6 +102,11 @@
0485 void MemoryMapping_Allocator::dealloc_block(void* ptr, u32bit n)
0486 {
0487 if(ptr == 0) return;
0488 +#ifdef MLOCK_NOT_VOID_PTR
0489 +# define MLOCK_TYPE_CAST (char *)
0490 +#else
0491 +# define MLOCK_TYPE_CAST
0492 +#endif
0493
0494 const u32bit OVERWRITE_PASSES = 12;
0495 const byte PATTERNS[] = { 0x00, 0xFF, 0xAA, 0x55, 0x73, 0x8C, 0x5F, 0xA0,
0496 @@ -110,14 +115,14 @@
0497 for(u32bit j = 0; j != OVERWRITE_PASSES; j++)
0498 {
0499 std::memset(ptr, PATTERNS[j % sizeof(PATTERNS)], n);
0500 - if(msync(ptr, n, MS_SYNC))
0501 + if(msync(MLOCK_TYPE_CAST ptr, n, MS_SYNC))
0502 throw MemoryMapping_Failed("Sync operation failed");
0503 }
0504 std::memset(ptr, 0, n);
0505 - if(msync(ptr, n, MS_SYNC))
0506 + if(msync(MLOCK_TYPE_CAST ptr, n, MS_SYNC))
0507 throw MemoryMapping_Failed("Sync operation failed");
0508
0509 - if(munmap(ptr, n))
0510 + if(munmap(MLOCK_TYPE_CAST ptr, n))
0511 throw MemoryMapping_Failed("Could not unmap file");
0512 }
0513
0514 diff -ur a/modules/mux_qt/mux_qt.cpp b/modules/mux_qt/mux_qt.cpp
0515 --- a/modules/mux_qt/mux_qt.cpp 2007-03-24 11:51:37.000000000 -0700
0516 +++ b/modules/mux_qt/mux_qt.cpp 2007-06-26 11:32:30.000000000 -0700
0517 @@ -6,7 +6,7 @@
0518 #include <botan/mux_qt.h>
0519 #include <qmutex.h>
0520
0521 -#if !defined(QT_THREAD_SUPPORT)
0522 +#if QT_VERSION <= 0x040000 && !defined(QT_THREAD_SUPPORT)
0523 #error Your version of Qt does not support threads or mutexes
0524 #endif
0525
0526 diff -ur a/src/big_code.cpp b/src/big_code.cpp
0527 --- a/src/big_code.cpp 2007-03-24 11:51:37.000000000 -0700
0528 +++ b/src/big_code.cpp 2007-06-26 11:31:30.000000000 -0700
0529 @@ -6,7 +6,9 @@
0530 #include <botan/bigint.h>
0531 #include <botan/numthry.h>
0532 #include <botan/charset.h>
0533 +#ifndef BOTAN_MINIMAL_BIGINT
0534 #include <botan/hex.h>
0535 +#endif
0536
0537 namespace Botan {
0538
0539 @@ -17,6 +19,7 @@
0540 {
0541 if(base == Binary)
0542 n.binary_encode(output);
0543 +#ifndef BOTAN_MINIMAL_BIGINT
0544 else if(base == Hexadecimal)
0545 {
0546 SecureVector<byte> binary(n.encoded_size(Binary));
0547 @@ -24,6 +27,7 @@
0548 for(u32bit j = 0; j != binary.size(); ++j)
0549 Hex_Encoder::encode(binary[j], output + 2*j);
0550 }
0551 +#endif
0552 else if(base == Octal)
0553 {
0554 BigInt copy = n;
0555 @@ -46,7 +50,15 @@
0556 output[output_size - 1 - j] =
0557 Charset::digit2char(remainder.word_at(0));
0558 if(copy.is_zero())
0559 + {
0560 + if(j < output_size - 1)
0561 + {
0562 + int extra = output_size - 1 - j;
0563 + memmove(output, output + extra, output_size - extra);
0564 + memset(output + output_size - extra, 0, extra);
0565 + }
0566 break;
0567 + }
0568 }
0569 }
0570 else
0571 @@ -99,6 +111,7 @@
0572 BigInt r;
0573 if(base == Binary)
0574 r.binary_decode(buf, length);
0575 +#ifndef BOTAN_MINIMAL_BIGINT
0576 else if(base == Hexadecimal)
0577 {
0578 SecureVector<byte> hex;
0579 @@ -119,6 +132,7 @@
0580 binary[j] = Hex_Decoder::decode(hex+2*j-offset);
0581 r.binary_decode(binary, binary.size());
0582 }
0583 +#endif
0584 else if(base == Decimal || base == Octal)
0585 {
0586 const u32bit RADIX = ((base == Decimal) ? 10 : 8);
0587 diff -ur a/src/big_io.cpp b/src/big_io.cpp
0588 --- a/src/big_io.cpp 2007-03-24 11:51:37.000000000 -0700
0589 +++ b/src/big_io.cpp 2007-06-26 11:31:30.000000000 -0700
0590 @@ -8,6 +8,8 @@
0591
0592 namespace Botan {
0593
0594 +#ifndef BOTAN_MINIMAL_BIGINT
0595 +
0596 /*************************************************
0597 * Write the BigInt into a stream *
0598 *************************************************/
0599 @@ -49,4 +51,6 @@
0600 return stream;
0601 }
0602
0603 +#endif
0604 +
0605 }
0606 diff -ur a/src/big_ops2.cpp b/src/big_ops2.cpp
0607 --- a/src/big_ops2.cpp 2007-03-24 11:51:37.000000000 -0700
0608 +++ b/src/big_ops2.cpp 2007-06-26 11:31:30.000000000 -0700
0609 @@ -19,7 +19,11 @@
0610 {
0611 const u32bit x_sw = sig_words(), y_sw = y.sig_words();
0612
0613 +#ifdef BOTAN_TYPES_QT
0614 + const u32bit reg_size = qMax(x_sw, y_sw) + 1;
0615 +#else
0616 const u32bit reg_size = std::max(x_sw, y_sw) + 1;
0617 +#endif
0618 grow_to(reg_size);
0619
0620 if((sign() == y.sign()))
0621 @@ -56,7 +60,11 @@
0622
0623 s32bit relative_size = bigint_cmp(data(), x_sw, y.data(), y_sw);
0624
0625 +#ifdef BOTAN_TYPES_QT
0626 + const u32bit reg_size = qMax(x_sw, y_sw) + 1;
0627 +#else
0628 const u32bit reg_size = std::max(x_sw, y_sw) + 1;
0629 +#endif
0630 grow_to(reg_size);
0631
0632 if(relative_size < 0)
0633 diff -ur a/src/big_ops3.cpp b/src/big_ops3.cpp
0634 --- a/src/big_ops3.cpp 2007-03-24 11:51:37.000000000 -0700
0635 +++ b/src/big_ops3.cpp 2007-06-26 11:31:30.000000000 -0700
0636 @@ -18,7 +18,11 @@
0637 {
0638 const u32bit x_sw = x.sig_words(), y_sw = y.sig_words();
0639
0640 +#ifdef BOTAN_TYPES_QT
0641 + BigInt z(x.sign(), qMax(x_sw, y_sw) + 1);
0642 +#else
0643 BigInt z(x.sign(), std::max(x_sw, y_sw) + 1);
0644 +#endif
0645
0646 if((x.sign() == y.sign()))
0647 bigint_add3(z.get_reg(), x.data(), x_sw, y.data(), y_sw);
0648 @@ -49,7 +53,11 @@
0649
0650 s32bit relative_size = bigint_cmp(x.data(), x_sw, y.data(), y_sw);
0651
0652 +#ifdef BOTAN_TYPES_QT
0653 + BigInt z(BigInt::Positive, qMax(x_sw, y_sw) + 1);
0654 +#else
0655 BigInt z(BigInt::Positive, std::max(x_sw, y_sw) + 1);
0656 +#endif
0657
0658 if(relative_size < 0)
0659 {
0660 diff -ur a/src/charset.cpp b/src/charset.cpp
0661 --- a/src/charset.cpp 2007-03-24 11:51:37.000000000 -0700
0662 +++ b/src/charset.cpp 2007-06-26 11:31:30.000000000 -0700
0663 @@ -4,10 +4,15 @@
0664 *************************************************/
0665
0666 #include <botan/charset.h>
0667 +#ifdef BOTAN_TOOLS_ONLY
0668 +#include <botan/exceptn.h>
0669 +#else
0670 #include <botan/hex.h>
0671 #include <botan/base64.h>
0672 +#endif
0673 #include <botan/libstate.h>
0674 #include <cctype>
0675 +#include <ctype.h>
0676
0677 namespace Botan {
0678
0679 @@ -16,11 +21,13 @@
0680 /*************************************************
0681 * Perform character set transcoding *
0682 *************************************************/
0683 +#ifndef BOTAN_TOOLS_ONLY
0684 std::string transcode(const std::string& str,
0685 Character_Set to, Character_Set from)
0686 {
0687 return global_state().transcode(str, to, from);
0688 }
0689 +#endif
0690
0691 /*************************************************
0692 * Check if a character represents a digit *
0693 @@ -92,11 +99,13 @@
0694 *************************************************/
0695 bool caseless_cmp(char a, char b)
0696 {
0697 - return (std::tolower((unsigned char)a) == std::tolower((unsigned char)b));
0698 + return (tolower((unsigned char)a) == tolower((unsigned char)b));
0699 }
0700
0701 }
0702
0703 +#ifndef BOTAN_TOOLS_ONLY
0704 +
0705 /*************************************************
0706 * Hex Encoder Lookup Tables *
0707 *************************************************/
0708 @@ -168,4 +177,6 @@
0709 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
0710 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80 };
0711
0712 +#endif
0713 +
0714 }
0715 diff -ur a/src/defalloc.cpp b/src/defalloc.cpp
0716 --- a/src/defalloc.cpp 2007-03-24 11:51:37.000000000 -0700
0717 +++ b/src/defalloc.cpp 2007-06-26 11:31:30.000000000 -0700
0718 @@ -8,6 +8,8 @@
0719 #include <botan/util.h>
0720 #include <cstdlib>
0721 #include <cstring>
0722 +#include <stdlib.h>
0723 +#include <string.h>
0724
0725 namespace Botan {
0726
0727 @@ -18,7 +20,7 @@
0728 *************************************************/
0729 void* do_malloc(u32bit n, bool do_lock)
0730 {
0731 - void* ptr = std::malloc(n);
0732 + void* ptr = malloc(n);
0733
0734 if(!ptr)
0735 return 0;
0736 @@ -26,7 +28,7 @@
0737 if(do_lock)
0738 lock_mem(ptr, n);
0739
0740 - std::memset(ptr, 0, n);
0741 + memset(ptr, 0, n);
0742 return ptr;
0743 }
0744
0745 @@ -38,11 +40,11 @@
0746 if(!ptr)
0747 return;
0748
0749 - std::memset(ptr, 0, n);
0750 + memset(ptr, 0, n);
0751 if(do_lock)
0752 unlock_mem(ptr, n);
0753
0754 - std::free(ptr);
0755 + free(ptr);
0756 }
0757
0758 }
0759 diff -ur a/src/libstate.cpp b/src/libstate.cpp
0760 --- a/src/libstate.cpp 2007-03-24 11:51:37.000000000 -0700
0761 +++ b/src/libstate.cpp 2007-06-26 11:31:30.000000000 -0700
0762 @@ -4,14 +4,20 @@
0763 *************************************************/
0764
0765 #include <botan/libstate.h>
0766 +#ifndef BOTAN_TOOLS_ONLY
0767 #include <botan/config.h>
0768 +#endif
0769 #include <botan/modules.h>
0770 +#ifndef BOTAN_TOOLS_ONLY
0771 #include <botan/engine.h>
0772 #include <botan/x509stat.h>
0773 +#endif
0774 #include <botan/stl_util.h>
0775 #include <botan/mutex.h>
0776 +#ifndef BOTAN_TOOLS_ONLY
0777 #include <botan/timers.h>
0778 #include <botan/charset.h>
0779 +#endif
0780 #include <algorithm>
0781
0782 namespace Botan {
0783 @@ -56,10 +62,12 @@
0784 /*************************************************
0785 * Increment the Engine iterator *
0786 *************************************************/
0787 +#ifndef BOTAN_TOOLS_ONLY
0788 Engine* Library_State::Engine_Iterator::next()
0789 {
0790 return lib.get_engine_n(n++);
0791 }
0792 +#endif
0793
0794 /*************************************************
0795 * Get a new mutex object *
0796 @@ -92,8 +100,11 @@
0797
0798 if(!cached_default_allocator)
0799 {
0800 +#ifdef BOTAN_TOOLS_ONLY
0801 + std::string chosen = default_allocator_type;
0802 +#else
0803 std::string chosen = config().option("base/default_allocator");
0804 -
0805 +#endif
0806 if(chosen == "")
0807 chosen = "malloc";
0808
0809 @@ -120,17 +131,26 @@
0810 /*************************************************
0811 * Set the default allocator type *
0812 *************************************************/
0813 +#ifdef BOTAN_TOOLS_ONLY
0814 +void Library_State::set_default_allocator(const std::string& type)
0815 +#else
0816 void Library_State::set_default_allocator(const std::string& type) const
0817 +#endif
0818 {
0819 Named_Mutex_Holder lock("allocator");
0820
0821 if(type == "")
0822 return;
0823
0824 +#ifdef BOTAN_TOOLS_ONLY
0825 + default_allocator_type = type;
0826 +#else
0827 config().set("conf", "base/default_allocator", type);
0828 +#endif
0829 cached_default_allocator = 0;
0830 }
0831
0832 +#ifndef BOTAN_TOOLS_ONLY
0833 /*************************************************
0834 * Set the high resolution clock implementation *
0835 *************************************************/
0836 @@ -317,13 +337,17 @@
0837 return (*config_obj);
0838 }
0839
0840 +#endif
0841 +
0842 /*************************************************
0843 * Load modules *
0844 *************************************************/
0845 void Library_State::load(Modules& modules)
0846 {
0847 +#ifndef BOTAN_TOOLS_ONLY
0848 set_timer(modules.timer());
0849 set_transcoder(modules.transcoder());
0850 +#endif
0851
0852 std::vector<Allocator*> mod_allocs = modules.allocators();
0853 for(u32bit j = 0; j != mod_allocs.size(); j++)
0854 @@ -331,6 +355,7 @@
0855
0856 set_default_allocator(modules.default_allocator());
0857
0858 +#ifndef BOTAN_TOOLS_ONLY
0859 std::vector<Engine*> mod_engines = modules.engines();
0860 for(u32bit j = 0; j != mod_engines.size(); ++j)
0861 {
0862 @@ -341,6 +366,7 @@
0863 std::vector<EntropySource*> sources = modules.entropy_sources();
0864 for(u32bit j = 0; j != sources.size(); ++j)
0865 add_entropy_source(sources[j]);
0866 +#endif
0867 }
0868
0869 /*************************************************
0870 @@ -352,25 +378,39 @@
0871 throw Exception("Library_State: no mutex found");
0872
0873 this->mutex_factory = mutex_factory;
0874 +#ifndef BOTAN_TOOLS_ONLY
0875 this->timer = new Timer();
0876 this->transcoder = 0;
0877 this->config_obj = new Config();
0878 +#endif
0879
0880 +#ifndef BOTAN_TOOLS_ONLY
0881 locks["settings"] = get_mutex();
0882 +#endif
0883 locks["allocator"] = get_mutex();
0884 +#ifndef BOTAN_TOOLS_ONLY
0885 locks["rng"] = get_mutex();
0886 locks["engine"] = get_mutex();
0887 rng = 0;
0888 +#endif
0889 cached_default_allocator = 0;
0890 +#ifndef BOTAN_TOOLS_ONLY
0891 x509_state_obj = 0;
0892 ui = 0;
0893 +#endif
0894 }
0895
0896 /*************************************************
0897 * Library_State Destructor *
0898 *************************************************/
0899 +static void delete_lock(std::pair<const std::string, Mutex*> &pair)
0900 + {
0901 + delete pair.second;
0902 + }
0903 +
0904 Library_State::~Library_State()
0905 {
0906 +#ifndef BOTAN_TOOLS_ONLY
0907 delete x509_state_obj;
0908 delete transcoder;
0909 delete rng;
0910 @@ -381,6 +421,7 @@
0911 std::for_each(entropy_sources.begin(), entropy_sources.end(),
0912 del_fun<EntropySource>());
0913 std::for_each(engines.begin(), engines.end(), del_fun<Engine>());
0914 +#endif
0915
0916 cached_default_allocator = 0;
0917
0918 @@ -390,8 +431,7 @@
0919 delete allocators[j];
0920 }
0921
0922 - std::for_each(locks.begin(), locks.end(),
0923 - delete2nd<std::map<std::string, Mutex*>::value_type>);
0924 + std::for_each(locks.begin(), locks.end(), delete_lock);
0925
0926 delete mutex_factory;
0927 }
0928 diff -ur a/src/mem_pool.cpp b/src/mem_pool.cpp
0929 --- a/src/mem_pool.cpp 2007-03-24 11:51:37.000000000 -0700
0930 +++ b/src/mem_pool.cpp 2007-06-26 11:31:30.000000000 -0700
0931 @@ -5,8 +5,12 @@
0932
0933 #include <botan/mem_pool.h>
0934 #include <botan/libstate.h>
0935 +#ifdef BOTAN_TOOLS_ONLY
0936 +#include <botan/mem_ops.h>
0937 +#else
0938 #include <botan/config.h>
0939 #include <botan/bit_ops.h>
0940 +#endif
0941 #include <botan/util.h>
0942 #include <algorithm>
0943
0944 @@ -22,7 +26,11 @@
0945 if(provided)
0946 return provided;
0947
0948 +#ifdef BOTAN_TOOLS_ONLY
0949 + u32bit result = (u32bit)global_state().prealloc_size;
0950 +#else
0951 u32bit result = global_config().option_as_u32bit("base/memory_chunk");
0952 +#endif
0953 if(result)
0954 return result;
0955
0956 @@ -42,16 +50,6 @@
0957 }
0958
0959 /*************************************************
0960 -* Compare a Memory_Block with a void pointer *
0961 -*************************************************/
0962 -inline bool Pooling_Allocator::Memory_Block::operator<(const void* other) const
0963 - {
0964 - if(buffer <= other && other < buffer_end)
0965 - return false;
0966 - return (buffer < other);
0967 - }
0968 -
0969 -/*************************************************
0970 * See if ptr is contained by this block *
0971 *************************************************/
0972 bool Pooling_Allocator::Memory_Block::contains(void* ptr,
0973 @@ -207,7 +205,7 @@
0974 const u32bit block_no = round_up(n, BLOCK_SIZE) / BLOCK_SIZE;
0975
0976 std::vector<Memory_Block>::iterator i =
0977 - std::lower_bound(blocks.begin(), blocks.end(), ptr);
0978 + std::lower_bound(blocks.begin(), blocks.end(), Memory_Block(ptr));
0979
0980 if(i == blocks.end() || !i->contains(ptr, block_no))
0981 throw Invalid_State("Pointer released to the wrong allocator");
0982 @@ -270,7 +268,10 @@
0983 }
0984
0985 std::sort(blocks.begin(), blocks.end());
0986 - last_used = std::lower_bound(blocks.begin(), blocks.end(), ptr);
0987 + last_used = std::lower_bound(blocks.begin(), blocks.end(), Memory_Block(ptr));
0988 }
0989
0990 +const u32bit Pooling_Allocator::Memory_Block::BITMAP_SIZE = 8 * sizeof(Pooling_Allocator::Memory_Block::bitmap_type);
0991 +const u32bit Pooling_Allocator::Memory_Block::BLOCK_SIZE = 64;
0992 +
0993 }
0994 diff -ur a/src/modules.cpp b/src/modules.cpp
0995 --- a/src/modules.cpp 2007-03-24 11:51:37.000000000 -0700
0996 +++ b/src/modules.cpp 2007-06-26 11:31:30.000000000 -0700
0997 @@ -5,71 +5,77 @@
0998
0999 #include <botan/modules.h>
1000 #include <botan/defalloc.h>
1001 +#ifndef BOTAN_TOOLS_ONLY
1002 #include <botan/def_char.h>
1003 #include <botan/eng_def.h>
1004 #include <botan/es_file.h>
1005 #include <botan/timers.h>
1006 +#endif
1007
1008 #if defined(BOTAN_EXT_MUTEX_PTHREAD)
1009 - #include <botan/mux_pthr.h>
1010 +# include <botan/mux_pthr.h>
1011 #elif defined(BOTAN_EXT_MUTEX_WIN32)
1012 - #include <botan/mux_win32.h>
1013 +# include <botan/mux_win32.h>
1014 #elif defined(BOTAN_EXT_MUTEX_QT)
1015 - #include <botan/mux_qt.h>
1016 +# include <botan/mux_qt.h>
1017 #endif
1018
1019 #if defined(BOTAN_EXT_ALLOC_MMAP)
1020 - #include <botan/mmap_mem.h>
1021 +# include <botan/mmap_mem.h>
1022 #endif
1023
1024 +#ifndef BOTAN_TOOLS_ONLY
1025 +
1026 #if defined(BOTAN_EXT_TIMER_HARDWARE)
1027 - #include <botan/tm_hard.h>
1028 +# include <botan/tm_hard.h>
1029 #elif defined(BOTAN_EXT_TIMER_POSIX)
1030 - #include <botan/tm_posix.h>
1031 +# include <botan/tm_posix.h>
1032 #elif defined(BOTAN_EXT_TIMER_UNIX)
1033 - #include <botan/tm_unix.h>
1034 +# include <botan/tm_unix.h>
1035 #elif defined(BOTAN_EXT_TIMER_WIN32)
1036 - #include <botan/tm_win32.h>
1037 +# include <botan/tm_win32.h>
1038 #endif
1039
1040 #if defined(BOTAN_EXT_ENGINE_AEP)
1041 - #include <botan/eng_aep.h>
1042 +# include <botan/eng_aep.h>
1043 #endif
1044
1045 #if defined(BOTAN_EXT_ENGINE_GNU_MP)
1046 - #include <botan/eng_gmp.h>
1047 +# include <botan/eng_gmp.h>
1048 #endif
1049
1050 #if defined(BOTAN_EXT_ENGINE_OPENSSL)
1051 - #include <botan/eng_ossl.h>
1052 +# include <botan/eng_ossl.h>
1053 #endif
1054
1055 #if defined(BOTAN_EXT_ENTROPY_SRC_AEP)
1056 - #include <botan/es_aep.h>
1057 +# include <botan/es_aep.h>
1058 #endif
1059
1060 #if defined(BOTAN_EXT_ENTROPY_SRC_EGD)
1061 - #include <botan/es_egd.h>
1062 +# include <botan/es_egd.h>
1063 #endif
1064
1065 #if defined(BOTAN_EXT_ENTROPY_SRC_UNIX)
1066 - #include <botan/es_unix.h>
1067 +# include <botan/es_unix.h>
1068 #endif
1069
1070 #if defined(BOTAN_EXT_ENTROPY_SRC_BEOS)
1071 - #include <botan/es_beos.h>
1072 +# include <botan/es_beos.h>
1073 #endif
1074
1075 #if defined(BOTAN_EXT_ENTROPY_SRC_CAPI)
1076 - #include <botan/es_capi.h>
1077 +# include <botan/es_capi.h>
1078 #endif
1079
1080 #if defined(BOTAN_EXT_ENTROPY_SRC_WIN32)
1081 - #include <botan/es_win32.h>
1082 +# include <botan/es_win32.h>
1083 #endif
1084
1085 #if defined(BOTAN_EXT_ENTROPY_SRC_FTW)
1086 - #include <botan/es_ftw.h>
1087 +# include <botan/es_ftw.h>
1088 +#endif
1089 +
1090 #endif
1091
1092 namespace Botan {
1093 @@ -93,6 +99,7 @@
1094 /*************************************************
1095 * Find a high resolution timer, if possible *
1096 *************************************************/
1097 +#ifndef BOTAN_TOOLS_ONLY
1098 Timer* Builtin_Modules::timer() const
1099 {
1100 #if defined(BOTAN_EXT_TIMER_HARDWARE)
1101 @@ -107,6 +114,7 @@
1102 return new Timer;
1103 #endif
1104 }
1105 +#endif
1106
1107 /*************************************************
1108 * Find any usable allocators *
1109 @@ -142,6 +150,8 @@
1110 return "malloc";
1111 }
1112
1113 +#ifndef BOTAN_TOOLS_ONLY
1114 +
1115 /*************************************************
1116 * Register any usable entropy sources *
1117 *************************************************/
1118 @@ -217,13 +227,22 @@
1119 return new Default_Charset_Transcoder;
1120 }
1121
1122 +#endif
1123 +
1124 /*************************************************
1125 * Builtin_Modules Constructor *
1126 *************************************************/
1127 +#ifdef BOTAN_TOOLS_ONLY
1128 +Builtin_Modules::Builtin_Modules() :
1129 + should_lock(true)
1130 + {
1131 + }
1132 +#else
1133 Builtin_Modules::Builtin_Modules(const InitializerOptions& args) :
1134 should_lock(args.secure_memory()),
1135 use_engines(args.use_engines())
1136 {
1137 }
1138 +#endif
1139
1140 }
1141 diff -ur a/src/mp_asm.cpp b/src/mp_asm.cpp
1142 --- a/src/mp_asm.cpp 2007-03-24 11:51:37.000000000 -0700
1143 +++ b/src/mp_asm.cpp 2007-06-26 11:31:30.000000000 -0700
1144 @@ -174,6 +174,7 @@
1145 /*************************************************
1146 * Montgomery Reduction Algorithm *
1147 *************************************************/
1148 +#ifndef BOTAN_MINIMAL_BIGINT
1149 void bigint_monty_redc(word z[], u32bit z_size,
1150 const word x[], u32bit x_size, word u)
1151 {
1152 @@ -199,6 +200,7 @@
1153 if(bigint_cmp(z + x_size, x_size + 1, x, x_size) >= 0)
1154 bigint_sub2(z + x_size, x_size + 1, x, x_size);
1155 }
1156 +#endif
1157
1158 }
1159
1160 diff -ur a/src/mutex.cpp b/src/mutex.cpp
1161 --- a/src/mutex.cpp 2007-03-24 11:51:37.000000000 -0700
1162 +++ b/src/mutex.cpp 2007-08-20 07:53:57.000000000 -0700
1163 @@ -3,8 +3,11 @@
1164 * (C) 1999-2007 The Botan Project *
1165 *************************************************/
1166
1167 +#include <stdlib.h>
1168 #include <botan/mutex.h>
1169 +#ifndef BOTAN_NO_LIBSTATE
1170 #include <botan/libstate.h>
1171 +#endif
1172
1173 namespace Botan {
1174
1175 @@ -26,6 +29,7 @@
1176 mux->unlock();
1177 }
1178
1179 +#ifndef BOTAN_NO_LIBSTATE
1180 /*************************************************
1181 * Named_Mutex_Holder Constructor *
1182 *************************************************/
1183 @@ -42,12 +46,17 @@
1184 {
1185 global_state().get_named_mutex(mutex_name)->unlock();
1186 }
1187 +#endif
1188
1189 /*************************************************
1190 * Default Mutex Factory *
1191 *************************************************/
1192 +#ifdef BOTAN_FIX_GDB
1193 +namespace {
1194 +#else
1195 Mutex* Default_Mutex_Factory::make()
1196 {
1197 +#endif
1198 class Default_Mutex : public Mutex
1199 {
1200 public:
1201 @@ -78,6 +87,12 @@
1202 bool locked;
1203 };
1204
1205 +#ifdef BOTAN_FIX_GDB
1206 + } // end unnamed namespace
1207 +Mutex* Default_Mutex_Factory::make()
1208 + {
1209 +#endif
1210 +
1211 return new Default_Mutex;
1212 }
1213
1214 diff -ur a/src/parsing.cpp b/src/parsing.cpp
1215 --- a/src/parsing.cpp 2007-03-24 11:51:37.000000000 -0700
1216 +++ b/src/parsing.cpp 2007-06-26 11:31:30.000000000 -0700
1217 @@ -12,6 +12,7 @@
1218 /*************************************************
1219 * Convert a string into an integer *
1220 *************************************************/
1221 +#ifndef BOTAN_TOOLS_ONLY
1222 u32bit to_u32bit(const std::string& number)
1223 {
1224 u32bit n = 0;
1225 @@ -29,7 +30,7 @@
1226 }
1227 return n;
1228 }
1229 -
1230 +#endif
1231
1232 /*************************************************
1233 * Convert an integer into a string *
1234 @@ -54,6 +55,7 @@
1235 return lenstr;
1236 }
1237
1238 +#ifndef BOTAN_TOOLS_ONLY
1239 /*************************************************
1240 * Parse a SCAN-style algorithm name *
1241 *************************************************/
1242 @@ -237,5 +239,6 @@
1243 else
1244 return to_u32bit(expr);
1245 }
1246 +#endif
1247
1248 }
1249 diff -ur a/src/util.cpp b/src/util.cpp
1250 --- a/src/util.cpp 2007-03-24 11:51:37.000000000 -0700
1251 +++ b/src/util.cpp 2007-06-26 11:31:30.000000000 -0700
1252 @@ -4,7 +4,9 @@
1253 *************************************************/
1254
1255 #include <botan/util.h>
1256 +#ifndef BOTAN_TOOLS_ONLY
1257 #include <botan/bit_ops.h>
1258 +#endif
1259 #include <algorithm>
1260 #include <cmath>
1261
1262 @@ -28,6 +30,7 @@
1263 return (n - (n % align_to));
1264 }
1265
1266 +#ifndef BOTAN_TOOLS_ONLY
1267 /*************************************************
1268 * Return the work required for solving DL *
1269 *************************************************/
1270 @@ -77,5 +80,6 @@
1271
1272 return (estimate / 2);
1273 }
1274 +#endif
1275
1276 }