summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Morton <akpm@osdl.org>2004-10-25 06:47:38 -0700
committerDavid S. Miller <davem@nuts.davemloft.net>2004-10-25 06:47:38 -0700
commite0abaebae36abff9e3dd6e9f8aac098c66542f18 (patch)
treed6401411bc0746d903463d0ef4039faabd13931e
parentbc30e521501808ab0241aba022377863e0274ee5 (diff)
[CRYPTO]: reduce sha512_transform() stack usage, speedup
Patch moves large temporary u64 W[80] from stack to ctx struct: * reduces stack usage by 640 bytes * saves one 640-byte memset() per sha512_transform() (we still do it after *all* iterations are done) * quite unexpectedly saves 1.6k of code on i386 because stack offsets now fit into 8bits and many stack addressing insns got 3 bytes smaller: # size sha512.o.org sha512.o text data bss dec hex filename 8281 372 0 8653 21cd sha512.o.org 6649 372 0 7021 1b6d sha512.o # objdump -d sha512.o.org | cut -b9- >sha512.d.org # objdump -d sha512.o | cut -b9- >sha512.d # diff -u sha512.d.org sha512.d [snip] Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--crypto/sha512.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/crypto/sha512.c b/crypto/sha512.c
index 763093b17c1e..6acaea9b7e2b 100644
--- a/crypto/sha512.c
+++ b/crypto/sha512.c
@@ -30,6 +30,7 @@ struct sha512_ctx {
u64 state[8];
u32 count[4];
u8 buf[128];
+ u64 W[80];
};
static inline u64 Ch(u64 x, u64 y, u64 z)
@@ -113,10 +114,9 @@ static inline void BLEND_OP(int I, u64 *W)
}
static void
-sha512_transform(u64 *state, const u8 *input)
+sha512_transform(u64 *state, u64 *W, const u8 *input)
{
u64 a, b, c, d, e, f, g, h, t1, t2;
- u64 W[80];
int i;
@@ -157,7 +157,6 @@ sha512_transform(u64 *state, const u8 *input)
/* erase our data */
a = b = c = d = e = f = g = h = t1 = t2 = 0;
- memset(W, 0, 80 * sizeof(u64));
}
static void
@@ -215,10 +214,10 @@ sha512_update(void *ctx, const u8 *data, unsigned int len)
/* Transform as many times as possible. */
if (len >= part_len) {
memcpy(&sctx->buf[index], data, part_len);
- sha512_transform(sctx->state, sctx->buf);
+ sha512_transform(sctx->state, sctx->W, sctx->buf);
for (i = part_len; i + 127 < len; i+=128)
- sha512_transform(sctx->state, &data[i]);
+ sha512_transform(sctx->state, sctx->W, &data[i]);
index = 0;
} else {
@@ -227,6 +226,9 @@ sha512_update(void *ctx, const u8 *data, unsigned int len)
/* Buffer remaining input */
memcpy(&sctx->buf[index], &data[i], len - i);
+
+ /* erase our data */
+ memset(sctx->W, 0, sizeof(sctx->W));
}
static void