summaryrefslogtreecommitdiff
path: root/md5.c
diff options
context:
space:
mode:
authorNiels Möller <nisse@lysator.liu.se>2013-09-28 09:43:12 +0200
committerNiels Möller <nisse@lysator.liu.se>2013-09-28 09:44:22 +0200
commitcb83bd331e5774027bcab965ccf9bcbe798ad167 (patch)
tree3bbf1e2ee88e1ff1a27c877bd6cd21dc65f1d4a6 /md5.c
parent89755c916c84f722f081b5d53e8472d963cfbfe4 (diff)
downloadnettle-cb83bd331e5774027bcab965ccf9bcbe798ad167.tar.gz
Made hash functions use an uint64_t for the block count.
Diffstat (limited to 'md5.c')
-rw-r--r--md5.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/md5.c b/md5.c
index 32c3583e..370361b8 100644
--- a/md5.c
+++ b/md5.c
@@ -49,7 +49,7 @@ md5_init(struct md5_ctx *ctx)
0x10325476,
};
memcpy(ctx->state, iv, sizeof(ctx->state));
- ctx->count_low = ctx->count_high = 0;
+ ctx->count = 0;
ctx->index = 0;
}
@@ -60,7 +60,7 @@ md5_update(struct md5_ctx *ctx,
size_t length,
const uint8_t *data)
{
- MD_UPDATE(ctx, length, data, COMPRESS, MD_INCR(ctx));
+ MD_UPDATE(ctx, length, data, COMPRESS, ctx->count++);
}
void
@@ -68,18 +68,16 @@ md5_digest(struct md5_ctx *ctx,
size_t length,
uint8_t *digest)
{
- uint32_t high, low;
+ uint64_t bit_count;
assert(length <= MD5_DIGEST_SIZE);
MD_PAD(ctx, 8, COMPRESS);
- /* There are 512 = 2^9 bits in one block */
- high = (ctx->count_high << 9) | (ctx->count_low >> 23);
- low = (ctx->count_low << 9) | (ctx->index << 3);
+ /* There are 512 = 2^9 bits in one block */
+ bit_count = (ctx->count << 9) | (ctx->index << 3);
- LE_WRITE_UINT32(ctx->block + (MD5_DATA_SIZE - 8), low);
- LE_WRITE_UINT32(ctx->block + (MD5_DATA_SIZE - 4), high);
+ LE_WRITE_UINT64(ctx->block + (MD5_DATA_SIZE - 8), bit_count);
_nettle_md5_compress(ctx->state, ctx->block);
_nettle_write_le32(length, digest, ctx->state);