private static SubWord ( uint x ) : uint | ||
x | uint | |
Результат | uint |
private uint[][] GenerateWorkingKey(byte[] key, bool forEncryption) { int num = key.Length / 4; if (num != 4 && num != 6 && num != 8) { throw new ArgumentException("Key length not 128/192/256 bits."); } this.ROUNDS = num + 6; uint[][] array = new uint[this.ROUNDS + 1][]; for (int i = 0; i <= this.ROUNDS; i++) { array[i] = new uint[4]; } int num2 = 0; int j = 0; while (j < key.Length) { array[num2 >> 2][num2 & 3] = Pack.LE_To_UInt32(key, j); j += 4; num2++; } int num3 = this.ROUNDS + 1 << 2; for (int k = num; k < num3; k++) { uint num4 = array[k - 1 >> 2][k - 1 & 3]; if (k % num == 0) { num4 = (AesEngine.SubWord(AesEngine.Shift(num4, 8)) ^ (uint)AesEngine.rcon[k / num - 1]); } else if (num > 6 && k % num == 4) { num4 = AesEngine.SubWord(num4); } array[k >> 2][k & 3] = (array[k - num >> 2][k - num & 3] ^ num4); } if (!forEncryption) { for (int l = 1; l < this.ROUNDS; l++) { uint[] array2 = array[l]; for (int m = 0; m < 4; m++) { array2[m] = AesEngine.Inv_Mcol(array2[m]); } } } return(array); }
// Token: 0x06000124 RID: 292 RVA: 0x000093FC File Offset: 0x000075FC private uint[][] GenerateWorkingKey(byte[] key, bool forEncryption) { int num = key.Length; if (num < 16 || num > 32 || (num & 7) != 0) { throw new ArgumentException("Key length not 128/192/256 bits."); } int num2 = num >> 2; this.ROUNDS = num2 + 6; uint[][] array = new uint[this.ROUNDS + 1][]; for (int i = 0; i <= this.ROUNDS; i++) { array[i] = new uint[4]; } switch (num2) { case 4: { uint num3 = Pack.LE_To_UInt32(key, 0); array[0][0] = num3; uint num4 = Pack.LE_To_UInt32(key, 4); array[0][1] = num4; uint num5 = Pack.LE_To_UInt32(key, 8); array[0][2] = num5; uint num6 = Pack.LE_To_UInt32(key, 12); array[0][3] = num6; for (int j = 1; j <= 10; j++) { uint num7 = AesEngine.SubWord(AesEngine.Shift(num6, 8)) ^ (uint)AesEngine.rcon[j - 1]; num3 ^= num7; array[j][0] = num3; num4 ^= num3; array[j][1] = num4; num5 ^= num4; array[j][2] = num5; num6 ^= num5; array[j][3] = num6; } goto IL_4EC; } case 6: { uint num8 = Pack.LE_To_UInt32(key, 0); array[0][0] = num8; uint num9 = Pack.LE_To_UInt32(key, 4); array[0][1] = num9; uint num10 = Pack.LE_To_UInt32(key, 8); array[0][2] = num10; uint num11 = Pack.LE_To_UInt32(key, 12); array[0][3] = num11; uint num12 = Pack.LE_To_UInt32(key, 16); array[1][0] = num12; uint num13 = Pack.LE_To_UInt32(key, 20); array[1][1] = num13; uint num14 = 1U; uint num15 = AesEngine.SubWord(AesEngine.Shift(num13, 8)) ^ num14; num14 <<= 1; num8 ^= num15; array[1][2] = num8; num9 ^= num8; array[1][3] = num9; num10 ^= num9; array[2][0] = num10; num11 ^= num10; array[2][1] = num11; num12 ^= num11; array[2][2] = num12; num13 ^= num12; array[2][3] = num13; for (int k = 3; k < 12; k += 3) { num15 = (AesEngine.SubWord(AesEngine.Shift(num13, 8)) ^ num14); num14 <<= 1; num8 ^= num15; array[k][0] = num8; num9 ^= num8; array[k][1] = num9; num10 ^= num9; array[k][2] = num10; num11 ^= num10; array[k][3] = num11; num12 ^= num11; array[k + 1][0] = num12; num13 ^= num12; array[k + 1][1] = num13; num15 = (AesEngine.SubWord(AesEngine.Shift(num13, 8)) ^ num14); num14 <<= 1; num8 ^= num15; array[k + 1][2] = num8; num9 ^= num8; array[k + 1][3] = num9; num10 ^= num9; array[k + 2][0] = num10; num11 ^= num10; array[k + 2][1] = num11; num12 ^= num11; array[k + 2][2] = num12; num13 ^= num12; array[k + 2][3] = num13; } num15 = (AesEngine.SubWord(AesEngine.Shift(num13, 8)) ^ num14); num8 ^= num15; array[12][0] = num8; num9 ^= num8; array[12][1] = num9; num10 ^= num9; array[12][2] = num10; num11 ^= num10; array[12][3] = num11; goto IL_4EC; } case 8: { uint num16 = Pack.LE_To_UInt32(key, 0); array[0][0] = num16; uint num17 = Pack.LE_To_UInt32(key, 4); array[0][1] = num17; uint num18 = Pack.LE_To_UInt32(key, 8); array[0][2] = num18; uint num19 = Pack.LE_To_UInt32(key, 12); array[0][3] = num19; uint num20 = Pack.LE_To_UInt32(key, 16); array[1][0] = num20; uint num21 = Pack.LE_To_UInt32(key, 20); array[1][1] = num21; uint num22 = Pack.LE_To_UInt32(key, 24); array[1][2] = num22; uint num23 = Pack.LE_To_UInt32(key, 28); array[1][3] = num23; uint num24 = 1U; uint num25; for (int l = 2; l < 14; l += 2) { num25 = (AesEngine.SubWord(AesEngine.Shift(num23, 8)) ^ num24); num24 <<= 1; num16 ^= num25; array[l][0] = num16; num17 ^= num16; array[l][1] = num17; num18 ^= num17; array[l][2] = num18; num19 ^= num18; array[l][3] = num19; num25 = AesEngine.SubWord(num19); num20 ^= num25; array[l + 1][0] = num20; num21 ^= num20; array[l + 1][1] = num21; num22 ^= num21; array[l + 1][2] = num22; num23 ^= num22; array[l + 1][3] = num23; } num25 = (AesEngine.SubWord(AesEngine.Shift(num23, 8)) ^ num24); num16 ^= num25; array[14][0] = num16; num17 ^= num16; array[14][1] = num17; num18 ^= num17; array[14][2] = num18; num19 ^= num18; array[14][3] = num19; goto IL_4EC; } } throw new InvalidOperationException("Should never get here"); IL_4EC: if (!forEncryption) { for (int m = 1; m < this.ROUNDS; m++) { uint[] array2 = array[m]; for (int n = 0; n < 4; n++) { array2[n] = AesEngine.Inv_Mcol(array2[n]); } } } return(array); }