]> git.codecow.com Git - Monocypher.git/commitdiff
Corrected failing test on 32-bit systems
authorLoup Vaillant <loup@loup-vaillant.fr>
Tue, 19 Jun 2018 22:26:41 +0000 (00:26 +0200)
committerLoup Vaillant <loup@loup-vaillant.fr>
Tue, 19 Jun 2018 22:26:41 +0000 (00:26 +0200)
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

index 8ee4a78360286b8e71728ccec321854eeb197f89..33e7b9201a0595d54b2648744c15013fba3ddc5c 100644 (file)
@@ -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);