On Sat, Nov 12, 2005 at 03:29:24PM -0500, Nicolas Pitre wrote: > > Looks fine indeed.
Thanks. I ended up moving src = data out of the if clause as well. So this is what I committed in the end. Cheers, -- Visit Openswan at http://www.openswan.org/ Email: Herbert Xu ~{PmV>HI~} <[EMAIL PROTECTED]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
0bca426e18e7626f8167bedecbd8118887d21c23 diff --git a/crypto/sha1.c b/crypto/sha1.c --- a/crypto/sha1.c +++ b/crypto/sha1.c @@ -50,22 +50,31 @@ static void sha1_update(void *ctx, const { 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); }
diff --git a/crypto/sha1.c b/crypto/sha1.c --- a/crypto/sha1.c +++ b/crypto/sha1.c @@ -49,32 +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; + unsigned int partial, done; const u8 *src; - j = (sctx->count >> 3) & 0x3f; + partial = (sctx->count >> 3) & 0x3f; sctx->count += len << 3; - i = 0; + done = 0; src = data; - if ((j + len) > 63) { + if ((partial + len) > 63) { u32 temp[SHA_WORKSPACE_WORDS]; - if (j) { - memcpy(&sctx->buffer[j], data, (i = 64-j)); + if (partial) { + done = 64 - partial; + memcpy(sctx->buffer + partial, data, done); src = sctx->buffer; } do { sha_transform(sctx->state, src, temp); - i += 64; - src = &data[i]; - } while (i + 63 < len); + done += 64; + src = data + done; + } while (done + 63 < len); memset(temp, 0, sizeof(temp)); - j = 0; + partial = 0; } - memcpy(&sctx->buffer[j], src, len - i); + memcpy(sctx->buffer + partial, src, len - done); }