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

# rng.h

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