Commit fa9b98fd authored by Nicolas Pitre's avatar Nicolas Pitre Committed by David S. Miller

[CRYPTO] sha1: Avoid shifting count left and right

This patch avoids shifting the count left and right needlessly for each
call to sha1_update().  It instead can be done only once at the end in
sha1_final().

Keeping the previous test example (sha1_update() successively called with
len=64), a 1.3% performance increase can be observed on i386, or 0.2% on
ARM.  The generated code is also smaller on ARM.
Signed-off-by: default avatarNicolas Pitre <nico@cam.org>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 9d70a6c8
...@@ -52,8 +52,8 @@ static void sha1_update(void *ctx, const u8 *data, unsigned int len) ...@@ -52,8 +52,8 @@ static void sha1_update(void *ctx, const u8 *data, unsigned int len)
unsigned int partial, done; unsigned int partial, done;
const u8 *src; const u8 *src;
partial = (sctx->count >> 3) & 0x3f; partial = sctx->count & 0x3f;
sctx->count += len << 3; sctx->count += len;
done = 0; done = 0;
src = data; src = data;
...@@ -88,10 +88,10 @@ static void sha1_final(void* ctx, u8 *out) ...@@ -88,10 +88,10 @@ static void sha1_final(void* ctx, u8 *out)
__be64 bits; __be64 bits;
static const u8 padding[64] = { 0x80, }; static const u8 padding[64] = { 0x80, };
bits = cpu_to_be64(sctx->count); bits = cpu_to_be64(sctx->count << 3);
/* Pad out to 56 mod 64 */ /* Pad out to 56 mod 64 */
index = (sctx->count >> 3) & 0x3f; index = sctx->count & 0x3f;
padlen = (index < 56) ? (56 - index) : ((64+56) - index); padlen = (index < 56) ? (56 - index) : ((64+56) - index);
sha1_update(sctx, padding, padlen); sha1_update(sctx, padding, padlen);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment