package com.facetec.sdk; 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 fy extends FilterInputStream { private byte[] a; private long[] b; private long[] c; private short d; private final int e; private int g; private int h; private int j; @Override // java.io.FilterInputStream, java.io.InputStream public final boolean markSupported() { return false; } public fy(InputStream inputStream, int i, int i2, short s, int i3, int i4) throws IOException { super(new BufferedInputStream(inputStream, 4096)); this.g = Integer.MAX_VALUE; int min = Math.min(Math.max((int) s, 4), 8); this.e = min; this.a = new byte[min]; this.b = new long[4]; this.c = new long[4]; this.j = min; this.h = min; this.b = gf.c(i ^ i4, min ^ i4); this.c = gf.c(i2 ^ i4, i3 ^ i4); } @Override // java.io.FilterInputStream, java.io.InputStream public final int read() throws IOException { a(); int i = this.j; if (i >= this.h) { return -1; } byte[] bArr = this.a; this.j = i + 1; return bArr[i] & UnsignedBytes.MAX_VALUE; } @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++) { a(); int i5 = this.j; if (i5 >= this.h) { if (i4 == i) { return -1; } return i2 - (i3 - i4); } byte[] bArr2 = this.a; this.j = 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 { a(); return this.h - this.j; } private int a() throws IOException { int i; if (this.g == Integer.MAX_VALUE) { this.g = ((FilterInputStream) this).in.read(); } if (this.j == this.e) { byte[] bArr = this.a; int i2 = this.g; bArr[0] = (byte) i2; if (i2 < 0) { throw new IllegalStateException("unexpected block size"); } int i3 = 1; do { int read = ((FilterInputStream) this).in.read(this.a, i3, this.e - i3); if (read <= 0) { break; } i3 += read; } while (i3 < this.e); if (i3 < this.e) { throw new IllegalStateException("unexpected block size"); } e(); int read2 = ((FilterInputStream) this).in.read(); this.g = read2; this.j = 0; if (read2 < 0) { int i4 = this.e; i = i4 - (this.a[i4 - 1] & UnsignedBytes.MAX_VALUE); } else { i = this.e; } this.h = i; } return this.h; } private void e() { long[] jArr = this.b; long[] jArr2 = this.c; short s = this.d; long j = jArr[s % 4]; long j2 = jArr2[(s + 2) % 4]; int i = (s + 3) % 4; jArr2[i] = ((jArr[i] * 2147483085) + j2) / 2147483647L; jArr[i] = ((j * 2147483085) + j2) % 2147483647L; for (int i2 = 0; i2 < this.e; i2++) { this.a[i2] = (byte) (r1[i2] ^ ((this.b[this.d] >> (i2 << 3)) & 255)); } this.d = (short) ((this.d + 1) % 4); } }