package org.bouncycastle.crypto.fpe;

/* JADX INFO: loaded from: E:\ios\vf_dex\classes4.dex */
public abstract class FPEEngine {
    protected final org.bouncycastle.crypto.BlockCipher a;
    protected boolean b;
    protected org.bouncycastle.crypto.params.FPEParameters c;

    protected FPEEngine(org.bouncycastle.crypto.BlockCipher blockCipher) {
        this.a = blockCipher;
    }

    protected static byte[] f(short[] sArr) {
        byte[] bArr = new byte[sArr.length * 2];
        for (int i = 0; i != sArr.length; i++) {
            org.bouncycastle.util.Pack.O(sArr[i], bArr, i * 2);
        }
        return bArr;
    }

    protected static short[] g(byte[] bArr) {
        if ((bArr.length & 1) != 0) {
            throw new java.lang.IllegalArgumentException("data must be an even number of bytes for a wide radix");
        }
        int length = bArr.length / 2;
        short[] sArr = new short[length];
        for (int i = 0; i != length; i++) {
            sArr[i] = org.bouncycastle.util.Pack.g(bArr, i * 2);
        }
        return sArr;
    }

    protected abstract int a(byte[] bArr, int i, int i2, byte[] bArr2, int i3);

    protected abstract int b(byte[] bArr, int i, int i2, byte[] bArr2, int i3);

    public abstract java.lang.String c();

    public abstract void d(boolean z, org.bouncycastle.crypto.CipherParameters cipherParameters);

    public int e(byte[] bArr, int i, int i2, byte[] bArr2, int i3) {
        if (this.c == null) {
            throw new java.lang.IllegalStateException("FPE engine not initialized");
        }
        if (i2 < 0) {
            throw new java.lang.IllegalArgumentException("input length cannot be negative");
        }
        if (bArr == null || bArr2 == null) {
            throw new java.lang.NullPointerException("buffer value is null");
        }
        if (bArr.length < i + i2) {
            throw new org.bouncycastle.crypto.DataLengthException("input buffer too short");
        }
        if (bArr2.length >= i3 + i2) {
            return this.b ? b(bArr, i, i2, bArr2, i3) : a(bArr, i, i2, bArr2, i3);
        }
        throw new org.bouncycastle.crypto.OutputLengthException("output buffer too short");
    }
}
