package org.bouncycastle.crypto.prng.drbg;

/* JADX INFO: loaded from: E:\ios\vf_dex\classes4.dex */
public class DualECSP800DRBG implements org.bouncycastle.crypto.prng.drbg.SP80090DRBG {
    private static final java.math.BigInteger l;
    private static final java.math.BigInteger m;
    private static final java.math.BigInteger n;
    private static final java.math.BigInteger o;
    private static final java.math.BigInteger p;
    private static final java.math.BigInteger q;
    private static final java.math.BigInteger r;
    private static final java.math.BigInteger s;
    private static final java.math.BigInteger t;
    private static final java.math.BigInteger u;
    private static final java.math.BigInteger v;
    private static final java.math.BigInteger w;
    private static final org.bouncycastle.crypto.prng.drbg.DualECPoints[] x;
    private org.bouncycastle.crypto.Digest a;
    private long b;
    private org.bouncycastle.crypto.prng.EntropySource c;
    private int d;
    private int e;
    private int f;
    private org.bouncycastle.math.ec.ECPoint g;
    private org.bouncycastle.math.ec.ECPoint h;
    private byte[] i;
    private int j;
    private org.bouncycastle.math.ec.ECMultiplier k;

    static {
        java.math.BigInteger bigInteger = new java.math.BigInteger("6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296", 16);
        l = bigInteger;
        java.math.BigInteger bigInteger2 = new java.math.BigInteger("4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5", 16);
        m = bigInteger2;
        java.math.BigInteger bigInteger3 = new java.math.BigInteger("c97445f45cdef9f0d3e05e1e585fc297235b82b5be8ff3efca67c59852018192", 16);
        n = bigInteger3;
        java.math.BigInteger bigInteger4 = new java.math.BigInteger("b28ef557ba31dfcbdd21ac46e2a91e3c304f44cb87058ada2cb815151e610046", 16);
        o = bigInteger4;
        java.math.BigInteger bigInteger5 = new java.math.BigInteger("aa87ca22be8b05378eb1c71ef320ad746e1d3b628ba79b9859f741e082542a385502f25dbf55296c3a545e3872760ab7", 16);
        p = bigInteger5;
        java.math.BigInteger bigInteger6 = new java.math.BigInteger("3617de4a96262c6f5d9e98bf9292dc29f8f41dbd289a147ce9da3113b5f0b8c00a60b1ce1d7e819d7a431d7c90ea0e5f", 16);
        q = bigInteger6;
        java.math.BigInteger bigInteger7 = new java.math.BigInteger("8e722de3125bddb05580164bfe20b8b432216a62926c57502ceede31c47816edd1e89769124179d0b695106428815065", 16);
        r = bigInteger7;
        java.math.BigInteger bigInteger8 = new java.math.BigInteger("023b1660dd701d0839fd45eec36f9ee7b32e13b315dc02610aa1b636e346df671f790f84c5e09b05674dbb7e45c803dd", 16);
        s = bigInteger8;
        java.math.BigInteger bigInteger9 = new java.math.BigInteger("c6858e06b70404e9cd9e3ecb662395b4429c648139053fb521f828af606b4d3dbaa14b5e77efe75928fe1dc127a2ffa8de3348b3c1856a429bf97e7e31c2e5bd66", 16);
        t = bigInteger9;
        java.math.BigInteger bigInteger10 = new java.math.BigInteger("11839296a789a3bc0045c8a5fb42c7d1bd998f54449579b446817afbd17273e662c97ee72995ef42640c550b9013fad0761353c7086a272c24088be94769fd16650", 16);
        u = bigInteger10;
        java.math.BigInteger bigInteger11 = new java.math.BigInteger("1b9fa3e518d683c6b65763694ac8efbaec6fab44f2276171a42726507dd08add4c3b3f4c1ebc5b1222ddba077f722943b24c3edfa0f85fe24d0c8c01591f0be6f63", 16);
        v = bigInteger11;
        java.math.BigInteger bigInteger12 = new java.math.BigInteger("1f3bdba585295d9a1110d1df1f9430ef8442c5018976ff3437ef91b81dc0b8132c8d5c39c32d0e004a3092b7d327c0e7a4d26d2c7b69b58f9066652911e457779de", 16);
        w = bigInteger12;
        x = new org.bouncycastle.crypto.prng.drbg.DualECPoints[]{new org.bouncycastle.crypto.prng.drbg.DualECPoints(128, fpC.h(bigInteger, bigInteger2), fpC.h(bigInteger3, bigInteger4), 1), new org.bouncycastle.crypto.prng.drbg.DualECPoints(192, fpC.h(bigInteger5, bigInteger6), fpC.h(bigInteger7, bigInteger8), 1), new org.bouncycastle.crypto.prng.drbg.DualECPoints(256, fpC.h(bigInteger9, bigInteger10), fpC.h(bigInteger11, bigInteger12), 1)};
        org.bouncycastle.math.ec.ECCurve.Fp fpC = org.bouncycastle.asn1.nist.NISTNamedCurves.c("P-256").c();
        org.bouncycastle.math.ec.ECCurve.Fp fpC2 = org.bouncycastle.asn1.nist.NISTNamedCurves.c("P-384").c();
        org.bouncycastle.math.ec.ECCurve.Fp fpC3 = org.bouncycastle.asn1.nist.NISTNamedCurves.c("P-521").c();
    }

    private byte[] c() {
        byte[] entropy = this.c.getEntropy();
        if (entropy.length >= (this.d + 7) / 8) {
            return entropy;
        }
        throw new java.lang.IllegalStateException("Insufficient entropy provided by entropy source");
    }

    private java.math.BigInteger d(org.bouncycastle.math.ec.ECPoint eCPoint, java.math.BigInteger bigInteger) {
        return this.k.a(eCPoint, bigInteger).A().f().v();
    }

    private byte[] e(byte[] bArr, int i) {
        int i2 = i % 8;
        if (i2 == 0) {
            return bArr;
        }
        int i3 = 8 - i2;
        int length = bArr.length - 1;
        int i4 = 0;
        while (length >= 0) {
            int i5 = bArr[length] & 255;
            bArr[length] = (byte) ((i4 >> (8 - i3)) | (i5 << i3));
            length--;
            i4 = i5;
        }
        return bArr;
    }

    private byte[] f(byte[] bArr, byte[] bArr2) {
        if (bArr2 == null) {
            return bArr;
        }
        int length = bArr.length;
        byte[] bArr3 = new byte[length];
        for (int i = 0; i != length; i++) {
            bArr3[i] = (byte) (bArr[i] ^ bArr2[i]);
        }
        return bArr3;
    }

    @Override // org.bouncycastle.crypto.prng.drbg.SP80090DRBG
    public int a(byte[] bArr, byte[] bArr2, boolean z) {
        int length = bArr.length * 8;
        int length2 = bArr.length / this.f;
        if (org.bouncycastle.crypto.prng.drbg.Utils.d(bArr2, 512)) {
            throw new java.lang.IllegalArgumentException("Additional input too large");
        }
        if (this.b + ((long) length2) > 2147483648L) {
            return -1;
        }
        if (z) {
            b(bArr2);
            bArr2 = null;
        }
        java.math.BigInteger bigInteger = bArr2 != null ? new java.math.BigInteger(1, f(this.i, org.bouncycastle.crypto.prng.drbg.Utils.c(this.a, bArr2, this.e))) : new java.math.BigInteger(1, this.i);
        int length3 = 0;
        org.bouncycastle.util.Arrays.G(bArr, (byte) 0);
        int length4 = 0;
        for (int i = 0; i < length2; i++) {
            bigInteger = d(this.g, bigInteger);
            byte[] byteArray = d(this.h, bigInteger).toByteArray();
            int length5 = byteArray.length;
            int i2 = this.f;
            if (length5 > i2) {
                java.lang.System.arraycopy(byteArray, byteArray.length - i2, bArr, length4, i2);
            } else {
                java.lang.System.arraycopy(byteArray, 0, bArr, (i2 - byteArray.length) + length4, byteArray.length);
            }
            length4 += this.f;
            this.b++;
        }
        if (length4 < bArr.length) {
            bigInteger = d(this.g, bigInteger);
            byte[] byteArray2 = d(this.h, bigInteger).toByteArray();
            int length6 = bArr.length - length4;
            int length7 = byteArray2.length;
            int i3 = this.f;
            if (length7 > i3) {
                length3 = byteArray2.length - i3;
            } else {
                length4 += i3 - byteArray2.length;
            }
            java.lang.System.arraycopy(byteArray2, length3, bArr, length4, length6);
            this.b++;
        }
        this.i = org.bouncycastle.util.BigIntegers.b(this.j, d(this.g, bigInteger));
        return length;
    }

    @Override // org.bouncycastle.crypto.prng.drbg.SP80090DRBG
    public void b(byte[] bArr) {
        if (org.bouncycastle.crypto.prng.drbg.Utils.d(bArr, 512)) {
            throw new java.lang.IllegalArgumentException("Additional input string too large");
        }
        this.i = org.bouncycastle.crypto.prng.drbg.Utils.c(this.a, org.bouncycastle.util.Arrays.u(e(this.i, this.e), c(), bArr), this.e);
        this.b = 0L;
    }
}
