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

49 lines
1.9 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.crypto.params.DHParameters;
import org.bouncycastle.math.ec.WNafUtil;
import org.bouncycastle.util.BigIntegers;
/* loaded from: classes6.dex */
class DHKeyGeneratorHelper {
static final DHKeyGeneratorHelper INSTANCE = new DHKeyGeneratorHelper();
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 BigInteger calculatePublic(DHParameters dHParameters, BigInteger bigInteger) {
return dHParameters.getG().modPow(bigInteger, dHParameters.getP());
}
/* JADX INFO: Access modifiers changed from: package-private */
public BigInteger calculatePrivate(DHParameters dHParameters, SecureRandom secureRandom) {
BigInteger createRandomInRange;
BigInteger bit;
int l = dHParameters.getL();
if (l == 0) {
BigInteger bigInteger = TWO;
int m = dHParameters.getM();
BigInteger shiftLeft = m != 0 ? ONE.shiftLeft(m - 1) : bigInteger;
BigInteger q = dHParameters.getQ();
if (q == null) {
q = dHParameters.getP();
}
BigInteger subtract = q.subtract(bigInteger);
int bitLength = subtract.bitLength();
do {
createRandomInRange = BigIntegers.createRandomInRange(shiftLeft, subtract, secureRandom);
} while (WNafUtil.getNafWeight(createRandomInRange) < (bitLength >>> 2));
return createRandomInRange;
}
do {
bit = new BigInteger(l, secureRandom).setBit(l - 1);
} while (WNafUtil.getNafWeight(bit) < (l >>> 2));
return bit;
}
private DHKeyGeneratorHelper() {
}
}