414 lines
27 KiB
Java
414 lines
27 KiB
Java
package org.bouncycastle.crypto.engines;
|
|
|
|
import com.google.common.base.Ascii;
|
|
import com.google.common.primitives.SignedBytes;
|
|
import com.google.common.primitives.UnsignedBytes;
|
|
import java.lang.reflect.Array;
|
|
import net.sf.scuba.smartcards.ISO7816;
|
|
import net.sf.scuba.smartcards.ISOFileInfo;
|
|
import org.bouncycastle.crypto.BlockCipher;
|
|
import org.bouncycastle.crypto.CipherParameters;
|
|
import org.bouncycastle.crypto.DataLengthException;
|
|
import org.bouncycastle.crypto.OutputLengthException;
|
|
import org.bouncycastle.crypto.params.KeyParameter;
|
|
import org.bouncycastle.crypto.signers.PSSSigner;
|
|
import org.bouncycastle.crypto.tls.CipherSuite;
|
|
import org.bouncycastle.util.Pack;
|
|
import org.jmrtd.lds.CVCAFile;
|
|
|
|
/* loaded from: classes6.dex */
|
|
public class AESLightEngine implements BlockCipher {
|
|
private static final int BLOCK_SIZE = 16;
|
|
private static final int m1 = -2139062144;
|
|
private static final int m2 = 2139062143;
|
|
private static final int m3 = 27;
|
|
private static final int m4 = -1061109568;
|
|
private static final int m5 = 1061109567;
|
|
private int C0;
|
|
private int C1;
|
|
private int C2;
|
|
private int C3;
|
|
private int ROUNDS;
|
|
private int[][] WorkingKey = null;
|
|
private boolean forEncryption;
|
|
private static final byte[] S = {99, 124, 119, 123, -14, 107, ISOFileInfo.FCI_BYTE, -59, ISO7816.INS_DECREASE, 1, 103, 43, -2, -41, ISOFileInfo.AB, 118, ISO7816.INS_GET_DATA, -126, -55, 125, -6, 89, 71, -16, -83, -44, -94, -81, -100, -92, 114, ISO7816.INS_GET_RESPONSE, -73, -3, -109, 38, 54, 63, -9, -52, ISO7816.INS_DECREASE_STAMPED, ISOFileInfo.A5, -27, -15, 113, ISO7816.INS_LOAD_KEY_FILE, 49, Ascii.NAK, 4, -57, 35, -61, Ascii.CAN, -106, 5, -102, 7, Ascii.DC2, Byte.MIN_VALUE, ISO7816.INS_APPEND_RECORD, -21, 39, -78, 117, 9, ISOFileInfo.FILE_IDENTIFIER, ISO7816.INS_UNBLOCK_CHV, Ascii.SUB, Ascii.ESC, 110, 90, ISOFileInfo.A0, 82, 59, ISO7816.INS_UPDATE_BINARY, ISO7816.INS_READ_RECORD2, 41, -29, 47, -124, 83, -47, 0, -19, 32, -4, ISO7816.INS_READ_BINARY2, 91, 106, -53, -66, 57, 74, 76, 88, -49, ISO7816.INS_WRITE_BINARY, -17, -86, -5, 67, 77, 51, ISOFileInfo.PROP_INFO, 69, -7, 2, Ascii.DEL, 80, 60, -97, -88, 81, -93, SignedBytes.MAX_POWER_OF_TWO, -113, -110, -99, 56, -11, PSSSigner.TRAILER_IMPLICIT, ISO7816.INS_READ_RECORD_STAMPED, ISO7816.INS_PUT_DATA, 33, 16, -1, -13, ISO7816.INS_WRITE_RECORD, -51, 12, 19, -20, 95, -105, ISO7816.INS_REHABILITATE_CHV, Ascii.ETB, -60, -89, 126, 61, ISOFileInfo.FMD_BYTE, 93, Ascii.EM, 115, 96, ISOFileInfo.DATA_BYTES2, 79, ISO7816.INS_UPDATE_RECORD, ISO7816.INS_MSE, ISO7816.INS_PSO, -112, -120, 70, -18, -72, Ascii.DC4, -34, 94, 11, -37, ISO7816.INS_CREATE_FILE, ISO7816.INS_INCREASE, 58, 10, 73, 6, ISO7816.INS_CHANGE_CHV, 92, ISO7816.INS_ENVELOPE, -45, -84, ISOFileInfo.FCP_BYTE, -111, -107, ISO7816.INS_DELETE_FILE, 121, -25, -56, 55, 109, ISOFileInfo.ENV_TEMP_EF, -43, 78, -87, 108, 86, -12, -22, 101, 122, -82, 8, -70, 120, 37, 46, 28, -90, ISO7816.INS_READ_BINARY_STAMPED, -58, -24, -35, 116, Ascii.US, 75, -67, ISOFileInfo.SECURITY_ATTR_EXP, ISOFileInfo.LCS_BYTE, ISO7816.INS_MANAGE_CHANNEL, 62, -75, 102, 72, 3, -10, 14, 97, 53, 87, -71, -122, -63, 29, -98, -31, -8, -104, 17, 105, -39, ISOFileInfo.CHANNEL_SECURITY, -108, -101, 30, ISOFileInfo.FCI_EXT, -23, -50, 85, 40, -33, ISOFileInfo.SECURITY_ATTR_COMPACT, ISOFileInfo.A1, -119, 13, -65, -26, CVCAFile.CAR_TAG, 104, 65, -103, 45, 15, ISO7816.INS_READ_BINARY, 84, -69, Ascii.SYN};
|
|
private static final byte[] Si = {82, 9, 106, -43, ISO7816.INS_DECREASE, 54, ISOFileInfo.A5, 56, -65, SignedBytes.MAX_POWER_OF_TWO, -93, -98, ISOFileInfo.DATA_BYTES2, -13, -41, -5, 124, -29, 57, -126, -101, 47, -1, ISOFileInfo.FCI_EXT, ISO7816.INS_DECREASE_STAMPED, ISOFileInfo.CHANNEL_SECURITY, 67, ISO7816.INS_REHABILITATE_CHV, -60, -34, -23, -53, 84, 123, -108, ISO7816.INS_INCREASE, -90, ISO7816.INS_ENVELOPE, 35, 61, -18, 76, -107, 11, CVCAFile.CAR_TAG, -6, -61, 78, 8, 46, ISOFileInfo.A1, 102, 40, -39, ISO7816.INS_CHANGE_CHV, -78, 118, 91, -94, 73, 109, ISOFileInfo.SECURITY_ATTR_EXP, -47, 37, 114, -8, -10, ISOFileInfo.FMD_BYTE, -122, 104, -104, Ascii.SYN, -44, -92, 92, -52, 93, 101, ISO7816.INS_READ_RECORD_STAMPED, -110, 108, ISO7816.INS_MANAGE_CHANNEL, 72, 80, -3, -19, -71, ISO7816.INS_PUT_DATA, 94, Ascii.NAK, 70, 87, -89, ISOFileInfo.ENV_TEMP_EF, -99, -124, -112, ISO7816.INS_LOAD_KEY_FILE, ISOFileInfo.AB, 0, ISOFileInfo.SECURITY_ATTR_COMPACT, PSSSigner.TRAILER_IMPLICIT, -45, 10, -9, ISO7816.INS_DELETE_FILE, 88, 5, -72, ISO7816.INS_READ_RECORD2, 69, 6, ISO7816.INS_WRITE_BINARY, ISO7816.INS_UNBLOCK_CHV, 30, -113, ISO7816.INS_GET_DATA, 63, 15, 2, -63, -81, -67, 3, 1, 19, ISOFileInfo.LCS_BYTE, 107, 58, -111, 17, 65, 79, 103, ISO7816.INS_UPDATE_RECORD, -22, -105, -14, -49, -50, -16, ISO7816.INS_READ_BINARY_STAMPED, -26, 115, -106, -84, 116, ISO7816.INS_MSE, -25, -83, 53, ISOFileInfo.PROP_INFO, ISO7816.INS_APPEND_RECORD, -7, 55, -24, 28, 117, -33, 110, 71, -15, Ascii.SUB, 113, 29, 41, -59, -119, ISOFileInfo.FCI_BYTE, -73, ISOFileInfo.FCP_BYTE, 14, -86, Ascii.CAN, -66, Ascii.ESC, -4, 86, 62, 75, -58, ISO7816.INS_WRITE_RECORD, 121, 32, -102, -37, ISO7816.INS_GET_RESPONSE, -2, 120, -51, 90, -12, Ascii.US, -35, -88, 51, -120, 7, -57, 49, ISO7816.INS_READ_BINARY2, Ascii.DC2, 16, 89, 39, Byte.MIN_VALUE, -20, 95, 96, 81, Ascii.DEL, -87, Ascii.EM, -75, 74, 13, 45, -27, 122, -97, -109, -55, -100, -17, ISOFileInfo.A0, ISO7816.INS_CREATE_FILE, 59, 77, -82, ISO7816.INS_PSO, -11, ISO7816.INS_READ_BINARY, -56, -21, -69, 60, ISOFileInfo.FILE_IDENTIFIER, 83, -103, 97, Ascii.ETB, 43, 4, 126, -70, 119, ISO7816.INS_UPDATE_BINARY, 38, -31, 105, Ascii.DC4, 99, 85, 33, 12, 125};
|
|
private static final int[] rcon = {1, 2, 4, 8, 16, 32, 64, 128, 27, 54, 108, 216, CipherSuite.TLS_DHE_PSK_WITH_AES_256_GCM_SHA384, 77, CipherSuite.TLS_DHE_RSA_WITH_SEED_CBC_SHA, 47, 94, 188, 99, 198, 151, 53, 106, 212, CipherSuite.TLS_DHE_PSK_WITH_AES_256_CBC_SHA384, 125, 250, 239, CipherSuite.TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA256, CipherSuite.TLS_DHE_PSK_WITH_AES_256_CBC_SHA};
|
|
|
|
private static int FFmulX(int i) {
|
|
return ((i & m2) << 1) ^ (((m1 & i) >>> 7) * 27);
|
|
}
|
|
|
|
private static int FFmulX2(int i) {
|
|
int i2 = m4 & i;
|
|
int i3 = i2 ^ (i2 >>> 1);
|
|
return (((i & m5) << 2) ^ (i3 >>> 2)) ^ (i3 >>> 5);
|
|
}
|
|
|
|
private static int shift(int i, int i2) {
|
|
return (i >>> i2) | (i << (-i2));
|
|
}
|
|
|
|
@Override // org.bouncycastle.crypto.BlockCipher
|
|
public int getBlockSize() {
|
|
return 16;
|
|
}
|
|
|
|
@Override // org.bouncycastle.crypto.BlockCipher
|
|
public void reset() {
|
|
}
|
|
|
|
@Override // org.bouncycastle.crypto.BlockCipher
|
|
public int processBlock(byte[] bArr, int i, byte[] bArr2, int i2) {
|
|
if (this.WorkingKey == null) {
|
|
throw new IllegalStateException("AES engine not initialised");
|
|
}
|
|
if (i + 16 > bArr.length) {
|
|
throw new DataLengthException("input buffer too short");
|
|
}
|
|
if (i2 + 16 > bArr2.length) {
|
|
throw new OutputLengthException("output buffer too short");
|
|
}
|
|
boolean z = this.forEncryption;
|
|
unpackBlock(bArr, i);
|
|
int[][] iArr = this.WorkingKey;
|
|
if (z) {
|
|
encryptBlock(iArr);
|
|
} else {
|
|
decryptBlock(iArr);
|
|
}
|
|
packBlock(bArr2, i2);
|
|
return 16;
|
|
}
|
|
|
|
@Override // org.bouncycastle.crypto.BlockCipher
|
|
public void init(boolean z, CipherParameters cipherParameters) {
|
|
if (cipherParameters instanceof KeyParameter) {
|
|
this.WorkingKey = generateWorkingKey(((KeyParameter) cipherParameters).getKey(), z);
|
|
this.forEncryption = z;
|
|
} else {
|
|
StringBuilder sb = new StringBuilder("invalid parameter passed to AES init - ");
|
|
sb.append(cipherParameters.getClass().getName());
|
|
throw new IllegalArgumentException(sb.toString());
|
|
}
|
|
}
|
|
|
|
@Override // org.bouncycastle.crypto.BlockCipher
|
|
public String getAlgorithmName() {
|
|
return "AES";
|
|
}
|
|
|
|
private void unpackBlock(byte[] bArr, int i) {
|
|
byte b = bArr[i];
|
|
this.C0 = (b & UnsignedBytes.MAX_VALUE) | ((bArr[i + 1] & UnsignedBytes.MAX_VALUE) << 8) | ((bArr[i + 2] & UnsignedBytes.MAX_VALUE) << 16) | (bArr[i + 3] << Ascii.CAN);
|
|
byte b2 = bArr[i + 4];
|
|
this.C1 = (b2 & UnsignedBytes.MAX_VALUE) | ((bArr[i + 5] & UnsignedBytes.MAX_VALUE) << 8) | ((bArr[i + 6] & UnsignedBytes.MAX_VALUE) << 16) | (bArr[i + 7] << Ascii.CAN);
|
|
byte b3 = bArr[i + 8];
|
|
this.C2 = (b3 & UnsignedBytes.MAX_VALUE) | ((bArr[i + 9] & UnsignedBytes.MAX_VALUE) << 8) | ((bArr[i + 10] & UnsignedBytes.MAX_VALUE) << 16) | (bArr[i + 11] << Ascii.CAN);
|
|
byte b4 = bArr[i + 12];
|
|
this.C3 = (bArr[i + 15] << Ascii.CAN) | ((bArr[i + 13] & UnsignedBytes.MAX_VALUE) << 8) | (b4 & UnsignedBytes.MAX_VALUE) | ((bArr[i + 14] & UnsignedBytes.MAX_VALUE) << 16);
|
|
}
|
|
|
|
private static int subWord(int i) {
|
|
byte[] bArr = S;
|
|
return (bArr[i >>> 24] << Ascii.CAN) | (bArr[i & 255] & UnsignedBytes.MAX_VALUE) | ((bArr[(i >> 8) & 255] & UnsignedBytes.MAX_VALUE) << 8) | ((bArr[(i >> 16) & 255] & UnsignedBytes.MAX_VALUE) << 16);
|
|
}
|
|
|
|
private void packBlock(byte[] bArr, int i) {
|
|
int i2 = this.C0;
|
|
bArr[i] = (byte) i2;
|
|
bArr[i + 1] = (byte) (i2 >> 8);
|
|
bArr[i + 2] = (byte) (i2 >> 16);
|
|
bArr[i + 3] = (byte) (i2 >> 24);
|
|
int i3 = this.C1;
|
|
bArr[i + 4] = (byte) i3;
|
|
bArr[i + 5] = (byte) (i3 >> 8);
|
|
bArr[i + 6] = (byte) (i3 >> 16);
|
|
bArr[i + 7] = (byte) (i3 >> 24);
|
|
int i4 = this.C2;
|
|
bArr[i + 8] = (byte) i4;
|
|
bArr[i + 9] = (byte) (i4 >> 8);
|
|
bArr[i + 10] = (byte) (i4 >> 16);
|
|
bArr[i + 11] = (byte) (i4 >> 24);
|
|
int i5 = this.C3;
|
|
bArr[i + 12] = (byte) i5;
|
|
bArr[i + 13] = (byte) (i5 >> 8);
|
|
bArr[i + 14] = (byte) (i5 >> 16);
|
|
bArr[i + 15] = (byte) (i5 >> 24);
|
|
}
|
|
|
|
private static int mcol(int i) {
|
|
int shift = shift(i, 8);
|
|
int i2 = i ^ shift;
|
|
return FFmulX(i2) ^ (shift ^ shift(i2, 16));
|
|
}
|
|
|
|
private static int inv_mcol(int i) {
|
|
int shift = shift(i, 8) ^ i;
|
|
int FFmulX = i ^ FFmulX(shift);
|
|
int FFmulX2 = shift ^ FFmulX2(FFmulX);
|
|
return FFmulX ^ (FFmulX2 ^ shift(FFmulX2, 16));
|
|
}
|
|
|
|
private int[][] generateWorkingKey(byte[] bArr, boolean z) {
|
|
int length = bArr.length;
|
|
if (length < 16 || length > 32 || (length & 7) != 0) {
|
|
throw new IllegalArgumentException("Key length not 128/192/256 bits.");
|
|
}
|
|
int i = length >> 2;
|
|
this.ROUNDS = i + 6;
|
|
int[][] iArr = (int[][]) Array.newInstance((Class<?>) Integer.TYPE, i + 7, 4);
|
|
if (i == 4) {
|
|
int littleEndianToInt = Pack.littleEndianToInt(bArr, 0);
|
|
iArr[0][0] = littleEndianToInt;
|
|
int littleEndianToInt2 = Pack.littleEndianToInt(bArr, 4);
|
|
iArr[0][1] = littleEndianToInt2;
|
|
int littleEndianToInt3 = Pack.littleEndianToInt(bArr, 8);
|
|
iArr[0][2] = littleEndianToInt3;
|
|
int littleEndianToInt4 = Pack.littleEndianToInt(bArr, 12);
|
|
iArr[0][3] = littleEndianToInt4;
|
|
for (int i2 = 1; i2 <= 10; i2++) {
|
|
littleEndianToInt ^= subWord(shift(littleEndianToInt4, 8)) ^ rcon[i2 - 1];
|
|
int[] iArr2 = iArr[i2];
|
|
iArr2[0] = littleEndianToInt;
|
|
littleEndianToInt2 ^= littleEndianToInt;
|
|
iArr2[1] = littleEndianToInt2;
|
|
littleEndianToInt3 ^= littleEndianToInt2;
|
|
iArr2[2] = littleEndianToInt3;
|
|
littleEndianToInt4 ^= littleEndianToInt3;
|
|
iArr2[3] = littleEndianToInt4;
|
|
}
|
|
} else if (i == 6) {
|
|
int littleEndianToInt5 = Pack.littleEndianToInt(bArr, 0);
|
|
iArr[0][0] = littleEndianToInt5;
|
|
int littleEndianToInt6 = Pack.littleEndianToInt(bArr, 4);
|
|
iArr[0][1] = littleEndianToInt6;
|
|
int littleEndianToInt7 = Pack.littleEndianToInt(bArr, 8);
|
|
iArr[0][2] = littleEndianToInt7;
|
|
int littleEndianToInt8 = Pack.littleEndianToInt(bArr, 12);
|
|
iArr[0][3] = littleEndianToInt8;
|
|
int littleEndianToInt9 = Pack.littleEndianToInt(bArr, 16);
|
|
iArr[1][0] = littleEndianToInt9;
|
|
int littleEndianToInt10 = Pack.littleEndianToInt(bArr, 20);
|
|
iArr[1][1] = littleEndianToInt10;
|
|
int subWord = littleEndianToInt5 ^ (subWord(shift(littleEndianToInt10, 8)) ^ 1);
|
|
int[] iArr3 = iArr[1];
|
|
iArr3[2] = subWord;
|
|
int i3 = littleEndianToInt6 ^ subWord;
|
|
iArr3[3] = i3;
|
|
int i4 = littleEndianToInt7 ^ i3;
|
|
int[] iArr4 = iArr[2];
|
|
iArr4[0] = i4;
|
|
int i5 = littleEndianToInt8 ^ i4;
|
|
iArr4[1] = i5;
|
|
int i6 = littleEndianToInt9 ^ i5;
|
|
iArr4[2] = i6;
|
|
int i7 = littleEndianToInt10 ^ i6;
|
|
iArr4[3] = i7;
|
|
int i8 = 3;
|
|
int i9 = 2;
|
|
while (i8 < 12) {
|
|
int subWord2 = subWord ^ (subWord(shift(i7, 8)) ^ i9);
|
|
int[] iArr5 = iArr[i8];
|
|
iArr5[0] = subWord2;
|
|
int i10 = i3 ^ subWord2;
|
|
iArr5[1] = i10;
|
|
int i11 = i4 ^ i10;
|
|
iArr5[2] = i11;
|
|
int i12 = i5 ^ i11;
|
|
iArr5[3] = i12;
|
|
int i13 = i6 ^ i12;
|
|
int i14 = i8 + 1;
|
|
int[] iArr6 = iArr[i14];
|
|
iArr6[0] = i13;
|
|
int i15 = i7 ^ i13;
|
|
iArr6[1] = i15;
|
|
int i16 = i9 << 2;
|
|
subWord = subWord2 ^ ((i9 << 1) ^ subWord(shift(i15, 8)));
|
|
int[] iArr7 = iArr[i14];
|
|
iArr7[2] = subWord;
|
|
i3 = i10 ^ subWord;
|
|
iArr7[3] = i3;
|
|
i4 = i11 ^ i3;
|
|
int[] iArr8 = iArr[i8 + 2];
|
|
iArr8[0] = i4;
|
|
i5 = i12 ^ i4;
|
|
iArr8[1] = i5;
|
|
i6 = i13 ^ i5;
|
|
iArr8[2] = i6;
|
|
i7 = i15 ^ i6;
|
|
iArr8[3] = i7;
|
|
i8 += 3;
|
|
i9 = i16;
|
|
}
|
|
int subWord3 = (subWord(shift(i7, 8)) ^ 128) ^ subWord;
|
|
int[] iArr9 = iArr[12];
|
|
iArr9[0] = subWord3;
|
|
int i17 = subWord3 ^ i3;
|
|
iArr9[1] = i17;
|
|
int i18 = i17 ^ i4;
|
|
iArr9[2] = i18;
|
|
iArr9[3] = i18 ^ i5;
|
|
} else {
|
|
if (i != 8) {
|
|
throw new IllegalStateException("Should never get here");
|
|
}
|
|
int littleEndianToInt11 = Pack.littleEndianToInt(bArr, 0);
|
|
iArr[0][0] = littleEndianToInt11;
|
|
int littleEndianToInt12 = Pack.littleEndianToInt(bArr, 4);
|
|
iArr[0][1] = littleEndianToInt12;
|
|
int littleEndianToInt13 = Pack.littleEndianToInt(bArr, 8);
|
|
iArr[0][2] = littleEndianToInt13;
|
|
int littleEndianToInt14 = Pack.littleEndianToInt(bArr, 12);
|
|
iArr[0][3] = littleEndianToInt14;
|
|
int littleEndianToInt15 = Pack.littleEndianToInt(bArr, 16);
|
|
iArr[1][0] = littleEndianToInt15;
|
|
int littleEndianToInt16 = Pack.littleEndianToInt(bArr, 20);
|
|
iArr[1][1] = littleEndianToInt16;
|
|
int littleEndianToInt17 = Pack.littleEndianToInt(bArr, 24);
|
|
iArr[1][2] = littleEndianToInt17;
|
|
int littleEndianToInt18 = Pack.littleEndianToInt(bArr, 28);
|
|
iArr[1][3] = littleEndianToInt18;
|
|
int i19 = 2;
|
|
int i20 = 1;
|
|
while (i19 < 14) {
|
|
littleEndianToInt11 ^= subWord(shift(littleEndianToInt18, 8)) ^ i20;
|
|
int[] iArr10 = iArr[i19];
|
|
iArr10[0] = littleEndianToInt11;
|
|
littleEndianToInt12 ^= littleEndianToInt11;
|
|
iArr10[1] = littleEndianToInt12;
|
|
littleEndianToInt13 ^= littleEndianToInt12;
|
|
iArr10[2] = littleEndianToInt13;
|
|
littleEndianToInt14 ^= littleEndianToInt13;
|
|
iArr10[3] = littleEndianToInt14;
|
|
littleEndianToInt15 ^= subWord(littleEndianToInt14);
|
|
int[] iArr11 = iArr[i19 + 1];
|
|
iArr11[0] = littleEndianToInt15;
|
|
littleEndianToInt16 ^= littleEndianToInt15;
|
|
iArr11[1] = littleEndianToInt16;
|
|
littleEndianToInt17 ^= littleEndianToInt16;
|
|
iArr11[2] = littleEndianToInt17;
|
|
littleEndianToInt18 ^= littleEndianToInt17;
|
|
iArr11[3] = littleEndianToInt18;
|
|
i19 += 2;
|
|
i20 <<= 1;
|
|
}
|
|
int subWord4 = (subWord(shift(littleEndianToInt18, 8)) ^ i20) ^ littleEndianToInt11;
|
|
int[] iArr12 = iArr[14];
|
|
iArr12[0] = subWord4;
|
|
int i21 = subWord4 ^ littleEndianToInt12;
|
|
iArr12[1] = i21;
|
|
int i22 = i21 ^ littleEndianToInt13;
|
|
iArr12[2] = i22;
|
|
iArr12[3] = i22 ^ littleEndianToInt14;
|
|
}
|
|
if (!z) {
|
|
for (int i23 = 1; i23 < this.ROUNDS; i23++) {
|
|
for (int i24 = 0; i24 < 4; i24++) {
|
|
int[] iArr13 = iArr[i23];
|
|
iArr13[i24] = inv_mcol(iArr13[i24]);
|
|
}
|
|
}
|
|
}
|
|
return iArr;
|
|
}
|
|
|
|
private void encryptBlock(int[][] iArr) {
|
|
int i = this.C0;
|
|
char c = 0;
|
|
int[] iArr2 = iArr[0];
|
|
int i2 = i ^ iArr2[0];
|
|
int i3 = this.C1 ^ iArr2[1];
|
|
int i4 = this.C2 ^ iArr2[2];
|
|
int i5 = iArr2[3] ^ this.C3;
|
|
int i6 = 1;
|
|
for (int i7 = 1; i6 < this.ROUNDS - i7; i7 = 1) {
|
|
byte[] bArr = S;
|
|
int mcol = mcol((((bArr[i2 & 255] & UnsignedBytes.MAX_VALUE) ^ ((bArr[(i3 >> 8) & 255] & UnsignedBytes.MAX_VALUE) << 8)) ^ ((bArr[(i4 >> 16) & 255] & UnsignedBytes.MAX_VALUE) << 16)) ^ (bArr[i5 >>> 24] << Ascii.CAN)) ^ iArr[i6][c];
|
|
int mcol2 = mcol((((bArr[i3 & 255] & UnsignedBytes.MAX_VALUE) ^ ((bArr[(i4 >> 8) & 255] & UnsignedBytes.MAX_VALUE) << 8)) ^ ((bArr[(i5 >> 16) & 255] & UnsignedBytes.MAX_VALUE) << 16)) ^ (bArr[i2 >>> 24] << Ascii.CAN)) ^ iArr[i6][i7];
|
|
int mcol3 = mcol((((bArr[i4 & 255] & UnsignedBytes.MAX_VALUE) ^ ((bArr[(i5 >> 8) & 255] & UnsignedBytes.MAX_VALUE) << 8)) ^ ((bArr[(i2 >> 16) & 255] & UnsignedBytes.MAX_VALUE) << 16)) ^ (bArr[i3 >>> 24] << Ascii.CAN)) ^ iArr[i6][2];
|
|
int mcol4 = mcol(((((bArr[(i2 >> 8) & 255] & UnsignedBytes.MAX_VALUE) << 8) ^ (bArr[i5 & 255] & UnsignedBytes.MAX_VALUE)) ^ ((bArr[(i3 >> 16) & 255] & UnsignedBytes.MAX_VALUE) << 16)) ^ (bArr[i4 >>> 24] << Ascii.CAN));
|
|
int i8 = i6 + 1;
|
|
int i9 = mcol4 ^ iArr[i6][3];
|
|
int mcol5 = mcol((((bArr[mcol & 255] & UnsignedBytes.MAX_VALUE) ^ ((bArr[(mcol2 >> 8) & 255] & UnsignedBytes.MAX_VALUE) << 8)) ^ ((bArr[(mcol3 >> 16) & 255] & UnsignedBytes.MAX_VALUE) << 16)) ^ (bArr[i9 >>> 24] << Ascii.CAN));
|
|
int i10 = iArr[i8][c];
|
|
int mcol6 = mcol((((bArr[mcol2 & 255] & UnsignedBytes.MAX_VALUE) ^ ((bArr[(mcol3 >> 8) & 255] & UnsignedBytes.MAX_VALUE) << 8)) ^ ((bArr[(i9 >> 16) & 255] & UnsignedBytes.MAX_VALUE) << 16)) ^ (bArr[mcol >>> 24] << Ascii.CAN));
|
|
int i11 = iArr[i8][i7];
|
|
int mcol7 = mcol(((((bArr[(i9 >> 8) & 255] & UnsignedBytes.MAX_VALUE) << 8) ^ (bArr[mcol3 & 255] & UnsignedBytes.MAX_VALUE)) ^ ((bArr[(mcol >> 16) & 255] & UnsignedBytes.MAX_VALUE) << 16)) ^ (bArr[mcol2 >>> 24] << Ascii.CAN));
|
|
int i12 = iArr[i8][2];
|
|
i6 += 2;
|
|
i5 = iArr[i8][3] ^ mcol((((bArr[i9 & 255] & UnsignedBytes.MAX_VALUE) ^ ((bArr[(mcol >> 8) & 255] & UnsignedBytes.MAX_VALUE) << 8)) ^ ((bArr[(mcol2 >> 16) & 255] & UnsignedBytes.MAX_VALUE) << 16)) ^ (bArr[mcol3 >>> 24] << Ascii.CAN));
|
|
i2 = mcol5 ^ i10;
|
|
i3 = mcol6 ^ i11;
|
|
i4 = mcol7 ^ i12;
|
|
c = 0;
|
|
}
|
|
byte[] bArr2 = S;
|
|
int mcol8 = mcol((((bArr2[i2 & 255] & UnsignedBytes.MAX_VALUE) ^ ((bArr2[(i3 >> 8) & 255] & UnsignedBytes.MAX_VALUE) << 8)) ^ ((bArr2[(i4 >> 16) & 255] & UnsignedBytes.MAX_VALUE) << 16)) ^ (bArr2[i5 >>> 24] << Ascii.CAN)) ^ iArr[i6][0];
|
|
int mcol9 = mcol((((bArr2[i3 & 255] & UnsignedBytes.MAX_VALUE) ^ ((bArr2[(i4 >> 8) & 255] & UnsignedBytes.MAX_VALUE) << 8)) ^ ((bArr2[(i5 >> 16) & 255] & UnsignedBytes.MAX_VALUE) << 16)) ^ (bArr2[i2 >>> 24] << Ascii.CAN)) ^ iArr[i6][1];
|
|
int mcol10 = mcol((((bArr2[i4 & 255] & UnsignedBytes.MAX_VALUE) ^ ((bArr2[(i5 >> 8) & 255] & UnsignedBytes.MAX_VALUE) << 8)) ^ ((bArr2[(i2 >> 16) & 255] & UnsignedBytes.MAX_VALUE) << 16)) ^ (bArr2[i3 >>> 24] << Ascii.CAN)) ^ iArr[i6][2];
|
|
int mcol11 = mcol(((((bArr2[(i2 >> 8) & 255] & UnsignedBytes.MAX_VALUE) << 8) ^ (bArr2[i5 & 255] & UnsignedBytes.MAX_VALUE)) ^ ((bArr2[(i3 >> 16) & 255] & UnsignedBytes.MAX_VALUE) << 16)) ^ (bArr2[i4 >>> 24] << Ascii.CAN)) ^ iArr[i6][3];
|
|
byte b = bArr2[mcol8 & 255];
|
|
byte b2 = bArr2[(mcol9 >> 8) & 255];
|
|
byte b3 = bArr2[(mcol10 >> 16) & 255];
|
|
byte b4 = bArr2[mcol11 >>> 24];
|
|
int[] iArr3 = iArr[i6 + 1];
|
|
this.C0 = ((((b & UnsignedBytes.MAX_VALUE) ^ ((b2 & UnsignedBytes.MAX_VALUE) << 8)) ^ ((b3 & UnsignedBytes.MAX_VALUE) << 16)) ^ (b4 << Ascii.CAN)) ^ iArr3[0];
|
|
this.C1 = ((((bArr2[mcol9 & 255] & UnsignedBytes.MAX_VALUE) ^ ((bArr2[(mcol10 >> 8) & 255] & UnsignedBytes.MAX_VALUE) << 8)) ^ ((bArr2[(mcol11 >> 16) & 255] & UnsignedBytes.MAX_VALUE) << 16)) ^ (bArr2[mcol8 >>> 24] << Ascii.CAN)) ^ iArr3[1];
|
|
this.C2 = ((((bArr2[mcol10 & 255] & UnsignedBytes.MAX_VALUE) ^ ((bArr2[(mcol11 >> 8) & 255] & UnsignedBytes.MAX_VALUE) << 8)) ^ ((bArr2[(mcol8 >> 16) & 255] & UnsignedBytes.MAX_VALUE) << 16)) ^ (bArr2[mcol9 >>> 24] << Ascii.CAN)) ^ iArr3[2];
|
|
this.C3 = ((((bArr2[mcol11 & 255] & UnsignedBytes.MAX_VALUE) ^ ((bArr2[(mcol8 >> 8) & 255] & UnsignedBytes.MAX_VALUE) << 8)) ^ ((bArr2[(mcol9 >> 16) & 255] & UnsignedBytes.MAX_VALUE) << 16)) ^ (bArr2[mcol10 >>> 24] << Ascii.CAN)) ^ iArr3[3];
|
|
}
|
|
|
|
private void decryptBlock(int[][] iArr) {
|
|
int i = this.C0;
|
|
int i2 = this.ROUNDS;
|
|
int[] iArr2 = iArr[i2];
|
|
char c = 0;
|
|
int i3 = i ^ iArr2[0];
|
|
int i4 = 1;
|
|
int i5 = this.C1 ^ iArr2[1];
|
|
int i6 = this.C2 ^ iArr2[2];
|
|
int i7 = i2 - 1;
|
|
int i8 = iArr2[3] ^ this.C3;
|
|
while (true) {
|
|
byte[] bArr = Si;
|
|
int i9 = i3 & 255;
|
|
if (i7 <= i4) {
|
|
int inv_mcol = inv_mcol((((bArr[i9] & UnsignedBytes.MAX_VALUE) ^ ((bArr[(i8 >> 8) & 255] & UnsignedBytes.MAX_VALUE) << 8)) ^ ((bArr[(i6 >> 16) & 255] & UnsignedBytes.MAX_VALUE) << 16)) ^ (bArr[i5 >>> 24] << Ascii.CAN)) ^ iArr[i7][0];
|
|
int inv_mcol2 = inv_mcol((((bArr[i5 & 255] & UnsignedBytes.MAX_VALUE) ^ ((bArr[(i3 >> 8) & 255] & UnsignedBytes.MAX_VALUE) << 8)) ^ ((bArr[(i8 >> 16) & 255] & UnsignedBytes.MAX_VALUE) << 16)) ^ (bArr[i6 >>> 24] << Ascii.CAN)) ^ iArr[i7][1];
|
|
int inv_mcol3 = inv_mcol((((bArr[i6 & 255] & UnsignedBytes.MAX_VALUE) ^ ((bArr[(i5 >> 8) & 255] & UnsignedBytes.MAX_VALUE) << 8)) ^ ((bArr[(i3 >> 16) & 255] & UnsignedBytes.MAX_VALUE) << 16)) ^ (bArr[i8 >>> 24] << Ascii.CAN)) ^ iArr[i7][2];
|
|
int inv_mcol4 = inv_mcol((bArr[i3 >>> 24] << Ascii.CAN) ^ (((bArr[i8 & 255] & UnsignedBytes.MAX_VALUE) ^ ((bArr[(i6 >> 8) & 255] & UnsignedBytes.MAX_VALUE) << 8)) ^ ((bArr[(i5 >> 16) & 255] & UnsignedBytes.MAX_VALUE) << 16))) ^ iArr[i7][3];
|
|
byte b = bArr[inv_mcol & 255];
|
|
byte b2 = bArr[(inv_mcol4 >> 8) & 255];
|
|
byte b3 = bArr[(inv_mcol3 >> 16) & 255];
|
|
byte b4 = bArr[inv_mcol2 >>> 24];
|
|
int[] iArr3 = iArr[0];
|
|
this.C0 = ((((b & UnsignedBytes.MAX_VALUE) ^ ((b2 & UnsignedBytes.MAX_VALUE) << 8)) ^ ((b3 & UnsignedBytes.MAX_VALUE) << 16)) ^ (b4 << Ascii.CAN)) ^ iArr3[0];
|
|
this.C1 = ((((bArr[inv_mcol2 & 255] & UnsignedBytes.MAX_VALUE) ^ ((bArr[(inv_mcol >> 8) & 255] & UnsignedBytes.MAX_VALUE) << 8)) ^ ((bArr[(inv_mcol4 >> 16) & 255] & UnsignedBytes.MAX_VALUE) << 16)) ^ (bArr[inv_mcol3 >>> 24] << Ascii.CAN)) ^ iArr3[1];
|
|
this.C2 = ((((bArr[inv_mcol3 & 255] & UnsignedBytes.MAX_VALUE) ^ ((bArr[(inv_mcol2 >> 8) & 255] & UnsignedBytes.MAX_VALUE) << 8)) ^ ((bArr[(inv_mcol >> 16) & 255] & UnsignedBytes.MAX_VALUE) << 16)) ^ (bArr[inv_mcol4 >>> 24] << Ascii.CAN)) ^ iArr3[2];
|
|
this.C3 = ((((bArr[inv_mcol4 & 255] & UnsignedBytes.MAX_VALUE) ^ ((bArr[(inv_mcol3 >> 8) & 255] & UnsignedBytes.MAX_VALUE) << 8)) ^ ((bArr[(inv_mcol2 >> 16) & 255] & UnsignedBytes.MAX_VALUE) << 16)) ^ (bArr[inv_mcol >>> 24] << Ascii.CAN)) ^ iArr3[3];
|
|
return;
|
|
}
|
|
int inv_mcol5 = inv_mcol((((bArr[i9] & UnsignedBytes.MAX_VALUE) ^ ((bArr[(i8 >> 8) & 255] & UnsignedBytes.MAX_VALUE) << 8)) ^ ((bArr[(i6 >> 16) & 255] & UnsignedBytes.MAX_VALUE) << 16)) ^ (bArr[i5 >>> 24] << Ascii.CAN)) ^ iArr[i7][c];
|
|
int inv_mcol6 = inv_mcol((((bArr[i5 & 255] & UnsignedBytes.MAX_VALUE) ^ ((bArr[(i3 >> 8) & 255] & UnsignedBytes.MAX_VALUE) << 8)) ^ ((bArr[(i8 >> 16) & 255] & UnsignedBytes.MAX_VALUE) << 16)) ^ (bArr[i6 >>> 24] << Ascii.CAN)) ^ iArr[i7][i4];
|
|
int inv_mcol7 = inv_mcol((((bArr[i6 & 255] & UnsignedBytes.MAX_VALUE) ^ ((bArr[(i5 >> 8) & 255] & UnsignedBytes.MAX_VALUE) << 8)) ^ ((bArr[(i3 >> 16) & 255] & UnsignedBytes.MAX_VALUE) << 16)) ^ (bArr[i8 >>> 24] << Ascii.CAN)) ^ iArr[i7][2];
|
|
int inv_mcol8 = inv_mcol((bArr[i3 >>> 24] << Ascii.CAN) ^ (((bArr[i8 & 255] & UnsignedBytes.MAX_VALUE) ^ ((bArr[(i6 >> 8) & 255] & UnsignedBytes.MAX_VALUE) << 8)) ^ ((bArr[(i5 >> 16) & 255] & UnsignedBytes.MAX_VALUE) << 16)));
|
|
int i10 = i7 - 1;
|
|
int i11 = inv_mcol8 ^ iArr[i7][3];
|
|
int inv_mcol9 = inv_mcol((((bArr[inv_mcol5 & 255] & UnsignedBytes.MAX_VALUE) ^ ((bArr[(i11 >> 8) & 255] & UnsignedBytes.MAX_VALUE) << 8)) ^ ((bArr[(inv_mcol7 >> 16) & 255] & UnsignedBytes.MAX_VALUE) << 16)) ^ (bArr[inv_mcol6 >>> 24] << Ascii.CAN));
|
|
int i12 = iArr[i10][c];
|
|
int inv_mcol10 = inv_mcol((((bArr[inv_mcol6 & 255] & UnsignedBytes.MAX_VALUE) ^ ((bArr[(inv_mcol5 >> 8) & 255] & UnsignedBytes.MAX_VALUE) << 8)) ^ ((bArr[(i11 >> 16) & 255] & UnsignedBytes.MAX_VALUE) << 16)) ^ (bArr[inv_mcol7 >>> 24] << Ascii.CAN));
|
|
int i13 = iArr[i10][i4];
|
|
int inv_mcol11 = inv_mcol(((((bArr[(inv_mcol6 >> 8) & 255] & UnsignedBytes.MAX_VALUE) << 8) ^ (bArr[inv_mcol7 & 255] & UnsignedBytes.MAX_VALUE)) ^ ((bArr[(inv_mcol5 >> 16) & 255] & UnsignedBytes.MAX_VALUE) << 16)) ^ (bArr[i11 >>> 24] << Ascii.CAN));
|
|
int i14 = iArr[i10][2];
|
|
i7 -= 2;
|
|
i8 = iArr[i10][3] ^ inv_mcol((((bArr[i11 & 255] & UnsignedBytes.MAX_VALUE) ^ ((bArr[(inv_mcol7 >> 8) & 255] & UnsignedBytes.MAX_VALUE) << 8)) ^ ((bArr[(inv_mcol6 >> 16) & 255] & UnsignedBytes.MAX_VALUE) << 16)) ^ (bArr[inv_mcol5 >>> 24] << Ascii.CAN));
|
|
i3 = inv_mcol9 ^ i12;
|
|
i5 = inv_mcol10 ^ i13;
|
|
i6 = inv_mcol11 ^ i14;
|
|
c = 0;
|
|
i4 = 1;
|
|
}
|
|
}
|
|
}
|