package org.bouncycastle.crypto.signers;

/* JADX INFO: loaded from: E:\ios\vf_dex\classes4.dex */
public class GOST3410Signer implements org.bouncycastle.crypto.DSAExt {
    org.bouncycastle.crypto.params.GOST3410KeyParameters g;
    java.security.SecureRandom h;

    @Override // org.bouncycastle.crypto.DSA
    public java.math.BigInteger[] a(byte[] bArr) {
        java.math.BigInteger bigIntegerF;
        java.math.BigInteger bigInteger = new java.math.BigInteger(1, org.bouncycastle.util.Arrays.f0(bArr));
        org.bouncycastle.crypto.params.GOST3410Parameters gOST3410ParametersG = this.g.g();
        do {
            bigIntegerF = org.bouncycastle.util.BigIntegers.f(gOST3410ParametersG.c().bitLength(), this.h);
        } while (bigIntegerF.compareTo(gOST3410ParametersG.c()) >= 0);
        java.math.BigInteger bigIntegerMod = gOST3410ParametersG.a().modPow(bigIntegerF, gOST3410ParametersG.b()).mod(gOST3410ParametersG.c());
        return new java.math.BigInteger[]{bigIntegerMod, bigIntegerF.multiply(bigInteger).add(((org.bouncycastle.crypto.params.GOST3410PrivateKeyParameters) this.g).h().multiply(bigIntegerMod)).mod(gOST3410ParametersG.c())};
    }

    @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));
        org.bouncycastle.crypto.params.GOST3410Parameters gOST3410ParametersG = this.g.g();
        java.math.BigInteger bigIntegerValueOf = java.math.BigInteger.valueOf(0L);
        if (bigIntegerValueOf.compareTo(bigInteger) >= 0 || gOST3410ParametersG.c().compareTo(bigInteger) <= 0 || bigIntegerValueOf.compareTo(bigInteger2) >= 0 || gOST3410ParametersG.c().compareTo(bigInteger2) <= 0) {
            return false;
        }
        java.math.BigInteger bigIntegerModPow = bigInteger3.modPow(gOST3410ParametersG.c().subtract(new java.math.BigInteger("2")), gOST3410ParametersG.c());
        return gOST3410ParametersG.a().modPow(bigInteger2.multiply(bigIntegerModPow).mod(gOST3410ParametersG.c()), gOST3410ParametersG.b()).multiply(((org.bouncycastle.crypto.params.GOST3410PublicKeyParameters) this.g).h().modPow(gOST3410ParametersG.c().subtract(bigInteger).multiply(bigIntegerModPow).mod(gOST3410ParametersG.c()), gOST3410ParametersG.b())).mod(gOST3410ParametersG.b()).mod(gOST3410ParametersG.c()).equals(bigInteger);
    }

    @Override // org.bouncycastle.crypto.DSAExt
    public java.math.BigInteger getOrder() {
        return this.g.g().c();
    }

    @Override // org.bouncycastle.crypto.DSA
    public void init(boolean z, org.bouncycastle.crypto.CipherParameters cipherParameters) {
        org.bouncycastle.crypto.params.GOST3410KeyParameters gOST3410KeyParameters;
        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();
            }
            gOST3410KeyParameters = (org.bouncycastle.crypto.params.GOST3410PrivateKeyParameters) cipherParameters;
        } else {
            gOST3410KeyParameters = (org.bouncycastle.crypto.params.GOST3410PublicKeyParameters) cipherParameters;
        }
        this.g = gOST3410KeyParameters;
        org.bouncycastle.crypto.CryptoServicesRegistrar.a(org.bouncycastle.crypto.signers.Utils.d("GOST3410", this.g, z));
    }
}
