Signed-off-by: Dmitry Eremin-Solenikov dbaryshkov@gmail.com --- md5-meta.c | 2 +- md5.c | 14 +++++++------- md5.h | 7 ++++++- 3 files changed, 14 insertions(+), 9 deletions(-)
diff --git a/md5-meta.c b/md5-meta.c index e4013edfd233..9d17be000f0a 100644 --- a/md5-meta.c +++ b/md5-meta.c @@ -38,4 +38,4 @@ #include "md5.h"
const struct nettle_hash nettle_md5 -= _NETTLE_HASH(md5, MD5); += _NETTLE_HASH_STATE(md5, MD5); diff --git a/md5.c b/md5.c index cc009b4a8dc8..4ffa064bacc5 100644 --- a/md5.c +++ b/md5.c @@ -56,19 +56,19 @@ md5_init(struct md5_ctx *ctx) 0x98badcfe, 0x10325476, }; - memcpy(ctx->state, iv, sizeof(ctx->state)); - ctx->count = 0; + memcpy(ctx->state.state, iv, sizeof(ctx->state.state)); + ctx->state.count = 0; ctx->index = 0; }
-#define COMPRESS(ctx, data) (nettle_md5_compress((ctx)->state, (data))) +#define COMPRESS(ctx, data) (nettle_md5_compress((ctx)->state.state, (data)))
void md5_update(struct md5_ctx *ctx, size_t length, const uint8_t *data) { - MD_UPDATE(ctx, length, data, COMPRESS, ctx->count++); + MD_UPDATE(ctx, length, data, COMPRESS, ctx->state.count++); }
void @@ -83,11 +83,11 @@ md5_digest(struct md5_ctx *ctx, MD_PAD(ctx, 8, COMPRESS);
/* There are 512 = 2^9 bits in one block */ - bit_count = (ctx->count << 9) | (ctx->index << 3); + bit_count = (ctx->state.count << 9) | (ctx->index << 3);
LE_WRITE_UINT64(ctx->block + (MD5_BLOCK_SIZE - 8), bit_count); - nettle_md5_compress(ctx->state, ctx->block); + nettle_md5_compress(ctx->state.state, ctx->block);
- _nettle_write_le32(length, digest, ctx->state); + _nettle_write_le32(length, digest, ctx->state.state); md5_init(ctx); } diff --git a/md5.h b/md5.h index 6feb39cc380b..258415479354 100644 --- a/md5.h +++ b/md5.h @@ -53,10 +53,15 @@ extern "C" { /* Digest is kept internally as 4 32-bit words. */ #define _MD5_DIGEST_LENGTH 4
-struct md5_ctx +struct md5_state { uint32_t state[_MD5_DIGEST_LENGTH]; uint64_t count; /* Block count */ +}; + +struct md5_ctx +{ + struct md5_state state; uint8_t block[MD5_BLOCK_SIZE]; /* Block buffer */ unsigned index; /* Into buffer */ };