Re-implement `SecureRandom`
MODIFY
WalletWasabi/Crypto/Randomness/InsecureRandom.cs
WalletWasabi/Crypto/Randomness/InsecureRandom.cs
namespace WalletWasabi.Crypto.Randomness;
+/// <seealso href="https://devblogs.microsoft.com/pfxteam/getting-random-numbers-in-a-thread-safe-way/"/>>
public class InsecureRandom : WasabiRandom
{
public InsecureRandom()

MODIFY
WalletWasabi/Crypto/Randomness/SecureRandom.cs
WalletWasabi/Crypto/Randomness/SecureRandom.cs
@@ -4,38 +4,22 @@ namespace WalletWasabi.Crypto.Randomness;
public class SecureRandom : WasabiRandom
{
- private bool _disposedValue;
-
public SecureRandom()
{
- Random = RandomNumberGenerator.Create();
}
- private RandomNumberGenerator Random { get; }
-
- public override void GetBytes(byte[] buffer) => Random.GetBytes(buffer);
-
- public override void GetBytes(Span<byte> buffer) => Random.GetBytes(buffer);
-
- public override int GetInt(int fromInclusive, int toExclusive) => RandomNumberGenerator.GetInt32(fromInclusive, toExclusive);
-
- protected virtual void Dispose(bool disposing)
+ public override void GetBytes(byte[] buffer)
{
- if (!_disposedValue)
- {
- if (disposing)
- {
- Random?.Dispose();
+ RandomNumberGenerator.Fill(buffer);
}
- _disposedValue = true;
- }
+ public override void GetBytes(Span<byte> buffer)
+ {
+ RandomNumberGenerator.Fill(buffer);
}
- public override void Dispose()
+ public override int GetInt(int fromInclusive, int toExclusive)
{
- // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
- Dispose(disposing: true);
- GC.SuppressFinalize(this);
+ return RandomNumberGenerator.GetInt32(fromInclusive, toExclusive);
}
}

Re-implement `SecureRandom`