예제 #1
0
        public void KDF()
        {
            // Decrypt packet salt
            if (ecmID != prevEcmID)
            {
                byte[] saltHmacKey = sha1.ComputeHash(F4FOldMethod.AppendBuf(sessionKey, packetIV));
                if (debug)
                {
                    Program.DebugLog("SaltHmacKey  : " + Hexlify(saltHmacKey));
                }
                shaSalt.Key = saltHmacKey;
                saltAesKey  = F4FOldMethod.BlockCopy(shaSalt.ComputeHash(hmacData1), 0, 16);
                if (debug)
                {
                    Program.DebugLog("SaltAesKey   : " + Hexlify(saltAesKey));
                }
                prevEcmID = ecmID;
            }
            if (debug)
            {
                Program.DebugLog("EncryptedSalt: " + Hexlify(packetSalt));
            }

            byte[] decryptedSalt = AesDecrypt(packetSalt, saltAesKey, packetIV);
            if (decryptedSalt == null)
            {
                Program.Quit("<c:Red>Error ocurred while decription salt of fagment.");
            }
            if (debug)
            {
                Program.DebugLog("DecryptedSalt: " + Hexlify(decryptedSalt));
            }
            decryptBytes = F4FOldMethod.ReadInt32(ref decryptedSalt, 0);
            if (debug)
            {
                Program.DebugLog("DecryptBytes : " + decryptBytes);
            }
            byte[] decryptedSalt2 = F4FOldMethod.BlockCopy(decryptedSalt, 4, 16);
            if (debug)
            {
                Program.DebugLog("DecryptedSalt: " + Hexlify(decryptedSalt2));
            }
            // Generate final packet decryption key
            byte[] finalHmacKey = sha1.ComputeHash(decryptedSalt2);
            if (debug)
            {
                Program.DebugLog("FinalHmacKey : " + Hexlify(finalHmacKey));
            }
            finalsha.Key = finalHmacKey;
            packetKey    = F4FOldMethod.BlockCopy(finalsha.ComputeHash(hmacData2), 0, 16);
            if (debug)
            {
                Program.DebugLog("PacketKey    : " + Hexlify(packetKey));
            }
        }