示例#1
0
 public static BigInteger CreateRandomInRange(BigInteger min, BigInteger max, SecureRandom random)
 {
     int num = min.CompareTo(max);
     if (num >= 0)
     {
         if (num > 0)
         {
             throw new ArgumentException("'min' may not be greater than 'max'");
         }
         return min;
     }
     if (min.BitLength > (max.BitLength / 2))
     {
         return CreateRandomInRange(BigInteger.Zero, max.Subtract(min), random).Add(min);
     }
     for (int i = 0; i < 0x3e8; i++)
     {
         BigInteger integer = new BigInteger(max.BitLength, random);
         if ((integer.CompareTo(min) >= 0) && (integer.CompareTo(max) <= 0))
         {
             return integer;
         }
     }
     return new BigInteger(max.Subtract(min).BitLength - 1, random).Add(min);
 }
示例#2
0
 public virtual void Init(BigInteger N, BigInteger g, IDigest digest, SecureRandom random)
 {
     this.N = N;
     this.g = g;
     this.digest = digest;
     this.random = random;
 }
示例#3
0
 public static BigInteger GeneratePrivateValue(IDigest digest, BigInteger N, BigInteger g, SecureRandom random)
 {
     int num = Math.Min(0x100, N.BitLength / 2);
     BigInteger min = BigInteger.One.ShiftLeft(num - 1);
     BigInteger max = N.Subtract(BigInteger.One);
     return BigIntegers.CreateRandomInRange(min, max, random);
 }