package com.facetec.sdk; import com.google.common.base.Ascii; import com.google.common.primitives.UnsignedBytes; import java.io.BufferedInputStream; import java.io.FilterInputStream; import java.io.IOException; import java.io.InputStream; /* loaded from: classes.dex */ public final class gd extends FilterInputStream { private final int[] f; private final int[] g; private final int h; private final byte[][] i; private final byte[] j; private int k; private final byte[] l; private int m; private int n; private static final byte[] c = ge.b; private static final int[] d = ge.c; private static final int[] b = ge.e; private static final int[] e = ge.a; private static final int[] a = ge.d; @Override // java.io.FilterInputStream, java.io.InputStream public final boolean markSupported() { return false; } public gd(InputStream inputStream, int i, byte[] bArr, byte[][] bArr2) { super(new BufferedInputStream(inputStream, 4096)); this.g = new int[4]; this.j = new byte[16]; this.l = new byte[16]; this.m = Integer.MAX_VALUE; this.n = 16; this.k = 16; this.h = i; this.f = ge.e(bArr, i); this.i = c(bArr2); } @Override // java.io.FilterInputStream, java.io.InputStream public final int read() throws IOException { c(); int i = this.n; if (i >= this.k) { return -1; } byte[] bArr = this.l; this.n = i + 1; return bArr[i] & UnsignedBytes.MAX_VALUE; } @Override // java.io.FilterInputStream, java.io.InputStream public final int read(byte[] bArr) throws IOException { return read(bArr, 0, bArr.length); } @Override // java.io.FilterInputStream, java.io.InputStream public final int read(byte[] bArr, int i, int i2) throws IOException { int i3 = i + i2; for (int i4 = i; i4 < i3; i4++) { c(); int i5 = this.n; if (i5 >= this.k) { if (i4 == i) { return -1; } return i2 - (i3 - i4); } byte[] bArr2 = this.l; this.n = i5 + 1; bArr[i4] = bArr2[i5]; } return i2; } @Override // java.io.FilterInputStream, java.io.InputStream public final long skip(long j) throws IOException { long j2 = 0; while (j2 < j && read() != -1) { j2++; } return j2; } @Override // java.io.FilterInputStream, java.io.InputStream public final int available() throws IOException { c(); return this.k - this.n; } @Override // java.io.FilterInputStream, java.io.InputStream, java.io.Closeable, java.lang.AutoCloseable public final void close() throws IOException { super.close(); } @Override // java.io.FilterInputStream, java.io.InputStream public final void mark(int i) { synchronized (this) { } } @Override // java.io.FilterInputStream, java.io.InputStream public final void reset() throws IOException { synchronized (this) { } } private static byte[][] c(byte[][] bArr) { byte[][] bArr2 = new byte[bArr.length]; for (int i = 0; i < bArr.length; i++) { bArr2[i] = new byte[bArr[i].length]; int i2 = 0; while (true) { byte[] bArr3 = bArr[i]; if (i2 < bArr3.length) { bArr2[i][bArr3[i2]] = (byte) i2; i2++; } } } return bArr2; } private int c() throws IOException { if (this.m == Integer.MAX_VALUE) { this.m = ((FilterInputStream) this).in.read(); } if (this.n == 16) { byte[] bArr = this.j; int i = this.m; bArr[0] = (byte) i; if (i < 0) { throw new IllegalStateException("unexpected block size"); } int i2 = 1; do { int read = ((FilterInputStream) this).in.read(this.j, i2, 16 - i2); if (read <= 0) { break; } i2 += read; } while (i2 < 16); if (i2 < 16) { throw new IllegalStateException("unexpected block size"); } b(this.j, this.l); int read2 = ((FilterInputStream) this).in.read(); this.m = read2; this.n = 0; this.k = read2 < 0 ? 16 - (this.l[15] & UnsignedBytes.MAX_VALUE) : 16; } return this.k; } private void b(byte[] bArr, byte[] bArr2) { gd gdVar = this; int[] iArr = gdVar.g; char c2 = 0; byte b2 = bArr[0]; char c3 = 1; byte b3 = bArr[1]; char c4 = 2; byte b4 = bArr[2]; char c5 = 3; byte b5 = bArr[3]; int[] iArr2 = gdVar.f; iArr[0] = ((((b2 << Ascii.CAN) | ((b3 & UnsignedBytes.MAX_VALUE) << 16)) | ((b4 & UnsignedBytes.MAX_VALUE) << 8)) | (b5 & UnsignedBytes.MAX_VALUE)) ^ iArr2[0]; iArr[1] = ((((bArr[4] << Ascii.CAN) | ((bArr[5] & UnsignedBytes.MAX_VALUE) << 16)) | ((bArr[6] & UnsignedBytes.MAX_VALUE) << 8)) | (bArr[7] & UnsignedBytes.MAX_VALUE)) ^ iArr2[1]; iArr[2] = ((((bArr[8] << Ascii.CAN) | ((bArr[9] & UnsignedBytes.MAX_VALUE) << 16)) | ((bArr[10] & UnsignedBytes.MAX_VALUE) << 8)) | (bArr[11] & UnsignedBytes.MAX_VALUE)) ^ iArr2[2]; byte b6 = bArr[12]; iArr[3] = (((((bArr[13] & UnsignedBytes.MAX_VALUE) << 16) | (b6 << Ascii.CAN)) | ((bArr[14] & UnsignedBytes.MAX_VALUE) << 8)) | (bArr[15] & UnsignedBytes.MAX_VALUE)) ^ iArr2[3]; int i = 4; int i2 = 1; while (i2 < gdVar.h) { int[] iArr3 = d; int[] iArr4 = gdVar.g; byte[][] bArr3 = gdVar.i; byte[] bArr4 = bArr3[c2]; int i3 = iArr3[iArr4[bArr4[c2]] >>> 24]; int[] iArr5 = b; byte[] bArr5 = bArr3[c3]; int i4 = iArr5[(iArr4[bArr5[c2]] >>> 16) & 255]; int[] iArr6 = e; byte[] bArr6 = bArr3[c4]; int i5 = iArr6[(iArr4[bArr6[c2]] >>> 8) & 255]; int[] iArr7 = a; byte[] bArr7 = bArr3[c5]; int i6 = iArr7[iArr4[bArr7[c2]] & 255]; int[] iArr8 = gdVar.f; int i7 = iArr8[i]; int i8 = iArr3[iArr4[bArr4[c3]] >>> 24]; int i9 = iArr5[(iArr4[bArr5[c3]] >>> 16) & 255]; int i10 = iArr6[(iArr4[bArr6[c3]] >>> 8) & 255]; int i11 = iArr7[iArr4[bArr7[c3]] & 255]; int i12 = iArr8[i + 1]; int i13 = iArr3[iArr4[bArr4[c4]] >>> 24]; int i14 = iArr5[(iArr4[bArr5[c4]] >>> 16) & 255]; int i15 = iArr6[(iArr4[bArr6[c4]] >>> 8) & 255]; int i16 = iArr7[iArr4[bArr7[2]] & 255]; int i17 = iArr8[i + 2]; int i18 = iArr3[iArr4[bArr4[3]] >>> 24]; int i19 = iArr5[(iArr4[bArr5[3]] >>> 16) & 255]; int i20 = iArr4[bArr6[3]]; int i21 = i2; int i22 = iArr6[(i20 >>> 8) & 255]; int i23 = iArr7[iArr4[bArr7[3]] & 255]; int i24 = iArr8[i + 3]; iArr4[0] = (i6 ^ (i5 ^ (i3 ^ i4))) ^ i7; iArr4[1] = (((i8 ^ i9) ^ i10) ^ i11) ^ i12; iArr4[2] = (i16 ^ ((i14 ^ i13) ^ i15)) ^ i17; iArr4[3] = (((i18 ^ i19) ^ i22) ^ i23) ^ i24; i2 = i21 + 1; i += 4; gdVar = this; c2 = 0; c3 = 1; c4 = 2; c5 = 3; } int[] iArr9 = gdVar.f; int i25 = iArr9[i]; byte[] bArr8 = c; int[] iArr10 = gdVar.g; byte[][] bArr9 = gdVar.i; byte[] bArr10 = bArr9[0]; bArr2[0] = (byte) (bArr8[iArr10[bArr10[0]] >>> 24] ^ (i25 >>> 24)); byte[] bArr11 = bArr9[1]; bArr2[1] = (byte) (bArr8[(iArr10[bArr11[0]] >>> 16) & 255] ^ (i25 >>> 16)); byte[] bArr12 = bArr9[2]; bArr2[2] = (byte) (bArr8[(iArr10[bArr12[0]] >>> 8) & 255] ^ (i25 >>> 8)); byte[] bArr13 = bArr9[3]; bArr2[3] = (byte) (i25 ^ bArr8[iArr10[bArr13[0]] & 255]); int i26 = iArr9[i + 1]; bArr2[4] = (byte) (bArr8[iArr10[bArr10[1]] >>> 24] ^ (i26 >>> 24)); bArr2[5] = (byte) (bArr8[(iArr10[bArr11[1]] >>> 16) & 255] ^ (i26 >>> 16)); bArr2[6] = (byte) (bArr8[(iArr10[bArr12[1]] >>> 8) & 255] ^ (i26 >>> 8)); bArr2[7] = (byte) (i26 ^ bArr8[iArr10[bArr13[1]] & 255]); int i27 = iArr9[i + 2]; bArr2[8] = (byte) (bArr8[iArr10[bArr10[2]] >>> 24] ^ (i27 >>> 24)); bArr2[9] = (byte) (bArr8[(iArr10[bArr11[2]] >>> 16) & 255] ^ (i27 >>> 16)); bArr2[10] = (byte) (bArr8[(iArr10[bArr12[2]] >>> 8) & 255] ^ (i27 >>> 8)); bArr2[11] = (byte) (i27 ^ bArr8[iArr10[bArr13[2]] & 255]); int i28 = iArr9[i + 3]; bArr2[12] = (byte) (bArr8[iArr10[bArr10[3]] >>> 24] ^ (i28 >>> 24)); bArr2[13] = (byte) (bArr8[(iArr10[bArr11[3]] >>> 16) & 255] ^ (i28 >>> 16)); bArr2[14] = (byte) (bArr8[(iArr10[bArr12[3]] >>> 8) & 255] ^ (i28 >>> 8)); bArr2[15] = (byte) (i28 ^ bArr8[iArr10[bArr13[3]] & 255]); } }