public void Pool_OneEventDigestIsNonZero() { var p = new EntropyPool(); p.Add(EventFromBytes(_Zero8Bytes)); Assert.IsFalse(p.GetDigest().All(b => b == 0)); }
public void Pool_List3InterleavedSources() { var p = new EntropyPool(); var s1 = new NullSource(); var s2 = new NullSource(); var s3 = new NullSource(); var e1 = new EntropyEvent(_Zero16Bytes, s1); var e2 = new EntropyEvent(_Zero16Bytes, s2); var e3 = new EntropyEvent(_Zero16Bytes, s3); using (var sw = new StreamWriter("pool_3interleaved.txt", false, Encoding.UTF8)) { sw.WriteLine($"Total: Source 1 : Source 2 : Source 3"); for (int i = 0; i < 10000; i++) { if (i % 3 == 0) { p.Add(e1); } else if (i % 3 == 1) { p.Add(e2); } else { p.Add(e3); } var counts = p.GetCountOfBytesBySource(); if (counts.Count == 3) { sw.WriteLine($"{p.EntropyBytesSinceLastDigest} :{counts[s1]:N0} :{counts[s2]:N0} :{counts[s3]:N0}"); } } } }
public void Pool_NoEntropyIsSameDigest() { var p1 = new EntropyPool(); var p2 = new EntropyPool(); CollectionAssert.AreEqual(p1.GetDigest(), p2.GetDigest()); }
public void Pool_CanUseIncrementalHash() { var p = new EntropyPool(IncrementalHash.CreateHash(HashAlgorithmName.SHA256)); p.Add(EventFromBytes(_Zero8Bytes)); Assert.IsFalse(p.GetDigest().All(b => b == 0)); }
public void Pool_NoEntropyIsZero() { var p = new EntropyPool(); Assert.AreEqual(p.TotalEntropyBytes, 0); Assert.AreEqual(p.EntropyBytesSinceLastDigest, 0); }
public void Pool_OneSourceIsLimitedWhenDominating() { var p = new EntropyPool(); var evt = EventFromBytes(_Zero16Bytes); var evt2 = EventFromBytes(_Zero16Bytes); p.Add(evt); p.Add(evt); p.Add(evt); p.Add(evt); // Ignored. Assert.AreEqual(p.TotalEntropyBytes, 48); Assert.AreEqual(p.EntropyBytesSinceLastDigest, 48); p.Add(evt2); p.Add(evt2); p.Add(evt2); Assert.AreEqual(p.TotalEntropyBytes, 96); Assert.AreEqual(p.EntropyBytesSinceLastDigest, 96); p.Add(evt); p.Add(evt); p.Add(evt); p.Add(evt); // Ignored. Assert.AreEqual(p.TotalEntropyBytes, 144); Assert.AreEqual(p.EntropyBytesSinceLastDigest, 144); }
public void Pool_CanUseDifferentHashAlgorithm() { var p = new EntropyPool(new SHA256Managed()); p.Add(EventFromBytes(_Zero8Bytes)); Assert.IsFalse(p.GetDigest().All(b => b == 0)); }
public void Pool_OneEventAddsToCounters() { var p = new EntropyPool(); p.Add(EventFromBytes(_Zero8Bytes)); Assert.AreEqual(p.TotalEntropyBytes, 8); Assert.AreEqual(p.EntropyBytesSinceLastDigest, 8); }
//[TestMethod] public void Pool_CanUseNonShaBasedAlgorithm() { var blake2b = System.Data.HashFunction.Blake2.Blake2BFactory.Instance.Create(); Assert.Fail("TODO: must change the EntropyPool to accept an object which we can plug various hash implementations into."); var p = new EntropyPool(new SHA256Managed()); p.Add(EventFromBytes(_Zero8Bytes)); Assert.IsFalse(p.GetDigest().All(b => b == 0)); }
public void Pool_GetDigestResetsCountsBySource() { var p = new EntropyPool(); var evt = EventFromBytes(_Zero16Bytes); p.Add(evt); Assert.AreEqual(p.GetCountOfBytesBySource().Count, 1); var digest = p.GetDigest(); Assert.AreEqual(p.GetCountOfBytesBySource().Count, 0); }
public void Pool_SameEntropyIsSameDigest() { var p1 = new EntropyPool(); var p2 = new EntropyPool(); p1.Add(EventFromBytes(_Zero8Bytes)); p2.Add(EventFromBytes(_Zero8Bytes)); CollectionAssert.AreEqual(p1.GetDigest(), p2.GetDigest()); p1.Add(EventFromBytes(_Incrementing16Bytes)); p2.Add(EventFromBytes(_Incrementing16Bytes)); CollectionAssert.AreEqual(p1.GetDigest(), p2.GetDigest()); }
public void Pool_First48BytesAreOK() { var p = new EntropyPool(); var evt = EventFromBytes(_Zero8Bytes); p.Add(evt); p.Add(evt); p.Add(evt); p.Add(evt); p.Add(evt); p.Add(evt); Assert.AreEqual(p.TotalEntropyBytes, 48); Assert.AreEqual(p.EntropyBytesSinceLastDigest, 48); }
public void Pool_After48BytesAreIgnored() { var p = new EntropyPool(); var evt = EventFromBytes(_Zero8Bytes); p.Add(evt); p.Add(evt); p.Add(evt); p.Add(evt); p.Add(evt); p.Add(evt); p.Add(evt); // This triggers the "too much entropy from one source" thing. Assert.AreEqual(p.TotalEntropyBytes, 48); Assert.AreEqual(p.EntropyBytesSinceLastDigest, 48); }
public void Pool_TwoSourcesCanGoBeyond48BytesEachWhenEvenlyDistributed() { var p = new EntropyPool(); var evt = EventFromBytes(_Zero16Bytes); var evt2 = EventFromBytes(_Zero16Bytes); p.Add(evt); p.Add(evt2); p.Add(evt); p.Add(evt2); p.Add(evt); p.Add(evt2); p.Add(evt); p.Add(evt2); Assert.AreEqual(p.TotalEntropyBytes, 128); Assert.AreEqual(p.EntropyBytesSinceLastDigest, 128); }
public void Pool_CountersResetAfterDigest() { var p = new EntropyPool(); p.Add(EventFromBytes(_Zero8Bytes)); Assert.AreEqual(p.TotalEntropyBytes, 8); Assert.AreEqual(p.EntropyBytesSinceLastDigest, 8); p.GetDigest(); Assert.AreEqual(p.TotalEntropyBytes, 8); Assert.AreEqual(p.EntropyBytesSinceLastDigest, 0); p.Add(EventFromBytes(_Zero16Bytes)); Assert.AreEqual(p.TotalEntropyBytes, 24); Assert.AreEqual(p.EntropyBytesSinceLastDigest, 16); p.GetDigest(); Assert.AreEqual(p.TotalEntropyBytes, 24); Assert.AreEqual(p.EntropyBytesSinceLastDigest, 0); }