monotone

monotone Mtn Source Tree

Root/cryptopp/rng.h

1#ifndef CRYPTOPP_RNG_H
2#define CRYPTOPP_RNG_H
3
4#include "cryptlib.h"
5#include "filters.h"
6
7NAMESPACE_BEGIN(CryptoPP)
8
9//! linear congruential generator
10/*! originally by William S. England, do not use for cryptographic purposes */
11class LC_RNG : public RandomNumberGenerator
12{
13public:
14LC_RNG(word32 init_seed)
15: seed(init_seed) {}
16
17byte GenerateByte();
18
19word32 GetSeed() {return seed;}
20
21private:
22word32 seed;
23
24static const word32 m;
25static const word32 q;
26static const word16 a;
27static const word16 r;
28};
29
30//! RNG derived from ANSI X9.17 Appendix C
31
32class X917RNG : public RandomNumberGenerator
33{
34public:
35// cipher will be deleted by destructor, deterministicTimeVector = 0 means obtain time vector from system
36X917RNG(BlockTransformation *cipher, const byte *seed, unsigned long deterministicTimeVector = 0);
37
38byte GenerateByte();
39
40private:
41member_ptr<BlockTransformation> cipher;
42const int S;// blocksize of cipher
43SecByteBlock dtbuf; // buffer for enciphered timestamp
44SecByteBlock randseed, randbuf;
45int randbuf_counter;// # of unused bytes left in randbuf
46unsigned long m_deterministicTimeVector;
47};
48
49/** This class implements Maurer's Universal Statistical Test for Random Bit Generators
50 it is intended for measuring the randomness of *PHYSICAL* RNGs.
51 For more details see his paper in Journal of Cryptology, 1992. */
52
53class MaurerRandomnessTest : public Sink
54{
55public:
56MaurerRandomnessTest();
57
58/** these two I just added in to make it compile. naughty bit-rot. graydon@pobox.com */
59virtual unsigned int Put2(const byte *inString, unsigned int length, int messageEnd, bool blocking) { return 0; }
60virtual bool IsolatedFlush(bool hardFlush, bool blocking) { return false; }
61
62void Put(byte inByte);
63void Put(const byte *inString, unsigned int length);
64
65// BytesNeeded() returns how many more bytes of input is needed by the test
66// GetTestValue() should not be called before BytesNeeded()==0
67unsigned int BytesNeeded() const {return n >= (Q+K) ? 0 : Q+K-n;}
68
69// returns a number between 0.0 and 1.0, describing the quality of the
70// random numbers entered
71double GetTestValue() const;
72
73private:
74enum {L=8, V=256, Q=2000, K=2000};
75double sum;
76unsigned int n;
77unsigned int tab[V];
78};
79
80NAMESPACE_END
81
82#endif

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status