From 054e9e78053bf9624c434d2c4e30c6763c540284 Mon Sep 17 00:00:00 2001 From: Ken Raeburn Date: Sun, 1 May 2005 08:20:56 +0000 Subject: [PATCH] * md4.c (Transform) [CONFIG_SMALL]: Roll loops for each round git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@17207 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/crypto/md4/ChangeLog | 4 ++++ src/lib/crypto/md4/md4.c | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/lib/crypto/md4/ChangeLog b/src/lib/crypto/md4/ChangeLog index 8968b27f2..06eac6c69 100644 --- a/src/lib/crypto/md4/ChangeLog +++ b/src/lib/crypto/md4/ChangeLog @@ -1,3 +1,7 @@ +2005-05-01 Ken Raeburn + + * md4.c (Transform) [CONFIG_SMALL]: Roll loops for each round. + 2004-02-18 Ken Raeburn * md4.c: Use ANSI C style function definitions. diff --git a/src/lib/crypto/md4/md4.c b/src/lib/crypto/md4/md4.c index 3541bce56..5e95d359f 100644 --- a/src/lib/crypto/md4/md4.c +++ b/src/lib/crypto/md4/md4.c @@ -167,6 +167,28 @@ static void Transform (krb5_ui_4 *buf, krb5_ui_4 *in) { register krb5_ui_4 a = buf[0], b = buf[1], c = buf[2], d = buf[3]; +#ifdef CONFIG_SMALL + int i; +#define ROTATE { krb5_ui_4 temp; temp = d, d = c, c = b, b = a, a = temp; } + for (i = 0; i < 16; i++) { + static const unsigned char round1consts[] = { 3, 7, 11, 19, }; + FF (a, b, c, d, in[i], round1consts[i%4]); ROTATE; + } + for (i = 0; i < 16; i++) { + static const unsigned char round2indices[] = { + 0,4,8,12,1,5,9,13,2,6,10,14,3,7,11,15 + }; + static const unsigned char round2consts[] = { 3, 5, 9, 13 }; + GG (a, b, c, d, in[round2indices[i]], round2consts[i%4]); ROTATE; + } + for (i = 0; i < 16; i++) { + static const unsigned char round3indices[] = { + 0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15 + }; + static const unsigned char round3consts[] = { 3, 9, 11, 15 }; + HH (a, b, c, d, in[round3indices[i]], round3consts[i%4]); ROTATE; + } +#else /* Round 1 */ FF (a, b, c, d, in[ 0], 3); FF (d, a, b, c, in[ 1], 7); @@ -220,6 +242,7 @@ static void Transform (krb5_ui_4 *buf, krb5_ui_4 *in) HH (d, a, b, c, in[11], 9); HH (c, d, a, b, in[ 7], 11); HH (b, c, d, a, in[15], 15); +#endif buf[0] += a; buf[1] += b; -- 2.26.2