Implement randomness
MODIFY
WalletWasabi/Crypto/Randomness/IWasabiRandom.cs
WalletWasabi/Crypto/Randomness/IWasabiRandom.cs
@@ -7,5 +7,11 @@ namespace WalletWasabi.Crypto.Randomness
{
public interface IWasabiRandom : IRandom
{
+ public byte[] GetBytes(int length)
+ {
+ var buffer = new byte[length];
+ GetBytes(buffer);
+ return buffer;
+ }
}
}

ADD
WalletWasabi/Crypto/Randomness/MockRandom.cs
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace WalletWasabi.Crypto.Randomness
+{
+ public class MockRandom : IWasabiRandom
+ {
+ public void GetBytes(byte[] output)
+ {
+ throw new NotImplementedException();
+ }
+
+ public void GetBytes(Span<byte> output)
+ {
+ throw new NotImplementedException();
+ }
+ }
+}

ADD
WalletWasabi/Crypto/Randomness/PseudoRandom.cs
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace WalletWasabi.Crypto.Randomness
+{
+ public class PseudoRandom : IWasabiRandom
+ {
+ public PseudoRandom()
+ {
+ Random = new Random();
+ }
+
+ public Random Random { get; }
+
+ public void GetBytes(byte[] buffer) => Random.NextBytes(buffer);
+
+ public void GetBytes(Span<byte> buffer) => Random.NextBytes(buffer);
+ }
+}

ADD
WalletWasabi/Crypto/Randomness/SecureRandom.cs
+using System;
+using System.Collections.Generic;
+using System.Security.Cryptography;
+using System.Text;
+
+namespace WalletWasabi.Crypto.Randomness
+{
+ public class SecureRandom : IWasabiRandom, IDisposable
+ {
+ private bool _disposedValue;
+
+ public SecureRandom()
+ {
+ Random = RandomNumberGenerator.Create();
+ }
+
+ public RandomNumberGenerator Random { get; }
+
+ public void GetBytes(byte[] buffer) => Random.GetBytes(buffer);
+
+ public void GetBytes(Span<byte> buffer) => Random.GetBytes(buffer);
+
+ protected virtual void Dispose(bool disposing)
+ {
+ if (!_disposedValue)
+ {
+ if (disposing)
+ {
+ Random?.Dispose();
+ }
+
+ _disposedValue = true;
+ }
+ }
+
+ public void Dispose()
+ {
+ // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
+ Dispose(disposing: true);
+ GC.SuppressFinalize(this);
+ }
+ }
+}

Implement randomness