summary refs log tree commit diff
path: root/crypto/src/security
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2015-11-17 18:57:14 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2015-11-17 18:57:14 +0700
commitced92a086526c85e31842aaa60ede4c4b8e0fdb9 (patch)
tree15b6cba6381bb5ee611fd5873c46b3ee37163889 /crypto/src/security
parentPort some DES/DESEDE changes from Java (diff)
downloadBouncyCastle.NET-ed25519-ced92a086526c85e31842aaa60ede4c4b8e0fdb9.tar.xz
Improve usage/behaviour of SecureRandom.GenerateSeed
Diffstat (limited to 'crypto/src/security')
-rw-r--r--crypto/src/security/SecureRandom.cs21
1 files changed, 11 insertions, 10 deletions
diff --git a/crypto/src/security/SecureRandom.cs b/crypto/src/security/SecureRandom.cs
index 8683b4729..cb831acc2 100644
--- a/crypto/src/security/SecureRandom.cs
+++ b/crypto/src/security/SecureRandom.cs
@@ -68,11 +68,18 @@ namespace Org.BouncyCastle.Security
             if (autoSeed)
             {
                 prng.AddSeedMaterial(NextCounterValue());
-                prng.AddSeedMaterial(GetSeed(digest.GetDigestSize()));
+                prng.AddSeedMaterial(GetNextBytes(Master, digest.GetDigestSize()));
             }
             return prng;
         }
 
+        public static byte[] GetNextBytes(SecureRandom secureRandom, int length)
+        {
+            byte[] result = new byte[length];
+            secureRandom.NextBytes(result);
+            return result;
+        }
+
         /// <summary>
         /// Create and auto-seed an instance based on the given algorithm.
         /// </summary>
@@ -104,12 +111,10 @@ namespace Org.BouncyCastle.Security
             throw new ArgumentException("Unrecognised PRNG algorithm: " + algorithm, "algorithm");
         }
 
+        [Obsolete("Call GenerateSeed() on a SecureRandom instance instead")]
         public static byte[] GetSeed(int length)
         {
-#if NETCF_1_0 || PORTABLE
-            lock (master)
-#endif
-            return Master.GenerateSeed(length);
+            return GetNextBytes(Master, length);
         }
 
         protected readonly IRandomGenerator generator;
@@ -145,11 +150,7 @@ namespace Org.BouncyCastle.Security
 
         public virtual byte[] GenerateSeed(int length)
         {
-            SetSeed(DateTime.Now.Ticks);
-
-            byte[] rv = new byte[length];
-            NextBytes(rv);
-            return rv;
+            return GetNextBytes(Master, length);
         }
 
         public virtual void SetSeed(byte[] seed)