2012-03-16 20:26:18

by Kent Yoder

[permalink] [raw]
Subject: [PATCH] crypto: Fix byte counter overflow in SHA-512

The current code only increments the upper 64 bits of the SHA-512 byte
counter when the number of bytes hashed happens to hit 2^64 exactly.

This patch increments the upper 64 bits whenever the lower 64 bits
overflows.

Signed-off-by: Kent Yoder <[email protected]>
---
crypto/sha512_generic.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/crypto/sha512_generic.c b/crypto/sha512_generic.c
index 107f6f7..dd30f40 100644
--- a/crypto/sha512_generic.c
+++ b/crypto/sha512_generic.c
@@ -174,7 +174,7 @@ sha512_update(struct shash_desc *desc, const u8 *data, unsigned int len)
index = sctx->count[0] & 0x7f;

/* Update number of bytes */
- if (!(sctx->count[0] += len))
+ if ((sctx->count[0] += len) < len)
sctx->count[1]++;

part_len = 128 - index;
--
1.7.5.4


2012-04-05 12:36:47

by Herbert Xu

[permalink] [raw]
Subject: Re: [PATCH] crypto: Fix byte counter overflow in SHA-512

On Fri, Mar 16, 2012 at 08:26:28PM +0000, Kent Yoder wrote:
> The current code only increments the upper 64 bits of the SHA-512 byte
> counter when the number of bytes hashed happens to hit 2^64 exactly.
>
> This patch increments the upper 64 bits whenever the lower 64 bits
> overflows.
>
> Signed-off-by: Kent Yoder <[email protected]>

Good catch. Patch applied to crypto and stable. Thanks a lot!
--
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt