2
Copyright (C) 1999-2007 The Botan Project. All rights reserved.
4
Redistribution and use in source and binary forms, for any use, with or without
5
modification, is permitted provided that the following conditions are met:
7
1. Redistributions of source code must retain the above copyright notice, this
8
list of conditions, and the following disclaimer.
10
2. Redistributions in binary form must reproduce the above copyright notice,
11
this list of conditions, and the following disclaimer in the documentation
12
and/or other materials provided with the distribution.
14
THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) "AS IS" AND ANY EXPRESS OR IMPLIED
15
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
16
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE DISCLAIMED.
18
IN NO EVENT SHALL THE AUTHOR(S) OR CONTRIBUTOR(S) BE LIABLE FOR ANY DIRECT,
19
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
20
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
22
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
23
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
namespace QCA { // WRAPNS_LINE
28
/*************************************************
29
* Module Factory Source File *
30
* (C) 1999-2007 The Botan Project *
31
*************************************************/
34
#include <botan/modules.h>
35
namespace QCA { // WRAPNS_LINE
37
#include <botan/defalloc.h>
38
namespace QCA { // WRAPNS_LINE
39
#ifndef BOTAN_TOOLS_ONLY
41
#include <botan/def_char.h>
42
namespace QCA { // WRAPNS_LINE
44
#include <botan/eng_def.h>
45
namespace QCA { // WRAPNS_LINE
47
#include <botan/es_file.h>
48
namespace QCA { // WRAPNS_LINE
50
#include <botan/timers.h>
51
namespace QCA { // WRAPNS_LINE
54
#if defined(BOTAN_EXT_MUTEX_PTHREAD)
56
# include <botan/mux_pthr.h>
57
namespace QCA { // WRAPNS_LINE
58
#elif defined(BOTAN_EXT_MUTEX_WIN32)
60
# include <botan/mux_win32.h>
61
namespace QCA { // WRAPNS_LINE
62
#elif defined(BOTAN_EXT_MUTEX_QT)
64
# include <botan/mux_qt.h>
65
namespace QCA { // WRAPNS_LINE
68
#if defined(BOTAN_EXT_ALLOC_MMAP)
70
# include <botan/mmap_mem.h>
71
namespace QCA { // WRAPNS_LINE
74
#ifndef BOTAN_TOOLS_ONLY
76
#if defined(BOTAN_EXT_TIMER_HARDWARE)
78
# include <botan/tm_hard.h>
79
namespace QCA { // WRAPNS_LINE
80
#elif defined(BOTAN_EXT_TIMER_POSIX)
82
# include <botan/tm_posix.h>
83
namespace QCA { // WRAPNS_LINE
84
#elif defined(BOTAN_EXT_TIMER_UNIX)
86
# include <botan/tm_unix.h>
87
namespace QCA { // WRAPNS_LINE
88
#elif defined(BOTAN_EXT_TIMER_WIN32)
90
# include <botan/tm_win32.h>
91
namespace QCA { // WRAPNS_LINE
94
#if defined(BOTAN_EXT_ENGINE_AEP)
96
# include <botan/eng_aep.h>
97
namespace QCA { // WRAPNS_LINE
100
#if defined(BOTAN_EXT_ENGINE_GNU_MP)
102
# include <botan/eng_gmp.h>
103
namespace QCA { // WRAPNS_LINE
106
#if defined(BOTAN_EXT_ENGINE_OPENSSL)
108
# include <botan/eng_ossl.h>
109
namespace QCA { // WRAPNS_LINE
112
#if defined(BOTAN_EXT_ENTROPY_SRC_AEP)
114
# include <botan/es_aep.h>
115
namespace QCA { // WRAPNS_LINE
118
#if defined(BOTAN_EXT_ENTROPY_SRC_EGD)
120
# include <botan/es_egd.h>
121
namespace QCA { // WRAPNS_LINE
124
#if defined(BOTAN_EXT_ENTROPY_SRC_UNIX)
126
# include <botan/es_unix.h>
127
namespace QCA { // WRAPNS_LINE
130
#if defined(BOTAN_EXT_ENTROPY_SRC_BEOS)
132
# include <botan/es_beos.h>
133
namespace QCA { // WRAPNS_LINE
136
#if defined(BOTAN_EXT_ENTROPY_SRC_CAPI)
138
# include <botan/es_capi.h>
139
namespace QCA { // WRAPNS_LINE
142
#if defined(BOTAN_EXT_ENTROPY_SRC_WIN32)
144
# include <botan/es_win32.h>
145
namespace QCA { // WRAPNS_LINE
148
#if defined(BOTAN_EXT_ENTROPY_SRC_FTW)
150
# include <botan/es_ftw.h>
151
namespace QCA { // WRAPNS_LINE
158
/*************************************************
159
* Return a mutex factory, if available *
160
*************************************************/
161
Mutex_Factory* Builtin_Modules::mutex_factory() const
163
#if defined(BOTAN_EXT_MUTEX_PTHREAD)
164
return new Pthread_Mutex_Factory;
165
#elif defined(BOTAN_EXT_MUTEX_WIN32)
166
return new Win32_Mutex_Factory;
167
#elif defined(BOTAN_EXT_MUTEX_QT)
168
return new Qt_Mutex_Factory;
174
/*************************************************
175
* Find a high resolution timer, if possible *
176
*************************************************/
177
#ifndef BOTAN_TOOLS_ONLY
178
Timer* Builtin_Modules::timer() const
180
#if defined(BOTAN_EXT_TIMER_HARDWARE)
181
return new Hardware_Timer;
182
#elif defined(BOTAN_EXT_TIMER_POSIX)
183
return new POSIX_Timer;
184
#elif defined(BOTAN_EXT_TIMER_UNIX)
185
return new Unix_Timer;
186
#elif defined(BOTAN_EXT_TIMER_WIN32)
187
return new Win32_Timer;
194
/*************************************************
195
* Find any usable allocators *
196
*************************************************/
197
std::vector<Allocator*> Builtin_Modules::allocators() const
199
std::vector<Allocator*> allocators;
201
#if defined(BOTAN_EXT_ALLOC_MMAP)
202
allocators.push_back(new MemoryMapping_Allocator);
205
allocators.push_back(new Locking_Allocator);
206
allocators.push_back(new Malloc_Allocator);
211
/*************************************************
212
* Return the default allocator *
213
*************************************************/
214
std::string Builtin_Modules::default_allocator() const
218
#if defined(BOTAN_EXT_ALLOC_MMAP)
228
#ifndef BOTAN_TOOLS_ONLY
230
/*************************************************
231
* Register any usable entropy sources *
232
*************************************************/
233
std::vector<EntropySource*> Builtin_Modules::entropy_sources() const
235
std::vector<EntropySource*> sources;
237
sources.push_back(new File_EntropySource);
239
#if defined(BOTAN_EXT_ENTROPY_SRC_AEP)
240
sources.push_back(new AEP_EntropySource);
243
#if defined(BOTAN_EXT_ENTROPY_SRC_EGD)
244
sources.push_back(new EGD_EntropySource);
247
#if defined(BOTAN_EXT_ENTROPY_SRC_CAPI)
248
sources.push_back(new Win32_CAPI_EntropySource);
251
#if defined(BOTAN_EXT_ENTROPY_SRC_WIN32)
252
sources.push_back(new Win32_EntropySource);
255
#if defined(BOTAN_EXT_ENTROPY_SRC_UNIX)
256
sources.push_back(new Unix_EntropySource);
259
#if defined(BOTAN_EXT_ENTROPY_SRC_BEOS)
260
sources.push_back(new BeOS_EntropySource);
263
#if defined(BOTAN_EXT_ENTROPY_SRC_FTW)
264
sources.push_back(new FTW_EntropySource);
270
/*************************************************
271
* Find any usable engines *
272
*************************************************/
273
std::vector<Engine*> Builtin_Modules::engines() const
275
std::vector<Engine*> engines;
279
#if defined(BOTAN_EXT_ENGINE_AEP)
280
engines.push_back(new AEP_Engine);
283
#if defined(BOTAN_EXT_ENGINE_GNU_MP)
284
engines.push_back(new GMP_Engine);
287
#if defined(BOTAN_EXT_ENGINE_OPENSSL)
288
engines.push_back(new OpenSSL_Engine);
292
engines.push_back(new Default_Engine);
297
/*************************************************
298
* Find the best transcoder option *
299
*************************************************/
300
Charset_Transcoder* Builtin_Modules::transcoder() const
302
return new Default_Charset_Transcoder;
307
/*************************************************
308
* Builtin_Modules Constructor *
309
*************************************************/
310
#ifdef BOTAN_TOOLS_ONLY
311
Builtin_Modules::Builtin_Modules() :
316
Builtin_Modules::Builtin_Modules(const InitializerOptions& args) :
317
should_lock(args.secure_memory()),
318
use_engines(args.use_engines())