File indexing completed on 2024-05-12 04:45:14
0001 /* 0002 Copyright (C) 1999-2007 The Botan Project. All rights reserved. 0003 0004 Redistribution and use in source and binary forms, for any use, with or without 0005 modification, is permitted provided that the following conditions are met: 0006 0007 1. Redistributions of source code must retain the above copyright notice, this 0008 list of conditions, and the following disclaimer. 0009 0010 2. Redistributions in binary form must reproduce the above copyright notice, 0011 this list of conditions, and the following disclaimer in the documentation 0012 and/or other materials provided with the distribution. 0013 0014 THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) "AS IS" AND ANY EXPRESS OR IMPLIED 0015 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 0016 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE DISCLAIMED. 0017 0018 IN NO EVENT SHALL THE AUTHOR(S) OR CONTRIBUTOR(S) BE LIABLE FOR ANY DIRECT, 0019 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 0020 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 0021 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 0022 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 0023 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 0024 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 0025 */ 0026 // LICENSEHEADER_END 0027 namespace QCA { // WRAPNS_LINE 0028 /************************************************* 0029 * Module Factory Source File * 0030 * (C) 1999-2007 The Botan Project * 0031 *************************************************/ 0032 0033 } // WRAPNS_LINE 0034 #include <botan/modules.h> 0035 namespace QCA { // WRAPNS_LINE 0036 } // WRAPNS_LINE 0037 #include <botan/defalloc.h> 0038 namespace QCA { // WRAPNS_LINE 0039 #ifndef BOTAN_TOOLS_ONLY 0040 } // WRAPNS_LINE 0041 #include <botan/def_char.h> 0042 namespace QCA { // WRAPNS_LINE 0043 } // WRAPNS_LINE 0044 #include <botan/eng_def.h> 0045 namespace QCA { // WRAPNS_LINE 0046 } // WRAPNS_LINE 0047 #include <botan/es_file.h> 0048 namespace QCA { // WRAPNS_LINE 0049 } // WRAPNS_LINE 0050 #include <botan/timers.h> 0051 namespace QCA { // WRAPNS_LINE 0052 #endif 0053 0054 #if defined(BOTAN_EXT_MUTEX_PTHREAD) 0055 } // WRAPNS_LINE 0056 #include <botan/mux_pthr.h> 0057 namespace QCA { // WRAPNS_LINE 0058 #elif defined(BOTAN_EXT_MUTEX_WIN32) 0059 } // WRAPNS_LINE 0060 #include <botan/mux_win32.h> 0061 namespace QCA { // WRAPNS_LINE 0062 #elif defined(BOTAN_EXT_MUTEX_QT) 0063 } // WRAPNS_LINE 0064 #include <botan/mux_qt.h> 0065 namespace QCA { // WRAPNS_LINE 0066 #endif 0067 0068 #if defined(BOTAN_EXT_ALLOC_MMAP) 0069 } // WRAPNS_LINE 0070 #include <botan/mmap_mem.h> 0071 namespace QCA { // WRAPNS_LINE 0072 #endif 0073 0074 #ifndef BOTAN_TOOLS_ONLY 0075 0076 #if defined(BOTAN_EXT_TIMER_HARDWARE) 0077 } // WRAPNS_LINE 0078 #include <botan/tm_hard.h> 0079 namespace QCA { // WRAPNS_LINE 0080 #elif defined(BOTAN_EXT_TIMER_POSIX) 0081 } // WRAPNS_LINE 0082 #include <botan/tm_posix.h> 0083 namespace QCA { // WRAPNS_LINE 0084 #elif defined(BOTAN_EXT_TIMER_UNIX) 0085 } // WRAPNS_LINE 0086 #include <botan/tm_unix.h> 0087 namespace QCA { // WRAPNS_LINE 0088 #elif defined(BOTAN_EXT_TIMER_WIN32) 0089 } // WRAPNS_LINE 0090 #include <botan/tm_win32.h> 0091 namespace QCA { // WRAPNS_LINE 0092 #endif 0093 0094 #if defined(BOTAN_EXT_ENGINE_AEP) 0095 } // WRAPNS_LINE 0096 #include <botan/eng_aep.h> 0097 namespace QCA { // WRAPNS_LINE 0098 #endif 0099 0100 #if defined(BOTAN_EXT_ENGINE_GNU_MP) 0101 } // WRAPNS_LINE 0102 #include <botan/eng_gmp.h> 0103 namespace QCA { // WRAPNS_LINE 0104 #endif 0105 0106 #if defined(BOTAN_EXT_ENGINE_OPENSSL) 0107 } // WRAPNS_LINE 0108 #include <botan/eng_ossl.h> 0109 namespace QCA { // WRAPNS_LINE 0110 #endif 0111 0112 #if defined(BOTAN_EXT_ENTROPY_SRC_AEP) 0113 } // WRAPNS_LINE 0114 #include <botan/es_aep.h> 0115 namespace QCA { // WRAPNS_LINE 0116 #endif 0117 0118 #if defined(BOTAN_EXT_ENTROPY_SRC_EGD) 0119 } // WRAPNS_LINE 0120 #include <botan/es_egd.h> 0121 namespace QCA { // WRAPNS_LINE 0122 #endif 0123 0124 #if defined(BOTAN_EXT_ENTROPY_SRC_UNIX) 0125 } // WRAPNS_LINE 0126 #include <botan/es_unix.h> 0127 namespace QCA { // WRAPNS_LINE 0128 #endif 0129 0130 #if defined(BOTAN_EXT_ENTROPY_SRC_BEOS) 0131 } // WRAPNS_LINE 0132 #include <botan/es_beos.h> 0133 namespace QCA { // WRAPNS_LINE 0134 #endif 0135 0136 #if defined(BOTAN_EXT_ENTROPY_SRC_CAPI) 0137 } // WRAPNS_LINE 0138 #include <botan/es_capi.h> 0139 namespace QCA { // WRAPNS_LINE 0140 #endif 0141 0142 #if defined(BOTAN_EXT_ENTROPY_SRC_WIN32) 0143 } // WRAPNS_LINE 0144 #include <botan/es_win32.h> 0145 namespace QCA { // WRAPNS_LINE 0146 #endif 0147 0148 #if defined(BOTAN_EXT_ENTROPY_SRC_FTW) 0149 } // WRAPNS_LINE 0150 #include <botan/es_ftw.h> 0151 namespace QCA { // WRAPNS_LINE 0152 #endif 0153 0154 #endif 0155 0156 namespace Botan { 0157 0158 /************************************************* 0159 * Return a mutex factory, if available * 0160 *************************************************/ 0161 Mutex_Factory *Builtin_Modules::mutex_factory() const 0162 { 0163 #if defined(BOTAN_EXT_MUTEX_PTHREAD) 0164 return new Pthread_Mutex_Factory; 0165 #elif defined(BOTAN_EXT_MUTEX_WIN32) 0166 return new Win32_Mutex_Factory; 0167 #elif defined(BOTAN_EXT_MUTEX_QT) 0168 return new Qt_Mutex_Factory; 0169 #else 0170 return 0; 0171 #endif 0172 } 0173 0174 /************************************************* 0175 * Find a high resolution timer, if possible * 0176 *************************************************/ 0177 #ifndef BOTAN_TOOLS_ONLY 0178 Timer *Builtin_Modules::timer() const 0179 { 0180 #if defined(BOTAN_EXT_TIMER_HARDWARE) 0181 return new Hardware_Timer; 0182 #elif defined(BOTAN_EXT_TIMER_POSIX) 0183 return new POSIX_Timer; 0184 #elif defined(BOTAN_EXT_TIMER_UNIX) 0185 return new Unix_Timer; 0186 #elif defined(BOTAN_EXT_TIMER_WIN32) 0187 return new Win32_Timer; 0188 #else 0189 return new Timer; 0190 #endif 0191 } 0192 #endif 0193 0194 /************************************************* 0195 * Find any usable allocators * 0196 *************************************************/ 0197 std::vector<Allocator *> Builtin_Modules::allocators() const 0198 { 0199 std::vector<Allocator *> allocators; 0200 0201 #if defined(BOTAN_EXT_ALLOC_MMAP) 0202 allocators.push_back(new MemoryMapping_Allocator); 0203 #endif 0204 0205 allocators.push_back(new Locking_Allocator); 0206 allocators.push_back(new Malloc_Allocator); 0207 0208 return allocators; 0209 } 0210 0211 /************************************************* 0212 * Return the default allocator * 0213 *************************************************/ 0214 std::string Builtin_Modules::default_allocator() const 0215 { 0216 if (should_lock) { 0217 #if defined(BOTAN_EXT_ALLOC_MMAP) 0218 return "mmap"; 0219 #else 0220 return "locking"; 0221 #endif 0222 } else 0223 return "malloc"; 0224 } 0225 0226 #ifndef BOTAN_TOOLS_ONLY 0227 0228 /************************************************* 0229 * Register any usable entropy sources * 0230 *************************************************/ 0231 std::vector<EntropySource *> Builtin_Modules::entropy_sources() const 0232 { 0233 std::vector<EntropySource *> sources; 0234 0235 sources.push_back(new File_EntropySource); 0236 0237 #if defined(BOTAN_EXT_ENTROPY_SRC_AEP) 0238 sources.push_back(new AEP_EntropySource); 0239 #endif 0240 0241 #if defined(BOTAN_EXT_ENTROPY_SRC_EGD) 0242 sources.push_back(new EGD_EntropySource); 0243 #endif 0244 0245 #if defined(BOTAN_EXT_ENTROPY_SRC_CAPI) 0246 sources.push_back(new Win32_CAPI_EntropySource); 0247 #endif 0248 0249 #if defined(BOTAN_EXT_ENTROPY_SRC_WIN32) 0250 sources.push_back(new Win32_EntropySource); 0251 #endif 0252 0253 #if defined(BOTAN_EXT_ENTROPY_SRC_UNIX) 0254 sources.push_back(new Unix_EntropySource); 0255 #endif 0256 0257 #if defined(BOTAN_EXT_ENTROPY_SRC_BEOS) 0258 sources.push_back(new BeOS_EntropySource); 0259 #endif 0260 0261 #if defined(BOTAN_EXT_ENTROPY_SRC_FTW) 0262 sources.push_back(new FTW_EntropySource); 0263 #endif 0264 0265 return sources; 0266 } 0267 0268 /************************************************* 0269 * Find any usable engines * 0270 *************************************************/ 0271 std::vector<Engine *> Builtin_Modules::engines() const 0272 { 0273 std::vector<Engine *> engines; 0274 0275 if (use_engines) { 0276 #if defined(BOTAN_EXT_ENGINE_AEP) 0277 engines.push_back(new AEP_Engine); 0278 #endif 0279 0280 #if defined(BOTAN_EXT_ENGINE_GNU_MP) 0281 engines.push_back(new GMP_Engine); 0282 #endif 0283 0284 #if defined(BOTAN_EXT_ENGINE_OPENSSL) 0285 engines.push_back(new OpenSSL_Engine); 0286 #endif 0287 } 0288 0289 engines.push_back(new Default_Engine); 0290 0291 return engines; 0292 } 0293 0294 /************************************************* 0295 * Find the best transcoder option * 0296 *************************************************/ 0297 Charset_Transcoder *Builtin_Modules::transcoder() const 0298 { 0299 return new Default_Charset_Transcoder; 0300 } 0301 0302 #endif 0303 0304 /************************************************* 0305 * Builtin_Modules Constructor * 0306 *************************************************/ 0307 #ifdef BOTAN_TOOLS_ONLY 0308 Builtin_Modules::Builtin_Modules() 0309 : should_lock(true) 0310 { 0311 } 0312 #else 0313 Builtin_Modules::Builtin_Modules(const InitializerOptions &args) 0314 : should_lock(args.secure_memory()) 0315 , use_engines(args.use_engines()) 0316 { 0317 } 0318 #endif 0319 0320 } 0321 } // WRAPNS_LINE