From 830c80a98a4b65a2f41e23513ed2faf73818a4f0 Mon Sep 17 00:00:00 2001 From: Ken Raeburn Date: Sun, 1 May 2005 08:42:12 +0000 Subject: [PATCH] * shs.c (SHSTransform) [CONFIG_SMALL]: Roll loops for each round git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@17209 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/crypto/sha1/ChangeLog | 4 ++++ src/lib/crypto/sha1/shs.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/lib/crypto/sha1/ChangeLog b/src/lib/crypto/sha1/ChangeLog index 487f09e40..9da70f9c4 100644 --- a/src/lib/crypto/sha1/ChangeLog +++ b/src/lib/crypto/sha1/ChangeLog @@ -1,3 +1,7 @@ +2005-05-01 Ken Raeburn + + * shs.c (SHSTransform) [CONFIG_SMALL]: Roll loops for each round. + 2004-02-18 Ken Raeburn * shs.c: Use ANSI C style function definitions. diff --git a/src/lib/crypto/sha1/shs.c b/src/lib/crypto/sha1/shs.c index f97856ee4..a6d3c9f8b 100644 --- a/src/lib/crypto/sha1/shs.c +++ b/src/lib/crypto/sha1/shs.c @@ -112,6 +112,32 @@ void SHSTransform(SHS_LONG *digest, const SHS_LONG *data) E = digest[ 4 ]; memcpy(eData, data, sizeof (eData)); +#ifdef CONFIG_SMALL + + { + int i; + SHS_LONG temp; + for (i = 0; i < 20; i++) { + SHS_LONG x = (i < 16) ? eData[i] : expand(eData, i); + subRound(A, B, C, D, E, f1, K1, x); + temp = E, E = D, D = C, C = B, B = A, A = temp; + } + for (i = 20; i < 40; i++) { + subRound(A, B, C, D, E, f2, K2, expand(eData, i)); + temp = E, E = D, D = C, C = B, B = A, A = temp; + } + for (i = 40; i < 60; i++) { + subRound(A, B, C, D, E, f3, K3, expand(eData, i)); + temp = E, E = D, D = C, C = B, B = A, A = temp; + } + for (i = 60; i < 80; i++) { + subRound(A, B, C, D, E, f4, K4, expand(eData, i)); + temp = E, E = D, D = C, C = B, B = A, A = temp; + } + } + +#else + /* Heavy mangling, in 4 sub-rounds of 20 interations each. */ subRound( A, B, C, D, E, f1, K1, eData[ 0 ] ); subRound( E, A, B, C, D, f1, K1, eData[ 1 ] ); @@ -197,6 +223,8 @@ void SHSTransform(SHS_LONG *digest, const SHS_LONG *data) subRound( C, D, E, A, B, f4, K4, expand( eData, 78 ) ); subRound( B, C, D, E, A, f4, K4, expand( eData, 79 ) ); +#endif + /* Build message digest */ digest[ 0 ] += A; digest[ 0 ] &= 0xffffffff; -- 2.26.2