Commit 976bd444 authored by Niels Möller's avatar Niels Möller
Browse files

(sha1_block): Deleted function; inlined where used.

(SHA1_INCR): New macro for incrementing the block count.

Rev: src/nettle/sha1.c:1.12
parent 8d8ecf44
...@@ -78,16 +78,7 @@ sha1_init(struct sha1_ctx *ctx) ...@@ -78,16 +78,7 @@ sha1_init(struct sha1_ctx *ctx)
ctx->index = 0; ctx->index = 0;
} }
/* FIXME: Inline where used? */ #define SHA1_INCR(ctx) ((ctx)->count_high += !++(ctx)->count_low)
static void
sha1_block(struct sha1_ctx *ctx, const uint8_t *block)
{
/* Update block count */
if (!++ctx->count_low)
++ctx->count_high;
_nettle_sha1_compress(ctx->digest, block);
}
void void
sha1_update(struct sha1_ctx *ctx, sha1_update(struct sha1_ctx *ctx,
...@@ -105,14 +96,19 @@ sha1_update(struct sha1_ctx *ctx, ...@@ -105,14 +96,19 @@ sha1_update(struct sha1_ctx *ctx,
else else
{ {
memcpy(ctx->block + ctx->index, buffer, left); memcpy(ctx->block + ctx->index, buffer, left);
sha1_block(ctx, ctx->block);
_nettle_sha1_compress(ctx->digest, ctx->block);
SHA1_INCR(ctx);
buffer += left; buffer += left;
length -= left; length -= left;
} }
} }
while (length >= SHA1_DATA_SIZE) while (length >= SHA1_DATA_SIZE)
{ {
sha1_block(ctx, buffer); _nettle_sha1_compress(ctx->digest, buffer);
SHA1_INCR(ctx);
buffer += SHA1_DATA_SIZE; buffer += SHA1_DATA_SIZE;
length -= SHA1_DATA_SIZE; length -= SHA1_DATA_SIZE;
} }
...@@ -130,13 +126,6 @@ sha1_final(struct sha1_ctx *ctx) ...@@ -130,13 +126,6 @@ sha1_final(struct sha1_ctx *ctx)
uint32_t bitcount_high; uint32_t bitcount_high;
uint32_t bitcount_low; uint32_t bitcount_low;
unsigned i; unsigned i;
/* The calls to sha1_block increments the block counter, so compute
the bit length first. */
/* There are 512 = 2^9 bits in one block */
bitcount_high = (ctx->count_high << 9) | (ctx->count_low >> 23);
bitcount_low = (ctx->count_low << 9) | (ctx->index << 3);
i = ctx->index; i = ctx->index;
...@@ -151,19 +140,23 @@ sha1_final(struct sha1_ctx *ctx) ...@@ -151,19 +140,23 @@ sha1_final(struct sha1_ctx *ctx)
pad with another one */ pad with another one */
memset(ctx->block + i, 0, SHA1_DATA_SIZE - i); memset(ctx->block + i, 0, SHA1_DATA_SIZE - i);
sha1_block(ctx, ctx->block); _nettle_sha1_compress(ctx->digest, ctx->block);
i = 0; i = 0;
} }
if (i < (SHA1_DATA_SIZE - 8)) if (i < (SHA1_DATA_SIZE - 8))
memset(ctx->block + i, 0, (SHA1_DATA_SIZE - 8) - i); memset(ctx->block + i, 0, (SHA1_DATA_SIZE - 8) - i);
/* There are 512 = 2^9 bits in one block */
bitcount_high = (ctx->count_high << 9) | (ctx->count_low >> 23);
bitcount_low = (ctx->count_low << 9) | (ctx->index << 3);
/* This is slightly inefficient, as the numbers are converted to /* This is slightly inefficient, as the numbers are converted to
big-endian format, and will be converted back by the compression big-endian format, and will be converted back by the compression
function. It's probably not worth the effort to fix this. */ function. It's probably not worth the effort to fix this. */
WRITE_UINT32(ctx->block + (SHA1_DATA_SIZE - 8), bitcount_high); WRITE_UINT32(ctx->block + (SHA1_DATA_SIZE - 8), bitcount_high);
WRITE_UINT32(ctx->block + (SHA1_DATA_SIZE - 4), bitcount_low); WRITE_UINT32(ctx->block + (SHA1_DATA_SIZE - 4), bitcount_low);
sha1_block(ctx, ctx->block); _nettle_sha1_compress(ctx->digest, ctx->block);
} }
void void
......
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