From 278c97d778ad68fdbd42a425747ab3b612296ecc Mon Sep 17 00:00:00 2001 From: Loup Vaillant Date: Wed, 20 Jun 2018 00:26:41 +0200 Subject: [PATCH] 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; --- tests/test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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); -- 2.47.3