[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] sha256: do not artificially restrict buffer length to be < 2^32
From: |
Jim Meyering |
Subject: |
[PATCH] sha256: do not artificially restrict buffer length to be < 2^32 |
Date: |
Mon, 26 May 2008 19:34:15 +0200 |
Tom's patch helped me spot a bug in sha256.h.
The buflen member there has type uint32_t,
yet we store in it values of type size_t.
Obviously that makes a difference for values larger than UINTMAX.
Here's the patch:
>From ef5f9af1559b043755d0af03c31676cd66fa40e7 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Mon, 26 May 2008 19:29:50 +0200
Subject: [PATCH] sha256: do not artificially restrict buffer length to be < 2^32
* lib/sha256.h (struct sha256_ctx) [buflen]: Change type from
uint32_t to size_t.
* lib/sha256.c (sha256_conclude_ctx): Change type of a local
to match.
---
ChangeLog | 6 ++++++
lib/sha256.c | 2 +-
lib/sha256.h | 2 +-
3 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 9aea4e6..a72b682 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
2008-05-26 Jim Meyering <address@hidden>
+ sha256: do not artificially restrict buffer length to be < 2^32
+ * lib/sha256.h (struct sha256_ctx) [buflen]: Change type from
+ uint32_t to size_t.
+ * lib/sha256.c (sha256_conclude_ctx): Change type of a local
+ to match.
+
avoid unaligned access errors, e.g., on sparc
* lib/sha512.c (sha512_conclude_ctx): Use set_uint64 rather than
direct access through a possibly-unaligned uint64* pointer.
diff --git a/lib/sha256.c b/lib/sha256.c
index a1362ca..0ad9444 100644
--- a/lib/sha256.c
+++ b/lib/sha256.c
@@ -126,7 +126,7 @@ static void
sha256_conclude_ctx (struct sha256_ctx *ctx)
{
/* Take yet unprocessed bytes into account. */
- uint32_t bytes = ctx->buflen;
+ size_t bytes = ctx->buflen;
size_t size = (bytes < 56) ? 64 / 4 : 64 * 2 / 4;
/* Now count remaining bytes. */
diff --git a/lib/sha256.h b/lib/sha256.h
index c35d6c1..3aa1ce9 100644
--- a/lib/sha256.h
+++ b/lib/sha256.h
@@ -27,7 +27,7 @@ struct sha256_ctx
uint32_t state[8];
uint32_t total[2];
- uint32_t buflen;
+ size_t buflen;
uint32_t buffer[32];
};
--
1.5.5.1.383.g8078b
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [PATCH] sha256: do not artificially restrict buffer length to be < 2^32,
Jim Meyering <=