summaryrefslogtreecommitdiff
path: root/rng.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'rng.cpp')
-rw-r--r--rng.cpp22
1 files changed, 12 insertions, 10 deletions
diff --git a/rng.cpp b/rng.cpp
index 0119d30..dfcd262 100644
--- a/rng.cpp
+++ b/rng.cpp
@@ -116,22 +116,24 @@ MaurerRandomnessTest::MaurerRandomnessTest()
tab[i] = 0;
}
-inline void MaurerRandomnessTest::Put(byte inByte)
-{
- if (n >= Q)
- sum += log(double(n - tab[inByte]));
- tab[inByte] = n;
- n++;
-}
-
-void MaurerRandomnessTest::Put(const byte *inString, unsigned int length)
+unsigned int MaurerRandomnessTest::Put2(const byte *inString, unsigned int length, int messageEnd, bool blocking)
{
while (length--)
- Put(*inString++);
+ {
+ byte inByte = *inString++;
+ if (n >= Q)
+ sum += log(double(n - tab[inByte]));
+ tab[inByte] = n;
+ n++;
+ }
+ return 0;
}
double MaurerRandomnessTest::GetTestValue() const
{
+ if (BytesNeeded() > 0)
+ throw Exception(Exception::OTHER_ERROR, "MaurerRandomnessTest: " + IntToString(BytesNeeded()) + " more bytes of input needed");
+
double fTu = (sum/(n-Q))/log(2.0); // this is the test value defined by Maurer
double value = fTu * 0.1392; // arbitrarily normalize it to