generatePrivateValue static method

BigInt? generatePrivateValue(
  1. Digest digest,
  2. BigInt N,
  3. BigInt g,
  4. SecureRandom random,
)

Implementation

static BigInt? generatePrivateValue(
    Digest digest, BigInt N, BigInt g, SecureRandom random) {
  var minBits = math.min(256, N.bitLength ~/ 2);
  var min = BigInt.one << (minBits - 1);
  var max = N - BigInt.one;

  BigInt result;
  do {
    result = random.nextBigInteger(minBits);
  } while (result > max || result < min);
  return result;
}