Ejemplo n.º 1
0
        /// <summary>
        /// Applies Nexon's implementation of AES on the buffer
        /// </summary>
        /// <param name="buffer">The data to encrypt</param>
        /// <param name="amount">The amount of bytes to encrypt in the buffer</param>
        /// <param name="offset">The starting point in the buffer</param>
        private void Transform(ref byte[] buffer, int amount, int offset)
        {
            int remaining = amount - offset,
                length    = 0x5B0,
                start     = 0,
                index;

            byte[] realIV = new byte[sizeof(int) * 4],
            IVBytes = IV.Bytes;

            while (remaining > 0)
            {
                for (index = 0; index < realIV.Length; ++index)
                {
                    realIV[index] = IVBytes[index % 4];
                }

                if (remaining < length)
                {
                    length = remaining;
                }
                for (index = start; index < (start + length); ++index)
                {
                    if (((index - start) % realIV.Length) == 0)
                    {
                        AES.TransformBlock(ref realIV);
                    }

                    buffer[index + offset] ^= realIV[(index - start) % realIV.Length];
                }
                start     += length;
                remaining -= length;
                length     = 0x5B4;
            }
            IV.Shuffle();
        }