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

85 lines
3.1 KiB
Java
Raw Normal View History

2024-07-27 18:17:47 +07:00
package o;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.security.GeneralSecurityException;
import java.security.InvalidKeyException;
import javax.crypto.AEADBadTagException;
import o.uAf;
/* loaded from: classes2.dex */
abstract class BRX {
private static uAf.RVV e = uAf.RVV.ALGORITHM_NOT_FIPS;
private final AbstractC5396bsJ a;
private final AbstractC5396bsJ b;
abstract AbstractC5396bsJ d(byte[] bArr, int i) throws InvalidKeyException;
public BRX(byte[] bArr) throws GeneralSecurityException {
if (!e.d()) {
throw new GeneralSecurityException("Can not use ChaCha20Poly1305 in FIPS-mode.");
}
this.a = d(bArr, 1);
this.b = d(bArr, 0);
}
public void b(ByteBuffer byteBuffer, byte[] bArr, byte[] bArr2, byte[] bArr3) throws GeneralSecurityException {
if (byteBuffer.remaining() < bArr2.length + 16) {
throw new IllegalArgumentException("Given ByteBuffer output is too small");
}
int position = byteBuffer.position();
this.a.e(byteBuffer, bArr, bArr2);
byteBuffer.position(position);
byteBuffer.limit(byteBuffer.limit() - 16);
if (bArr3 == null) {
bArr3 = new byte[0];
}
byte[] bArr4 = new byte[32];
this.b.b(bArr, 0).get(bArr4);
byte[] c = C5926cDf.c(bArr4, e(bArr3, byteBuffer));
byteBuffer.limit(byteBuffer.limit() + 16);
byteBuffer.put(c);
}
public byte[] a(ByteBuffer byteBuffer, byte[] bArr, byte[] bArr2) throws GeneralSecurityException {
if (byteBuffer.remaining() < 16) {
throw new GeneralSecurityException("ciphertext too short");
}
int position = byteBuffer.position();
byte[] bArr3 = new byte[16];
byteBuffer.position(byteBuffer.limit() - 16);
byteBuffer.get(bArr3);
byteBuffer.position(position);
byteBuffer.limit(byteBuffer.limit() - 16);
if (bArr2 == null) {
bArr2 = new byte[0];
}
try {
byte[] bArr4 = new byte[32];
this.b.b(bArr, 0).get(bArr4);
if (vil.d(C5926cDf.c(bArr4, e(bArr2, byteBuffer)), bArr3)) {
byteBuffer.position(position);
return this.a.c(bArr, byteBuffer);
}
throw new GeneralSecurityException("invalid MAC");
} catch (GeneralSecurityException e2) {
throw new AEADBadTagException(e2.toString());
}
}
private static byte[] e(byte[] bArr, ByteBuffer byteBuffer) {
int length = bArr.length % 16 == 0 ? bArr.length : (bArr.length + 16) - (bArr.length % 16);
int remaining = byteBuffer.remaining();
int i = remaining % 16;
int i2 = (i == 0 ? remaining : (remaining + 16) - i) + length;
ByteBuffer order = ByteBuffer.allocate(i2 + 16).order(ByteOrder.LITTLE_ENDIAN);
order.put(bArr);
order.position(length);
order.put(byteBuffer);
order.position(i2);
order.putLong(bArr.length);
order.putLong(remaining);
return order.array();
}
}