Jujusoft

TEA Encryption

I take no credit for the TEA algorithm, and in fact i can not even explain why it works. I just trust it because it seems to do a good job. Please go here to find out more about how it works.

JujuEdit and JujuStash support an encrypted text format (using file extension *.xtx). The encryption used is known as the "Tiny Encryption Algorithm - new variant", a system which encodes 64-bit chunks at a time using a 128-bit key. TEA was created by David Wheeler and Roger Needham at the Computer Laboratory of Cambridge University, and more info is here

I like it because it is simple and fast, and apparently pretty secure. I've included source code so that technically minded people can evaluate the security of this method, and let me know if there's any problem with it.

Because TEA processes only 64-bit (8 byte) chunks of data, i use the following method to apply the algorithm to an arbitrarily long sequence of bytes. Note the inclusion of an auxillary variable (Aux), added to prevent stretches of identical 64-bit chunks being enciphered in the same way... something that could reveal information about the structure of a file.

To Encrypt:

  1. Hash password (or phrase) into a 128-bit key
  2. XOR 8 byte chunk of source with Aux value (chunk #)
  3. Encipher chunk with 128-bit Key
  4. Increment Aux value
  5. Repeat steps 2-4 for each whole 8 byte chunk
  6. If any bytes are left over, Encipher 8 null bytes using key, and XOR with remaining bytes.*

To Decrypt:

  1. Hash password (or phrase) into a 128-bit key
  2. Decipher 8 byte chunk of source with 128-bit Key
  3. XOR chunk with Aux value (chunk #)
  4. Increment Aux value
  5. Repeat steps 2-4 for each whole 8 byte chunk
  6. If any bytes are left over, Encipher 8 null bytes using key, and XOR with remaining bytes.*

* The reason for not simply padding the raw file with zero bytes is that the encrypted file length would be different from the raw file length,


 View sample C++ code


References:

 http://vader.brad.ac.uk/tea/tea.shtml - the page i used for reference