Пример #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));
        }
Пример #2
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;
        }