Ejemplo n.º 1
0
		static RandomImpl()
		{
			if (Core.Unix)
			{
				_Random = new SimpleRandom();
			}
			else if (Core.Is64Bit && File.Exists("rdrand64.dll"))
			{
				_Random = new RDRand64();
			}
			else if (!Core.Is64Bit && File.Exists("rdrand32.dll"))
			{
				_Random = new RDRand32();
			}
			else
			{
				_Random = new CSPRandom();
			}

			if (_Random is IHardwareRNG)
			{
				if (!((IHardwareRNG)_Random).IsSupported())
				{
					_Random = new CSPRandom();
				}
			}
		}
Ejemplo n.º 2
0
        static RandomImpl()
        {
            if (Core.Unix && Core.Is64Bit && File.Exists("libdrng.so"))
            {
                _Random = new RDRand64();
            }
            else if (Core.Unix && File.Exists("libdrng.so"))
            {
                _Random = new RDRand32();
            }
            else if (Core.Unix)
            {
                _Random = new SimpleRandom();
            }
            else if (Core.Is64Bit && File.Exists("drng64.dll"))
            {
                _Random = new RDRand64();
            }
            else if (!Core.Is64Bit && File.Exists("drng32.dll"))
            {
                _Random = new RDRand32();
            }
            else
            {
                _Random = new CSPRandom();
            }

            if (_Random is IHardwareRNG)
            {
                if (!((IHardwareRNG)_Random).IsSupported())
                {
                    _Random = new CSPRandom();
                }
            }
        }
Ejemplo n.º 3
0
 public void Random(string name)
 {
     if (name.Equals(Program.mien))
     {
         iRandomImpl = new MonRandom();
     }
     else if (name.Equals(Program.csharp))
     {
         iRandomImpl = new CSharpRandom();
     }
 }
Ejemplo n.º 4
0
        static Randoms()
        {
            _Random = new CryptoServiceRandoms();

            if (_Random is IHardwareRNG)
            {
                if (!((IHardwareRNG)_Random).IsSupported())
                {
                    _Random = new CryptoServiceRandoms();
                }
            }
        }
Ejemplo n.º 5
0
        public Randor(RNGType r, bool pooling)
        {
            _Pooling = pooling;

            _RNGType = r;
            _Random  = RandomImpl.Acquire(r);

            if (_Pooling)
            {
                _Working = new byte[BUFFER_SIZE];
                _Buffer  = new byte[BUFFER_SIZE];
                _Random.GetBytes(_Working);
                ThreadPool.QueueUserWorkItem(new WaitCallback(Fill));
            }
        }
Ejemplo n.º 6
0
 static RandomImpl()
 {
     if (Core.Unix)
     {
         _Random = new CSPRandom();
     }
     else if (Core.Is64Bit && File.Exists("rdrand64.dll"))
     {
         _Random = new RDRand64();
     }
     else if (!Core.Is64Bit && File.Exists("rdrand32.dll"))
     {
         _Random = new RDRand32();
     }
     else
     {
         _Random = new CSPRandom();
     }
     if (_Random is IHardwareRNG r && !r.IsSupported())
     {
         _Random = new CSPRandom();
     }
 }
Ejemplo n.º 7
0
        public static IRandomImpl Acquire(RNGType r)
        {
            bool autodetect = (r == RNGType.AutoDetect);

            if (autodetect)
            {
                bool _unix    = false;
                int  platform = (int)Environment.OSVersion.Platform;
                if (platform == 4 || platform == 128)                 // MS 4, MONO 128
                {
                    _unix = true;
                }

                if (_unix)
                {
                    r = RNGType.CSPRandom;
                }
                else if (Environment.Is64BitProcess)
                {
                    r = RNGType.RDRand64;
                }
                else
                {
                    r = RNGType.RDRand32;
                }
            }

            if (r == RNGType.RDRand32)
            {
                if (!File.Exists("rdrand32.dll"))
                {
                    if (autodetect)
                    {
                        r = RNGType.CSPRandom;
                    }
                    else
                    {
                        throw new NotSupportedException("The selected hardware random number generator is not supported.");
                    }
                }
            }
            else if (r == RNGType.RDRand64)
            {
                if (!File.Exists("rdrand64.dll"))
                {
                    if (autodetect)
                    {
                        r = RNGType.CSPRandom;
                    }
                    else
                    {
                        throw new NotSupportedException("The selected hardware random number generator is not supported.");
                    }
                }
            }

            if (_Instances.ContainsKey(r))
            {
                return(_Instances[r]);
            }

            IRandomImpl i = null;

            switch (r)
            {
            case RNGType.CSPRandom: _Instances[r] = i = new CSPRandom(); break;

            case RNGType.RDRand32: _Instances[r] = i = new RDRand32(); break;

            case RNGType.RDRand64: _Instances[r] = i = new RDRand64(); break;

            default: throw new NotImplementedException("Unknown RNGType");
            }

            if (i is IHardwareRNG && !((IHardwareRNG)i).IsSupported())
            {
                if (autodetect)
                {
                    _Instances.Remove(r);
                    _Instances[RNGType.CSPRandom] = i = new CSPRandom();
                }
                else
                {
                    throw new NotSupportedException("The selected hardware random number generator is not supported.");
                }
            }

            return(i);
        }