Skip to content
Snippets Groups Projects
Commit af89b978 authored by Niels Möller's avatar Niels Möller
Browse files

(sha1_digest): Use _nettle_write_be32.

Rev: nettle/sha1.c:1.2
parent e6dc6b62
No related branches found
No related tags found
No related merge requests found
...@@ -47,6 +47,7 @@ ...@@ -47,6 +47,7 @@
#include "sha.h" #include "sha.h"
#include "macros.h" #include "macros.h"
#include "nettle-write.h"
/* A block, treated as a sequence of 32-bit words. */ /* A block, treated as a sequence of 32-bit words. */
#define SHA1_DATA_LENGTH 16 #define SHA1_DATA_LENGTH 16
...@@ -164,42 +165,9 @@ sha1_digest(struct sha1_ctx *ctx, ...@@ -164,42 +165,9 @@ sha1_digest(struct sha1_ctx *ctx,
unsigned length, unsigned length,
uint8_t *digest) uint8_t *digest)
{ {
unsigned i;
unsigned words;
unsigned leftover;
assert(length <= SHA1_DIGEST_SIZE); assert(length <= SHA1_DIGEST_SIZE);
sha1_final(ctx); sha1_final(ctx);
_nettle_write_be32(length, digest, ctx->digest);
words = length / 4;
leftover = length % 4;
for (i = 0; i < words; i++, digest += 4)
WRITE_UINT32(digest, ctx->digest[i]);
if (leftover)
{
uint32_t word;
unsigned j = leftover;
assert(i < _SHA1_DIGEST_LENGTH);
word = ctx->digest[i];
switch (leftover)
{
default:
abort();
case 3:
digest[--j] = (word >> 8) & 0xff;
/* Fall through */
case 2:
digest[--j] = (word >> 16) & 0xff;
/* Fall through */
case 1:
digest[--j] = (word >> 24) & 0xff;
}
}
sha1_init(ctx); sha1_init(ctx);
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment