* lib/md5.h (buflen): Add comments regarding range.
* lib/sha1.h (buflen): Likewise.
* lib/sha256.h (buflen): Likewise.
* lib/sha512.h (buflen): Likewise.
* lib/md5.c (md5_process_bytes): Add comment why memmove is not needed.
* lib/sha1.c (sha1_process_bytes): Likewise.
* lib/sha256.c (sha256_process_bytes): Likewise.
* lib/sha512.c (sha512_process_bytes): Likewise.
Reported by Coverity via Tim Rühsen.
+2017-03-31 Bruno Haible <bruno@clisp.org>
+
+ md5, sha1, sha256, sha512: Add comments regarding correctness.
+ * lib/md5.h (buflen): Add comments regarding range.
+ * lib/sha1.h (buflen): Likewise.
+ * lib/sha256.h (buflen): Likewise.
+ * lib/sha512.h (buflen): Likewise.
+ * lib/md5.c (md5_process_bytes): Add comment why memmove is not needed.
+ * lib/sha1.c (sha1_process_bytes): Likewise.
+ * lib/sha256.c (sha256_process_bytes): Likewise.
+ * lib/sha512.c (sha512_process_bytes): Likewise.
+ Reported by Coverity via Tim Rühsen.
+
2017-03-22 Paul Eggert <eggert@cs.ucla.edu>
getopt: merge from glibc
md5_process_block (ctx->buffer, ctx->buflen & ~63, ctx);
ctx->buflen &= 63;
- /* The regions in the following copy operation cannot overlap. */
+ /* The regions in the following copy operation cannot overlap,
+ because ctx->buflen < 64 ≤ (left_over + add) & ~63. */
memcpy (ctx->buffer,
&((char *) ctx->buffer)[(left_over + add) & ~63],
ctx->buflen);
{
md5_process_block (ctx->buffer, 64, ctx);
left_over -= 64;
+ /* The regions in the following copy operation cannot overlap,
+ because left_over ≤ 64. */
memcpy (ctx->buffer, &ctx->buffer[16], left_over);
}
ctx->buflen = left_over;
uint32_t D;
uint32_t total[2];
- uint32_t buflen;
- uint32_t buffer[32];
+ uint32_t buflen; /* ≥ 0, ≤ 128 */
+ uint32_t buffer[32]; /* 128 bytes; the first buflen bytes are in use */
};
/*
sha1_process_block (ctx->buffer, ctx->buflen & ~63, ctx);
ctx->buflen &= 63;
- /* The regions in the following copy operation cannot overlap. */
+ /* The regions in the following copy operation cannot overlap,
+ because ctx->buflen < 64 ≤ (left_over + add) & ~63. */
memcpy (ctx->buffer,
&((char *) ctx->buffer)[(left_over + add) & ~63],
ctx->buflen);
{
sha1_process_block (ctx->buffer, 64, ctx);
left_over -= 64;
+ /* The regions in the following copy operation cannot overlap,
+ because left_over ≤ 64. */
memcpy (ctx->buffer, &ctx->buffer[16], left_over);
}
ctx->buflen = left_over;
uint32_t E;
uint32_t total[2];
- uint32_t buflen;
- uint32_t buffer[32];
+ uint32_t buflen; /* ≥ 0, ≤ 128 */
+ uint32_t buffer[32]; /* 128 bytes; the first buflen bytes are in use */
};
/* Initialize structure containing state of computation. */
sha256_process_block (ctx->buffer, ctx->buflen & ~63, ctx);
ctx->buflen &= 63;
- /* The regions in the following copy operation cannot overlap. */
+ /* The regions in the following copy operation cannot overlap,
+ because ctx->buflen < 64 ≤ (left_over + add) & ~63. */
memcpy (ctx->buffer,
&((char *) ctx->buffer)[(left_over + add) & ~63],
ctx->buflen);
{
sha256_process_block (ctx->buffer, 64, ctx);
left_over -= 64;
+ /* The regions in the following copy operation cannot overlap,
+ because left_over ≤ 64. */
memcpy (ctx->buffer, &ctx->buffer[16], left_over);
}
ctx->buflen = left_over;
uint32_t state[8];
uint32_t total[2];
- size_t buflen;
- uint32_t buffer[32];
+ size_t buflen; /* ≥ 0, ≤ 128 */
+ uint32_t buffer[32]; /* 128 bytes; the first buflen bytes are in use */
};
/* Initialize structure containing state of computation. */
sha512_process_block (ctx->buffer, ctx->buflen & ~127, ctx);
ctx->buflen &= 127;
- /* The regions in the following copy operation cannot overlap. */
+ /* The regions in the following copy operation cannot overlap,
+ because ctx->buflen < 128 ≤ (left_over + add) & ~127. */
memcpy (ctx->buffer,
&((char *) ctx->buffer)[(left_over + add) & ~127],
ctx->buflen);
{
sha512_process_block (ctx->buffer, 128, ctx);
left_over -= 128;
+ /* The regions in the following copy operation cannot overlap,
+ because left_over ≤ 128. */
memcpy (ctx->buffer, &ctx->buffer[16], left_over);
}
ctx->buflen = left_over;
u64 state[8];
u64 total[2];
- size_t buflen;
- u64 buffer[32];
+ size_t buflen; /* ≥ 0, ≤ 256 */
+ u64 buffer[32]; /* 256 bytes; the first buflen bytes are in use */
};
/* Initialize structure containing state of computation. */