diff options
Diffstat (limited to 'src/init_def.cpp')
-rw-r--r-- | src/init_def.cpp | 40 |
1 files changed, 23 insertions, 17 deletions
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"); + } } } |