Line
Link Here
|
0 |
-- a/src/sha.c |
0 |
++ b/src/sha.c |
Lines 78-83
sha_finish_ctx (struct sha_ctx *ctx, voi
Link Here
|
78 |
{ |
78 |
{ |
79 |
/* Take yet unprocessed bytes into account. */ |
79 |
/* Take yet unprocessed bytes into account. */ |
80 |
md5_uint32 bytes = ctx->buflen; |
80 |
md5_uint32 bytes = ctx->buflen; |
|
|
81 |
md5_uint32 notswap_bytes; |
81 |
size_t pad; |
82 |
size_t pad; |
82 |
|
83 |
|
83 |
/* Now count remaining bytes. */ |
84 |
/* Now count remaining bytes. */ |
Lines 88-97
sha_finish_ctx (struct sha_ctx *ctx, voi
Link Here
|
88 |
pad = bytes >= 56 ? 64 + 56 - bytes : 56 - bytes; |
89 |
pad = bytes >= 56 ? 64 + 56 - bytes : 56 - bytes; |
89 |
memcpy (&ctx->buffer[bytes], fillbuf, pad); |
90 |
memcpy (&ctx->buffer[bytes], fillbuf, pad); |
90 |
|
91 |
|
91 |
/* Put the 64-bit file length in *bits* at the end of the buffer. */ |
92 |
/* Put the 64-bit file length in *bits* at the end of the buffer. |
92 |
*(md5_uint32 *) &ctx->buffer[bytes + pad + 4] = NOTSWAP (ctx->total[0] << 3); |
93 |
Use memcpy to avoid aliasing problems. On most systems, this |
93 |
*(md5_uint32 *) &ctx->buffer[bytes + pad] = NOTSWAP ((ctx->total[1] << 3) | |
94 |
will be optimized away to the same code. */ |
94 |
(ctx->total[0] >> 29)); |
95 |
notswap_bytes = NOTSWAP (ctx->total[0] << 3); |
|
|
96 |
memcpy (&ctx->buffer[bytes + pad + 4], ¬swap_bytes, sizeof (notswap_bytes)); |
97 |
notswap_bytes = NOTSWAP ((ctx->total[1] << 3) | (ctx->total[0] >> 29)); |
98 |
memcpy (&ctx->buffer[bytes + pad], ¬swap_bytes, sizeof (notswap_bytes)); |
95 |
|
99 |
|
96 |
/* Process last bytes. */ |
100 |
/* Process last bytes. */ |
97 |
sha_process_block (ctx->buffer, bytes + pad + 8, ctx); |
101 |
sha_process_block (ctx->buffer, bytes + pad + 8, ctx); |