// rng.h - written and placed in the public domain by Wei Dai //! \file rng.h //! \brief Miscellaneous classes for RNGs //! \details This file contains miscellaneous classes for RNGs, including LC_RNG(), //! X917RNG() and MaurerRandomnessTest() //! \sa osrng.h, randpool.h #ifndef CRYPTOPP_RNG_H #define CRYPTOPP_RNG_H #include "cryptlib.h" #include "filters.h" #include "smartptr.h" NAMESPACE_BEGIN(CryptoPP) //! \brief Linear Congruential Generator (LCG) //! \details Originally by William S. England, do not use for cryptographic purposes class LC_RNG : public RandomNumberGenerator { public: LC_RNG(word32 init_seed) : seed(init_seed) {} void GenerateBlock(byte *output, size_t size); word32 GetSeed() {return seed;} private: word32 seed; static const word32 m; static const word32 q; static const word16 a; static const word16 r; }; //! \class X917RNG //! \brief ANSI X9.17 RNG //! \details X917RNG is from ANSI X9.17 Appendix C. //! \sa AutoSeededX917RNG, DefaultAutoSeededRNG class CRYPTOPP_DLL X917RNG : public RandomNumberGenerator, public NotCopyable { public: //! \brief Construct a X917RNG //! \param cipher the block cipher to use for the generator //! \param seed a byte buffer to use as a seed //! \param deterministicTimeVector additional entropy //! \details cipher will be deleted by the destructor. seed must be at least //! BlockSize() in length. deterministicTimeVector = 0 means obtain time vector //! from the system. //! \details When constructing an AutoSeededX917RNG, the generator must be keyed or an //! access violation will occur because the time vector is encrypted using the block cipher. //! To key the generator during constructions, perform the following: //!
//! SecByteBlock key(AES::DEFAULT_KEYLENGTH), seed(AES::BLOCKSIZE); //! OS_GenerateRandomBlock(false, key, key.size()); //! OS_GenerateRandomBlock(false, seed, seed.size()); //! X917RNG prng(new AES::Encryption(key, AES::DEFAULT_KEYLENGTH), seed, NULL); //!//! \sa AutoSeededX917RNG X917RNG(BlockTransformation *cipher, const byte *seed, const byte *deterministicTimeVector = 0); void GenerateIntoBufferedTransformation(BufferedTransformation &target, const std::string &channel, lword size); private: member_ptr