diff options
author | Jim Meyering <meyering@redhat.com> | 2008-05-26 16:25:28 +0200 |
---|---|---|
committer | Jim Meyering <meyering@redhat.com> | 2008-05-26 16:30:45 +0200 |
commit | e341e7caaea9a3fd5f311195b023af8d280944fa (patch) | |
tree | 827d40c22d07ec44c072eb12a5ef5c70592dee75 /lib/sha512.c | |
parent | 49c2c800d98967210cdae5122c15f03891964da7 (diff) | |
download | gnulib-e341e7caaea9a3fd5f311195b023af8d280944fa.tar.gz |
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.
* lib/sha256.c (sha256_conclude_ctx): Use set_uint32 rather than
direct access through a possibly-unaligned uint32* pointer.
Prompted by this patch from Tom "spot" Callaway:
http://thread.gmane.org/gmane.comp.gnu.coreutils.bugs/13638
Diffstat (limited to 'lib/sha512.c')
-rw-r--r-- | lib/sha512.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/lib/sha512.c b/lib/sha512.c index 66cfaa9bfc..261a7bb02f 100644 --- a/lib/sha512.c +++ b/lib/sha512.c @@ -141,10 +141,14 @@ sha512_conclude_ctx (struct sha512_ctx *ctx) if (u64lt (ctx->total[0], u64lo (bytes))) ctx->total[1] = u64plus (ctx->total[1], u64lo (1)); - /* Put the 128-bit file length in *bits* at the end of the buffer. */ - ctx->buffer[size - 2] = SWAP (u64or (u64shl (ctx->total[1], 3), - u64shr (ctx->total[0], 61))); - ctx->buffer[size - 1] = SWAP (u64shl (ctx->total[0], 3)); + /* Put the 128-bit file length in *bits* at the end of the buffer. + Use set_uint64 rather than a simple assignment, to avoid risk of + unaligned access. */ + set_uint64 ((char *) &ctx->buffer[size - 2], + SWAP (u64or (u64shl (ctx->total[1], 3), + u64shr (ctx->total[0], 61)))); + set_uint64 ((char *) &ctx->buffer[size - 1], + SWAP (u64shl (ctx->total[0], 3))); memcpy (&((char *) ctx->buffer)[bytes], fillbuf, (size - 2) * 8 - bytes); |