From: Loup Vaillant Date: Tue, 19 Jun 2018 22:26:41 +0000 (+0200) Subject: Corrected failing test on 32-bit systems X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=278c97d778ad68fdbd42a425747ab3b612296ecc;p=Monocypher.git Corrected failing test on 32-bit systems 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; --- diff --git a/tests/test.c b/tests/test.c index 8ee4a78..33e7b92 100644 --- a/tests/test.c +++ b/tests/test.c @@ -361,7 +361,7 @@ static int p_chacha20_set_ctr() 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);