]> git.ipfire.org Git - thirdparty/wireguard-tools.git/commitdiff
embeddable-wg-library: do not left shift negative numbers
authorJason A. Donenfeld <Jason@zx2c4.com>
Thu, 19 Jul 2018 17:15:15 +0000 (19:15 +0200)
committerJason A. Donenfeld <Jason@zx2c4.com>
Tue, 24 Jul 2018 16:15:17 +0000 (18:15 +0200)
Otherwise we incur undefined behavior.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
contrib/embeddable-wg-library/wireguard.c

index c052355544b058d2aa78c9330993fc8675691893..a65dbce5cab313f361b768d62fe484668d61c1b6 100644 (file)
@@ -1593,16 +1593,11 @@ static __attribute__((noinline)) void memzero_explicit(void *s, size_t count)
 static void carry(fe o)
 {
        int i;
-       int64_t c;
 
        for (i = 0; i < 16; ++i) {
-               o[i] += (1LL << 16);
-               c = o[i] >> 16;
-               o[(i + 1) * (i < 15)] += c - 1 + 37 * (c - 1) * (i == 15);
-               o[i] -= c << 16;
+               o[(i + 1) % 16] += (i == 15 ? 38 : 1) * (o[i] >> 16);
+               o[i] &= 0xffff;
        }
-
-       memzero_explicit(&c, sizeof(c));
 }
 
 static void cswap(fe p, fe q, int b)