// Token: 0x06000753 RID: 1875 RVA: 0x0002FF98 File Offset: 0x0002E198 public static byte[] InitKey(byte[] key, byte[] data, int size) { YSDecrypt._dynamicKeyIndex = 0; int num = (size >= 2048) ? 256 : (size >> 3); uint num2 = (uint)((num ^ 3) & num); byte[] array = new byte[16]; Buffer.BlockCopy(key, 0, array, 0, 16); byte[] array2 = BH3ES.BH3ESDecrypt(array); for (int i = 0; i < 16; i++) { array2[i] ^= YSKey.XorKey[i]; } ulong num3 = ulong.MaxValue; ulong num4 = 0UL; ulong num5 = 0UL; ulong num6 = 0UL; byte[] result; using (BinaryStream binaryStream = new BinaryStream(data, BinaryAccess.ReadWrite, null)) { int num7 = 0; while ((long)num7 < (long)((ulong)num2)) { num3 ^= binaryStream.ReadUInt64(BinaryEndian.LittleEndian); num4 ^= binaryStream.ReadUInt64(BinaryEndian.LittleEndian); num5 ^= binaryStream.ReadUInt64(BinaryEndian.LittleEndian); num6 ^= binaryStream.ReadUInt64(BinaryEndian.LittleEndian); num7 += 4; } num3 ^= (num4 ^ num5 ^ num6); if ((ulong)num2 != (ulong)((long)num)) { long num8 = (long)num - (long)((ulong)num2); int num9 = 0; while ((long)num9 < num8) { num3 ^= binaryStream.ReadUInt64(BinaryEndian.LittleEndian); num9++; } } ulong num10 = BitConverter.ToUInt64(array2, 0); ulong num11 = BitConverter.ToUInt64(array2, 8); using (BinaryStream binaryStream2 = YSDecrypt.InitKeyData(num10 ^ num11 ^ num3 ^ 7936877569879298522UL ^ 11567864270080435830UL)) { using (BinaryStream binaryStream3 = new BinaryStream(new byte[4096], BinaryAccess.ReadWrite, null)) { for (int j = 0; j < 512; j++) { ulong dynamicKey = YSDecrypt.GetDynamicKey(binaryStream2); binaryStream3.WriteUInt64(dynamicKey, BinaryEndian.LittleEndian); } result = binaryStream3.ToArray(); } } } return(result); }
// Token: 0x060006FC RID: 1788 RVA: 0x0002E814 File Offset: 0x0002CA14 private static void TransformMatrix(ref byte[] keyData, ref byte[] matrixData) { for (int i = 0; i < keyData.Length; i++) { uint num = 31U * (BH3ES.GetDynamicKey() % 31U) + 3U + (uint)((byte)(BH3ES.GetDynamicKey() & 63U)); for (int j = 0; j < 16; j++) { matrixData[i * 16 + j] = BH3Key.MatrixKey[(int)(checked ((IntPtr)(unchecked ((long)(2 * j) + (long)((ulong)num)))))]; } byte b = keyData[i]; for (int k = 1; k < 16; k++) { b ^= matrixData[i * 16 + k]; } matrixData[i * 16] = b; } }
// Token: 0x060006FA RID: 1786 RVA: 0x0002E6B8 File Offset: 0x0002C8B8 public static byte[] BH3ESDecrypt(byte[] keyData) { if (keyData.Length != 16) { throw new Exception("BH3ESDecrypt keyData Length is not 128bit"); } byte[] array = new byte[256]; int i = 1; BH3ES.TransformMatrix(ref keyData, ref array); BH3ES.XorMatrix(ref array); while (i < 10) { BH3ES.XorRoundKey(ref keyData, ref array); BH3ES.TransformMatrix(ref keyData, ref array); BH3ES.XorMatrix(ref array, i << 8); i++; } BH3ES.MatrixToColumnKey(ref keyData, ref array); BH3ES.TransformMatrix(ref keyData, ref array); BH3ES.XorMatrix(ref array, i << 8); BH3ES.MatrixToKey(ref keyData, ref array); return(keyData); }