Fabcoin Core  0.16.2
P2P Digital Currency
rng.h
Go to the documentation of this file.
1 // rng.h - written and placed in the public domain by Wei Dai
2 
8 
9 #ifndef CRYPTOPP_RNG_H
10 #define CRYPTOPP_RNG_H
11 
12 #include "cryptlib.h"
13 #include "filters.h"
14 #include "smartptr.h"
15 
17 
18 class LC_RNG : public RandomNumberGenerator
23 {
24 public:
27  LC_RNG(word32 init_seed)
28  : seed(init_seed) {}
29 
30  void GenerateBlock(byte *output, size_t size);
31 
32  word32 GetSeed() {return seed;}
33 
34 private:
36 
37  static const word32 m;
38  static const word32 q;
39  static const word16 a;
40  static const word16 r;
41 };
42 
49 {
50 public:
67  X917RNG(BlockTransformation *cipher, const byte *seed, const byte *deterministicTimeVector = 0);
68 
69  void GenerateIntoBufferedTransformation(BufferedTransformation &target, const std::string &channel, lword size);
70 
71 private:
73  const unsigned int m_size; // S, blocksize of cipher
74  SecByteBlock m_datetime; // DT, buffer for enciphered timestamp
75  SecByteBlock m_randseed, m_lastBlock, m_deterministicTimeVector;
76 };
77 
84 class MaurerRandomnessTest : public Bufferless<Sink>
85 {
86 public:
89 
90  size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking);
91 
94  // BytesNeeded() returns how many more bytes of input is needed by the test
95  // GetTestValue() should not be called before BytesNeeded()==0
96  unsigned int BytesNeeded() const {return n >= (Q+K) ? 0 : Q+K-n;}
97 
98  // returns a number between 0.0 and 1.0, describing the quality of the
99  // random numbers entered
100  double GetTestValue() const;
101 
102 private:
103  enum {L=8, V=256, Q=2000, K=2000};
104  double sum;
105  unsigned int n;
106  unsigned int tab[V];
107 };
108 
110 
111 #endif
SecByteBlock m_datetime
Definition: rng.h:74
uint8_t byte
Definition: Common.h:57
unsigned int BytesNeeded() const
Provides the number of bytes of input is needed by the test.
Definition: rng.h:96
unsigned short word16
Definition: config.h:230
ANSI X9.17 RNG.
Definition: rng.h:48
#define NAMESPACE_BEGIN(x)
Definition: config.h:200
Linear Congruential Generator (LCG)
Definition: rng.h:22
word32 GetSeed()
Definition: rng.h:32
#define Q(i)
Definition: cast.cpp:199
word32 seed
Definition: rng.h:35
unsigned int n
Definition: rng.h:105
Abstract base classes that provide a uniform interface to this library.
Classes for automatic resource management.
Interface for random number generators.
Definition: cryptlib.h:1188
Interface for buffered transformations.
Definition: cryptlib.h:1352
SecByteBlock m_randseed
Definition: rng.h:75
static const word16 a
Definition: rng.h:39
const unsigned int m_size
Definition: rng.h:73
Maurer&#39;s Universal Statistical Test for Random Bit Generators.
Definition: rng.h:84
LC_RNG(word32 init_seed)
Construct a Linear Congruential Generator (LCG)
Definition: rng.h:27
Implementation of BufferedTransformation&#39;s attachment interface.
member_ptr< BlockTransformation > m_cipher
Definition: rng.h:72
uint8_t const size_t const size
Definition: sha3.h:20
#define NAMESPACE_END
Definition: config.h:201
static const word32 q
Definition: rng.h:38
word64 lword
Definition: config.h:245
Interface for the data processing part of block ciphers.
Definition: cryptlib.h:734
static const word32 m
Definition: rng.h:37
#define CRYPTOPP_DLL
Definition: config.h:704
unsigned int word32
Definition: config.h:231
Ensures an object is not copyable.
Definition: misc.h:217
static const word16 r
Definition: rng.h:40
virtual void GenerateIntoBufferedTransformation(BufferedTransformation &target, const std::string &channel, lword length)
Generate random bytes into a BufferedTransformation.
Definition: cryptlib.cpp:344
Base class for bufferless filters.
Definition: simple.h:83