diff options
author | Nicolas Pitre <nico@cam.org> | 2005-11-12 18:47:20 -0500 |
---|---|---|
committer | David S. Miller <davem@sunset.davemloft.net> | 2006-01-09 17:15:41 -0500 |
commit | cfa8d17cc836905ad174fd924701b352585d62f1 (patch) | |
tree | 6c966440661a678aea2082cf72c1bee0886a0a57 | |
parent | c8a19c91b5b488fed8cce04200a84c6a35c0bf0c (diff) |
[CRYPTO] sha1: Avoid useless memcpy()
The current code unconditionally copy the first block for every call to
sha1_update(). This can be avoided if there is no pending partial block.
This is always the case on the first call to sha1_update() (if the length
is >= 64 of course.
Furthermore, temp does need to be called if sha_transform is never invoked.
Also consolidate the sha_transform calls into one to reduce code size.
Signed-off-by: Nicolas Pitre <nico@cam.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r-- | crypto/sha1.c | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/crypto/sha1.c b/crypto/sha1.c index c686e7826174..292dcc13ff92 100644 --- a/crypto/sha1.c +++ b/crypto/sha1.c | |||
@@ -50,22 +50,31 @@ static void sha1_update(void *ctx, const u8 *data, unsigned int len) | |||
50 | { | 50 | { |
51 | struct sha1_ctx *sctx = ctx; | 51 | struct sha1_ctx *sctx = ctx; |
52 | unsigned int i, j; | 52 | unsigned int i, j; |
53 | u32 temp[SHA_WORKSPACE_WORDS]; | 53 | const u8 *src; |
54 | 54 | ||
55 | j = (sctx->count >> 3) & 0x3f; | 55 | j = (sctx->count >> 3) & 0x3f; |
56 | sctx->count += len << 3; | 56 | sctx->count += len << 3; |
57 | i = 0; | ||
58 | src = data; | ||
57 | 59 | ||
58 | if ((j + len) > 63) { | 60 | if ((j + len) > 63) { |
59 | memcpy(&sctx->buffer[j], data, (i = 64-j)); | 61 | u32 temp[SHA_WORKSPACE_WORDS]; |
60 | sha_transform(sctx->state, sctx->buffer, temp); | 62 | |
61 | for ( ; i + 63 < len; i += 64) { | 63 | if (j) { |
62 | sha_transform(sctx->state, &data[i], temp); | 64 | memcpy(&sctx->buffer[j], data, (i = 64-j)); |
65 | src = sctx->buffer; | ||
63 | } | 66 | } |
67 | |||
68 | do { | ||
69 | sha_transform(sctx->state, src, temp); | ||
70 | i += 64; | ||
71 | src = &data[i]; | ||
72 | } while (i + 63 < len); | ||
73 | |||
74 | memset(temp, 0, sizeof(temp)); | ||
64 | j = 0; | 75 | j = 0; |
65 | } | 76 | } |
66 | else i = 0; | 77 | memcpy(&sctx->buffer[j], src, len - i); |
67 | memset(temp, 0, sizeof(temp)); | ||
68 | memcpy(&sctx->buffer[j], &data[i], len - i); | ||
69 | } | 78 | } |
70 | 79 | ||
71 | 80 | ||