package o; import java.security.GeneralSecurityException; import javax.crypto.Cipher; import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.SecretKeySpec; import o.uAf; /* loaded from: classes2.dex */ public final class RxO implements InterfaceC13537fcG { private final int b; private final int d; private final SecretKeySpec e; private static uAf.RVV c = uAf.RVV.ALGORITHM_REQUIRES_BORINGCRYPTO; private static final ThreadLocal a = new ThreadLocal() { // from class: o.RxO.2 @Override // java.lang.ThreadLocal protected final /* synthetic */ Cipher initialValue() { return c(); } private static Cipher c() { try { return YYT.a.e("AES/CTR/NoPadding"); } catch (GeneralSecurityException e) { throw new IllegalStateException(e); } } }; public RxO(byte[] bArr, int i) throws GeneralSecurityException { if (!c.d()) { throw new GeneralSecurityException("Can not use AES-CTR in FIPS-mode, as BoringCrypto module is not available."); } ifG.e(bArr.length); this.e = new SecretKeySpec(bArr, "AES"); int blockSize = a.get().getBlockSize(); this.b = blockSize; if (i < 12 || i > blockSize) { throw new GeneralSecurityException("invalid IV size"); } this.d = i; } @Override // o.InterfaceC13537fcG public final byte[] b(byte[] bArr) throws GeneralSecurityException { int length = bArr.length; int i = this.d; if (length > Integer.MAX_VALUE - i) { StringBuilder sb = new StringBuilder("plaintext length can not exceed "); sb.append(Integer.MAX_VALUE - this.d); throw new GeneralSecurityException(sb.toString()); } byte[] bArr2 = new byte[bArr.length + i]; byte[] b = YTf.b(i); System.arraycopy(b, 0, bArr2, 0, this.d); e(bArr, 0, bArr.length, bArr2, this.d, b, true); return bArr2; } @Override // o.InterfaceC13537fcG public final byte[] e(byte[] bArr) throws GeneralSecurityException { int length = bArr.length; int i = this.d; if (length < i) { throw new GeneralSecurityException("ciphertext too short"); } byte[] bArr2 = new byte[i]; System.arraycopy(bArr, 0, bArr2, 0, i); int length2 = bArr.length; int i2 = this.d; byte[] bArr3 = new byte[length2 - i2]; e(bArr, i2, bArr.length - i2, bArr3, 0, bArr2, false); return bArr3; } private void e(byte[] bArr, int i, int i2, byte[] bArr2, int i3, byte[] bArr3, boolean z) throws GeneralSecurityException { Cipher cipher = a.get(); byte[] bArr4 = new byte[this.b]; System.arraycopy(bArr3, 0, bArr4, 0, this.d); IvParameterSpec ivParameterSpec = new IvParameterSpec(bArr4); if (z) { cipher.init(1, this.e, ivParameterSpec); } else { cipher.init(2, this.e, ivParameterSpec); } if (cipher.doFinal(bArr, i, i2, bArr2, i3) != i2) { throw new GeneralSecurityException("stored output's length does not match input's length"); } } }