package org.bouncycastle.crypto.params;

/* JADX INFO: loaded from: E:\ios\vf_dex\classes4.dex */
public class DHPublicKeyParameters extends org.bouncycastle.crypto.params.DHKeyParameters {
    private static final java.math.BigInteger d = java.math.BigInteger.valueOf(1);
    private static final java.math.BigInteger e = java.math.BigInteger.valueOf(2);
    private java.math.BigInteger c;

    public DHPublicKeyParameters(java.math.BigInteger bigInteger, org.bouncycastle.crypto.params.DHParameters dHParameters) {
        super(false, dHParameters);
        this.c = j(bigInteger, dHParameters);
    }

    private static int i(java.math.BigInteger bigInteger, java.math.BigInteger bigInteger2) {
        int iBitLength = bigInteger2.bitLength();
        int[] iArrQ = org.bouncycastle.math.raw.Nat.q(iBitLength, bigInteger);
        int[] iArrQ2 = org.bouncycastle.math.raw.Nat.q(iBitLength, bigInteger2);
        int length = iArrQ2.length;
        int i = 0;
        while (true) {
            int i2 = iArrQ[0];
            if (i2 == 0) {
                org.bouncycastle.math.raw.Nat.K(length, iArrQ, 0);
            } else {
                int iC = org.bouncycastle.util.Integers.c(i2);
                if (iC > 0) {
                    org.bouncycastle.math.raw.Nat.I(length, iArrQ, iC, 0);
                    int i3 = iArrQ2[0];
                    i ^= (iC << 1) & (i3 ^ (i3 >>> 1));
                }
                int iJ = org.bouncycastle.math.raw.Nat.j(length, iArrQ, iArrQ2);
                if (iJ == 0) {
                    break;
                }
                if (iJ < 0) {
                    i ^= iArrQ[0] & iArrQ2[0];
                    int[] iArr = iArrQ2;
                    iArrQ2 = iArrQ;
                    iArrQ = iArr;
                }
                while (true) {
                    int i4 = length - 1;
                    if (iArrQ[i4] != 0) {
                        break;
                    }
                    length = i4;
                }
                org.bouncycastle.math.raw.Nat.S(length, iArrQ, iArrQ2, iArrQ);
            }
        }
        if (org.bouncycastle.math.raw.Nat.z(length, iArrQ2)) {
            return 1 - (i & 2);
        }
        return 0;
    }

    private java.math.BigInteger j(java.math.BigInteger bigInteger, org.bouncycastle.crypto.params.DHParameters dHParameters) {
        if (bigInteger == null) {
            throw new java.lang.NullPointerException("y value cannot be null");
        }
        java.math.BigInteger bigIntegerF = dHParameters.f();
        java.math.BigInteger bigInteger2 = e;
        if (bigInteger.compareTo(bigInteger2) < 0 || bigInteger.compareTo(bigIntegerF.subtract(bigInteger2)) > 0) {
            throw new java.lang.IllegalArgumentException("invalid DH public key");
        }
        java.math.BigInteger bigIntegerG = dHParameters.g();
        if (bigIntegerG != null && (!(bigIntegerF.testBit(0) && bigIntegerF.bitLength() - 1 == bigIntegerG.bitLength() && bigIntegerF.shiftRight(1).equals(bigIntegerG)) ? d.equals(bigInteger.modPow(bigIntegerG, bigIntegerF)) : 1 == i(bigInteger, bigIntegerF))) {
            throw new java.lang.IllegalArgumentException("Y value does not appear to be in correct group");
        }
        return bigInteger;
    }

    @Override // org.bouncycastle.crypto.params.DHKeyParameters
    public boolean equals(java.lang.Object obj) {
        return (obj instanceof org.bouncycastle.crypto.params.DHPublicKeyParameters) && ((org.bouncycastle.crypto.params.DHPublicKeyParameters) obj).h().equals(this.c) && super.equals(obj);
    }

    public java.math.BigInteger h() {
        return this.c;
    }

    @Override // org.bouncycastle.crypto.params.DHKeyParameters
    public int hashCode() {
        return super.hashCode() ^ this.c.hashCode();
    }
}
