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

136 lines
4.3 KiB
Java

package org.bouncycastle.crypto.macs;
import org.bouncycastle.crypto.BlockCipher;
import org.bouncycastle.crypto.CipherParameters;
import org.bouncycastle.crypto.Mac;
import org.bouncycastle.crypto.paddings.BlockCipherPadding;
/* loaded from: classes6.dex */
public class CFBBlockCipherMac implements Mac {
private byte[] buf;
private int bufOff;
private MacCFBBlockCipher cipher;
private byte[] mac;
private int macSize;
private BlockCipherPadding padding;
@Override // org.bouncycastle.crypto.Mac
public void update(byte[] bArr, int i, int i2) {
if (i2 < 0) {
throw new IllegalArgumentException("Can't have a negative input length!");
}
int blockSize = this.cipher.getBlockSize();
int i3 = this.bufOff;
int i4 = blockSize - i3;
if (i2 > i4) {
System.arraycopy(bArr, i, this.buf, i3, i4);
this.cipher.processBlock(this.buf, 0, this.mac, 0);
this.bufOff = 0;
i2 -= i4;
i += i4;
while (i2 > blockSize) {
this.cipher.processBlock(bArr, i, this.mac, 0);
i2 -= blockSize;
i += blockSize;
}
}
System.arraycopy(bArr, i, this.buf, this.bufOff, i2);
this.bufOff += i2;
}
@Override // org.bouncycastle.crypto.Mac
public void update(byte b) {
int i = this.bufOff;
byte[] bArr = this.buf;
if (i == bArr.length) {
this.cipher.processBlock(bArr, 0, this.mac, 0);
this.bufOff = 0;
}
byte[] bArr2 = this.buf;
int i2 = this.bufOff;
this.bufOff = i2 + 1;
bArr2[i2] = b;
}
@Override // org.bouncycastle.crypto.Mac
public void reset() {
int i = 0;
while (true) {
byte[] bArr = this.buf;
if (i >= bArr.length) {
this.bufOff = 0;
this.cipher.reset();
return;
} else {
bArr[i] = 0;
i++;
}
}
}
@Override // org.bouncycastle.crypto.Mac
public void init(CipherParameters cipherParameters) {
reset();
this.cipher.init(cipherParameters);
}
@Override // org.bouncycastle.crypto.Mac
public int getMacSize() {
return this.macSize;
}
@Override // org.bouncycastle.crypto.Mac
public String getAlgorithmName() {
return this.cipher.getAlgorithmName();
}
@Override // org.bouncycastle.crypto.Mac
public int doFinal(byte[] bArr, int i) {
int blockSize = this.cipher.getBlockSize();
BlockCipherPadding blockCipherPadding = this.padding;
if (blockCipherPadding == null) {
while (true) {
int i2 = this.bufOff;
if (i2 >= blockSize) {
break;
}
this.buf[i2] = 0;
this.bufOff = i2 + 1;
}
} else {
blockCipherPadding.addPadding(this.buf, this.bufOff);
}
this.cipher.processBlock(this.buf, 0, this.mac, 0);
this.cipher.getMacBlock(this.mac);
System.arraycopy(this.mac, 0, bArr, i, this.macSize);
reset();
return this.macSize;
}
public CFBBlockCipherMac(BlockCipher blockCipher, BlockCipherPadding blockCipherPadding) {
this(blockCipher, 8, (blockCipher.getBlockSize() << 3) / 2, blockCipherPadding);
}
public CFBBlockCipherMac(BlockCipher blockCipher, int i, int i2, BlockCipherPadding blockCipherPadding) {
this.padding = null;
if (i2 % 8 != 0) {
throw new IllegalArgumentException("MAC size must be multiple of 8");
}
this.mac = new byte[blockCipher.getBlockSize()];
MacCFBBlockCipher macCFBBlockCipher = new MacCFBBlockCipher(blockCipher, i);
this.cipher = macCFBBlockCipher;
this.padding = blockCipherPadding;
this.macSize = i2 / 8;
this.buf = new byte[macCFBBlockCipher.getBlockSize()];
this.bufOff = 0;
}
public CFBBlockCipherMac(BlockCipher blockCipher, int i, int i2) {
this(blockCipher, i, i2, null);
}
public CFBBlockCipherMac(BlockCipher blockCipher) {
this(blockCipher, 8, (blockCipher.getBlockSize() << 3) / 2, null);
}
}