package o; import com.google.common.base.Ascii; import java.security.GeneralSecurityException; import java.security.InvalidKeyException; import java.util.Arrays; import java.util.Collection; import javax.crypto.AEADBadTagException; import javax.crypto.Cipher; import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.SecretKeySpec; import o.uAf; /* loaded from: classes2.dex */ public final class rWh implements GHh { private static uAf.RVV a = uAf.RVV.ALGORITHM_NOT_FIPS; private static final Collection c = Arrays.asList(64); private static final byte[] d = new byte[16]; private final byte[] b; private final C17618yNf e; public rWh(byte[] bArr) throws GeneralSecurityException { if (!a.d()) { throw new GeneralSecurityException("Can not use AES-SIV in FIPS-mode."); } if (!c.contains(Integer.valueOf(bArr.length))) { StringBuilder sb = new StringBuilder("invalid key size: "); sb.append(bArr.length); sb.append(" bytes; key must have 64 bytes"); throw new InvalidKeyException(sb.toString()); } byte[] copyOfRange = Arrays.copyOfRange(bArr, 0, bArr.length / 2); this.b = Arrays.copyOfRange(bArr, bArr.length / 2, bArr.length); this.e = new C17618yNf(copyOfRange); } private byte[] c(byte[]... bArr) throws GeneralSecurityException { byte[] c2; int length = bArr.length; byte[] c3 = this.e.c(d, 16); int i = 0; while (true) { int length2 = bArr.length; if (i <= 0) { byte[] bArr2 = bArr[0]; if (bArr2 == null) { bArr2 = new byte[0]; } byte[] c4 = UKk.c(c3); byte[] c5 = this.e.c(bArr2, 16); if (c4.length != c5.length) { throw new IllegalArgumentException("The lengths of x and y should match."); } c3 = vil.c(c4, 0, c5, 0, c4.length); i++; } else { int length3 = bArr.length; byte[] bArr3 = bArr[1]; if (bArr3.length >= 16) { if (bArr3.length < c3.length) { throw new IllegalArgumentException("xorEnd requires a.length >= b.length"); } int length4 = bArr3.length; int length5 = c3.length; c2 = Arrays.copyOf(bArr3, bArr3.length); for (int i2 = 0; i2 < c3.length; i2++) { int i3 = (length4 - length5) + i2; c2[i3] = (byte) (c2[i3] ^ c3[i2]); } } else { if (bArr3.length >= 16) { throw new IllegalArgumentException("x must be smaller than a block."); } byte[] copyOf = Arrays.copyOf(bArr3, 16); copyOf[bArr3.length] = Byte.MIN_VALUE; byte[] c6 = UKk.c(c3); if (copyOf.length != c6.length) { throw new IllegalArgumentException("The lengths of x and y should match."); } c2 = vil.c(copyOf, 0, c6, 0, copyOf.length); } return this.e.c(c2, 16); } } } @Override // o.GHh public final byte[] e(byte[] bArr, byte[] bArr2) throws GeneralSecurityException { if (bArr.length > 2147483631) { throw new GeneralSecurityException("plaintext too long"); } Cipher e = YYT.a.e("AES/CTR/NoPadding"); byte[] c2 = c(bArr2, bArr); byte[] bArr3 = (byte[]) c2.clone(); bArr3[8] = (byte) (bArr3[8] & Ascii.DEL); bArr3[12] = (byte) (bArr3[12] & Ascii.DEL); e.init(1, new SecretKeySpec(this.b, "AES"), new IvParameterSpec(bArr3)); return vil.a(c2, e.doFinal(bArr)); } @Override // o.GHh public final byte[] a(byte[] bArr, byte[] bArr2) throws GeneralSecurityException { if (bArr.length < 16) { throw new GeneralSecurityException("Ciphertext too short."); } Cipher e = YYT.a.e("AES/CTR/NoPadding"); byte[] copyOfRange = Arrays.copyOfRange(bArr, 0, 16); byte[] bArr3 = (byte[]) copyOfRange.clone(); bArr3[8] = (byte) (bArr3[8] & Ascii.DEL); bArr3[12] = (byte) (bArr3[12] & Ascii.DEL); e.init(2, new SecretKeySpec(this.b, "AES"), new IvParameterSpec(bArr3)); byte[] copyOfRange2 = Arrays.copyOfRange(bArr, 16, bArr.length); byte[] doFinal = e.doFinal(copyOfRange2); if (copyOfRange2.length == 0 && doFinal == null && "The Android Project".equals(System.getProperty("java.vendor"))) { doFinal = new byte[0]; } if (vil.d(copyOfRange, c(bArr2, doFinal))) { return doFinal; } throw new AEADBadTagException("Integrity check failed."); } }