package k1;

import java.io.IOException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import l1.AbstractC0621d;
import l1.C0622e;

/* JADX INFO: renamed from: k1.s, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public class C0601s implements U {

    /* JADX INFO: renamed from: H, reason: collision with root package name */
    static C0622e f5025H = C0622e.a();

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private MessageDigest f5026b;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    private byte[] f5027g;

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    private boolean f5028r;

    /* JADX INFO: renamed from: x, reason: collision with root package name */
    private int f5029x;

    /* JADX INFO: renamed from: y, reason: collision with root package name */
    private int f5030y;

    public C0601s(byte[] bArr, boolean z2) throws V {
        this.f5028r = false;
        try {
            this.f5026b = MessageDigest.getInstance("MD5");
            this.f5027g = bArr;
            this.f5028r = z2;
            this.f5029x = 0;
            this.f5030y = 0;
            if (C0622e.f5384g >= 5) {
                f5025H.println("macSigningKey:");
                AbstractC0621d.a(f5025H, bArr, 0, bArr.length);
            }
        } catch (NoSuchAlgorithmException e2) {
            if (C0622e.f5384g > 0) {
                e2.printStackTrace(f5025H);
            }
            throw new V("MD5", e2);
        }
    }

    public byte[] a() throws IOException {
        byte[] bArrDigest = this.f5026b.digest();
        if (C0622e.f5384g >= 5) {
            f5025H.println("digest: ");
            AbstractC0621d.a(f5025H, bArrDigest, 0, bArrDigest.length);
            f5025H.flush();
        }
        this.f5029x = 0;
        return bArrDigest;
    }

    void b(byte[] bArr, int i2, int i3, AbstractC0600r abstractC0600r, AbstractC0600r abstractC0600r2) {
        int i4 = this.f5030y;
        abstractC0600r.f5015i0 = i4;
        if (abstractC0600r2 != null) {
            abstractC0600r2.f5015i0 = i4 + 1;
            abstractC0600r2.f5016j0 = false;
        }
        try {
            try {
                byte[] bArr2 = this.f5027g;
                c(bArr2, 0, bArr2.length);
                int i5 = i2 + 14;
                for (int i6 = 0; i6 < 8; i6++) {
                    bArr[i5 + i6] = 0;
                }
                AbstractC0600r.y(this.f5030y, bArr, i5);
                c(bArr, i2, i3);
                System.arraycopy(a(), 0, bArr, i5, 8);
                if (this.f5028r) {
                    this.f5028r = false;
                    System.arraycopy("BSRSPYL ".getBytes(), 0, bArr, i5, 8);
                }
            } catch (Exception e2) {
                if (C0622e.f5384g > 0) {
                    e2.printStackTrace(f5025H);
                }
            }
            this.f5030y += 2;
        } catch (Throwable th) {
            this.f5030y += 2;
            throw th;
        }
    }

    public void c(byte[] bArr, int i2, int i3) throws IOException {
        if (C0622e.f5384g >= 5) {
            f5025H.println("update: " + this.f5029x + " " + i2 + ":" + i3);
            AbstractC0621d.a(f5025H, bArr, i2, Math.min(i3, 256));
            f5025H.flush();
        }
        if (i3 == 0) {
            return;
        }
        this.f5026b.update(bArr, i2, i3);
        this.f5029x++;
    }

    boolean d(byte[] bArr, int i2, AbstractC0600r abstractC0600r) throws IOException {
        byte[] bArr2 = this.f5027g;
        c(bArr2, 0, bArr2.length);
        c(bArr, i2, 14);
        int i3 = i2 + 14;
        byte[] bArr3 = new byte[8];
        AbstractC0600r.y(abstractC0600r.f5015i0, bArr3, 0);
        c(bArr3, 0, 8);
        int i4 = i2 + 22;
        if (abstractC0600r.f5021r == 46) {
            C0571H c0571h = (C0571H) abstractC0600r;
            c(bArr, i4, (abstractC0600r.f5001H - c0571h.f4591w0) - 22);
            c(c0571h.f4588t0, c0571h.f4589u0, c0571h.f4591w0);
        } else {
            c(bArr, i4, abstractC0600r.f5001H - 22);
        }
        byte[] bArrA = a();
        for (int i5 = 0; i5 < 8; i5++) {
            if (bArrA[i5] != bArr[i3 + i5]) {
                if (C0622e.f5384g >= 2) {
                    f5025H.println("signature verification failure");
                    AbstractC0621d.a(f5025H, bArrA, 0, 8);
                    AbstractC0621d.a(f5025H, bArr, i3, 8);
                }
                abstractC0600r.f5016j0 = true;
                return true;
            }
        }
        abstractC0600r.f5016j0 = false;
        return false;
    }

    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("LM_COMPATIBILITY=");
        sb.append(U.f4717w);
        sb.append(" MacSigningKey=");
        byte[] bArr = this.f5027g;
        sb.append(AbstractC0621d.d(bArr, 0, bArr.length));
        return sb.toString();
    }
}
