Here's the XTEA functions in C#, in case someone needs them. For third party developers, you'll have to read they key from the clients memory.
Code
public unsafe static bool XteaEncrypt(ref byte[] buffer, ref int length, int index, uint[] key)
{
if (key == null)
return false;
int msgSize = length - index;
int pad = msgSize % 8;
if (pad > 0)
{
msgSize += (8 - pad);
length = index + msgSize;
}
fixed (byte* bufferPtr = buffer)
{
uint* words = (uint*)(bufferPtr + index);
for (int pos = 0; pos < msgSize / 4; pos += 2)
{
uint x_sum = 0, x_delta = 0x9e3779b9, x_count = 32;
while (x_count-- > 0)
{
words[pos] += (words[pos+1] << 4 ^ words[pos+1] >> 5) + words[pos+1] ^ x_sum
+ key[x_sum & 3];
x_sum += x_delta;
words[pos+1] += (words[pos] << 4 ^ words[pos] >> 5) + words[pos] ^ x_sum
+ key[x_sum >> 11 & 3];
}
}
}
return true;
}
public unsafe static bool XteaDecrypt(ref byte[] buffer, ref int length, int index, uint[] key)
{
if (length <= index || (length - index) % 8 > 0 || key == null)
return false;
fixed (byte* bufferPtr = buffer)
{
uint* words = (uint*)(bufferPtr + index);
int msgSize = length - index;
for (int pos = 0; pos < msgSize / 4; pos += 2)
{
uint x_count = 32, x_sum = 0xC6EF3720, x_delta = 0x9E3779B9;
while (x_count-- > 0)
{
words[pos + 1] -= (words[pos] << 4 ^ words[pos] >> 5) + words[pos] ^ x_sum
+ key[x_sum >> 11 & 3];
x_sum -= x_delta;
words[pos] -= (words[pos + 1] << 4 ^ words[pos + 1] >> 5) + words[pos + 1] ^ x_sum
+ key[x_sum & 3];
}
}
}
length = (int)(BitConverter.ToUInt16(buffer, index) + 2 + index);
return true;
}