When size_t is not uint64_t, converting "negative" size_t integers to
uint64_t yields nonsensical results. That is, the following isn't
portable:
size_t x = 42;
uint64_t y = -i;
Because y might be missing the high order bits if size_t is smaller than
uint64_t. Instead, we want to convert to a large sized integer *before*
we negate it:
size_t x = 42;
uint64_t y = -(uint64_t)i;
status |= memcmp(output_part, output_all, STREAM_SIZE);
// Encrypt before the begining
- crypto_chacha20_set_ctr(&ctx, -i);
+ crypto_chacha20_set_ctr(&ctx, -(u64)i);
crypto_chacha20_stream(&ctx,
output_more + STREAM_SIZE - limit,
STREAM_SIZE + limit);