Implementing XTEA

Hello.

I’m working on an XTEA implementation and have a few questions about my mode-of-operation functions (cipher block chain). My goal is to be compatible with some of the online XTEA tools I have found; namely, something like this when set to XTEA-CBC. That tool seems to do the heavy lifting server-side, so I can’t see what’s going on, but I’d like to know how it works with keys of any length. XTEA specifies a key length of 128 bits, so maybe this tool hashes your input string to 128b and uses that checksum as the key? Also, I’m trying to figure out where to include my IV (randomly-generated) in the ciphertext, if at all, so that decryption can happen successfully.

I’m attaching my current agent and device files. Oh yeah, and I just learned of squirrel’s “>>>” operator this morning, so I need to go through and replace my bitmask right-shift hacks in the {en,de}cryptblock() functions.

It’s funny that this forum software doesn’t allow us to upload files ending in “.nut”. :slight_smile:

Some of the other online implementations I’ve found either truncate the key to 16 characters (like this one) or force you to do that manually (like this one — just the raw block cipher). Maybe the tool I linked above does that, or maybe it just takes an MD5. hard to tell when the IV is obviously randomized (mash ‘encrypt’ to prove that).

Edit: Oops, the first link in this post isn’t even XTEA; it’s just normal TEA. Whoops :stuck_out_tongue:

I also looked at this python implementation. It only accepts keys of exactly 128 bits and plaintext messages with length of integer multiples of the block size. Boooooring. Clearly I’ll have to do some padding or similar, but I’m still trying to figure that out.