From: Loup Vaillant Date: Tue, 20 Jul 2021 14:07:08 +0000 (+0200) Subject: Fixed MSVC warnings X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=63be0d34eb58c7b2b22fe4351e27dd5e8643e1c9;p=Monocypher.git Fixed MSVC warnings Fixes #215 MSVC doesn't like when we expand unsigned integers after a bitwise negation. A fair distaste, except this time it's wrong. Writing `(~x & 0xffffffff)` instead of just `~x` shows MSVC the error of its ways. Also made a potentially lossy conversion to `int` explicit (and explained in a comment why there is no actual loss). --- diff --git a/src/monocypher.c b/src/monocypher.c index 46bfe68..4205814 100644 --- a/src/monocypher.c +++ b/src/monocypher.c @@ -1609,10 +1609,10 @@ static int is_above_l(const u32 x[8]) // (-L == ~L + 1) u64 carry = 1; FOR (i, 0, 8) { - carry += (u64)x[i] + ~L[i]; + carry += (u64)x[i] + (~L[i] & 0xffffffff); carry >>= 32; } - return carry; + return (int)carry; // carry is either 0 or 1 } // Final reduction modulo L, by conditionally removing L. @@ -1662,7 +1662,7 @@ static void mod_l(u8 reduced[32], const u32 x[16]) // xr = x - xr u64 carry = 1; FOR (i, 0, 8) { - carry += (u64)x[i] + ~xr[i]; + carry += (u64)x[i] + (~xr[i] & 0xffffffff); xr[i] = (u32)carry; carry >>= 32; }