#ifdef CCAN_CRYPTO_SHA256_USE_OPENSSL
ctx->c.md_len = 0;
#else
- ctx->bytes = -1ULL;
+ ctx->bytes = (size_t)-1;
#endif
}
#ifdef CCAN_CRYPTO_SHA256_USE_OPENSSL
assert(ctx->c.md_len != 0);
#else
- assert(ctx->bytes != -1ULL);
+ assert(ctx->bytes != (size_t)-1);
#endif
}
size_t bufsize = ctx->bytes % 64;
if (bufsize + len >= 64) {
- // Fill the buffer, and process it.
+ /* Fill the buffer, and process it. */
memcpy(ctx->buf.u8 + bufsize, data, 64 - bufsize);
ctx->bytes += 64 - bufsize;
data += 64 - bufsize;
}
while (len >= 64) {
- // Process full chunks directly from the source.
+ /* Process full chunks directly from the source. */
if (alignment_ok(data, sizeof(uint32_t)))
Transform(ctx->s, (const uint32_t *)data);
else {
}
if (len) {
- // Fill the buffer with what remains.
+ /* Fill the buffer with what remains. */
memcpy(ctx->buf.u8 + bufsize, data, len);
ctx->bytes += len;
}
uint64_t sizedesc;
size_t i;
- sizedesc = cpu_to_be64(ctx->bytes << 3);
+ sizedesc = cpu_to_be64((uint64_t)ctx->bytes << 3);
/* Add '1' bit to terminate, then all 0 bits, up to next block - 8. */
- add(ctx, pad, 1 + ((119 - (ctx->bytes % 64)) % 64));
+ add(ctx, pad, 1 + ((128 - 8 - (ctx->bytes % 64) - 1) % 64));
/* Add number of bits of data (big endian) */
add(ctx, &sizedesc, 8);
for (i = 0; i < sizeof(ctx->s) / sizeof(ctx->s[0]); i++)