package Y3;

import java.nio.ByteBuffer;
import java.security.GeneralSecurityException;
import java.util.Arrays;

/* JADX INFO: loaded from: classes3.dex */
public final class m implements L3.a {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final p f8833a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final L3.j f8834b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final int f8835c;

    public m(p pVar, L3.j jVar, int i6) {
        this.f8833a = pVar;
        this.f8834b = jVar;
        this.f8835c = i6;
    }

    @Override // L3.a
    public final byte[] a(byte[] bArr, byte[] bArr2) throws GeneralSecurityException {
        a aVar = (a) this.f8833a;
        aVar.getClass();
        int length = bArr.length;
        int i6 = aVar.f8794b;
        int i7 = Integer.MAX_VALUE - i6;
        if (length > i7) {
            throw new GeneralSecurityException(Z0.o.l("plaintext length can not exceed ", i7));
        }
        byte[] bArr3 = new byte[bArr.length + i6];
        byte[] bArrA = s.a(i6);
        System.arraycopy(bArrA, 0, bArr3, 0, i6);
        aVar.a(bArr, 0, bArr.length, bArr3, aVar.f8794b, bArrA, true);
        if (bArr2 == null) {
            bArr2 = new byte[0];
        }
        return j.c(bArr3, this.f8834b.b(j.c(bArr2, bArr3, Arrays.copyOf(ByteBuffer.allocate(8).putLong(((long) bArr2.length) * 8).array(), 8))));
    }

    @Override // L3.a
    public final byte[] b(byte[] bArr, byte[] bArr2) throws GeneralSecurityException {
        int length = bArr.length;
        int i6 = this.f8835c;
        if (length < i6) {
            throw new GeneralSecurityException("ciphertext too short");
        }
        byte[] bArrCopyOfRange = Arrays.copyOfRange(bArr, 0, bArr.length - i6);
        byte[] bArrCopyOfRange2 = Arrays.copyOfRange(bArr, bArr.length - i6, bArr.length);
        if (bArr2 == null) {
            bArr2 = new byte[0];
        }
        this.f8834b.a(bArrCopyOfRange2, j.c(bArr2, bArrCopyOfRange, Arrays.copyOf(ByteBuffer.allocate(8).putLong(((long) bArr2.length) * 8).array(), 8)));
        a aVar = (a) this.f8833a;
        aVar.getClass();
        int length2 = bArrCopyOfRange.length;
        int i7 = aVar.f8794b;
        if (length2 < i7) {
            throw new GeneralSecurityException("ciphertext too short");
        }
        byte[] bArr3 = new byte[i7];
        System.arraycopy(bArrCopyOfRange, 0, bArr3, 0, i7);
        int length3 = bArrCopyOfRange.length;
        int i8 = aVar.f8794b;
        byte[] bArr4 = new byte[length3 - i8];
        aVar.a(bArrCopyOfRange, i8, bArrCopyOfRange.length - i8, bArr4, 0, bArr3, false);
        return bArr4;
    }
}
