예제 #1
0
        public TinHatRandom()
        {
            this.EntropyHashers = new List<SupportingClasses.EntropyHasher>();

            // Add the .NET implementation of SHA256 and RNGCryptoServiceProvider
            {
                var RNG = new EntropySources.SystemRNGCryptoServiceProvider();
                var HashWrapper = new SupportingClasses.HashAlgorithmWrapper(SHA256.Create());
                this.EntropyHashers.Add(new SupportingClasses.EntropyHasher(RNG, HashWrapper));
            }

            // Add the ThreadedSeedGeneratorRNG as entropy source, and chain SHA256 and RipeMD256 as hash algorithms
            {
                var RNG = new EntropySources.ThreadedSeedGeneratorRNG();
                var HashWrappers = new List<SupportingClasses.HashAlgorithmWrapper>();
                HashWrappers.Add(new SupportingClasses.HashAlgorithmWrapper(SHA256.Create()));
                HashWrappers.Add(new SupportingClasses.HashAlgorithmWrapper(new RipeMD256Digest()));
                this.EntropyHashers.Add(new SupportingClasses.EntropyHasher(RNG, HashWrappers));
            }

            // Add the ThreadSchedulerRNG as entropy source, and SHA256 as hash algorithm
            {
                var RNG = new EntropySources.ThreadSchedulerRNG();
                var HashWrapper = new SupportingClasses.HashAlgorithmWrapper(new Sha256Digest());
                this.EntropyHashers.Add(new SupportingClasses.EntropyHasher(RNG, HashWrapper));
            }

            // If available, add EntropyFileRNG as entropy source
            {
                EntropySources.EntropyFileRNG RNG = null;
                try
                {
                    RNG = new EntropySources.EntropyFileRNG();
                }
                catch
                { }     // EntropyFileRNG thows exceptions if it hasn't been seeded yet, if it encouters corruption, etc.
                if (RNG != null)
                {
                    var HashWrapper = new SupportingClasses.HashAlgorithmWrapper(SHA256.Create());
                    this.EntropyHashers.Add(new SupportingClasses.EntropyHasher(RNG, HashWrapper));
                }
            }

            CtorSanityCheck();
        }
예제 #2
0
 public EntropyHasher(RandomNumberGenerator RNG, HashAlgorithmWrapper HashWrapper)
 {
     this.RNG = RNG;
     this.HashWrappers = new List<HashAlgorithmWrapper>();
     this.HashWrappers.Add(HashWrapper);
 }