summary refs log tree commit diff
path: root/crypto/src/security
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2022-10-23 17:36:05 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2022-10-23 17:36:05 +0700
commit6523b613d4a657b02da0777083116a2f5df55e98 (patch)
treecc49fe502a5d73648cad86b3ca2dfce73a8b9d28 /crypto/src/security
parentChange BigInteger arbitrary random source (diff)
downloadBouncyCastle.NET-ed25519-6523b613d4a657b02da0777083116a2f5df55e98.tar.xz
Complete SecureRandom refactoring
Diffstat (limited to 'crypto/src/security')
-rw-r--r--crypto/src/security/JksStore.cs2
-rw-r--r--crypto/src/security/SecureRandom.cs9
2 files changed, 6 insertions, 5 deletions
diff --git a/crypto/src/security/JksStore.cs b/crypto/src/security/JksStore.cs
index c679270a3..69ade11af 100644
--- a/crypto/src/security/JksStore.cs
+++ b/crypto/src/security/JksStore.cs
@@ -154,7 +154,7 @@ namespace Org.BouncyCastle.Security
             byte[] pkcs8Key = PrivateKeyInfoFactory.CreatePrivateKeyInfo(key).GetEncoded();
             byte[] protectedKey = new byte[pkcs8Key.Length + 40];
 
-            SecureRandom rnd = new SecureRandom();
+            SecureRandom rnd = CryptoServicesRegistrar.GetSecureRandom();
             rnd.NextBytes(protectedKey, 0, 20);
 
             IDigest digest = DigestUtilities.GetDigest("SHA-1");
diff --git a/crypto/src/security/SecureRandom.cs b/crypto/src/security/SecureRandom.cs
index 53e5be069..521e7db0e 100644
--- a/crypto/src/security/SecureRandom.cs
+++ b/crypto/src/security/SecureRandom.cs
@@ -17,7 +17,8 @@ namespace Org.BouncyCastle.Security
             return Interlocked.Increment(ref counter);
         }
 
-        private static readonly SecureRandom Master = new SecureRandom(new CryptoApiRandomGenerator());
+        private static readonly SecureRandom MasterRandom = new SecureRandom(new CryptoApiRandomGenerator());
+        internal static readonly SecureRandom ArbitraryRandom = new SecureRandom(new VmpcRandomGenerator(), 16);
 
         private static DigestRandomGenerator CreatePrng(string digestName, bool autoSeed)
         {
@@ -102,13 +103,13 @@ namespace Org.BouncyCastle.Security
 
         public virtual byte[] GenerateSeed(int length)
         {
-            return GetNextBytes(Master, length);
+            return GetNextBytes(MasterRandom, length);
         }
 
 #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER
         public virtual void GenerateSeed(Span<byte> seed)
         {
-            Master.NextBytes(seed);
+            MasterRandom.NextBytes(seed);
         }
 #endif
 
@@ -255,7 +256,7 @@ namespace Org.BouncyCastle.Security
 #else
                 byte[] seed = new byte[seedLength];
 #endif
-            Master.NextBytes(seed);
+            MasterRandom.NextBytes(seed);
             generator.AddSeedMaterial(seed);
         }
     }