package org.bouncycastle.crypto.engines;

/* JADX INFO: loaded from: E:\ios\vf_dex\classes4.dex */
public class ChaCha7539Engine extends org.bouncycastle.crypto.engines.Salsa20Engine {
    @Override // org.bouncycastle.crypto.engines.Salsa20Engine
    protected void a() {
        int[] iArr = this.c;
        int i = iArr[12] + 1;
        iArr[12] = i;
        if (i == 0) {
            throw new java.lang.IllegalStateException("attempt to increase counter past 2^32.");
        }
    }

    @Override // org.bouncycastle.crypto.engines.Salsa20Engine
    protected void b(long j) {
        int i = (int) (j >>> 32);
        int i2 = (int) j;
        if (i > 0) {
            throw new java.lang.IllegalStateException("attempt to increase counter past 2^32.");
        }
        int[] iArr = this.c;
        int i3 = iArr[12];
        int i4 = i2 + i3;
        iArr[12] = i4;
        if (i3 != 0 && i4 < i3) {
            throw new java.lang.IllegalStateException("attempt to increase counter past 2^32.");
        }
    }

    @Override // org.bouncycastle.crypto.engines.Salsa20Engine
    protected void c(byte[] bArr) {
        org.bouncycastle.crypto.engines.ChaChaEngine.p(this.a, this.c, this.d);
        org.bouncycastle.util.Pack.n(this.d, bArr, 0);
    }

    @Override // org.bouncycastle.crypto.engines.Salsa20Engine
    protected long d() {
        return ((long) this.c[12]) & 4294967295L;
    }

    @Override // org.bouncycastle.crypto.engines.Salsa20Engine
    protected int f() {
        return 12;
    }

    @Override // org.bouncycastle.crypto.engines.Salsa20Engine, org.bouncycastle.crypto.StreamCipher
    public java.lang.String getAlgorithmName() {
        return "ChaCha7539";
    }

    @Override // org.bouncycastle.crypto.engines.Salsa20Engine
    protected void j() {
        this.c[12] = 0;
    }

    @Override // org.bouncycastle.crypto.engines.Salsa20Engine
    protected void l() {
        int[] iArr = this.c;
        int i = iArr[12];
        if (i == 0) {
            throw new java.lang.IllegalStateException("attempt to reduce counter past zero.");
        }
        iArr[12] = i - 1;
    }

    @Override // org.bouncycastle.crypto.engines.Salsa20Engine
    protected void m(long j) {
        int i = (int) (j >>> 32);
        int i2 = (int) j;
        if (i != 0) {
            throw new java.lang.IllegalStateException("attempt to reduce counter past zero.");
        }
        int[] iArr = this.c;
        int i3 = iArr[12];
        if ((((long) i3) & 4294967295L) < (4294967295L & ((long) i2))) {
            throw new java.lang.IllegalStateException("attempt to reduce counter past zero.");
        }
        iArr[12] = i3 - i2;
    }

    @Override // org.bouncycastle.crypto.engines.Salsa20Engine
    protected void o(byte[] bArr, byte[] bArr2) {
        if (bArr != null) {
            if (bArr.length != 32) {
                throw new java.lang.IllegalArgumentException(getAlgorithmName() + " requires 256 bit key");
            }
            i(bArr.length, this.c, 0);
            org.bouncycastle.util.Pack.s(bArr, 0, this.c, 4, 8);
        }
        org.bouncycastle.util.Pack.s(bArr2, 0, this.c, 13, 3);
    }
}
