package com.google.android.gms.internal.p002firebaseauthapi; import java.security.GeneralSecurityException; import javax.crypto.Cipher; import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.SecretKeySpec; /* loaded from: classes2.dex */ public final class zzpj implements zzqk { private static final ThreadLocal zza = new zzpi(); private final SecretKeySpec zzb; private final int zzc; private final int zzd; public zzpj(byte[] bArr, int i) throws GeneralSecurityException { if (!zzdv.zza(2)) { throw new GeneralSecurityException("Can not use AES-CTR in FIPS-mode, as BoringCrypto module is not available."); } zzqs.zzb(bArr.length); this.zzb = new SecretKeySpec(bArr, "AES"); int blockSize = ((Cipher) zza.get()).getBlockSize(); this.zzd = blockSize; if (i < 12 || i > blockSize) { throw new GeneralSecurityException("invalid IV size"); } this.zzc = i; } @Override // com.google.android.gms.internal.p002firebaseauthapi.zzqk public final byte[] zza(byte[] bArr) throws GeneralSecurityException { int length = bArr.length; int i = this.zzc; if (length >= i) { byte[] bArr2 = new byte[i]; System.arraycopy(bArr, 0, bArr2, 0, i); int i2 = this.zzc; int i3 = length - i2; byte[] bArr3 = new byte[i3]; Cipher cipher = (Cipher) zza.get(); byte[] bArr4 = new byte[this.zzd]; System.arraycopy(bArr2, 0, bArr4, 0, this.zzc); cipher.init(2, this.zzb, new IvParameterSpec(bArr4)); if (cipher.doFinal(bArr, i2, i3, bArr3, 0) == i3) { return bArr3; } throw new GeneralSecurityException("stored output's length does not match input's length"); } throw new GeneralSecurityException("ciphertext too short"); } }