]> git.codecow.com Git - Monocypher.git/commitdiff
Fixed MSVC warnings
authorLoup Vaillant <loup@loup-vaillant.fr>
Tue, 20 Jul 2021 14:07:08 +0000 (16:07 +0200)
committerLoup Vaillant <loup@loup-vaillant.fr>
Tue, 20 Jul 2021 14:07:08 +0000 (16:07 +0200)
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).

src/monocypher.c

index 46bfe6817a46ad7ea4b1b73b832470d514f452fb..42058145afd0a9eb04ef0de34c1de38770afcf83 100644 (file)
@@ -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;
     }