From: Paul Mackerras Date: Sun, 21 May 2006 07:21:28 +0000 (+0000) Subject: Avoid bus errors from unaligned input to SHA1Update X-Git-Tag: ppp-2.4.7~125 X-Git-Url: http://git.ozlabs.org/?p=ppp.git;a=commitdiff_plain;h=a89d7bd8e80c08aa0793e523ffcc5ca5af9d03e2 Avoid bus errors from unaligned input to SHA1Update --- diff --git a/pppd/sha1.c b/pppd/sha1.c index da142f1..d18a19c 100644 --- a/pppd/sha1.c +++ b/pppd/sha1.c @@ -121,18 +121,17 @@ SHA1_Update(SHA1_CTX *context, const unsigned char *data, unsigned int len) j = (context->count[0] >> 3) & 63; if ((context->count[0] += len << 3) < (len << 3)) context->count[1]++; context->count[1] += (len >> 29); - if ((j + len) > 63) { - memcpy(&context->buffer[j], data, (i = 64-j)); + i = 64 - j; + while (len >= i) { + memcpy(&context->buffer[j], data, i); SHA1_Transform(context->state, context->buffer); - for ( ; i + 63 < len; i += 64) { - SHA1_Transform(context->state, &data[i]); - } + data += i; + len -= i; + i = 64; j = 0; } - else - i = 0; - memcpy(&context->buffer[j], &data[i], len - i); + memcpy(&context->buffer[j], data, len); }