what-the-bank/sources/org/bouncycastle/crypto/macs/MacCFBBlockCipher.java

95 lines
3.2 KiB
Java
Raw Normal View History

2024-07-27 18:17:47 +07:00
package org.bouncycastle.crypto.macs;
import org.bouncycastle.crypto.BlockCipher;
import org.bouncycastle.crypto.CipherParameters;
import org.bouncycastle.crypto.DataLengthException;
import org.bouncycastle.crypto.params.ParametersWithIV;
/* loaded from: classes6.dex */
class MacCFBBlockCipher {
private byte[] IV;
private int blockSize;
private byte[] cfbOutV;
private byte[] cfbV;
private BlockCipher cipher;
public void reset() {
byte[] bArr = this.IV;
System.arraycopy(bArr, 0, this.cfbV, 0, bArr.length);
this.cipher.reset();
}
public int processBlock(byte[] bArr, int i, byte[] bArr2, int i2) throws DataLengthException, IllegalStateException {
int i3 = this.blockSize;
if (i + i3 > bArr.length) {
throw new DataLengthException("input buffer too short");
}
if (i3 + i2 > bArr2.length) {
throw new DataLengthException("output buffer too short");
}
this.cipher.processBlock(this.cfbV, 0, this.cfbOutV, 0);
int i4 = 0;
while (true) {
int i5 = this.blockSize;
if (i4 >= i5) {
byte[] bArr3 = this.cfbV;
System.arraycopy(bArr3, i5, bArr3, 0, bArr3.length - i5);
byte[] bArr4 = this.cfbV;
int length = bArr4.length;
int i6 = this.blockSize;
System.arraycopy(bArr2, i2, bArr4, length - i6, i6);
return this.blockSize;
}
bArr2[i2 + i4] = (byte) (this.cfbOutV[i4] ^ bArr[i + i4]);
i4++;
}
}
public void init(CipherParameters cipherParameters) throws IllegalArgumentException {
BlockCipher blockCipher;
if (cipherParameters instanceof ParametersWithIV) {
ParametersWithIV parametersWithIV = (ParametersWithIV) cipherParameters;
byte[] iv = parametersWithIV.getIV();
int length = iv.length;
byte[] bArr = this.IV;
if (length < bArr.length) {
System.arraycopy(iv, 0, bArr, bArr.length - iv.length, iv.length);
} else {
System.arraycopy(iv, 0, bArr, 0, bArr.length);
}
reset();
blockCipher = this.cipher;
cipherParameters = parametersWithIV.getParameters();
} else {
reset();
blockCipher = this.cipher;
}
blockCipher.init(true, cipherParameters);
}
/* JADX INFO: Access modifiers changed from: package-private */
public void getMacBlock(byte[] bArr) {
this.cipher.processBlock(this.cfbV, 0, bArr, 0);
}
public int getBlockSize() {
return this.blockSize;
}
public String getAlgorithmName() {
StringBuilder sb = new StringBuilder();
sb.append(this.cipher.getAlgorithmName());
sb.append("/CFB");
sb.append(this.blockSize << 3);
return sb.toString();
}
public MacCFBBlockCipher(BlockCipher blockCipher, int i) {
this.cipher = blockCipher;
this.blockSize = i / 8;
this.IV = new byte[blockCipher.getBlockSize()];
this.cfbV = new byte[blockCipher.getBlockSize()];
this.cfbOutV = new byte[blockCipher.getBlockSize()];
}
}