Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

rng.h

00001 #ifndef CRYPTOPP_RNG_H 00002 #define CRYPTOPP_RNG_H 00003 00004 #include "cryptlib.h" 00005 #include "filters.h" 00006 00007 NAMESPACE_BEGIN(CryptoPP) 00008 00009 //! linear congruential generator 00010 /*! originally by William S. England, do not use for cryptographic purposes */ 00011 class LC_RNG : public RandomNumberGenerator 00012 { 00013 public: 00014 LC_RNG(word32 init_seed) 00015 : seed(init_seed) {} 00016 00017 byte GenerateByte(); 00018 00019 word32 GetSeed() {return seed;} 00020 00021 private: 00022 word32 seed; 00023 00024 static const word32 m; 00025 static const word32 q; 00026 static const word16 a; 00027 static const word16 r; 00028 }; 00029 00030 //! RNG derived from ANSI X9.17 Appendix C 00031 00032 class X917RNG : public RandomNumberGenerator 00033 { 00034 public: 00035 // cipher will be deleted by destructor, deterministicTimeVector = 0 means obtain time vector from system 00036 X917RNG(BlockTransformation *cipher, const byte *seed, unsigned long deterministicTimeVector = 0); 00037 00038 byte GenerateByte(); 00039 00040 private: 00041 member_ptr<BlockTransformation> cipher; 00042 const int S; // blocksize of cipher 00043 SecByteBlock dtbuf; // buffer for enciphered timestamp 00044 SecByteBlock randseed, randbuf; 00045 int randbuf_counter; // # of unused bytes left in randbuf 00046 unsigned long m_deterministicTimeVector; 00047 }; 00048 00049 /** This class implements Maurer's Universal Statistical Test for Random Bit Generators 00050 it is intended for measuring the randomness of *PHYSICAL* RNGs. 00051 For more details see his paper in Journal of Cryptology, 1992. */ 00052 00053 class MaurerRandomnessTest : public Sink 00054 { 00055 public: 00056 MaurerRandomnessTest(); 00057 00058 void Put(byte inByte); 00059 void Put(const byte *inString, unsigned int length); 00060 00061 // BytesNeeded() returns how many more bytes of input is needed by the test 00062 // GetTestValue() should not be called before BytesNeeded()==0 00063 unsigned int BytesNeeded() const {return n >= (Q+K) ? 0 : Q+K-n;} 00064 00065 // returns a number between 0.0 and 1.0, describing the quality of the 00066 // random numbers entered 00067 double GetTestValue() const; 00068 00069 private: 00070 enum {L=8, V=256, Q=2000, K=2000}; 00071 double sum; 00072 unsigned int n; 00073 unsigned int tab[V]; 00074 }; 00075 00076 NAMESPACE_END 00077 00078 #endif

Generated on Fri Aug 13 09:56:54 2004 for Crypto++ by doxygen 1.3.7