Files
SuperVPN/output/Libraries/BouncyCastle.Crypto/Org/BouncyCastle/Crypto/Prng/BasicEntropySourceProvider.cs
2025-10-09 09:57:24 +09:00

47 lines
1.2 KiB
C#

using Org.BouncyCastle.Security;
namespace Org.BouncyCastle.Crypto.Prng;
public class BasicEntropySourceProvider : IEntropySourceProvider
{
private class BasicEntropySource : IEntropySource
{
private readonly SecureRandom mSecureRandom;
private readonly bool mPredictionResistant;
private readonly int mEntropySize;
bool IEntropySource.IsPredictionResistant => mPredictionResistant;
int IEntropySource.EntropySize => mEntropySize;
internal BasicEntropySource(SecureRandom secureRandom, bool predictionResistant, int entropySize)
{
mSecureRandom = secureRandom;
mPredictionResistant = predictionResistant;
mEntropySize = entropySize;
}
byte[] IEntropySource.GetEntropy()
{
return SecureRandom.GetNextBytes(mSecureRandom, (mEntropySize + 7) / 8);
}
}
private readonly SecureRandom mSecureRandom;
private readonly bool mPredictionResistant;
public BasicEntropySourceProvider(SecureRandom secureRandom, bool isPredictionResistant)
{
mSecureRandom = secureRandom;
mPredictionResistant = isPredictionResistant;
}
public IEntropySource Get(int bitsRequired)
{
return new BasicEntropySource(mSecureRandom, mPredictionResistant, bitsRequired);
}
}