monotone

monotone Mtn Source Tree

Root/botan/init_def.cpp

1/*************************************************
2* Default Initialization Function Source File *
3* (C) 1999-2006 The Botan Project *
4*************************************************/
5
6#include <botan/init.h>
7#include <botan/libstate.h>
8#include <botan/modules.h>
9#include <botan/config.h>
10#include <botan/defalloc.h>
11#include <botan/fips140.h>
12#include <botan/x931_rng.h>
13#include <botan/def_char.h>
14
15namespace Botan {
16
17/*************************************************
18* Library Initialization *
19*************************************************/
20void LibraryInitializer::initialize(const std::string& arg_string)
21 {
22 InitializerOptions args(arg_string);
23 initialize(args);
24 }
25
26/*************************************************
27* Library Initialization *
28*************************************************/
29void LibraryInitializer::initialize(const InitializerOptions& args)
30 {
31 Builtin_Modules modules(args);
32 initialize(args, modules);
33 }
34
35/*************************************************
36* Library Initialization *
37*************************************************/
38void LibraryInitializer::initialize(const InitializerOptions& args,
39 Modules& modules)
40 {
41 try
42 {
43 set_global_state(
44 new Library_State(
45 args.thread_safe() ?
46 modules.mutex_factory() :
47 new Default_Mutex_Factory
48 )
49 );
50
51 global_state().config().load_defaults();
52 if(args.config_file() != "")
53 global_config().load_inifile(args.config_file());
54
55 global_state().load(modules);
56 global_state().set_prng(new ANSI_X931_RNG);
57
58 if(args.seed_rng())
59 {
60 for(u32bit j = 0; j != 4; ++j)
61 {
62 global_state().seed_prng(true, 384);
63 if(global_state().rng_is_seeded())
64 break;
65 }
66
67 if(!global_state().rng_is_seeded())
68 throw PRNG_Unseeded("Unable to collect sufficient entropy");
69 }
70
71 if(args.fips_mode() || args.self_test())
72 {
73 if(!FIPS140::passes_self_tests())
74 throw Self_Test_Failure("FIPS-140 startup tests");
75 }
76 }
77 catch(...)
78 {
79 deinitialize();
80 throw;
81 }
82 }
83
84/*************************************************
85* Library Shutdown *
86*************************************************/
87void LibraryInitializer::deinitialize()
88 {
89 set_global_state(0);
90 }
91
92}

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status