package org.bouncycastle.crypto.generators;

/* JADX INFO: loaded from: E:\ios\vf_dex\classes4.dex */
public class DSAKeyPairGenerator implements org.bouncycastle.crypto.AsymmetricCipherKeyPairGenerator {
    private static final java.math.BigInteger h = java.math.BigInteger.valueOf(1);
    private org.bouncycastle.crypto.params.DSAKeyGenerationParameters g;

    private static java.math.BigInteger c(java.math.BigInteger bigInteger, java.math.BigInteger bigInteger2, java.math.BigInteger bigInteger3) {
        return bigInteger2.modPow(bigInteger3, bigInteger);
    }

    private static java.math.BigInteger d(java.math.BigInteger bigInteger, java.security.SecureRandom secureRandom) {
        java.math.BigInteger bigIntegerG;
        int iBitLength = bigInteger.bitLength() >>> 2;
        do {
            java.math.BigInteger bigInteger2 = h;
            bigIntegerG = org.bouncycastle.util.BigIntegers.g(bigInteger2, bigInteger.subtract(bigInteger2), secureRandom);
        } while (org.bouncycastle.math.ec.WNafUtil.h(bigIntegerG) < iBitLength);
        return bigIntegerG;
    }

    @Override // org.bouncycastle.crypto.AsymmetricCipherKeyPairGenerator
    public org.bouncycastle.crypto.AsymmetricCipherKeyPair a() {
        org.bouncycastle.crypto.params.DSAParameters dSAParametersC = this.g.c();
        java.math.BigInteger bigIntegerD = d(dSAParametersC.c(), this.g.a());
        return new org.bouncycastle.crypto.AsymmetricCipherKeyPair(new org.bouncycastle.crypto.params.DSAPublicKeyParameters(c(dSAParametersC.b(), dSAParametersC.a(), bigIntegerD), dSAParametersC), new org.bouncycastle.crypto.params.DSAPrivateKeyParameters(bigIntegerD, dSAParametersC));
    }

    @Override // org.bouncycastle.crypto.AsymmetricCipherKeyPairGenerator
    public void b(org.bouncycastle.crypto.KeyGenerationParameters keyGenerationParameters) {
        org.bouncycastle.crypto.params.DSAKeyGenerationParameters dSAKeyGenerationParameters = (org.bouncycastle.crypto.params.DSAKeyGenerationParameters) keyGenerationParameters;
        this.g = dSAKeyGenerationParameters;
        org.bouncycastle.crypto.CryptoServicesRegistrar.a(new org.bouncycastle.crypto.constraints.DefaultServiceProperties("DSAKeyGen", org.bouncycastle.crypto.constraints.ConstraintUtils.a(dSAKeyGenerationParameters.c().b()), this.g.c(), org.bouncycastle.crypto.CryptoServicePurpose.KEYGEN));
    }
}
