1
diff -ur a/include/bigint.h b/include/bigint.h
2
--- a/include/bigint.h 2007-03-24 11:51:37.000000000 -0700
3
+++ b/include/bigint.h 2007-06-26 11:31:40.000000000 -0700
5
#ifndef BOTAN_BIGINT_H__
6
#define BOTAN_BIGINT_H__
8
-#include <botan/base.h>
9
+#ifdef BOTAN_MINIMAL_BIGINT
10
+# include <botan/secmem.h>
11
+# include <botan/exceptn.h>
13
+# include <botan/base.h>
16
#include <botan/mp_types.h>
20
word operator[](u32bit index) const { return reg[index]; }
21
void clear() { reg.clear(); }
23
+#ifndef BOTAN_MINIMAL_BIGINT
24
void randomize(u32bit = 0);
27
void binary_encode(byte[]) const;
28
void binary_decode(const byte[], u32bit);
30
BigInt(const std::string&);
31
BigInt(const byte[], u32bit, Base = Binary);
33
+#ifndef BOTAN_MINIMAL_BIGINT
34
BigInt(NumberType, u32bit);
37
void grow_to(u32bit) const;
38
SecureVector<word> reg;
40
/*************************************************
42
*************************************************/
43
+#ifndef BOTAN_MINIMAL_BIGINT
44
std::ostream& operator<<(std::ostream&, const BigInt&);
45
std::istream& operator>>(std::istream&, BigInt&);
50
+#ifndef BOTAN_MINIMAL_BIGINT
53
inline void swap(Botan::BigInt& a, Botan::BigInt& b) { a.swap(b); }
59
diff -ur a/include/charset.h b/include/charset.h
60
--- a/include/charset.h 2007-03-24 11:51:37.000000000 -0700
61
+++ b/include/charset.h 2007-06-26 11:31:40.000000000 -0700
63
#define BOTAN_CHARSET_H__
65
#include <botan/types.h>
66
+#ifndef BOTAN_TOOLS_ONLY
67
#include <botan/enums.h>
73
/*************************************************
74
* Character Set Transcoder Interface *
75
*************************************************/
76
+#ifndef BOTAN_TOOLS_ONLY
77
class Charset_Transcoder
82
virtual ~Charset_Transcoder() {}
88
/*************************************************
89
* Character Set Handling *
90
*************************************************/
91
+#ifndef BOTAN_TOOLS_ONLY
92
std::string transcode(const std::string&, Character_Set, Character_Set);
97
diff -ur a/include/libstate.h b/include/libstate.h
98
--- a/include/libstate.h 2007-03-24 11:51:37.000000000 -0700
99
+++ b/include/libstate.h 2007-06-26 11:31:40.000000000 -0700
101
#ifndef BOTAN_LIB_STATE_H__
102
#define BOTAN_LIB_STATE_H__
104
+#ifdef BOTAN_TOOLS_ONLY
105
+#include <botan/allocate.h>
107
#include <botan/base.h>
108
#include <botan/enums.h>
109
#include <botan/ui.h>
118
+#ifndef BOTAN_TOOLS_ONLY
119
class Engine_Iterator
123
virtual void pulse(Pulse_Type) {}
129
Allocator* get_allocator(const std::string& = "") const;
130
void add_allocator(Allocator*);
131
+#ifdef BOTAN_TOOLS_ONLY
132
+ void set_default_allocator(const std::string&);
134
void set_default_allocator(const std::string&) const;
137
+#ifndef BOTAN_TOOLS_ONLY
138
bool rng_is_seeded() const { return rng->is_seeded(); }
139
void randomize(byte[], u32bit);
142
void add_entropy(const byte[], u32bit);
143
void add_entropy(EntropySource&, bool);
144
u32bit seed_prng(bool, u32bit);
147
void load(class Modules&);
149
+#ifndef BOTAN_TOOLS_ONLY
150
void set_timer(class Timer*);
151
u64bit system_clock() const;
153
class Config& config() const;
155
void add_engine(class Engine*);
158
class Mutex* get_mutex() const;
159
class Mutex* get_named_mutex(const std::string&);
161
+#ifndef BOTAN_TOOLS_ONLY
162
void set_x509_state(class X509_GlobalState*);
163
class X509_GlobalState& x509_state();
166
void set_transcoder(class Charset_Transcoder*);
167
std::string transcode(const std::string,
168
Character_Set, Character_Set) const;
171
Library_State(class Mutex_Factory*);
174
Library_State(const Library_State&) {}
175
Library_State& operator=(const Library_State&) { return (*this); }
177
+#ifndef BOTAN_TOOLS_ONLY
178
class Engine* get_engine_n(u32bit) const;
181
class Mutex_Factory* mutex_factory;
182
+#ifndef BOTAN_TOOLS_ONLY
184
class Config* config_obj;
185
class X509_GlobalState* x509_state_obj;
188
std::map<std::string, class Mutex*> locks;
189
std::map<std::string, Allocator*> alloc_factory;
190
mutable Allocator* cached_default_allocator;
191
+#ifdef BOTAN_TOOLS_ONLY
192
+ std::string default_allocator_type;
195
+#ifndef BOTAN_TOOLS_ONLY
197
class Charset_Transcoder* transcoder;
198
RandomNumberGenerator* rng;
200
std::vector<Allocator*> allocators;
201
+#ifndef BOTAN_TOOLS_ONLY
202
std::vector<EntropySource*> entropy_sources;
203
std::vector<class Engine*> engines;
207
/*************************************************
208
diff -ur a/include/mem_ops.h b/include/mem_ops.h
209
--- a/include/mem_ops.h 2007-03-24 11:51:37.000000000 -0700
210
+++ b/include/mem_ops.h 2007-06-26 11:31:40.000000000 -0700
213
#include <botan/types.h>
220
* Memory Manipulation Functions *
221
*************************************************/
222
template<typename T> inline void copy_mem(T* out, const T* in, u32bit n)
223
- { std::memmove(out, in, sizeof(T)*n); }
224
+ { memmove(out, in, sizeof(T)*n); }
226
template<typename T> inline void clear_mem(T* ptr, u32bit n)
227
- { std::memset(ptr, 0, sizeof(T)*n); }
228
+ { memset(ptr, 0, sizeof(T)*n); }
230
template<typename T> inline void set_mem(T* ptr, u32bit n, byte val)
231
- { std::memset(ptr, val, sizeof(T)*n); }
232
+ { memset(ptr, val, sizeof(T)*n); }
234
template<typename T> inline bool same_mem(const T* p1, const T* p2, u32bit n)
235
- { return (std::memcmp(p1, p2, sizeof(T)*n) == 0); }
236
+ { return (memcmp(p1, p2, sizeof(T)*n) == 0); }
240
diff -ur a/include/mem_pool.h b/include/mem_pool.h
241
--- a/include/mem_pool.h 2007-03-24 11:51:37.000000000 -0700
242
+++ b/include/mem_pool.h 2007-06-26 11:31:40.000000000 -0700
244
byte* alloc(u32bit) throw();
245
void free(void*, u32bit) throw();
247
- bool operator<(const void*) const;
248
bool operator<(const Memory_Block& other) const
249
- { return (buffer < other.buffer); }
251
+ if(buffer < other.buffer && other.buffer < buffer_end)
253
+ return (buffer < other.buffer);
257
typedef u64bit bitmap_type;
258
- static const u32bit BITMAP_SIZE = 8 * sizeof(bitmap_type);
259
- static const u32bit BLOCK_SIZE = 64;
260
+ static const u32bit BITMAP_SIZE;
261
+ static const u32bit BLOCK_SIZE;
264
byte* buffer, *buffer_end;
265
Only in b/include: mmap_mem.h
266
diff -ur a/include/modules.h b/include/modules.h
267
--- a/include/modules.h 2007-03-24 11:51:37.000000000 -0700
268
+++ b/include/modules.h 2007-06-26 11:31:40.000000000 -0700
270
#ifndef BOTAN_MODULE_FACTORIES_H__
271
#define BOTAN_MODULE_FACTORIES_H__
273
+#ifndef BOTAN_TOOLS_ONLY
274
#include <botan/init.h>
282
virtual class Mutex_Factory* mutex_factory() const = 0;
283
+#ifndef BOTAN_TOOLS_ONLY
284
virtual class Timer* timer() const = 0;
285
virtual class Charset_Transcoder* transcoder() const = 0;
288
virtual std::string default_allocator() const = 0;
290
virtual std::vector<class Allocator*> allocators() const = 0;
291
+#ifndef BOTAN_TOOLS_ONLY
292
virtual std::vector<class EntropySource*> entropy_sources() const = 0;
293
virtual std::vector<class Engine*> engines() const = 0;
296
virtual ~Modules() {}
301
class Mutex_Factory* mutex_factory() const;
302
+#ifndef BOTAN_TOOLS_ONLY
303
class Timer* timer() const;
304
class Charset_Transcoder* transcoder() const;
307
std::string default_allocator() const;
309
std::vector<class Allocator*> allocators() const;
310
+#ifndef BOTAN_TOOLS_ONLY
311
std::vector<class EntropySource*> entropy_sources() const;
312
std::vector<class Engine*> engines() const;
315
+#ifdef BOTAN_TOOLS_ONLY
318
Builtin_Modules(const InitializerOptions&);
321
+#ifdef BOTAN_TOOLS_ONLY
322
+ const bool should_lock;
324
const bool should_lock, use_engines;
329
diff -ur a/include/mutex.h b/include/mutex.h
330
--- a/include/mutex.h 2007-03-24 11:51:37.000000000 -0700
331
+++ b/include/mutex.h 2007-06-26 11:31:40.000000000 -0700
333
/*************************************************
334
* Named Mutex Holder *
335
*************************************************/
336
+#ifndef BOTAN_NO_LIBSTATE
337
class Named_Mutex_Holder
342
const std::string mutex_name;
348
Only in b/include: mux_qt.h
349
diff -ur a/include/numthry.h b/include/numthry.h
350
--- a/include/numthry.h 2007-03-24 11:51:37.000000000 -0700
351
+++ b/include/numthry.h 2007-06-26 11:31:40.000000000 -0700
353
#define BOTAN_NUMBTHRY_H__
355
#include <botan/bigint.h>
356
+#ifndef BOTAN_MINIMAL_BIGINT
357
#include <botan/reducer.h>
358
#include <botan/pow_mod.h>
363
+#ifndef BOTAN_MINIMAL_BIGINT
364
/*************************************************
365
* Fused Arithmetic Operations *
366
*************************************************/
368
* Number Theory Functions *
369
*************************************************/
370
inline BigInt abs(const BigInt& n) { return n.abs(); }
373
void divide(const BigInt&, const BigInt&, BigInt&, BigInt&);
375
+#ifndef BOTAN_MINIMAL_BIGINT
376
BigInt gcd(const BigInt&, const BigInt&);
377
BigInt lcm(const BigInt&, const BigInt&);
380
Fixed_Exponent_Power_Mod pow_mod;
381
Modular_Reducer reducer;
387
diff -ur a/include/parsing.h b/include/parsing.h
388
--- a/include/parsing.h 2007-03-24 11:51:37.000000000 -0700
389
+++ b/include/parsing.h 2007-06-26 11:31:40.000000000 -0700
391
/*************************************************
392
* String Parsing Functions *
393
*************************************************/
394
+#ifndef BOTAN_TOOLS_ONLY
395
std::vector<std::string> parse_algorithm_name(const std::string&);
396
std::vector<std::string> split_on(const std::string&, char);
397
std::vector<u32bit> parse_asn1_oid(const std::string&);
398
bool x500_name_cmp(const std::string&, const std::string&);
399
u32bit parse_expr(const std::string&);
402
/*************************************************
403
* String/Integer Conversions *
404
*************************************************/
405
std::string to_string(u64bit, u32bit = 0);
406
+#ifndef BOTAN_TOOLS_ONLY
407
u32bit to_u32bit(const std::string&);
412
diff -ur a/include/types.h b/include/types.h
413
--- a/include/types.h 2007-03-24 11:51:37.000000000 -0700
414
+++ b/include/types.h 2007-06-26 11:31:40.000000000 -0700
416
#ifndef BOTAN_TYPES_H__
417
#define BOTAN_TYPES_H__
419
+#ifdef BOTAN_TYPES_QT
422
#include <botan/build.h>
427
+#ifdef BOTAN_TYPES_QT
429
+typedef quint8 byte;
430
+typedef quint16 u16bit;
431
+typedef quint32 u32bit;
432
+typedef qint32 s32bit;
433
+typedef quint64 u64bit;
437
typedef unsigned char byte;
438
typedef unsigned short u16bit;
439
typedef unsigned int u32bit;
441
typedef unsigned long long u64bit;
444
+#endif // BOTAN_TYPES_QT
448
namespace Botan_types {
449
diff -ur a/include/util.h b/include/util.h
450
--- a/include/util.h 2007-03-24 11:51:37.000000000 -0700
451
+++ b/include/util.h 2007-06-26 11:31:40.000000000 -0700
453
/*************************************************
454
* Timer Access Functions *
455
*************************************************/
456
+#ifndef BOTAN_TOOLS_ONLY
457
u64bit system_time();
458
u64bit system_clock();
461
/*************************************************
462
* Memory Locking Functions *
464
*************************************************/
465
u32bit round_up(u32bit, u32bit);
466
u32bit round_down(u32bit, u32bit);
467
+#ifndef BOTAN_TOOLS_ONLY
468
u64bit combine_timers(u32bit, u32bit, u32bit);
471
/*************************************************
472
* Work Factor Estimates *
473
*************************************************/
474
+#ifndef BOTAN_TOOLS_ONLY
475
u32bit entropy_estimate(const byte[], u32bit);
476
u32bit dl_work_factor(u32bit);
481
diff -ur a/modules/alloc_mmap/mmap_mem.cpp b/modules/alloc_mmap/mmap_mem.cpp
482
--- a/modules/alloc_mmap/mmap_mem.cpp 2007-03-24 11:51:37.000000000 -0700
483
+++ b/modules/alloc_mmap/mmap_mem.cpp 2007-08-20 07:51:08.000000000 -0700
485
void MemoryMapping_Allocator::dealloc_block(void* ptr, u32bit n)
488
+#ifdef MLOCK_NOT_VOID_PTR
489
+# define MLOCK_TYPE_CAST (char *)
491
+# define MLOCK_TYPE_CAST
494
const u32bit OVERWRITE_PASSES = 12;
495
const byte PATTERNS[] = { 0x00, 0xFF, 0xAA, 0x55, 0x73, 0x8C, 0x5F, 0xA0,
496
@@ -110,14 +115,14 @@
497
for(u32bit j = 0; j != OVERWRITE_PASSES; j++)
499
std::memset(ptr, PATTERNS[j % sizeof(PATTERNS)], n);
500
- if(msync(ptr, n, MS_SYNC))
501
+ if(msync(MLOCK_TYPE_CAST ptr, n, MS_SYNC))
502
throw MemoryMapping_Failed("Sync operation failed");
504
std::memset(ptr, 0, n);
505
- if(msync(ptr, n, MS_SYNC))
506
+ if(msync(MLOCK_TYPE_CAST ptr, n, MS_SYNC))
507
throw MemoryMapping_Failed("Sync operation failed");
510
+ if(munmap(MLOCK_TYPE_CAST ptr, n))
511
throw MemoryMapping_Failed("Could not unmap file");
514
diff -ur a/modules/mux_qt/mux_qt.cpp b/modules/mux_qt/mux_qt.cpp
515
--- a/modules/mux_qt/mux_qt.cpp 2007-03-24 11:51:37.000000000 -0700
516
+++ b/modules/mux_qt/mux_qt.cpp 2007-06-26 11:32:30.000000000 -0700
518
#include <botan/mux_qt.h>
521
-#if !defined(QT_THREAD_SUPPORT)
522
+#if QT_VERSION <= 0x040000 && !defined(QT_THREAD_SUPPORT)
523
#error Your version of Qt does not support threads or mutexes
526
diff -ur a/src/big_code.cpp b/src/big_code.cpp
527
--- a/src/big_code.cpp 2007-03-24 11:51:37.000000000 -0700
528
+++ b/src/big_code.cpp 2007-06-26 11:31:30.000000000 -0700
530
#include <botan/bigint.h>
531
#include <botan/numthry.h>
532
#include <botan/charset.h>
533
+#ifndef BOTAN_MINIMAL_BIGINT
534
#include <botan/hex.h>
542
n.binary_encode(output);
543
+#ifndef BOTAN_MINIMAL_BIGINT
544
else if(base == Hexadecimal)
546
SecureVector<byte> binary(n.encoded_size(Binary));
548
for(u32bit j = 0; j != binary.size(); ++j)
549
Hex_Encoder::encode(binary[j], output + 2*j);
552
else if(base == Octal)
556
output[output_size - 1 - j] =
557
Charset::digit2char(remainder.word_at(0));
560
+ if(j < output_size - 1)
562
+ int extra = output_size - 1 - j;
563
+ memmove(output, output + extra, output_size - extra);
564
+ memset(output + output_size - extra, 0, extra);
574
r.binary_decode(buf, length);
575
+#ifndef BOTAN_MINIMAL_BIGINT
576
else if(base == Hexadecimal)
578
SecureVector<byte> hex;
580
binary[j] = Hex_Decoder::decode(hex+2*j-offset);
581
r.binary_decode(binary, binary.size());
584
else if(base == Decimal || base == Octal)
586
const u32bit RADIX = ((base == Decimal) ? 10 : 8);
587
diff -ur a/src/big_io.cpp b/src/big_io.cpp
588
--- a/src/big_io.cpp 2007-03-24 11:51:37.000000000 -0700
589
+++ b/src/big_io.cpp 2007-06-26 11:31:30.000000000 -0700
594
+#ifndef BOTAN_MINIMAL_BIGINT
596
/*************************************************
597
* Write the BigInt into a stream *
598
*************************************************/
606
diff -ur a/src/big_ops2.cpp b/src/big_ops2.cpp
607
--- a/src/big_ops2.cpp 2007-03-24 11:51:37.000000000 -0700
608
+++ b/src/big_ops2.cpp 2007-06-26 11:31:30.000000000 -0700
611
const u32bit x_sw = sig_words(), y_sw = y.sig_words();
613
+#ifdef BOTAN_TYPES_QT
614
+ const u32bit reg_size = qMax(x_sw, y_sw) + 1;
616
const u32bit reg_size = std::max(x_sw, y_sw) + 1;
620
if((sign() == y.sign()))
623
s32bit relative_size = bigint_cmp(data(), x_sw, y.data(), y_sw);
625
+#ifdef BOTAN_TYPES_QT
626
+ const u32bit reg_size = qMax(x_sw, y_sw) + 1;
628
const u32bit reg_size = std::max(x_sw, y_sw) + 1;
632
if(relative_size < 0)
633
diff -ur a/src/big_ops3.cpp b/src/big_ops3.cpp
634
--- a/src/big_ops3.cpp 2007-03-24 11:51:37.000000000 -0700
635
+++ b/src/big_ops3.cpp 2007-06-26 11:31:30.000000000 -0700
638
const u32bit x_sw = x.sig_words(), y_sw = y.sig_words();
640
+#ifdef BOTAN_TYPES_QT
641
+ BigInt z(x.sign(), qMax(x_sw, y_sw) + 1);
643
BigInt z(x.sign(), std::max(x_sw, y_sw) + 1);
646
if((x.sign() == y.sign()))
647
bigint_add3(z.get_reg(), x.data(), x_sw, y.data(), y_sw);
650
s32bit relative_size = bigint_cmp(x.data(), x_sw, y.data(), y_sw);
652
+#ifdef BOTAN_TYPES_QT
653
+ BigInt z(BigInt::Positive, qMax(x_sw, y_sw) + 1);
655
BigInt z(BigInt::Positive, std::max(x_sw, y_sw) + 1);
658
if(relative_size < 0)
660
diff -ur a/src/charset.cpp b/src/charset.cpp
661
--- a/src/charset.cpp 2007-03-24 11:51:37.000000000 -0700
662
+++ b/src/charset.cpp 2007-06-26 11:31:30.000000000 -0700
664
*************************************************/
666
#include <botan/charset.h>
667
+#ifdef BOTAN_TOOLS_ONLY
668
+#include <botan/exceptn.h>
670
#include <botan/hex.h>
671
#include <botan/base64.h>
673
#include <botan/libstate.h>
680
/*************************************************
681
* Perform character set transcoding *
682
*************************************************/
683
+#ifndef BOTAN_TOOLS_ONLY
684
std::string transcode(const std::string& str,
685
Character_Set to, Character_Set from)
687
return global_state().transcode(str, to, from);
691
/*************************************************
692
* Check if a character represents a digit *
694
*************************************************/
695
bool caseless_cmp(char a, char b)
697
- return (std::tolower((unsigned char)a) == std::tolower((unsigned char)b));
698
+ return (tolower((unsigned char)a) == tolower((unsigned char)b));
703
+#ifndef BOTAN_TOOLS_ONLY
705
/*************************************************
706
* Hex Encoder Lookup Tables *
707
*************************************************/
709
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
710
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80 };
715
diff -ur a/src/defalloc.cpp b/src/defalloc.cpp
716
--- a/src/defalloc.cpp 2007-03-24 11:51:37.000000000 -0700
717
+++ b/src/defalloc.cpp 2007-06-26 11:31:30.000000000 -0700
719
#include <botan/util.h>
728
*************************************************/
729
void* do_malloc(u32bit n, bool do_lock)
731
- void* ptr = std::malloc(n);
732
+ void* ptr = malloc(n);
740
- std::memset(ptr, 0, n);
749
- std::memset(ptr, 0, n);
759
diff -ur a/src/libstate.cpp b/src/libstate.cpp
760
--- a/src/libstate.cpp 2007-03-24 11:51:37.000000000 -0700
761
+++ b/src/libstate.cpp 2007-06-26 11:31:30.000000000 -0700
763
*************************************************/
765
#include <botan/libstate.h>
766
+#ifndef BOTAN_TOOLS_ONLY
767
#include <botan/config.h>
769
#include <botan/modules.h>
770
+#ifndef BOTAN_TOOLS_ONLY
771
#include <botan/engine.h>
772
#include <botan/x509stat.h>
774
#include <botan/stl_util.h>
775
#include <botan/mutex.h>
776
+#ifndef BOTAN_TOOLS_ONLY
777
#include <botan/timers.h>
778
#include <botan/charset.h>
784
/*************************************************
785
* Increment the Engine iterator *
786
*************************************************/
787
+#ifndef BOTAN_TOOLS_ONLY
788
Engine* Library_State::Engine_Iterator::next()
790
return lib.get_engine_n(n++);
794
/*************************************************
795
* Get a new mutex object *
798
if(!cached_default_allocator)
800
+#ifdef BOTAN_TOOLS_ONLY
801
+ std::string chosen = default_allocator_type;
803
std::string chosen = config().option("base/default_allocator");
809
@@ -120,17 +131,26 @@
810
/*************************************************
811
* Set the default allocator type *
812
*************************************************/
813
+#ifdef BOTAN_TOOLS_ONLY
814
+void Library_State::set_default_allocator(const std::string& type)
816
void Library_State::set_default_allocator(const std::string& type) const
819
Named_Mutex_Holder lock("allocator");
824
+#ifdef BOTAN_TOOLS_ONLY
825
+ default_allocator_type = type;
827
config().set("conf", "base/default_allocator", type);
829
cached_default_allocator = 0;
832
+#ifndef BOTAN_TOOLS_ONLY
833
/*************************************************
834
* Set the high resolution clock implementation *
835
*************************************************/
836
@@ -317,13 +337,17 @@
837
return (*config_obj);
842
/*************************************************
844
*************************************************/
845
void Library_State::load(Modules& modules)
847
+#ifndef BOTAN_TOOLS_ONLY
848
set_timer(modules.timer());
849
set_transcoder(modules.transcoder());
852
std::vector<Allocator*> mod_allocs = modules.allocators();
853
for(u32bit j = 0; j != mod_allocs.size(); j++)
856
set_default_allocator(modules.default_allocator());
858
+#ifndef BOTAN_TOOLS_ONLY
859
std::vector<Engine*> mod_engines = modules.engines();
860
for(u32bit j = 0; j != mod_engines.size(); ++j)
863
std::vector<EntropySource*> sources = modules.entropy_sources();
864
for(u32bit j = 0; j != sources.size(); ++j)
865
add_entropy_source(sources[j]);
869
/*************************************************
870
@@ -352,25 +378,39 @@
871
throw Exception("Library_State: no mutex found");
873
this->mutex_factory = mutex_factory;
874
+#ifndef BOTAN_TOOLS_ONLY
875
this->timer = new Timer();
876
this->transcoder = 0;
877
this->config_obj = new Config();
880
+#ifndef BOTAN_TOOLS_ONLY
881
locks["settings"] = get_mutex();
883
locks["allocator"] = get_mutex();
884
+#ifndef BOTAN_TOOLS_ONLY
885
locks["rng"] = get_mutex();
886
locks["engine"] = get_mutex();
889
cached_default_allocator = 0;
890
+#ifndef BOTAN_TOOLS_ONLY
896
/*************************************************
897
* Library_State Destructor *
898
*************************************************/
899
+static void delete_lock(std::pair<const std::string, Mutex*> &pair)
901
+ delete pair.second;
904
Library_State::~Library_State()
906
+#ifndef BOTAN_TOOLS_ONLY
907
delete x509_state_obj;
911
std::for_each(entropy_sources.begin(), entropy_sources.end(),
912
del_fun<EntropySource>());
913
std::for_each(engines.begin(), engines.end(), del_fun<Engine>());
916
cached_default_allocator = 0;
919
delete allocators[j];
922
- std::for_each(locks.begin(), locks.end(),
923
- delete2nd<std::map<std::string, Mutex*>::value_type>);
924
+ std::for_each(locks.begin(), locks.end(), delete_lock);
926
delete mutex_factory;
928
diff -ur a/src/mem_pool.cpp b/src/mem_pool.cpp
929
--- a/src/mem_pool.cpp 2007-03-24 11:51:37.000000000 -0700
930
+++ b/src/mem_pool.cpp 2007-06-26 11:31:30.000000000 -0700
933
#include <botan/mem_pool.h>
934
#include <botan/libstate.h>
935
+#ifdef BOTAN_TOOLS_ONLY
936
+#include <botan/mem_ops.h>
938
#include <botan/config.h>
939
#include <botan/bit_ops.h>
941
#include <botan/util.h>
948
+#ifdef BOTAN_TOOLS_ONLY
949
+ u32bit result = (u32bit)global_state().prealloc_size;
951
u32bit result = global_config().option_as_u32bit("base/memory_chunk");
959
/*************************************************
960
-* Compare a Memory_Block with a void pointer *
961
-*************************************************/
962
-inline bool Pooling_Allocator::Memory_Block::operator<(const void* other) const
964
- if(buffer <= other && other < buffer_end)
966
- return (buffer < other);
969
-/*************************************************
970
* See if ptr is contained by this block *
971
*************************************************/
972
bool Pooling_Allocator::Memory_Block::contains(void* ptr,
974
const u32bit block_no = round_up(n, BLOCK_SIZE) / BLOCK_SIZE;
976
std::vector<Memory_Block>::iterator i =
977
- std::lower_bound(blocks.begin(), blocks.end(), ptr);
978
+ std::lower_bound(blocks.begin(), blocks.end(), Memory_Block(ptr));
980
if(i == blocks.end() || !i->contains(ptr, block_no))
981
throw Invalid_State("Pointer released to the wrong allocator");
985
std::sort(blocks.begin(), blocks.end());
986
- last_used = std::lower_bound(blocks.begin(), blocks.end(), ptr);
987
+ last_used = std::lower_bound(blocks.begin(), blocks.end(), Memory_Block(ptr));
990
+const u32bit Pooling_Allocator::Memory_Block::BITMAP_SIZE = 8 * sizeof(Pooling_Allocator::Memory_Block::bitmap_type);
991
+const u32bit Pooling_Allocator::Memory_Block::BLOCK_SIZE = 64;
994
diff -ur a/src/modules.cpp b/src/modules.cpp
995
--- a/src/modules.cpp 2007-03-24 11:51:37.000000000 -0700
996
+++ b/src/modules.cpp 2007-06-26 11:31:30.000000000 -0700
999
#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>
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>
1019
#if defined(BOTAN_EXT_ALLOC_MMAP)
1020
- #include <botan/mmap_mem.h>
1021
+# include <botan/mmap_mem.h>
1024
+#ifndef BOTAN_TOOLS_ONLY
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>
1040
#if defined(BOTAN_EXT_ENGINE_AEP)
1041
- #include <botan/eng_aep.h>
1042
+# include <botan/eng_aep.h>
1045
#if defined(BOTAN_EXT_ENGINE_GNU_MP)
1046
- #include <botan/eng_gmp.h>
1047
+# include <botan/eng_gmp.h>
1050
#if defined(BOTAN_EXT_ENGINE_OPENSSL)
1051
- #include <botan/eng_ossl.h>
1052
+# include <botan/eng_ossl.h>
1055
#if defined(BOTAN_EXT_ENTROPY_SRC_AEP)
1056
- #include <botan/es_aep.h>
1057
+# include <botan/es_aep.h>
1060
#if defined(BOTAN_EXT_ENTROPY_SRC_EGD)
1061
- #include <botan/es_egd.h>
1062
+# include <botan/es_egd.h>
1065
#if defined(BOTAN_EXT_ENTROPY_SRC_UNIX)
1066
- #include <botan/es_unix.h>
1067
+# include <botan/es_unix.h>
1070
#if defined(BOTAN_EXT_ENTROPY_SRC_BEOS)
1071
- #include <botan/es_beos.h>
1072
+# include <botan/es_beos.h>
1075
#if defined(BOTAN_EXT_ENTROPY_SRC_CAPI)
1076
- #include <botan/es_capi.h>
1077
+# include <botan/es_capi.h>
1080
#if defined(BOTAN_EXT_ENTROPY_SRC_WIN32)
1081
- #include <botan/es_win32.h>
1082
+# include <botan/es_win32.h>
1085
#if defined(BOTAN_EXT_ENTROPY_SRC_FTW)
1086
- #include <botan/es_ftw.h>
1087
+# include <botan/es_ftw.h>
1094
/*************************************************
1095
* Find a high resolution timer, if possible *
1096
*************************************************/
1097
+#ifndef BOTAN_TOOLS_ONLY
1098
Timer* Builtin_Modules::timer() const
1100
#if defined(BOTAN_EXT_TIMER_HARDWARE)
1107
/*************************************************
1108
* Find any usable allocators *
1113
+#ifndef BOTAN_TOOLS_ONLY
1115
/*************************************************
1116
* Register any usable entropy sources *
1117
*************************************************/
1118
@@ -217,13 +227,22 @@
1119
return new Default_Charset_Transcoder;
1124
/*************************************************
1125
* Builtin_Modules Constructor *
1126
*************************************************/
1127
+#ifdef BOTAN_TOOLS_ONLY
1128
+Builtin_Modules::Builtin_Modules() :
1133
Builtin_Modules::Builtin_Modules(const InitializerOptions& args) :
1134
should_lock(args.secure_memory()),
1135
use_engines(args.use_engines())
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
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)
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);
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
1164
* (C) 1999-2007 The Botan Project *
1165
*************************************************/
1167
+#include <stdlib.h>
1168
#include <botan/mutex.h>
1169
+#ifndef BOTAN_NO_LIBSTATE
1170
#include <botan/libstate.h>
1179
+#ifndef BOTAN_NO_LIBSTATE
1180
/*************************************************
1181
* Named_Mutex_Holder Constructor *
1182
*************************************************/
1185
global_state().get_named_mutex(mutex_name)->unlock();
1189
/*************************************************
1190
* Default Mutex Factory *
1191
*************************************************/
1192
+#ifdef BOTAN_FIX_GDB
1195
Mutex* Default_Mutex_Factory::make()
1198
class Default_Mutex : public Mutex
1205
+#ifdef BOTAN_FIX_GDB
1206
+ } // end unnamed namespace
1207
+Mutex* Default_Mutex_Factory::make()
1211
return new Default_Mutex;
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
1218
/*************************************************
1219
* Convert a string into an integer *
1220
*************************************************/
1221
+#ifndef BOTAN_TOOLS_ONLY
1222
u32bit to_u32bit(const std::string& number)
1232
/*************************************************
1233
* Convert an integer into a string *
1238
+#ifndef BOTAN_TOOLS_ONLY
1239
/*************************************************
1240
* Parse a SCAN-style algorithm name *
1241
*************************************************/
1244
return to_u32bit(expr);
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
1253
*************************************************/
1255
#include <botan/util.h>
1256
+#ifndef BOTAN_TOOLS_ONLY
1257
#include <botan/bit_ops.h>
1259
#include <algorithm>
1263
return (n - (n % align_to));
1266
+#ifndef BOTAN_TOOLS_ONLY
1267
/*************************************************
1268
* Return the work required for solving DL *
1269
*************************************************/
1272
return (estimate / 2);