what-the-bank/sources/org/bouncycastle/crypto/modes/GCFBBlockCipher.java

97 lines
4.2 KiB
Java
Raw Permalink Normal View History

2024-07-27 18:17:47 +07:00
package org.bouncycastle.crypto.modes;
import com.google.common.base.Ascii;
import net.sf.scuba.smartcards.ISO7816;
import net.sf.scuba.smartcards.ISOFileInfo;
import okhttp3.internal.ws.RealWebSocket;
import org.bouncycastle.crypto.BlockCipher;
import org.bouncycastle.crypto.CipherParameters;
import org.bouncycastle.crypto.DataLengthException;
import org.bouncycastle.crypto.StreamBlockCipher;
import org.bouncycastle.crypto.params.KeyParameter;
import org.bouncycastle.crypto.params.ParametersWithIV;
import org.bouncycastle.crypto.params.ParametersWithRandom;
import org.bouncycastle.crypto.params.ParametersWithSBox;
/* loaded from: classes6.dex */
public class GCFBBlockCipher extends StreamBlockCipher {
private static final byte[] C = {105, 0, 114, ISO7816.INS_MSE, ISOFileInfo.FMD_BYTE, -55, 4, 35, ISOFileInfo.ENV_TEMP_EF, 58, -37, -106, 70, -23, ISO7816.INS_PSO, -60, Ascii.CAN, -2, -84, -108, 0, -19, 7, Ascii.DC2, ISO7816.INS_GET_RESPONSE, -122, ISO7816.INS_UPDATE_RECORD, ISO7816.INS_ENVELOPE, -17, 76, -87, 43};
private final CFBBlockCipher cfbEngine;
private long counter;
private boolean forEncryption;
private KeyParameter key;
@Override // org.bouncycastle.crypto.BlockCipher
public void reset() {
this.counter = 0L;
this.cfbEngine.reset();
}
@Override // org.bouncycastle.crypto.BlockCipher
public int processBlock(byte[] bArr, int i, byte[] bArr2, int i2) throws DataLengthException, IllegalStateException {
processBytes(bArr, i, this.cfbEngine.getBlockSize(), bArr2, i2);
return this.cfbEngine.getBlockSize();
}
@Override // org.bouncycastle.crypto.BlockCipher
public void init(boolean z, CipherParameters cipherParameters) throws IllegalArgumentException {
this.counter = 0L;
this.cfbEngine.init(z, cipherParameters);
this.forEncryption = z;
if (cipherParameters instanceof ParametersWithIV) {
cipherParameters = ((ParametersWithIV) cipherParameters).getParameters();
}
if (cipherParameters instanceof ParametersWithRandom) {
cipherParameters = ((ParametersWithRandom) cipherParameters).getParameters();
}
if (cipherParameters instanceof ParametersWithSBox) {
cipherParameters = ((ParametersWithSBox) cipherParameters).getParameters();
}
this.key = (KeyParameter) cipherParameters;
}
@Override // org.bouncycastle.crypto.BlockCipher
public int getBlockSize() {
return this.cfbEngine.getBlockSize();
}
@Override // org.bouncycastle.crypto.BlockCipher
public String getAlgorithmName() {
String algorithmName = this.cfbEngine.getAlgorithmName();
StringBuilder sb = new StringBuilder();
sb.append(algorithmName.substring(0, algorithmName.indexOf(47)));
sb.append("/G");
sb.append(algorithmName.substring(algorithmName.indexOf(47) + 1));
return sb.toString();
}
@Override // org.bouncycastle.crypto.StreamBlockCipher
public byte calculateByte(byte b) {
long j = this.counter;
if (j > 0 && j % RealWebSocket.DEFAULT_MINIMUM_DEFLATE_SIZE == 0) {
BlockCipher underlyingCipher = this.cfbEngine.getUnderlyingCipher();
underlyingCipher.init(false, this.key);
byte[] bArr = new byte[32];
byte[] bArr2 = C;
underlyingCipher.processBlock(bArr2, 0, bArr, 0);
underlyingCipher.processBlock(bArr2, 8, bArr, 8);
underlyingCipher.processBlock(bArr2, 16, bArr, 16);
underlyingCipher.processBlock(bArr2, 24, bArr, 24);
KeyParameter keyParameter = new KeyParameter(bArr);
this.key = keyParameter;
underlyingCipher.init(true, keyParameter);
byte[] currentIV = this.cfbEngine.getCurrentIV();
underlyingCipher.processBlock(currentIV, 0, currentIV, 0);
this.cfbEngine.init(this.forEncryption, new ParametersWithIV(this.key, currentIV));
}
this.counter++;
return this.cfbEngine.calculateByte(b);
}
public GCFBBlockCipher(BlockCipher blockCipher) {
super(blockCipher);
this.counter = 0L;
this.cfbEngine = new CFBBlockCipher(blockCipher, blockCipher.getBlockSize() << 3);
}
}