1 | /* |
2 | Copyright (C) 1999-2007 The Botan Project. All rights reserved. |
3 | |
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: |
6 | |
7 | 1. Redistributions of source code must retain the above copyright notice, this |
8 | list of conditions, and the following disclaimer. |
9 | |
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. |
13 | |
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. |
17 | |
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. |
25 | */ |
26 | // LICENSEHEADER_END |
27 | namespace QCA { // WRAPNS_LINE |
28 | /************************************************* |
29 | * Module Factory Source File * |
30 | * (C) 1999-2007 The Botan Project * |
31 | *************************************************/ |
32 | |
33 | } // WRAPNS_LINE |
34 | #include <botan/modules.h> |
35 | namespace QCA { // WRAPNS_LINE |
36 | } // WRAPNS_LINE |
37 | #include <botan/defalloc.h> |
38 | namespace QCA { // WRAPNS_LINE |
39 | #ifndef BOTAN_TOOLS_ONLY |
40 | } // WRAPNS_LINE |
41 | #include <botan/def_char.h> |
42 | namespace QCA { // WRAPNS_LINE |
43 | } // WRAPNS_LINE |
44 | #include <botan/eng_def.h> |
45 | namespace QCA { // WRAPNS_LINE |
46 | } // WRAPNS_LINE |
47 | #include <botan/es_file.h> |
48 | namespace QCA { // WRAPNS_LINE |
49 | } // WRAPNS_LINE |
50 | #include <botan/timers.h> |
51 | namespace QCA { // WRAPNS_LINE |
52 | #endif |
53 | |
54 | #if defined(BOTAN_EXT_MUTEX_PTHREAD) |
55 | } // WRAPNS_LINE |
56 | #include <botan/mux_pthr.h> |
57 | namespace QCA { // WRAPNS_LINE |
58 | #elif defined(BOTAN_EXT_MUTEX_WIN32) |
59 | } // WRAPNS_LINE |
60 | #include <botan/mux_win32.h> |
61 | namespace QCA { // WRAPNS_LINE |
62 | #elif defined(BOTAN_EXT_MUTEX_QT) |
63 | } // WRAPNS_LINE |
64 | #include <botan/mux_qt.h> |
65 | namespace QCA { // WRAPNS_LINE |
66 | #endif |
67 | |
68 | #if defined(BOTAN_EXT_ALLOC_MMAP) |
69 | } // WRAPNS_LINE |
70 | #include <botan/mmap_mem.h> |
71 | namespace QCA { // WRAPNS_LINE |
72 | #endif |
73 | |
74 | #ifndef BOTAN_TOOLS_ONLY |
75 | |
76 | #if defined(BOTAN_EXT_TIMER_HARDWARE) |
77 | } // WRAPNS_LINE |
78 | #include <botan/tm_hard.h> |
79 | namespace QCA { // WRAPNS_LINE |
80 | #elif defined(BOTAN_EXT_TIMER_POSIX) |
81 | } // WRAPNS_LINE |
82 | #include <botan/tm_posix.h> |
83 | namespace QCA { // WRAPNS_LINE |
84 | #elif defined(BOTAN_EXT_TIMER_UNIX) |
85 | } // WRAPNS_LINE |
86 | #include <botan/tm_unix.h> |
87 | namespace QCA { // WRAPNS_LINE |
88 | #elif defined(BOTAN_EXT_TIMER_WIN32) |
89 | } // WRAPNS_LINE |
90 | #include <botan/tm_win32.h> |
91 | namespace QCA { // WRAPNS_LINE |
92 | #endif |
93 | |
94 | #if defined(BOTAN_EXT_ENGINE_AEP) |
95 | } // WRAPNS_LINE |
96 | #include <botan/eng_aep.h> |
97 | namespace QCA { // WRAPNS_LINE |
98 | #endif |
99 | |
100 | #if defined(BOTAN_EXT_ENGINE_GNU_MP) |
101 | } // WRAPNS_LINE |
102 | #include <botan/eng_gmp.h> |
103 | namespace QCA { // WRAPNS_LINE |
104 | #endif |
105 | |
106 | #if defined(BOTAN_EXT_ENGINE_OPENSSL) |
107 | } // WRAPNS_LINE |
108 | #include <botan/eng_ossl.h> |
109 | namespace QCA { // WRAPNS_LINE |
110 | #endif |
111 | |
112 | #if defined(BOTAN_EXT_ENTROPY_SRC_AEP) |
113 | } // WRAPNS_LINE |
114 | #include <botan/es_aep.h> |
115 | namespace QCA { // WRAPNS_LINE |
116 | #endif |
117 | |
118 | #if defined(BOTAN_EXT_ENTROPY_SRC_EGD) |
119 | } // WRAPNS_LINE |
120 | #include <botan/es_egd.h> |
121 | namespace QCA { // WRAPNS_LINE |
122 | #endif |
123 | |
124 | #if defined(BOTAN_EXT_ENTROPY_SRC_UNIX) |
125 | } // WRAPNS_LINE |
126 | #include <botan/es_unix.h> |
127 | namespace QCA { // WRAPNS_LINE |
128 | #endif |
129 | |
130 | #if defined(BOTAN_EXT_ENTROPY_SRC_BEOS) |
131 | } // WRAPNS_LINE |
132 | #include <botan/es_beos.h> |
133 | namespace QCA { // WRAPNS_LINE |
134 | #endif |
135 | |
136 | #if defined(BOTAN_EXT_ENTROPY_SRC_CAPI) |
137 | } // WRAPNS_LINE |
138 | #include <botan/es_capi.h> |
139 | namespace QCA { // WRAPNS_LINE |
140 | #endif |
141 | |
142 | #if defined(BOTAN_EXT_ENTROPY_SRC_WIN32) |
143 | } // WRAPNS_LINE |
144 | #include <botan/es_win32.h> |
145 | namespace QCA { // WRAPNS_LINE |
146 | #endif |
147 | |
148 | #if defined(BOTAN_EXT_ENTROPY_SRC_FTW) |
149 | } // WRAPNS_LINE |
150 | #include <botan/es_ftw.h> |
151 | namespace QCA { // WRAPNS_LINE |
152 | #endif |
153 | |
154 | #endif |
155 | |
156 | namespace Botan { |
157 | |
158 | /************************************************* |
159 | * Return a mutex factory, if available * |
160 | *************************************************/ |
161 | Mutex_Factory *Builtin_Modules::mutex_factory() const |
162 | { |
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; |
169 | #else |
170 | return 0; |
171 | #endif |
172 | } |
173 | |
174 | /************************************************* |
175 | * Find a high resolution timer, if possible * |
176 | *************************************************/ |
177 | #ifndef BOTAN_TOOLS_ONLY |
178 | Timer *Builtin_Modules::timer() const |
179 | { |
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; |
188 | #else |
189 | return new Timer; |
190 | #endif |
191 | } |
192 | #endif |
193 | |
194 | /************************************************* |
195 | * Find any usable allocators * |
196 | *************************************************/ |
197 | std::vector<Allocator *> Builtin_Modules::allocators() const |
198 | { |
199 | std::vector<Allocator *> allocators; |
200 | |
201 | #if defined(BOTAN_EXT_ALLOC_MMAP) |
202 | allocators.push_back(x: new MemoryMapping_Allocator); |
203 | #endif |
204 | |
205 | allocators.push_back(x: new Locking_Allocator); |
206 | allocators.push_back(x: new Malloc_Allocator); |
207 | |
208 | return allocators; |
209 | } |
210 | |
211 | /************************************************* |
212 | * Return the default allocator * |
213 | *************************************************/ |
214 | std::string Builtin_Modules::default_allocator() const |
215 | { |
216 | if (should_lock) { |
217 | #if defined(BOTAN_EXT_ALLOC_MMAP) |
218 | return "mmap" ; |
219 | #else |
220 | return "locking" ; |
221 | #endif |
222 | } else |
223 | return "malloc" ; |
224 | } |
225 | |
226 | #ifndef BOTAN_TOOLS_ONLY |
227 | |
228 | /************************************************* |
229 | * Register any usable entropy sources * |
230 | *************************************************/ |
231 | std::vector<EntropySource *> Builtin_Modules::entropy_sources() const |
232 | { |
233 | std::vector<EntropySource *> sources; |
234 | |
235 | sources.push_back(new File_EntropySource); |
236 | |
237 | #if defined(BOTAN_EXT_ENTROPY_SRC_AEP) |
238 | sources.push_back(new AEP_EntropySource); |
239 | #endif |
240 | |
241 | #if defined(BOTAN_EXT_ENTROPY_SRC_EGD) |
242 | sources.push_back(new EGD_EntropySource); |
243 | #endif |
244 | |
245 | #if defined(BOTAN_EXT_ENTROPY_SRC_CAPI) |
246 | sources.push_back(new Win32_CAPI_EntropySource); |
247 | #endif |
248 | |
249 | #if defined(BOTAN_EXT_ENTROPY_SRC_WIN32) |
250 | sources.push_back(new Win32_EntropySource); |
251 | #endif |
252 | |
253 | #if defined(BOTAN_EXT_ENTROPY_SRC_UNIX) |
254 | sources.push_back(new Unix_EntropySource); |
255 | #endif |
256 | |
257 | #if defined(BOTAN_EXT_ENTROPY_SRC_BEOS) |
258 | sources.push_back(new BeOS_EntropySource); |
259 | #endif |
260 | |
261 | #if defined(BOTAN_EXT_ENTROPY_SRC_FTW) |
262 | sources.push_back(new FTW_EntropySource); |
263 | #endif |
264 | |
265 | return sources; |
266 | } |
267 | |
268 | /************************************************* |
269 | * Find any usable engines * |
270 | *************************************************/ |
271 | std::vector<Engine *> Builtin_Modules::engines() const |
272 | { |
273 | std::vector<Engine *> engines; |
274 | |
275 | if (use_engines) { |
276 | #if defined(BOTAN_EXT_ENGINE_AEP) |
277 | engines.push_back(new AEP_Engine); |
278 | #endif |
279 | |
280 | #if defined(BOTAN_EXT_ENGINE_GNU_MP) |
281 | engines.push_back(new GMP_Engine); |
282 | #endif |
283 | |
284 | #if defined(BOTAN_EXT_ENGINE_OPENSSL) |
285 | engines.push_back(new OpenSSL_Engine); |
286 | #endif |
287 | } |
288 | |
289 | engines.push_back(new Default_Engine); |
290 | |
291 | return engines; |
292 | } |
293 | |
294 | /************************************************* |
295 | * Find the best transcoder option * |
296 | *************************************************/ |
297 | Charset_Transcoder *Builtin_Modules::transcoder() const |
298 | { |
299 | return new Default_Charset_Transcoder; |
300 | } |
301 | |
302 | #endif |
303 | |
304 | /************************************************* |
305 | * Builtin_Modules Constructor * |
306 | *************************************************/ |
307 | #ifdef BOTAN_TOOLS_ONLY |
308 | Builtin_Modules::Builtin_Modules() |
309 | : should_lock(true) |
310 | { |
311 | } |
312 | #else |
313 | Builtin_Modules::Builtin_Modules(const InitializerOptions &args) |
314 | : should_lock(args.secure_memory()) |
315 | , use_engines(args.use_engines()) |
316 | { |
317 | } |
318 | #endif |
319 | |
320 | } |
321 | } // WRAPNS_LINE |
322 | |