X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fsha512.c;h=261a7bb02f72011258abea6fe64f2ea8d3a61704;hb=29dd8b5548ce047ce51ff9a73d6c4b50c9886771;hp=66cfaa9bfc18a9465fce6cd7999661593770e2ca;hpb=49c2c800d98967210cdae5122c15f03891964da7;p=gnulib.git diff --git a/lib/sha512.c b/lib/sha512.c index 66cfaa9bf..261a7bb02 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);