diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2014-09-28 22:10:24 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2014-09-28 22:10:24 +0700 |
commit | b494cecf549016c5db4493d50f3a738963a2eeb6 (patch) | |
tree | d2c21b5f37644943613fde0e6a82227e5cfb79ea /crypto/test | |
parent | Formatting (diff) | |
download | BouncyCastle.NET-ed25519-b494cecf549016c5db4493d50f3a738963a2eeb6.tar.xz |
Use platform RNG as master, where available release-1.8.0-beta.4
Obsolete seeded constructor in favour of GetInstance variant
Diffstat (limited to 'crypto/test')
-rw-r--r-- | crypto/test/src/security/test/SecureRandomTest.cs | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/crypto/test/src/security/test/SecureRandomTest.cs b/crypto/test/src/security/test/SecureRandomTest.cs index eedcd0ebc..4f05a286a 100644 --- a/crypto/test/src/security/test/SecureRandomTest.cs +++ b/crypto/test/src/security/test/SecureRandomTest.cs @@ -1,8 +1,10 @@ using System; +using System.Text; using NUnit.Framework; using Org.BouncyCastle.Crypto.Prng; +using Org.BouncyCastle.Utilities; namespace Org.BouncyCastle.Security.Tests { @@ -32,16 +34,28 @@ namespace Org.BouncyCastle.Security.Tests public void TestSha1Prng() { SecureRandom random = SecureRandom.GetInstance("SHA1PRNG"); - random.SetSeed(SecureRandom.GetSeed(20)); CheckSecureRandom(random); } [Test] + public void TestSha1PrngBackward() + { + byte[] seed = Encoding.ASCII.GetBytes("backward compatible"); + + SecureRandom sx = new SecureRandom(seed); + SecureRandom sy = SecureRandom.GetInstance("SHA1PRNG", false); sy.SetSeed(seed); + + byte[] bx = new byte[128]; sx.NextBytes(bx); + byte[] by = new byte[128]; sy.NextBytes(by); + + Assert.IsTrue(Arrays.AreEqual(bx, by)); + } + + [Test] public void TestSha256Prng() { SecureRandom random = SecureRandom.GetInstance("SHA256PRNG"); - random.SetSeed(SecureRandom.GetSeed(32)); CheckSecureRandom(random); } @@ -49,8 +63,8 @@ namespace Org.BouncyCastle.Security.Tests [Test] public void TestThreadedSeed() { - SecureRandom random = new SecureRandom( - new ThreadedSeedGenerator().GenerateSeed(20, false)); + SecureRandom random = SecureRandom.GetInstance("SHA1PRNG", false); + random.SetSeed(new ThreadedSeedGenerator().GenerateSeed(20, false)); CheckSecureRandom(random); } |