what-the-bank/sources/o/WCy.java

80 lines
2.9 KiB
Java
Raw Normal View History

2024-07-27 18:17:47 +07:00
package o;
import java.nio.ByteBuffer;
import java.security.GeneralSecurityException;
import java.security.spec.AlgorithmParameterSpec;
import java.util.Arrays;
import javax.crypto.Cipher;
import o.uAf;
/* loaded from: classes2.dex */
public final class WCy implements InterfaceC4280bVg {
private static uAf.RVV d = uAf.RVV.ALGORITHM_REQUIRES_BORINGCRYPTO;
private final Jkv c;
public WCy(byte[] bArr) throws GeneralSecurityException {
if (!d.d()) {
throw new GeneralSecurityException("Can not use AES-GCM in FIPS-mode, as BoringCrypto module is not available.");
}
this.c = new Jkv(bArr);
}
@Override // o.InterfaceC4280bVg
public final byte[] b(byte[] bArr, byte[] bArr2) throws GeneralSecurityException {
int length;
byte[] b = YTf.b(12);
Jkv jkv = this.c;
if (b.length != 12) {
throw new GeneralSecurityException("iv is wrong size");
}
if (bArr.length > 2147483619) {
throw new GeneralSecurityException("plaintext too long");
}
boolean z = jkv.b;
if (z) {
length = bArr.length + 28;
} else {
length = bArr.length + 16;
}
byte[] bArr3 = new byte[length];
if (z) {
System.arraycopy(b, 0, bArr3, 0, 12);
}
AlgorithmParameterSpec e = Jkv.e(b);
ThreadLocal<Cipher> threadLocal = Jkv.c;
threadLocal.get().init(1, jkv.e, e);
if (bArr2 != null && bArr2.length != 0) {
threadLocal.get().updateAAD(bArr2);
}
int doFinal = threadLocal.get().doFinal(bArr, 0, bArr.length, bArr3, jkv.b ? 12 : 0);
if (doFinal == bArr.length + 16) {
return bArr3;
}
throw new GeneralSecurityException(String.format("encryption failed; GCM tag must be %s bytes, but got only %s bytes", 16, Integer.valueOf(doFinal - bArr.length)));
}
@Override // o.InterfaceC4280bVg
public final byte[] d(byte[] bArr, byte[] bArr2) throws GeneralSecurityException {
byte[] copyOf = Arrays.copyOf(bArr, 12);
Jkv jkv = this.c;
if (copyOf.length != 12) {
throw new GeneralSecurityException("iv is wrong size");
}
boolean z = jkv.b;
if (bArr.length < (z ? 28 : 16)) {
throw new GeneralSecurityException("ciphertext too short");
}
if (z && !ByteBuffer.wrap(copyOf).equals(ByteBuffer.wrap(bArr, 0, 12))) {
throw new GeneralSecurityException("iv does not match prepended iv");
}
AlgorithmParameterSpec e = Jkv.e(copyOf);
ThreadLocal<Cipher> threadLocal = Jkv.c;
threadLocal.get().init(2, jkv.e, e);
if (bArr2 != null && bArr2.length != 0) {
threadLocal.get().updateAAD(bArr2);
}
boolean z2 = jkv.b;
return threadLocal.get().doFinal(bArr, z2 ? 12 : 0, z2 ? bArr.length - 12 : bArr.length);
}
}