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

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

/* JADX INFO: loaded from: classes3.dex */
abstract class zzhm {
    int[] zza;
    private final int zzb;

    public zzhm(byte[] bArr, int i6) throws InvalidKeyException {
        if (bArr.length != 32) {
            throw new InvalidKeyException("The key length in bytes must be 32.");
        }
        this.zza = zzhh.zza(bArr);
        this.zzb = i6;
    }

    public abstract int zza();

    public final ByteBuffer zza(byte[] bArr, int i6) {
        int[] iArrZza = zza(zzhh.zza(bArr), i6);
        int[] iArr = (int[]) iArrZza.clone();
        zzhh.zza(iArr);
        for (int i7 = 0; i7 < iArrZza.length; i7++) {
            iArrZza[i7] = iArrZza[i7] + iArr[i7];
        }
        ByteBuffer byteBufferOrder = ByteBuffer.allocate(64).order(ByteOrder.LITTLE_ENDIAN);
        byteBufferOrder.asIntBuffer().put(iArrZza, 0, 16);
        return byteBufferOrder;
    }

    public abstract int[] zza(int[] iArr, int i6);

    public void zza(ByteBuffer byteBuffer, byte[] bArr, byte[] bArr2) throws GeneralSecurityException {
        if (byteBuffer.remaining() >= bArr2.length) {
            zza(bArr, byteBuffer, ByteBuffer.wrap(bArr2));
            return;
        }
        throw new IllegalArgumentException("Given ByteBuffer output is too small");
    }

    private final void zza(byte[] bArr, ByteBuffer byteBuffer, ByteBuffer byteBuffer2) throws GeneralSecurityException {
        if (bArr.length == zza()) {
            int iRemaining = byteBuffer2.remaining();
            int i6 = iRemaining / 64;
            int i7 = i6 + 1;
            for (int i8 = 0; i8 < i7; i8++) {
                ByteBuffer byteBufferZza = zza(bArr, this.zzb + i8);
                if (i8 == i6) {
                    zzyc.zza(byteBuffer, byteBuffer2, byteBufferZza, iRemaining % 64);
                } else {
                    zzyc.zza(byteBuffer, byteBuffer2, byteBufferZza, 64);
                }
            }
            return;
        }
        throw new GeneralSecurityException(o.l("The nonce length (in bytes) must be ", zza()));
    }

    public byte[] zza(byte[] bArr, ByteBuffer byteBuffer) throws GeneralSecurityException {
        ByteBuffer byteBufferAllocate = ByteBuffer.allocate(byteBuffer.remaining());
        zza(bArr, byteBufferAllocate, byteBuffer);
        return byteBufferAllocate.array();
    }
}
