diff options
author | lloyd <[email protected]> | 2006-07-28 14:13:44 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2006-07-28 14:13:44 +0000 |
commit | 0a9ee0e122aed780e6da5428fe0f0a007c84b87b (patch) | |
tree | 0f26da86ec14ec9d7a9f40fc8b18c586bd883f59 | |
parent | 2b4733d5893f0301b15f987c3309befc88eeb768 (diff) |
Change Builtin_Module constructor to take an InitializerOptions
instead of just a boolean, so it can (if desired) examine any arguments
it likes.
Only run the startup self tests if the selftest or fips140 option is
toggled on.
-rw-r--r-- | include/modules.h | 3 | ||||
-rw-r--r-- | src/init_def.cpp | 40 | ||||
-rw-r--r-- | src/modules.cpp | 8 |
3 files changed, 33 insertions, 18 deletions
diff --git a/include/modules.h b/include/modules.h index d2d83985c..f81fcb64a 100644 --- a/include/modules.h +++ b/include/modules.h @@ -6,6 +6,7 @@ #ifndef BOTAN_MODULE_FACTORIES_H__ #define BOTAN_MODULE_FACTORIES_H__ +#include <botan/init.h> #include <string> #include <vector> @@ -46,7 +47,7 @@ class Builtin_Modules : public Modules std::vector<class EntropySource*> entropy_sources() const; std::vector<class Engine*> engines() const; - Builtin_Modules(bool sl) : should_lock(sl) {} + Builtin_Modules(const InitializerOptions&); private: const bool should_lock; }; diff --git a/src/init_def.cpp b/src/init_def.cpp index 31cb89ea7..f05ef6952 100644 --- a/src/init_def.cpp +++ b/src/init_def.cpp @@ -46,7 +46,7 @@ namespace Init { *************************************************/ void initialize(const InitializerOptions& args) { - Builtin_Modules modules(args.secure_memory()); + Builtin_Modules modules(args); set_global_state( new Library_State( @@ -63,31 +63,37 @@ void initialize(const InitializerOptions& args) global_state().load(modules); global_state().set_prng(new ANSI_X931_RNG); - const u32bit min_entropy = - global_config().option_as_u32bit("rng/min_entropy"); - - if(min_entropy != 0 && args.seed_rng()) + if(args.seed_rng()) { - u32bit bits_so_far = 0; + const u32bit min_entropy = + global_config().option_as_u32bit("rng/min_entropy"); - for(u32bit j = 0; j != 4; ++j) + if(min_entropy != 0) { - u32bit to_get = min_entropy - bits_so_far; + u32bit bits_so_far = 0; - bits_so_far += global_state().seed_prng(true, to_get); + for(u32bit j = 0; j != 4; ++j) + { + u32bit to_get = min_entropy - bits_so_far; - if(bits_so_far >= min_entropy) - break; - } + bits_so_far += global_state().seed_prng(true, to_get); + + if(bits_so_far >= min_entropy) + break; + } - if(bits_so_far < min_entropy) - throw PRNG_Unseeded("Unable to collect sufficient entropy"); + if(bits_so_far < min_entropy) + throw PRNG_Unseeded("Unable to collect sufficient entropy"); + } } - if(!FIPS140::passes_self_tests()) + if(args.fips_mode() || args.self_test()) { - deinitialize(); - throw Self_Test_Failure("FIPS-140 startup tests"); + if(!FIPS140::passes_self_tests()) + { + deinitialize(); + throw Self_Test_Failure("FIPS-140 startup tests"); + } } } diff --git a/src/modules.cpp b/src/modules.cpp index 48b043afe..47a62c13f 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -213,4 +213,12 @@ Charset_Transcoder* Builtin_Modules::transcoder() const return new Default_Charset_Transcoder; } +/************************************************* +* Builtin_Modules Constructor * +*************************************************/ +Builtin_Modules::Builtin_Modules(const InitializerOptions& args) : + should_lock(args.secure_memory()) + { + } + } |