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

49 lines
2.3 KiB
Java
Raw Permalink 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.AsymmetricCipherKeyPair;
import org.bouncycastle.crypto.AsymmetricCipherKeyPairGenerator;
import org.bouncycastle.crypto.KeyGenerationParameters;
import org.bouncycastle.crypto.params.AsymmetricKeyParameter;
import org.bouncycastle.crypto.params.ECDomainParameters;
import org.bouncycastle.crypto.params.ECKeyGenerationParameters;
import org.bouncycastle.crypto.params.ECPrivateKeyParameters;
import org.bouncycastle.crypto.params.ECPublicKeyParameters;
import org.bouncycastle.math.ec.ECConstants;
import org.bouncycastle.math.ec.ECMultiplier;
import org.bouncycastle.math.ec.FixedPointCombMultiplier;
import org.bouncycastle.math.ec.WNafUtil;
/* loaded from: classes6.dex */
public class ECKeyPairGenerator implements AsymmetricCipherKeyPairGenerator, ECConstants {
ECDomainParameters params;
SecureRandom random;
@Override // org.bouncycastle.crypto.AsymmetricCipherKeyPairGenerator
public void init(KeyGenerationParameters keyGenerationParameters) {
ECKeyGenerationParameters eCKeyGenerationParameters = (ECKeyGenerationParameters) keyGenerationParameters;
this.random = eCKeyGenerationParameters.getRandom();
this.params = eCKeyGenerationParameters.getDomainParameters();
if (this.random == null) {
this.random = new SecureRandom();
}
}
@Override // org.bouncycastle.crypto.AsymmetricCipherKeyPairGenerator
public AsymmetricCipherKeyPair generateKeyPair() {
BigInteger n = this.params.getN();
int bitLength = n.bitLength();
while (true) {
BigInteger bigInteger = new BigInteger(bitLength, this.random);
if (bigInteger.compareTo(TWO) >= 0 && bigInteger.compareTo(n) < 0 && WNafUtil.getNafWeight(bigInteger) >= (bitLength >>> 2)) {
return new AsymmetricCipherKeyPair((AsymmetricKeyParameter) new ECPublicKeyParameters(createBasePointMultiplier().multiply(this.params.getG(), bigInteger), this.params), (AsymmetricKeyParameter) new ECPrivateKeyParameters(bigInteger, this.params));
}
}
}
protected ECMultiplier createBasePointMultiplier() {
return new FixedPointCombMultiplier();
}
}