summaryrefslogtreecommitdiffstats
path: root/crypto/sha1.c
diff options
context:
space:
mode:
authorNicolas Pitre <nico@cam.org>2005-11-13 10:47:20 +1100
committerDavid S. Miller <davem@sunset.davemloft.net>2006-01-09 14:15:41 -0800
commitcfa8d17cc836905ad174fd924701b352585d62f1 (patch)
tree6c966440661a678aea2082cf72c1bee0886a0a57 /crypto/sha1.c
parentc8a19c91b5b488fed8cce04200a84c6a35c0bf0c (diff)
downloadop-kernel-dev-cfa8d17cc836905ad174fd924701b352585d62f1.zip
op-kernel-dev-cfa8d17cc836905ad174fd924701b352585d62f1.tar.gz
[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>
Diffstat (limited to 'crypto/sha1.c')
-rw-r--r--crypto/sha1.c25
1 files changed, 17 insertions, 8 deletions
diff --git a/crypto/sha1.c b/crypto/sha1.c
index c686e78..292dcc1 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)
{
struct sha1_ctx *sctx = ctx;
unsigned int i, j;
- u32 temp[SHA_WORKSPACE_WORDS];
+ const u8 *src;
j = (sctx->count >> 3) & 0x3f;
sctx->count += len << 3;
+ i = 0;
+ src = data;
if ((j + len) > 63) {
- memcpy(&sctx->buffer[j], data, (i = 64-j));
- sha_transform(sctx->state, sctx->buffer, temp);
- for ( ; i + 63 < len; i += 64) {
- sha_transform(sctx->state, &data[i], temp);
+ u32 temp[SHA_WORKSPACE_WORDS];
+
+ if (j) {
+ memcpy(&sctx->buffer[j], data, (i = 64-j));
+ src = sctx->buffer;
}
+
+ do {
+ sha_transform(sctx->state, src, temp);
+ i += 64;
+ src = &data[i];
+ } while (i + 63 < len);
+
+ memset(temp, 0, sizeof(temp));
j = 0;
}
- else i = 0;
- memset(temp, 0, sizeof(temp));
- memcpy(&sctx->buffer[j], &data[i], len - i);
+ memcpy(&sctx->buffer[j], src, len - i);
}
OpenPOWER on IntegriCloud