libmicrohttpd

HTTP/1.x server C library (MHD 1.x, stable)
Log | Files | Refs | Submodules | README | LICENSE

commit 7887edc2b44c840bf2cbe60cb1bf02eceab80dd3
parent 5194dd1615286342a1fbd137028fb1bc831234ba
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date:   Mon, 15 Apr 2019 22:53:29 +0300

MD5: count bytes, not bits
MHD do not add bites, no need to count more precise than bytes

Diffstat:
Msrc/microhttpd/md5.c | 16+++++++++-------
Msrc/microhttpd/md5.h | 2+-
2 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/src/microhttpd/md5.c b/src/microhttpd/md5.c @@ -71,21 +71,23 @@ MD5Init (void *ctx_) static void MD5Pad (struct MD5Context *ctx) { - uint8_t count[8]; + uint8_t count_le[8]; size_t padlen; + uint64_t count_bits; mhd_assert (ctx != NULL); /* Convert count to 8 bytes in little endian order. */ - PUT_64BIT_LE(count, ctx->count); + count_bits = ctx->count << 3; + PUT_64BIT_LE(count_le, count_bits); /* Pad out to 56 mod 64. */ padlen = MD5_BLOCK_SIZE - - ((ctx->count >> 3) & (MD5_BLOCK_SIZE - 1)); + ((ctx->count) & (MD5_BLOCK_SIZE - 1)); if (padlen < 1 + 8) padlen += MD5_BLOCK_SIZE; MD5Update(ctx, PADDING, padlen - 8); /* padlen - 8 <= 64 */ - MD5Update(ctx, count, 8); + MD5Update(ctx, count_le, 8); } @@ -244,11 +246,11 @@ MD5Update (void *ctx_, mhd_assert ((ctx != NULL) || (len == 0)); /* Check how many bytes we already have and how many more we need. */ - have = (size_t)((ctx->count >> 3) & (MD5_BLOCK_SIZE - 1)); + have = (size_t)((ctx->count) & (MD5_BLOCK_SIZE - 1)); need = MD5_BLOCK_SIZE - have; - /* Update bitcount */ - ctx->count += (uint64_t)len << 3; + /* Update bytecount */ + ctx->count += (uint64_t)len; if (len >= need) { diff --git a/src/microhttpd/md5.h b/src/microhttpd/md5.h @@ -27,7 +27,7 @@ struct MD5Context { uint32_t state[4]; /* state */ - uint64_t count; /* number of bits, mod 2^64 */ + uint64_t count; /* number of bytes, mod 2^64 */ uint8_t buffer[MD5_BLOCK_SIZE]; /* input buffer */ };