aboutsummaryrefslogtreecommitdiffstats
path: root/include/rng.h
blob: f8b9a7f62b300e04adddaf4d113d2f0c0373fad4 (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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*************************************************
* RandomNumberGenerator Header File              *
* (C) 1999-2008 Jack Lloyd                       *
*************************************************/

#ifndef BOTAN_RANDOM_NUMBER_GENERATOR__
#define BOTAN_RANDOM_NUMBER_GENERATOR__

#include <botan/exceptn.h>

namespace Botan {

/*************************************************
* Entropy Source                                 *
*************************************************/
class BOTAN_DLL EntropySource
   {
   public:
      virtual u32bit slow_poll(byte[], u32bit) = 0;
      virtual u32bit fast_poll(byte[], u32bit);
      virtual ~EntropySource() {}
   };

/*************************************************
* Random Number Generator                        *
*************************************************/
class BOTAN_DLL RandomNumberGenerator
   {
   public:
      static RandomNumberGenerator* make_rng();

      virtual void randomize(byte[], u32bit) = 0;
      virtual bool is_seeded() const = 0;
      virtual void clear() throw() = 0;

      byte next_byte();

      virtual void reseed() {}
      virtual void add_entropy_source(EntropySource*) = 0;
      virtual void add_entropy(const byte[], u32bit) = 0;

      RandomNumberGenerator() {}
      virtual ~RandomNumberGenerator() {}
   private:
      RandomNumberGenerator(const RandomNumberGenerator&) {}
      RandomNumberGenerator& operator=(const RandomNumberGenerator&)
         { return (*this); }
   };

/*************************************************
* Null Random Number Generator                   *
*************************************************/
class BOTAN_DLL Null_RNG : public RandomNumberGenerator
   {
   public:
      void randomize(byte[], u32bit) { throw PRNG_Unseeded("Null_RNG"); }
      void clear() throw() {};

      bool is_seeded() const { return false; }
      void add_entropy(const byte[], u32bit) {}
      void add_entropy_source(EntropySource* es) { delete es; }
   };

}

#endif