package org.bouncycastle.crypto.modes;

/* JADX INFO: loaded from: E:\ios\vf_dex\classes4.dex */
public class GCFBBlockCipher extends org.bouncycastle.crypto.StreamBlockCipher {
    private static final byte[] g = {105, 0, 114, 34, 100, -55, 4, 35, -115, 58, -37, -106, 70, -23, 42, -60, 24, -2, -84, -108, 0, -19, 7, 18, -64, -122, -36, -62, -17, 76, -87, 43};
    private final org.bouncycastle.crypto.modes.CFBBlockCipher b;
    private org.bouncycastle.crypto.params.ParametersWithIV c;
    private org.bouncycastle.crypto.params.KeyParameter d;
    private long e;
    private boolean f;

    public GCFBBlockCipher(org.bouncycastle.crypto.BlockCipher blockCipher) {
        super(blockCipher);
        this.e = 0L;
        this.b = new org.bouncycastle.crypto.modes.CFBBlockCipher(blockCipher, blockCipher.b() * 8);
    }

    @Override // org.bouncycastle.crypto.BlockCipher
    public int b() {
        return this.b.b();
    }

    @Override // org.bouncycastle.crypto.BlockCipher
    public int c(byte[] bArr, int i, byte[] bArr2, int i2) {
        processBytes(bArr, i, this.b.b(), bArr2, i2);
        return this.b.b();
    }

    @Override // org.bouncycastle.crypto.StreamBlockCipher
    protected byte f(byte b) {
        long j = this.e;
        if (j > 0 && (j & 1023) == 0) {
            org.bouncycastle.crypto.BlockCipher underlyingCipher = this.b.getUnderlyingCipher();
            underlyingCipher.init(false, this.d);
            byte[] bArr = new byte[32];
            int iB = underlyingCipher.b();
            for (int i = 0; i < 32; i += iB) {
                underlyingCipher.c(g, i, bArr, i);
            }
            org.bouncycastle.crypto.params.KeyParameter keyParameter = new org.bouncycastle.crypto.params.KeyParameter(bArr);
            this.d = keyParameter;
            underlyingCipher.init(true, keyParameter);
            byte[] bArrI = this.b.i();
            underlyingCipher.c(bArrI, 0, bArrI, 0);
            this.b.init(this.f, new org.bouncycastle.crypto.params.ParametersWithIV(this.d, bArrI));
        }
        this.e++;
        return this.b.f(b);
    }

    @Override // org.bouncycastle.crypto.BlockCipher
    public java.lang.String getAlgorithmName() {
        java.lang.String algorithmName = this.b.getAlgorithmName();
        return algorithmName.substring(0, algorithmName.indexOf(47)) + "/G" + algorithmName.substring(algorithmName.indexOf(47) + 1);
    }

    @Override // org.bouncycastle.crypto.BlockCipher
    public void init(boolean z, org.bouncycastle.crypto.CipherParameters cipherParameters) {
        byte[] bArr;
        org.bouncycastle.crypto.params.ParametersWithIV parametersWithIV;
        org.bouncycastle.crypto.params.ParametersWithIV parametersWithIV2;
        this.e = 0L;
        this.b.init(z, cipherParameters);
        this.f = z;
        if (cipherParameters instanceof org.bouncycastle.crypto.params.ParametersWithIV) {
            org.bouncycastle.crypto.params.ParametersWithIV parametersWithIV3 = (org.bouncycastle.crypto.params.ParametersWithIV) cipherParameters;
            org.bouncycastle.crypto.CipherParameters cipherParametersB = parametersWithIV3.b();
            byte[] bArrA = parametersWithIV3.a();
            cipherParameters = cipherParametersB;
            bArr = bArrA;
        } else {
            bArr = null;
        }
        if (cipherParameters instanceof org.bouncycastle.crypto.params.ParametersWithRandom) {
            cipherParameters = ((org.bouncycastle.crypto.params.ParametersWithRandom) cipherParameters).a();
        }
        if (cipherParameters instanceof org.bouncycastle.crypto.params.ParametersWithSBox) {
            cipherParameters = ((org.bouncycastle.crypto.params.ParametersWithSBox) cipherParameters).a();
        }
        org.bouncycastle.crypto.params.KeyParameter keyParameter = (org.bouncycastle.crypto.params.KeyParameter) cipherParameters;
        this.d = keyParameter;
        if (keyParameter == null && (parametersWithIV2 = this.c) != null) {
            this.d = (org.bouncycastle.crypto.params.KeyParameter) parametersWithIV2.b();
        }
        this.c = new org.bouncycastle.crypto.params.ParametersWithIV(this.d, (bArr != null || (parametersWithIV = this.c) == null) ? this.b.i() : parametersWithIV.a());
    }

    @Override // org.bouncycastle.crypto.BlockCipher
    public void reset() {
        this.e = 0L;
        org.bouncycastle.crypto.params.ParametersWithIV parametersWithIV = this.c;
        if (parametersWithIV == null) {
            this.b.reset();
        } else {
            this.d = (org.bouncycastle.crypto.params.KeyParameter) parametersWithIV.b();
            this.b.init(this.f, this.c);
        }
    }
}
