From: Jason A. Donenfeld Date: Thu, 19 Jul 2018 17:15:15 +0000 (+0200) Subject: embeddable-wg-library: do not left shift negative numbers X-Git-Tag: v1.0.20191226~85 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c61c5a03ee2e3186eae57c3f7934f270df7045a7;p=thirdparty%2Fwireguard-tools.git embeddable-wg-library: do not left shift negative numbers Otherwise we incur undefined behavior. Signed-off-by: Jason A. Donenfeld --- diff --git a/contrib/embeddable-wg-library/wireguard.c b/contrib/embeddable-wg-library/wireguard.c index c052355..a65dbce 100644 --- a/contrib/embeddable-wg-library/wireguard.c +++ b/contrib/embeddable-wg-library/wireguard.c @@ -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)