monotone

monotone Mtn Source Tree

Root/botan/es_file.cpp

1/*************************************************
2* File EntropySource Source File *
3* (C) 1999-2005 The Botan Project *
4*************************************************/
5
6#include <botan/es_file.h>
7#include <botan/conf.h>
8#include <botan/parsing.h>
9#include <fstream>
10
11namespace Botan {
12
13/*************************************************
14* File_EntropySource Constructor *
15*************************************************/
16File_EntropySource::File_EntropySource(const std::string& sources)
17 {
18 std::vector<std::string> source_list = split_on(sources, ':');
19 std::vector<std::string> defaults = Config::get_list("rng/es_files");
20
21 for(u32bit j = 0; j != source_list.size(); j++)
22 add_source(source_list[j]);
23 for(u32bit j = 0; j != defaults.size(); j++)
24 add_source(defaults[j]);
25 }
26
27/*************************************************
28* Add another file to the list *
29*************************************************/
30void File_EntropySource::add_source(const std::string& source)
31 {
32 sources.push_back(source);
33 }
34
35/*************************************************
36* Gather Entropy from Randomness Source *
37*************************************************/
38u32bit File_EntropySource::slow_poll(byte output[], u32bit length)
39 {
40 u32bit read = 0;
41 for(u32bit j = 0; j != sources.size(); j++)
42 {
43 std::ifstream random_source(sources[j].c_str(), std::ios::binary);
44 if(!random_source) continue;
45 random_source.read((char*)output + read, length);
46 read += random_source.gcount();
47 length -= random_source.gcount();
48 if(length == 0)
49 break;
50 }
51 return read;
52 }
53
54}

Archive Download this file

Branches

Tags

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