package org.bouncycastle.crypto.signers;

/* JADX INFO: loaded from: E:\ios\vf_dex\classes4.dex */
public class ECGOST3410Signer implements org.bouncycastle.crypto.DSAExt {
    org.bouncycastle.crypto.params.ECKeyParameters g;
    java.security.SecureRandom h;

    @Override // org.bouncycastle.crypto.DSA
    public java.math.BigInteger[] a(byte[] bArr) {
        java.math.BigInteger bigInteger = new java.math.BigInteger(1, org.bouncycastle.util.Arrays.f0(bArr));
        org.bouncycastle.crypto.params.ECDomainParameters eCDomainParametersG = this.g.g();
        java.math.BigInteger bigIntegerE = eCDomainParametersG.e();
        java.math.BigInteger bigIntegerH = ((org.bouncycastle.crypto.params.ECPrivateKeyParameters) this.g).h();
        org.bouncycastle.math.ec.ECMultiplier eCMultiplierC = c();
        while (true) {
            java.math.BigInteger bigIntegerF = org.bouncycastle.util.BigIntegers.f(bigIntegerE.bitLength(), this.h);
            java.math.BigInteger bigInteger2 = org.bouncycastle.math.ec.ECConstants.a;
            if (!bigIntegerF.equals(bigInteger2)) {
                java.math.BigInteger bigIntegerMod = eCMultiplierC.a(eCDomainParametersG.b(), bigIntegerF).A().f().v().mod(bigIntegerE);
                if (bigIntegerMod.equals(bigInteger2)) {
                    continue;
                } else {
                    java.math.BigInteger bigIntegerMod2 = bigIntegerF.multiply(bigInteger).add(bigIntegerH.multiply(bigIntegerMod)).mod(bigIntegerE);
                    if (!bigIntegerMod2.equals(bigInteger2)) {
                        return new java.math.BigInteger[]{bigIntegerMod, bigIntegerMod2};
                    }
                }
            }
        }
    }

    @Override // org.bouncycastle.crypto.DSA
    public boolean b(byte[] bArr, java.math.BigInteger bigInteger, java.math.BigInteger bigInteger2) {
        java.math.BigInteger bigInteger3 = new java.math.BigInteger(1, org.bouncycastle.util.Arrays.f0(bArr));
        java.math.BigInteger bigIntegerE = this.g.g().e();
        java.math.BigInteger bigInteger4 = org.bouncycastle.math.ec.ECConstants.b;
        if (bigInteger.compareTo(bigInteger4) < 0 || bigInteger.compareTo(bigIntegerE) >= 0 || bigInteger2.compareTo(bigInteger4) < 0 || bigInteger2.compareTo(bigIntegerE) >= 0) {
            return false;
        }
        java.math.BigInteger bigIntegerO = org.bouncycastle.util.BigIntegers.o(bigIntegerE, bigInteger3);
        org.bouncycastle.math.ec.ECPoint eCPointA = org.bouncycastle.math.ec.ECAlgorithms.r(this.g.g().b(), bigInteger2.multiply(bigIntegerO).mod(bigIntegerE), ((org.bouncycastle.crypto.params.ECPublicKeyParameters) this.g).h(), bigIntegerE.subtract(bigInteger).multiply(bigIntegerO).mod(bigIntegerE)).A();
        if (eCPointA.u()) {
            return false;
        }
        return eCPointA.f().v().mod(bigIntegerE).equals(bigInteger);
    }

    protected org.bouncycastle.math.ec.ECMultiplier c() {
        return new org.bouncycastle.math.ec.FixedPointCombMultiplier();
    }

    @Override // org.bouncycastle.crypto.DSAExt
    public java.math.BigInteger getOrder() {
        return this.g.g().e();
    }

    @Override // org.bouncycastle.crypto.DSA
    public void init(boolean z, org.bouncycastle.crypto.CipherParameters cipherParameters) {
        org.bouncycastle.crypto.params.ECKeyParameters eCKeyParameters;
        if (z) {
            if (cipherParameters instanceof org.bouncycastle.crypto.params.ParametersWithRandom) {
                org.bouncycastle.crypto.params.ParametersWithRandom parametersWithRandom = (org.bouncycastle.crypto.params.ParametersWithRandom) cipherParameters;
                this.h = parametersWithRandom.b();
                cipherParameters = parametersWithRandom.a();
            } else {
                this.h = org.bouncycastle.crypto.CryptoServicesRegistrar.d();
            }
            eCKeyParameters = (org.bouncycastle.crypto.params.ECPrivateKeyParameters) cipherParameters;
        } else {
            eCKeyParameters = (org.bouncycastle.crypto.params.ECPublicKeyParameters) cipherParameters;
        }
        this.g = eCKeyParameters;
        org.bouncycastle.crypto.CryptoServicesRegistrar.a(org.bouncycastle.crypto.signers.Utils.c("ECGOST3410", this.g, z));
    }
}
