X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=crypto%2Fsha1.c;h=21571ed35b7ee7f90792a5f8b83ea2b42ff6cac6;hb=581249966ffeb0463bad1b0e087e1bb29ed53707;hp=c686e7826174fd3184328eeac58356b5dafd42f6;hpb=06ace7a9bafeb9047352707eb79e8eaa0dfdf5f2;p=powerpc.git diff --git a/crypto/sha1.c b/crypto/sha1.c index c686e78261..21571ed35b 100644 --- a/crypto/sha1.c +++ b/crypto/sha1.c @@ -49,23 +49,33 @@ static void sha1_init(void *ctx) 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]; + unsigned int partial, done; + const u8 *src; - j = (sctx->count >> 3) & 0x3f; - sctx->count += len << 3; + partial = sctx->count & 0x3f; + sctx->count += len; + done = 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); + if ((partial + len) > 63) { + u32 temp[SHA_WORKSPACE_WORDS]; + + if (partial) { + done = -partial; + memcpy(sctx->buffer + partial, data, done + 64); + src = sctx->buffer; } - j = 0; + + do { + sha_transform(sctx->state, src, temp); + done += 64; + src = data + done; + } while (done + 63 < len); + + memset(temp, 0, sizeof(temp)); + partial = 0; } - else i = 0; - memset(temp, 0, sizeof(temp)); - memcpy(&sctx->buffer[j], &data[i], len - i); + memcpy(sctx->buffer + partial, src, len - done); } @@ -78,10 +88,10 @@ static void sha1_final(void* ctx, u8 *out) __be64 bits; 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 */ - index = (sctx->count >> 3) & 0x3f; + index = sctx->count & 0x3f; padlen = (index < 56) ? (56 - index) : ((64+56) - index); sha1_update(sctx, padding, padlen);