You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1006 B
44 lines
1006 B
using System;
|
|
|
|
using Org.BouncyCastle.Math;
|
|
using Org.BouncyCastle.Security;
|
|
|
|
namespace Org.BouncyCastle.Crypto.Signers
|
|
{
|
|
public class RandomDsaKCalculator
|
|
: IDsaKCalculator
|
|
{
|
|
private BigInteger q;
|
|
private SecureRandom random;
|
|
|
|
public virtual bool IsDeterministic
|
|
{
|
|
get { return false; }
|
|
}
|
|
|
|
public virtual void Init(BigInteger n, SecureRandom random)
|
|
{
|
|
this.q = n;
|
|
this.random = random;
|
|
}
|
|
|
|
public virtual void Init(BigInteger n, BigInteger d, byte[] message)
|
|
{
|
|
throw new InvalidOperationException("Operation not supported");
|
|
}
|
|
|
|
public virtual BigInteger NextK()
|
|
{
|
|
int qBitLength = q.BitLength;
|
|
|
|
BigInteger k;
|
|
do
|
|
{
|
|
k = new BigInteger(qBitLength, random);
|
|
}
|
|
while (k.SignValue < 1 || k.CompareTo(q) >= 0);
|
|
|
|
return k;
|
|
}
|
|
}
|
|
}
|
|
|