Esempio n. 1
0
        private void DGCDRBGTest(byte[] Seed, byte[] Expected)
        {
            DGCDrbg rGen = new DGCDrbg(new SHA256());

            byte[] output = new byte[32];

            rGen.Update(Seed);

            for (int i = 0; i != 1024; i++)
                rGen.Generate(output);

            if (Compare.AreEqual(Expected, output) == false)
                throw new Exception("DGCDRBG: Values are not equal! Expected: " + HexConverter.ToString(output) + " Received: " + HexConverter.ToString(Expected));
        }
Esempio n. 2
0
        private void Dispose(bool Disposing)
        {
            if (!_isDisposed && Disposing)
            {
                try
                {
                    if (_rngGenerator != null)
                    {
                        _rngGenerator.Dispose();
                        _rngGenerator = null;
                    }
                    if (_seedGenerator != null)
                    {
                        _seedGenerator.Dispose();
                        _seedGenerator = null;
                    }
                    if (_byteBuffer != null)
                    {
                        Array.Clear(_byteBuffer, 0, _byteBuffer.Length);
                        _byteBuffer = null;
                    }
                }
                catch { }

                _isDisposed = true;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Reset the RNGCryptoServiceProvider instance.
        /// </summary>
        public void Reset()
        {
            if (_digestEngine != null)
            {
                _digestEngine.Dispose();
                _digestEngine = null;
            }
            if (_seedGenerator != null)
            {
                _seedGenerator.Dispose();
                _seedGenerator = null;
            }

            _digestEngine = GetDigest(_digestType);
            _rngGenerator = new DGCDrbg(_digestEngine);

            if (_stateSeed != null)
            {
                _rngGenerator.Initialize(_stateSeed);
            }
            else
            {
                _seedGenerator = GetSeedGenerator(_seedType);
                _rngGenerator.Initialize(_seedGenerator.GetSeed((_digestEngine.BlockSize * 2) + 8));   // 2 * block + counter (2*bs+8)
            }

            _rngGenerator.Generate(_byteBuffer);
            _bufferIndex = 0;
        }