From d36cd2408f4e6104ce325cc14a3b302e713c72e6 Mon Sep 17 00:00:00 2001 From: mdw Date: Sat, 29 Jul 2000 09:56:47 +0000 Subject: [PATCH] Allow the number of rounds to be configured. This isn't exported through the gcipher interface, but it may be useful anyway. --- tea.c | 17 +++++++++++------ tea.h | 7 ++++++- xtea.c | 17 +++++++++++------ xtea.h | 7 ++++++- 4 files changed, 34 insertions(+), 14 deletions(-) diff --git a/tea.c b/tea.c index 90d97cb..2043337 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.2 2000/07/29 09:56:47 mdw Exp $ * * The Tiny Encryption Algorithm * @@ -30,6 +30,10 @@ /*----- Revision history --------------------------------------------------* * * $Log: tea.c,v $ + * Revision 1.2 2000/07/29 09:56:47 mdw + * Allow the number of rounds to be configured. This isn't exported + * through the gcipher interface, but it may be useful anyway. + * * Revision 1.1 2000/07/15 13:44:31 mdw * New ciphers. * @@ -76,8 +80,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 +108,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 +120,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; diff --git a/tea.h b/tea.h index c227ec5..38a8da1 100644 --- a/tea.h +++ b/tea.h @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: tea.h,v 1.1 2000/07/15 13:44:31 mdw Exp $ + * $Id: tea.h,v 1.2 2000/07/29 09:56:47 mdw Exp $ * * The Tiny Encryption Algorithm * @@ -30,6 +30,10 @@ /*----- Revision history --------------------------------------------------* * * $Log: tea.h,v $ + * Revision 1.2 2000/07/29 09:56:47 mdw + * Allow the number of rounds to be configured. This isn't exported + * through the gcipher interface, but it may be useful anyway. + * * Revision 1.1 2000/07/15 13:44:31 mdw * New ciphers. * @@ -69,6 +73,7 @@ extern const octet tea_keysz[]; /*----- Data structures ---------------------------------------------------*/ typedef struct tea_ctx { + unsigned r; uint32 ka, kb, kc, kd; } tea_ctx; diff --git a/xtea.c b/xtea.c index 1d65c4d..32702fe 100644 --- a/xtea.c +++ b/xtea.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: xtea.c,v 1.1 2000/07/15 13:44:31 mdw Exp $ + * $Id: xtea.c,v 1.2 2000/07/29 09:56:47 mdw Exp $ * * The Extended Tiny Encryption Algorithm * @@ -30,6 +30,10 @@ /*----- Revision history --------------------------------------------------* * * $Log: xtea.c,v $ + * Revision 1.2 2000/07/29 09:56:47 mdw + * Allow the number of rounds to be configured. This isn't exported + * through the gcipher interface, but it may be useful anyway. + * * Revision 1.1 2000/07/15 13:44:31 mdw * New ciphers. * @@ -76,8 +80,9 @@ void xtea_init(xtea_ctx *k, const void *buf, size_t sz) p = kb; } - k->k[0] = LOAD32(p + 0); k->k[1] = LOAD32(p + 4); - k->k[2] = LOAD32(p + 8); k->k[3] = LOAD32(p + 12); + k->k[0] = LOAD32(p + 0); k->k[1] = LOAD32(p + 4); + k->k[2] = LOAD32(p + 8); k->k[3] = LOAD32(p + 12); + k->r = 32; if (p == kb) BURN(kb); @@ -102,7 +107,7 @@ void xtea_eblk(const xtea_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++) { y = U32(y + ((((z << 4) ^ (z >> 5)) + z) ^ (n + k->k[n & 3]))); n += DELTA; z = U32(z + ((((y << 4) ^ (y >> 5)) + y) ^ (n + k->k[(n >> 11) & 3]))); @@ -113,10 +118,10 @@ void xtea_eblk(const xtea_ctx *k, const uint32 *s, uint32 *d) void xtea_dblk(const xtea_ctx *k, const uint32 *s, uint32 *d) { uint32 y = s[0], z = s[1]; - 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) ^ (y >> 5)) + y) ^ (n + k->k[(n >> 11) & 3]))); n -= DELTA; y = U32(y - ((((z << 4) ^ (z >> 5)) + z) ^ (n + k->k[n & 3]))); diff --git a/xtea.h b/xtea.h index 94f8d2c..af6c3a0 100644 --- a/xtea.h +++ b/xtea.h @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: xtea.h,v 1.2 2000/07/15 13:47:14 mdw Exp $ + * $Id: xtea.h,v 1.3 2000/07/29 09:56:47 mdw Exp $ * * The Extended Tiny Encryption Algorithm * @@ -30,6 +30,10 @@ /*----- Revision history --------------------------------------------------* * * $Log: xtea.h,v $ + * Revision 1.3 2000/07/29 09:56:47 mdw + * Allow the number of rounds to be configured. This isn't exported + * through the gcipher interface, but it may be useful anyway. + * * Revision 1.2 2000/07/15 13:47:14 mdw * Whoops. Fix the purpose comment. * @@ -72,6 +76,7 @@ extern const octet xtea_keysz[]; /*----- Data structures ---------------------------------------------------*/ typedef struct xtea_ctx { + unsigned r; uint32 k[4]; } xtea_ctx; -- 2.11.0