package p138.p176.p278.p279.p290;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.security.GeneralSecurityException;
import javax.crypto.AEADBadTagException;
import p138.p176.p177.p242.p246.p251.C4303;
import p138.p176.p278.p279.InterfaceC5176;

/* JADX INFO: renamed from: ދ.ހ.ހ.֏.ޞ.މ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
public abstract class AbstractC5513 implements InterfaceC5176 {

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final AbstractC5511 f15893;

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public final AbstractC5511 f15894;

    public AbstractC5513(byte[] bArr) {
        this.f15893 = mo8888(bArr, 1);
        this.f15894 = mo8888(bArr, 0);
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public static byte[] m8889(byte[] bArr, ByteBuffer byteBuffer) {
        int length = bArr.length % 16 == 0 ? bArr.length : (bArr.length + 16) - (bArr.length % 16);
        int iRemaining = byteBuffer.remaining();
        int i = iRemaining % 16;
        int i2 = (i == 0 ? iRemaining : (iRemaining + 16) - i) + length;
        ByteBuffer byteBufferOrder = ByteBuffer.allocate(i2 + 16).order(ByteOrder.LITTLE_ENDIAN);
        byteBufferOrder.put(bArr);
        byteBufferOrder.position(length);
        byteBufferOrder.put(byteBuffer);
        byteBufferOrder.position(i2);
        byteBufferOrder.putLong(bArr.length);
        byteBufferOrder.putLong(iRemaining);
        return byteBufferOrder.array();
    }

    /* JADX INFO: renamed from: ֏ */
    public abstract AbstractC5511 mo8888(byte[] bArr, int i);

    @Override // p138.p176.p278.p279.InterfaceC5176
    /* JADX INFO: renamed from: ֏ */
    public byte[] mo8647(byte[] bArr, byte[] bArr2) throws GeneralSecurityException {
        if (bArr.length > (Integer.MAX_VALUE - this.f15893.mo8877()) - 16) {
            throw new GeneralSecurityException("plaintext too long");
        }
        ByteBuffer byteBufferAllocate = ByteBuffer.allocate(this.f15893.mo8877() + bArr.length + 16);
        if (byteBufferAllocate.remaining() < this.f15893.mo8877() + bArr.length + 16) {
            throw new IllegalArgumentException("Given ByteBuffer output is too small");
        }
        int iPosition = byteBufferAllocate.position();
        this.f15893.m8885(byteBufferAllocate, bArr);
        byteBufferAllocate.position(iPosition);
        byte[] bArr3 = new byte[this.f15893.mo8877()];
        byteBufferAllocate.get(bArr3);
        byteBufferAllocate.limit(byteBufferAllocate.limit() - 16);
        if (bArr2 == null) {
            bArr2 = new byte[0];
        }
        byte[] bArr4 = new byte[32];
        this.f15894.m8884(bArr3, 0).get(bArr4);
        byte[] bArrM7143 = C4303.m7143(bArr4, m8889(bArr2, byteBufferAllocate));
        byteBufferAllocate.limit(byteBufferAllocate.limit() + 16);
        byteBufferAllocate.put(bArrM7143);
        return byteBufferAllocate.array();
    }

    @Override // p138.p176.p278.p279.InterfaceC5176
    /* JADX INFO: renamed from: ؠ */
    public byte[] mo8648(byte[] bArr, byte[] bArr2) throws GeneralSecurityException {
        ByteBuffer byteBufferWrap = ByteBuffer.wrap(bArr);
        if (byteBufferWrap.remaining() < this.f15893.mo8877() + 16) {
            throw new GeneralSecurityException("ciphertext too short");
        }
        int iPosition = byteBufferWrap.position();
        byte[] bArr3 = new byte[16];
        byteBufferWrap.position(byteBufferWrap.limit() - 16);
        byteBufferWrap.get(bArr3);
        byteBufferWrap.position(iPosition);
        byteBufferWrap.limit(byteBufferWrap.limit() - 16);
        byte[] bArr4 = new byte[this.f15893.mo8877()];
        byteBufferWrap.get(bArr4);
        if (bArr2 == null) {
            bArr2 = new byte[0];
        }
        try {
            byte[] bArr5 = new byte[32];
            this.f15894.m8884(bArr4, 0).get(bArr5);
            if (!C4303.m7172(C4303.m7143(bArr5, m8889(bArr2, byteBufferWrap)), bArr3)) {
                throw new GeneralSecurityException("invalid MAC");
            }
            byteBufferWrap.position(iPosition);
            return this.f15893.m8887(byteBufferWrap);
        } catch (GeneralSecurityException e) {
            throw new AEADBadTagException(e.toString());
        }
    }
}
