X-Git-Url: https://git.distorted.org.uk/u/mdw/catacomb/blobdiff_plain/ea937a0ebd081c146194a848ff3ca3829265a341..578a86d91941a0f722b87973d88e84ec2cf9a608:/tea.c diff --git a/tea.c b/tea.c index 90d97cb..97e92c4 100644 --- a/tea.c +++ b/tea.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: tea.c,v 1.1 2000/07/15 13:44:31 mdw Exp $ + * $Id: tea.c,v 1.3 2004/04/08 01:36:15 mdw Exp $ * * The Tiny Encryption Algorithm * @@ -27,14 +27,6 @@ * MA 02111-1307, USA. */ -/*----- Revision history --------------------------------------------------* - * - * $Log: tea.c,v $ - * Revision 1.1 2000/07/15 13:44:31 mdw - * New ciphers. - * - */ - /*----- Header files ------------------------------------------------------*/ #include @@ -76,8 +68,9 @@ void tea_init(tea_ctx *k, const void *buf, size_t sz) p = kb; } - k->ka = LOAD32(p + 0); k->kb = LOAD32(p + 4); - k->kc = LOAD32(p + 8); k->kd = LOAD32(p + 12); + k->ka = LOAD32(p + 0); k->kb = LOAD32(p + 4); + k->kc = LOAD32(p + 8); k->kd = LOAD32(p + 12); + k->r = 32; if (p == kb) BURN(kb); @@ -103,7 +96,7 @@ void tea_eblk(const tea_ctx *k, const uint32 *s, uint32 *d) uint32 n = 0; unsigned i; - for (i = 0; i < 32; i++) { + for (i = 0; i < k->r; i++) { n += DELTA; y = U32(y + (((z << 4) + ka) ^ (z + n) ^ ((z >> 5) + kb))); z = U32(z + (((y << 4) + kc) ^ (y + n) ^ ((y >> 5) + kd))); @@ -115,10 +108,10 @@ void tea_dblk(const tea_ctx *k, const uint32 *s, uint32 *d) { uint32 y = s[0], z = s[1]; uint32 ka = k->ka, kb = k->kb, kc = k->kc, kd = k->kd; - uint32 n = DELTA << 5; + uint32 n = DELTA * k->r; unsigned i; - for (i = 0; i < 32; i++) { + for (i = 0; i < k->r; i++) { z = U32(z - (((y << 4) + kc) ^ (y + n) ^ ((y >> 5) + kd))); y = U32(y - (((z << 4) + ka) ^ (z + n) ^ ((z >> 5) + kb))); n -= DELTA;