Esempio n. 1
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}");
                    }
                }
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Adds a single entropy event to the pool.
 /// </summary>
 public void Add(EntropyEvent e)
 {
     if (e == null)
     {
         throw new ArgumentNullException(nameof(e));
     }
     if (e.Entropy == null)
     {
         throw new ArgumentNullException(nameof(e.Entropy));
     }
     if (e.Source == null)
     {
         throw new ArgumentNullException(nameof(e.Source));
     }
     Add(e.Entropy, e.Source);
 }
Esempio n. 3
0
        /// <summary>
        /// Adds entropy from a particular source to the accumulator.
        /// </summary>
        public void Add(EntropyEvent entropy)
        {
            // Based on Fortunata spec 9.5.6

            // Entropy is added in a round robin fashion.
            // Larger packets are broken up into smaller chunks to be distributed more evenly between pools.
            var poolIndex = _PoolIndex;

            foreach (var e in entropy.ToChunks(_ChunkSize))
            {
                if (poolIndex >= _AllPools.Length)
                {
                    poolIndex = 0;
                }
                _AllPools[poolIndex].Add(e, entropy.Source);
                poolIndex = poolIndex + 1;
            }
            _PoolIndex = poolIndex;
        }