summaryrefslogtreecommitdiff
path: root/rng.h
diff options
context:
space:
mode:
authorweidai <weidai@57ff6487-cd31-0410-9ec3-f628ee90f5f0>2002-10-04 17:31:41 +0000
committerweidai <weidai@57ff6487-cd31-0410-9ec3-f628ee90f5f0>2002-10-04 17:31:41 +0000
commitb21162cf8e06f40baa1f58be6a8c17435cebc34d (patch)
tree8b045309c238226c32a563b1df6b9c30a2f0e0b3 /rng.h
downloadcryptopp-b21162cf8e06f40baa1f58be6a8c17435cebc34d.tar.gz
Initial revision
git-svn-id: svn://svn.code.sf.net/p/cryptopp/code/trunk/c5@2 57ff6487-cd31-0410-9ec3-f628ee90f5f0
Diffstat (limited to 'rng.h')
-rw-r--r--rng.h77
1 files changed, 77 insertions, 0 deletions
diff --git a/rng.h b/rng.h
new file mode 100644
index 0000000..f4afaeb
--- /dev/null
+++ b/rng.h
@@ -0,0 +1,77 @@
+#ifndef CRYPTOPP_RNG_H
+#define CRYPTOPP_RNG_H
+
+#include "cryptlib.h"
+#include "filters.h"
+
+NAMESPACE_BEGIN(CryptoPP)
+
+//! linear congruential generator
+/*! 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) {}
+
+ byte GenerateByte();
+
+ word32 GetSeed() {return seed;}
+
+private:
+ word32 seed;
+
+ static const word32 m;
+ static const word32 q;
+ static const word16 a;
+ static const word16 r;
+};
+
+//! RNG derived from ANSI X9.17 Appendix C
+
+class X917RNG : public RandomNumberGenerator
+{
+public:
+ // cipher will be deleted by destructor
+ X917RNG(BlockTransformation *cipher, const byte *seed);
+
+ byte GenerateByte();
+
+private:
+ member_ptr<BlockTransformation> cipher;
+ const int S; // blocksize of cipher
+ SecByteBlock dtbuf; // buffer for enciphered timestamp
+ SecByteBlock randseed, randbuf;
+ int randbuf_counter; // # of unused bytes left in randbuf
+};
+
+/** This class implements Maurer's Universal Statistical Test for Random Bit Generators
+ it is intended for measuring the randomness of *PHYSICAL* RNGs.
+ For more details see his paper in Journal of Cryptology, 1992. */
+
+class MaurerRandomnessTest : public Sink
+{
+public:
+ MaurerRandomnessTest();
+
+ void Put(byte inByte);
+ void Put(const byte *inString, unsigned int length);
+
+ // BytesNeeded() returns how many more bytes of input is needed by the test
+ // GetTestValue() should not be called before BytesNeeded()==0
+ unsigned int BytesNeeded() const {return n >= (Q+K) ? 0 : Q+K-n;}
+
+ // returns a number between 0.0 and 1.0, describing the quality of the
+ // random numbers entered
+ double GetTestValue() const;
+
+private:
+ enum {L=8, V=256, Q=2000, K=2000};
+ double sum;
+ unsigned int n;
+ unsigned int tab[V];
+};
+
+NAMESPACE_END
+
+#endif