Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
2.1 KiB

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