82 lines
3.2 KiB
Java
82 lines
3.2 KiB
Java
|
package org.bouncycastle.crypto.engines;
|
||
|
|
||
|
import org.bouncycastle.crypto.CipherParameters;
|
||
|
import org.bouncycastle.crypto.DataLengthException;
|
||
|
import org.bouncycastle.crypto.OutputLengthException;
|
||
|
import org.bouncycastle.crypto.params.KeyParameter;
|
||
|
|
||
|
/* loaded from: classes6.dex */
|
||
|
public class DESedeEngine extends DESEngine {
|
||
|
protected static final int BLOCK_SIZE = 8;
|
||
|
private boolean forEncryption;
|
||
|
private int[] workingKey1 = null;
|
||
|
private int[] workingKey2 = null;
|
||
|
private int[] workingKey3 = null;
|
||
|
|
||
|
@Override // org.bouncycastle.crypto.engines.DESEngine, org.bouncycastle.crypto.BlockCipher
|
||
|
public int getBlockSize() {
|
||
|
return 8;
|
||
|
}
|
||
|
|
||
|
@Override // org.bouncycastle.crypto.engines.DESEngine, org.bouncycastle.crypto.BlockCipher
|
||
|
public void reset() {
|
||
|
}
|
||
|
|
||
|
@Override // org.bouncycastle.crypto.engines.DESEngine, org.bouncycastle.crypto.BlockCipher
|
||
|
public int processBlock(byte[] bArr, int i, byte[] bArr2, int i2) {
|
||
|
int[] iArr = this.workingKey1;
|
||
|
if (iArr == null) {
|
||
|
throw new IllegalStateException("DESede engine not initialised");
|
||
|
}
|
||
|
if (i + 8 > bArr.length) {
|
||
|
throw new DataLengthException("input buffer too short");
|
||
|
}
|
||
|
if (i2 + 8 > bArr2.length) {
|
||
|
throw new OutputLengthException("output buffer too short");
|
||
|
}
|
||
|
byte[] bArr3 = new byte[8];
|
||
|
if (this.forEncryption) {
|
||
|
desFunc(iArr, bArr, i, bArr3, 0);
|
||
|
desFunc(this.workingKey2, bArr3, 0, bArr3, 0);
|
||
|
desFunc(this.workingKey3, bArr3, 0, bArr2, i2);
|
||
|
} else {
|
||
|
desFunc(this.workingKey3, bArr, i, bArr3, 0);
|
||
|
desFunc(this.workingKey2, bArr3, 0, bArr3, 0);
|
||
|
desFunc(this.workingKey1, bArr3, 0, bArr2, i2);
|
||
|
}
|
||
|
return 8;
|
||
|
}
|
||
|
|
||
|
@Override // org.bouncycastle.crypto.engines.DESEngine, org.bouncycastle.crypto.BlockCipher
|
||
|
public void init(boolean z, CipherParameters cipherParameters) {
|
||
|
if (!(cipherParameters instanceof KeyParameter)) {
|
||
|
StringBuilder sb = new StringBuilder("invalid parameter passed to DESede init - ");
|
||
|
sb.append(cipherParameters.getClass().getName());
|
||
|
throw new IllegalArgumentException(sb.toString());
|
||
|
}
|
||
|
byte[] key = ((KeyParameter) cipherParameters).getKey();
|
||
|
if (key.length != 24 && key.length != 16) {
|
||
|
throw new IllegalArgumentException("key size must be 16 or 24 bytes.");
|
||
|
}
|
||
|
this.forEncryption = z;
|
||
|
byte[] bArr = new byte[8];
|
||
|
System.arraycopy(key, 0, bArr, 0, 8);
|
||
|
this.workingKey1 = generateWorkingKey(z, bArr);
|
||
|
byte[] bArr2 = new byte[8];
|
||
|
System.arraycopy(key, 8, bArr2, 0, 8);
|
||
|
this.workingKey2 = generateWorkingKey(!z, bArr2);
|
||
|
if (key.length != 24) {
|
||
|
this.workingKey3 = this.workingKey1;
|
||
|
return;
|
||
|
}
|
||
|
byte[] bArr3 = new byte[8];
|
||
|
System.arraycopy(key, 16, bArr3, 0, 8);
|
||
|
this.workingKey3 = generateWorkingKey(z, bArr3);
|
||
|
}
|
||
|
|
||
|
@Override // org.bouncycastle.crypto.engines.DESEngine, org.bouncycastle.crypto.BlockCipher
|
||
|
public String getAlgorithmName() {
|
||
|
return "DESede";
|
||
|
}
|
||
|
}
|