예제 #1
0
        /// <summary>
        /// Initializes an instance of the PRNG using the seed provided and cipher and entropy source groups chosen
        /// </summary>
        /// <param name="seedStream">stream containing seed information</param>
        /// <param name="cipher">cipher to use</param>
        /// <param name="sourceGroup">local, remote or both</param>
        /// <returns>initialised PRNG</returns>
        public static IRNGVenturaProvider Create(Stream seedStream, Cipher cipher, ReseedEntropySourceGroup sourceGroup)
        {
            var extractors = new List <IEntropyExtractor>();

            switch (sourceGroup)
            {
            case ReseedEntropySourceGroup.Local:
                extractors.Add(new GarbageCollectorExtractor(new EventEmitter(0)));
                extractors.Add(new AppDomainExtractor(new EventEmitter(1)));
                extractors.Add(new ProcessEntropyExtractor(new EventEmitter(2)));
                extractors.Add(new SystemUtcExtractor(new EventEmitter(3)));
                break;

            case ReseedEntropySourceGroup.Remote:
                extractors.Add(new AtmosphericNoiseExtractor(new EventEmitter(0)));
                extractors.Add(new HotBitsExtractor(new EventEmitter(1)));
                extractors.Add(new WeatherEntropyExtractor(new EventEmitter(2)));
                break;

            case ReseedEntropySourceGroup.Full:
                extractors.Add(new GarbageCollectorExtractor(new EventEmitter(0)));
                extractors.Add(new AppDomainExtractor(new EventEmitter(1)));
                extractors.Add(new ProcessEntropyExtractor(new EventEmitter(2)));
                extractors.Add(new SystemUtcExtractor(new EventEmitter(3)));
                extractors.Add(new AtmosphericNoiseExtractor(new EventEmitter(4)));
                extractors.Add(new HotBitsExtractor(new EventEmitter(5)));
                extractors.Add(new WeatherEntropyExtractor(new EventEmitter(6)));
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(sourceGroup), sourceGroup, null);
            }

            return(new RNGVenturaProvider(new VenturaAccumulator(extractors), new VenturaGenerator(cipher), seedStream));
        }
예제 #2
0
        /// <summary>
        /// Initializes an instance of the PRNG and seeds it with a pseudorandomly
        /// picked remote entropy source. A MemoryStream is used to store
        /// the seed which is discarded on exit.
        /// </summary>
        /// <param name="cipher">cipher to use</param>
        /// <param name="sourceGroup">local or remote</param>
        /// <returns>initialised PRNG</returns>
        public static IRNGVenturaProvider CreateSeeded(Cipher cipher, ReseedEntropySourceGroup sourceGroup)
        {
            var extractors = new List <IEntropyExtractor>()
            {
                new WeatherEntropyExtractor(new EventEmitter(0)),
                new AtmosphericNoiseExtractor(new EventEmitter(1)),
                new HotBitsExtractor(new EventEmitter(2))
            };

            byte[] seed = new SeedProvider(extractors).GetBytes();

            return(Create(Convert(seed), cipher, sourceGroup));
        }
예제 #3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="seedStream"></param>
 /// <param name="cipher"></param>
 /// <param name="sourceGroup"></param>
 /// <returns></returns>
 public static RandomNumberGenerator CreateRng(Stream seedStream, Cipher cipher, ReseedEntropySourceGroup sourceGroup)
 {
     return((RandomNumberGenerator)Create(seedStream, cipher, sourceGroup));
 }