package com.google.android.gms.internal.ads;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.security.GeneralSecurityException;
import java.security.InvalidKeyException;

/* JADX INFO: loaded from: classes2.dex */
public abstract class cz1 {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final int[] f10117a;

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

    public cz1(byte[] bArr, int i10, int i11) throws InvalidKeyException {
        if (i11 == 1) {
            if (bArr.length != 32) {
                throw new InvalidKeyException("The key length in bytes must be 32.");
            }
            this.f10117a = com.google.android.gms.internal.pal.e8.c(bArr);
            this.f10118b = i10;
            return;
        }
        if (i11 != 2) {
            if (bArr.length != 32) {
                throw new InvalidKeyException("The key length in bytes must be 32.");
            }
            this.f10117a = az1.c(bArr);
            this.f10118b = i10;
            return;
        }
        if (bArr.length != 32) {
            throw new InvalidKeyException("The key length in bytes must be 32.");
        }
        this.f10117a = fa.j.e(bArr);
        this.f10118b = i10;
    }

    public final ByteBuffer a(int i10, byte[] bArr) {
        int[] iArrB = b(i10, fa.j.e(bArr));
        int[] iArr = (int[]) iArrB.clone();
        fa.j.d(iArr);
        for (int i11 = 0; i11 < iArrB.length; i11++) {
            iArrB[i11] = iArrB[i11] + iArr[i11];
        }
        ByteBuffer byteBufferOrder = ByteBuffer.allocate(64).order(ByteOrder.LITTLE_ENDIAN);
        byteBufferOrder.asIntBuffer().put(iArrB, 0, 16);
        return byteBufferOrder;
    }

    public abstract int[] b(int i10, int[] iArr);

    public final byte[] c(byte[] bArr, byte[] bArr2) throws GeneralSecurityException {
        ByteBuffer byteBufferWrap = ByteBuffer.wrap(bArr2);
        ByteBuffer byteBufferAllocate = ByteBuffer.allocate(byteBufferWrap.remaining());
        e(bArr, byteBufferAllocate, byteBufferWrap);
        return byteBufferAllocate.array();
    }

    public abstract int d();

    public final void e(byte[] bArr, ByteBuffer byteBuffer, ByteBuffer byteBuffer2) throws GeneralSecurityException {
        if (bArr.length != d()) {
            throw new GeneralSecurityException("The nonce length (in bytes) must be " + d());
        }
        int iRemaining = byteBuffer2.remaining();
        int i10 = iRemaining / 64;
        int i11 = i10 + 1;
        for (int i12 = 0; i12 < i11; i12++) {
            ByteBuffer byteBufferA = a(this.f10118b + i12, bArr);
            if (i12 == i10) {
                com.google.android.gms.measurement.internal.c2.n(byteBuffer, byteBuffer2, byteBufferA, iRemaining % 64);
            } else {
                com.google.android.gms.measurement.internal.c2.n(byteBuffer, byteBuffer2, byteBufferA, 64);
            }
        }
    }

    public abstract int f();

    public abstract int[] g(int i10, int[] iArr);

    public abstract int h();

    public abstract int[] i(int i10, int[] iArr);

    public final ByteBuffer j(int i10, byte[] bArr) {
        int[] iArrI = i(i10, com.google.android.gms.internal.pal.e8.c(bArr));
        int[] iArr = (int[]) iArrI.clone();
        com.google.android.gms.internal.pal.e8.b(iArr);
        for (int i11 = 0; i11 < 16; i11++) {
            iArrI[i11] = iArrI[i11] + iArr[i11];
        }
        ByteBuffer byteBufferOrder = ByteBuffer.allocate(64).order(ByteOrder.LITTLE_ENDIAN);
        byteBufferOrder.asIntBuffer().put(iArrI, 0, 16);
        return byteBufferOrder;
    }

    public final ByteBuffer k(int i10, byte[] bArr) {
        int[] iArrG = g(i10, az1.c(bArr));
        int[] iArr = (int[]) iArrG.clone();
        az1.a(iArr);
        for (int i11 = 0; i11 < 16; i11++) {
            iArrG[i11] = iArrG[i11] + iArr[i11];
        }
        ByteBuffer byteBufferOrder = ByteBuffer.allocate(64).order(ByteOrder.LITTLE_ENDIAN);
        byteBufferOrder.asIntBuffer().put(iArrG, 0, 16);
        return byteBufferOrder;
    }
}
