Commit a43c6468 authored by Niels Möller's avatar Niels Möller

* sha512.c: (sha512_digest): Simplified handling of any final

partial word of the digest.

Rev: nettle/ChangeLog:1.58
Rev: nettle/sha512.c:1.3
parent d35e6f95
2010-03-24 Niels Mller <nisse@lysator.liu.se> 2010-03-24 Niels Mller <nisse@lysator.liu.se>
* sha512.c: (sha512_digest): Simplified handling of any final
partial word of the digest.
* sha512.c: Reorganized to use _nettle_sha512_compress. * sha512.c: Reorganized to use _nettle_sha512_compress.
* sha512-compress.c (_nettle_sha512_compress): Compression * sha512-compress.c (_nettle_sha512_compress): Compression
......
...@@ -237,37 +237,14 @@ sha512_digest(struct sha512_ctx *ctx, ...@@ -237,37 +237,14 @@ sha512_digest(struct sha512_ctx *ctx,
if (leftover) if (leftover)
{ {
uint64_t word; /* Truncate to the right size */
unsigned j = leftover; uint64_t word = ctx->state[i] >> (8*(8 - leftover));
assert(i < _SHA512_DIGEST_LENGTH); do {
digest[--leftover] = word & 0xff;
word = ctx->state[i]; word >>= 8;
} while (leftover);
switch (leftover)
{
default:
abort();
case 7:
digest[--j] = (word >> 8) & 0xff;
/* Fall through */
case 6:
digest[--j] = (word >> 16) & 0xff;
/* Fall through */
case 5:
digest[--j] = (word >> 24) & 0xff;
/* Fall through */
case 4:
digest[--j] = (word >> 32) & 0xff;
case 3:
digest[--j] = (word >> 40) & 0xff;
/* Fall through */
case 2:
digest[--j] = (word >> 48) & 0xff;
/* Fall through */
case 1:
digest[--j] = (word >> 56) & 0xff;
}
} }
sha512_init(ctx); sha512_init(ctx);
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment