[PATCH 3/5] crypto/sha1.c: move related code together

From: Nicolas Pitre
Date: Mon Oct 24 2005 - 12:58:19 EST



The final length buffer construction in sha1_final() is moved just before
where it is used. This makes for slightly more readable code and actually
more efficient as well since the compiler doesn't have to bother preserving
the bits array across the first call to sha1_update(). In fact it makes for
slightly smaller stack usage on i386 or slightly smaller code size on ARM
(depending on your GCC version that could vary of course).

Signed-off-by: Nicolas Pitre <nico@xxxxxxx>

Index: linux-2.6/crypto/sha1.c
===================================================================
--- linux-2.6.orig/crypto/sha1.c
+++ linux-2.6/crypto/sha1.c
@@ -76,11 +76,17 @@
{
struct sha1_ctx *sctx = ctx;
u32 i, j, index, padlen;
- u64 t;
- u8 bits[8] = { 0, };
+ u64 t, count = sctx->count;
+ u8 bits[8];
static const u8 padding[64] = { 0x80, };

- t = sctx->count << 3;
+ /* Pad out to 56 mod 64 */
+ index = count & 0x3f;
+ padlen = (index < 56) ? (56 - index) : ((64+56) - index);
+ sha1_update(sctx, padding, padlen);
+
+ /* Append length */
+ t = count << 3;
bits[7] = 0xff & t; t>>=8;
bits[6] = 0xff & t; t>>=8;
bits[5] = 0xff & t; t>>=8;
@@ -89,13 +95,6 @@
bits[2] = 0xff & t; t>>=8;
bits[1] = 0xff & t; t>>=8;
bits[0] = 0xff & t;
-
- /* Pad out to 56 mod 64 */
- index = sctx->count & 0x3f;
- padlen = (index < 56) ? (56 - index) : ((64+56) - index);
- sha1_update(sctx, padding, padlen);
-
- /* Append length */
sha1_update(sctx, bits, sizeof bits);

/* Store state in digest */
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/