aboutsummaryrefslogtreecommitdiffstats
path: root/src/es_file.cpp
blob: 4d9a52d820210ff7475b6e29c0d392e540844f9b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/*************************************************
* File EntropySource Source File                 *
* (C) 1999-2006 The Botan Project                *
*************************************************/

#include <botan/es_file.h>
#include <botan/config.h>
#include <fstream>

namespace Botan {

/*************************************************
* Gather Entropy from Randomness Source          *
*************************************************/
u32bit File_EntropySource::slow_poll(byte output[], u32bit length)
   {
   std::vector<std::string> sources =
      global_config().option_as_list("rng/es_files");

   u32bit read = 0;
   for(u32bit j = 0; j != sources.size(); ++j)
      {
      std::ifstream random_source(sources[j].c_str(), std::ios::binary);
      if(!random_source) continue;
      random_source.read((char*)output + read, length);
      read += random_source.gcount();
      length -= random_source.gcount();
      if(length == 0)
         break;
      }
   return read;
   }

}