[PATCH] Fix PPC SHA1 routine for large input buffers
- From
Paul Mackerras <paulus@samba.org>
- Date
- Jun 18, 2006, 23:25 UTC
- Message-ID
- <17557.57564.267469.561683@cargo.ozlabs.ibm.com>
- In-Reply-To
- <Pine.LNX.4.64.0606181543270.5498@g5.osdl.org>
The PPC SHA1 routine had an overflow which meant that it gave incorrect results for input buffers >= 512MB. This fixes it by ensuring that the update of the total length in bits is done using 64-bit arithmetic.
Signed-off-by: Paul Mackerras <paulus@samba.org> --- Linus Torvalds writes:
> Paul - I think the ppc SHA1_Update() overflows in 32 bits, when the length > of the memory area to be checksummed is huge.
Yep. I checked the assembly output of this, and it looks right, but I haven't actually tested it by running it...
Paul.
diff --git a/ppc/sha1.c b/ppc/sha1.c index 5ba4fc5..0820398 100644 --- a/ppc/sha1.c +++ b/ppc/sha1.c @@ -30,7 +30,7 @@ int SHA1_Update(SHA_CTX *c, const void * unsigned long nb; const unsigned char *p = ptr; - c->len += n << 3; + c->len += (uint64_t) n << 3; while (n != 0) { if (c->cnt || n < 64) { nb = 64 - c->cnt;