1

I cribbed the public domain TEA source from wikipedia ( http://en.wikipedia.org/wiki/Tiny_Encryption_Algorithm ), looks like this -

uint32_t v0=v[0], v1=v[1], sum=0, i;           /* set up */

uint32_t delta=0x9e3779b9;                     /* a key schedule constant */

uint32_t k0=k[0], k1=k[1], k2=k[2], k3=k[3];   /* cache key */

for (i = 0; i < 32; i++) { /* basic cycle start */
   sum += delta;
   v0 += ((v1 << 4) + k0) ^ (v1 + sum) ^ ((v1 >> 5) + k1);
   v1 += ((v0 << 4) + k2) ^ (v0 + sum) ^ ((v0 >> 5) + k3);
} /* end cycle */
v[0] = v0;
v[1] = v1;
}

It works fine, but I am trying to understand crypto a little more so I am tweaking and exploring. I would have thought that changing the number of rounds (32 in the example) would work great as long as the decrypt function changed to use the same number. However, I bumped it to 50 on each side and now my output does not match the initial plaintext. Thinking that may be too high, I tried 20; no dice. Then I thought to try very close, set it to 31 then 33, and neither worked.

Is the number of rounds in TEA required to be 32 for some reason? I cannot see why, but I am far from expert.

  • 1
    There's probably something else you didn't change that's still assuming 32 rounds are used and that's throwing decryption off. – Thomas Dec 27 '13 at 14:38
  • 5
    This question appears to be off-topic. It's more suited at Crypto.SE. – Adi Dec 27 '13 at 15:00
  • @Adnan feel free to move, not sure how or if I have privs. There sure are a lot of stack exchanges. – blah44 Dec 27 '13 at 15:08
3

Sure enough Thomas, the decryption constant 0xC6EF3720 is simply 0x9e3779b9*ROUNDS and needs to be adjusted accordingly.

  • Well, in all fairness, now that I read it again, my comment was somewhat tautological. Glad you found the problem though! – Thomas Dec 27 '13 at 17:41

Not the answer you're looking for? Browse other questions tagged or ask your own question.