private static BigInteger generatePrivateKey(BigInteger q, SecureRandom random) { // B.1.2 Key Pair Generation by Testing Candidates int minWeight = q.bitLength() >>> 2; for (;;) { // TODO Prefer this method? (change test cases that used fixed random) // B.1.1 Key Pair Generation Using Extra Random Bits // BigInteger x = new BigInteger(q.bitLength() + 64, random).mod(q.subtract(ONE)).add(ONE); BigInteger x = BigIntegers.createRandomInRange(ONE, q.subtract(ONE), random); if (WNafUtil.getNafWeight(x) >= minWeight) { return x; } } }
private static BigInteger generatePrivateKey(BigInteger q, SecureRandom random) { // B.1.2 Key Pair Generation by Testing Candidates int minWeight = q.bitLength() >>> 2; for (;;) { // TODO Prefer this method? (change test cases that used fixed random) // B.1.1 Key Pair Generation Using Extra Random Bits // BigInteger x = new BigInteger(q.bitLength() + 64, random).mod(q.subtract(ONE)).add(ONE); BigInteger x = BigIntegers.createRandomInRange(ONE, q.subtract(ONE), random); if (WNafUtil.getNafWeight(x) >= minWeight) { return x; } } }
if (WNafUtil.getNafWeight(p) < minWeight)
if (WNafUtil.getNafWeight(p) < minWeight)
if (WNafUtil.getNafWeight(x) >= minWeight) if (WNafUtil.getNafWeight(x) >= minWeight)
private static BigInteger calculatePrivate(DHParameters dhParams) { int limit = dhParams.getL(); if (limit != 0) { int minWeight = limit >>> 2; for (;;) { BigInteger x = new BigInteger(limit, new BadRandom()).setBit(limit - 1); if (WNafUtil.getNafWeight(x) >= minWeight) { return x; } } } BigInteger min = TWO; int m = dhParams.getM(); if (m != 0) { min = ONE.shiftLeft(m - 1); } BigInteger q = dhParams.getQ(); if (q == null) { q = dhParams.getP(); } BigInteger max = q.subtract(TWO); int minWeight = max.bitLength() >>> 2; for (;;) { BigInteger x = BigIntegers.createRandomInRange(min, max, new BadRandom()); if (WNafUtil.getNafWeight(x) >= minWeight) { return x; } } }
if (WNafUtil.getNafWeight(x) >= minWeight) if (WNafUtil.getNafWeight(x) >= minWeight)
if (WNafUtil.getNafWeight(n) < minWeight)
if (WNafUtil.getNafWeight(d) < minWeight)
if (WNafUtil.getNafWeight(n) < minWeight)
/** * Given the domain parameters this routine generates an EC key * pair in accordance with X9.62 section 5.2.1 pages 26, 27. */ public AsymmetricCipherKeyPair generateKeyPair() { BigInteger n = params.getN(); int nBitLength = n.bitLength(); int minWeight = nBitLength >>> 2; BigInteger d; for (;;) { d = BigIntegers.createRandomBigInteger(nBitLength, random); if (d.compareTo(TWO) < 0 || (d.compareTo(n) >= 0)) { continue; } if (WNafUtil.getNafWeight(d) < minWeight) { continue; } break; } ECPoint Q = createBasePointMultiplier().multiply(params.getG(), d); return new AsymmetricCipherKeyPair( new ECPublicKeyParameters(Q, params), new ECPrivateKeyParameters(d, params)); }
if (WNafUtil.getNafWeight(x) < minWeight)
if (WNafUtil.getNafWeight(x) < minWeight)