Crypto++
rng.h
1 // rng.h - misc RNG related classes, see also osrng.h, randpool.h
2 
3 #ifndef CRYPTOPP_RNG_H
4 #define CRYPTOPP_RNG_H
5 
6 #include "cryptlib.h"
7 #include "filters.h"
8 
9 NAMESPACE_BEGIN(CryptoPP)
10 
11 //! linear congruential generator
12 /*! originally by William S. England, do not use for cryptographic purposes */
14 {
15 public:
16  LC_RNG(word32 init_seed)
17  : seed(init_seed) {}
18 
19  void GenerateBlock(byte *output, size_t size);
20 
21  word32 GetSeed() {return seed;}
22 
23 private:
24  word32 seed;
25 
26  static const word32 m;
27  static const word32 q;
28  static const word16 a;
29  static const word16 r;
30 };
31 
32 //! RNG derived from ANSI X9.17 Appendix C
33 
34 class CRYPTOPP_DLL X917RNG : public RandomNumberGenerator, public NotCopyable
35 {
36 public:
37  // cipher will be deleted by destructor, deterministicTimeVector = 0 means obtain time vector from system
38  X917RNG(BlockTransformation *cipher, const byte *seed, const byte *deterministicTimeVector = 0);
39 
40  void GenerateIntoBufferedTransformation(BufferedTransformation &target, const std::string &channel, lword size);
41 
42 private:
44  unsigned int S; // blocksize of cipher
45  SecByteBlock dtbuf; // buffer for enciphered timestamp
46  SecByteBlock randseed, m_lastBlock, m_deterministicTimeVector;
47 };
48 
49 /** This class implements Maurer's Universal Statistical Test for Random Bit Generators
50  it is intended for measuring the randomness of *PHYSICAL* RNGs.
51  For more details see his paper in Journal of Cryptology, 1992. */
52 
53 class MaurerRandomnessTest : public Bufferless<Sink>
54 {
55 public:
57 
58  size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking);
59 
60  // BytesNeeded() returns how many more bytes of input is needed by the test
61  // GetTestValue() should not be called before BytesNeeded()==0
62  unsigned int BytesNeeded() const {return n >= (Q+K) ? 0 : Q+K-n;}
63 
64  // returns a number between 0.0 and 1.0, describing the quality of the
65  // random numbers entered
66  double GetTestValue() const;
67 
68 private:
69  enum {L=8, V=256, Q=2000, K=2000};
70  double sum;
71  unsigned int n;
72  unsigned int tab[V];
73 };
74 
75 NAMESPACE_END
76 
77 #endif
RNG derived from ANSI X9.17 Appendix C.
Definition: rng.h:34
linear congruential generator
Definition: rng.h:13
interface for random number generators
Definition: cryptlib.h:668
interface for buffered transformations
Definition: cryptlib.h:770
size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking)
input multiple bytes for blocking or non-blocking processing
This class implements Maurer's Universal Statistical Test for Random Bit Generators it is intended fo...
Definition: rng.h:53
virtual void GenerateIntoBufferedTransformation(BufferedTransformation &target, const std::string &channel, lword length)
generate random bytes as input to a BufferedTransformation
interface for the data processing part of block ciphers
Definition: cryptlib.h:428
_
Definition: simple.h:49