what-the-bank/sources/org/bouncycastle/crypto/generators/DHParametersHelper.java

40 lines
1.5 KiB
Java
Raw Normal View History

2024-07-27 18:17:47 +07:00
package org.bouncycastle.crypto.generators;
import java.math.BigInteger;
import java.security.SecureRandom;
import org.bouncycastle.math.ec.WNafUtil;
import org.bouncycastle.util.BigIntegers;
/* loaded from: classes6.dex */
class DHParametersHelper {
private static final BigInteger ONE = BigInteger.valueOf(1);
private static final BigInteger TWO = BigInteger.valueOf(2);
/* JADX INFO: Access modifiers changed from: package-private */
public static BigInteger selectGenerator(BigInteger bigInteger, BigInteger bigInteger2, SecureRandom secureRandom) {
BigInteger modPow;
BigInteger subtract = bigInteger.subtract(TWO);
do {
BigInteger bigInteger3 = TWO;
modPow = BigIntegers.createRandomInRange(bigInteger3, subtract, secureRandom).modPow(bigInteger3, bigInteger);
} while (modPow.equals(ONE));
return modPow;
}
/* JADX INFO: Access modifiers changed from: package-private */
public static BigInteger[] generateSafePrimes(int i, int i2, SecureRandom secureRandom) {
while (true) {
BigInteger bigInteger = new BigInteger(i - 1, 2, secureRandom);
BigInteger add = bigInteger.shiftLeft(1).add(ONE);
if (add.isProbablePrime(i2) && (i2 <= 2 || bigInteger.isProbablePrime(i2 - 2))) {
if (WNafUtil.getNafWeight(add) >= (i >>> 2)) {
return new BigInteger[]{add, bigInteger};
}
}
}
}
DHParametersHelper() {
}
}