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

39 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.AsymmetricCipherKeyPair;
import org.bouncycastle.crypto.AsymmetricCipherKeyPairGenerator;
import org.bouncycastle.crypto.KeyGenerationParameters;
import org.bouncycastle.crypto.params.AsymmetricKeyParameter;
import org.bouncycastle.crypto.params.GOST3410KeyGenerationParameters;
import org.bouncycastle.crypto.params.GOST3410Parameters;
import org.bouncycastle.crypto.params.GOST3410PrivateKeyParameters;
import org.bouncycastle.crypto.params.GOST3410PublicKeyParameters;
import org.bouncycastle.math.ec.WNafUtil;
/* loaded from: classes6.dex */
public class GOST3410KeyPairGenerator implements AsymmetricCipherKeyPairGenerator {
private GOST3410KeyGenerationParameters param;
@Override // org.bouncycastle.crypto.AsymmetricCipherKeyPairGenerator
public void init(KeyGenerationParameters keyGenerationParameters) {
this.param = (GOST3410KeyGenerationParameters) keyGenerationParameters;
}
@Override // org.bouncycastle.crypto.AsymmetricCipherKeyPairGenerator
public AsymmetricCipherKeyPair generateKeyPair() {
GOST3410Parameters parameters = this.param.getParameters();
SecureRandom random = this.param.getRandom();
BigInteger q = parameters.getQ();
BigInteger p = parameters.getP();
BigInteger a = parameters.getA();
while (true) {
BigInteger bigInteger = new BigInteger(256, random);
if (bigInteger.signum() > 0 && bigInteger.compareTo(q) < 0 && WNafUtil.getNafWeight(bigInteger) >= 64) {
return new AsymmetricCipherKeyPair((AsymmetricKeyParameter) new GOST3410PublicKeyParameters(a.modPow(bigInteger, p), parameters), (AsymmetricKeyParameter) new GOST3410PrivateKeyParameters(bigInteger, parameters));
}
}
}
}