diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-07-19 19:15:15 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-07-24 18:15:17 +0200 |
commit | bf0005ef18942e9aa878ec065046aa7fd1f49359 (patch) | |
tree | 6adf3f19881f0f43166a8a75ce24e063a99f0ac4 | |
parent | receive: check against proper return value type (diff) | |
download | wireguard-monolithic-historical-bf0005ef18942e9aa878ec065046aa7fd1f49359.tar.xz wireguard-monolithic-historical-bf0005ef18942e9aa878ec065046aa7fd1f49359.zip |
embeddable-wg-library: do not left shift negative numbers
Otherwise we incur undefined behavior.
-rw-r--r-- | contrib/examples/embeddable-wg-library/wireguard.c | 9 |
1 files changed, 2 insertions, 7 deletions
diff --git a/contrib/examples/embeddable-wg-library/wireguard.c b/contrib/examples/embeddable-wg-library/wireguard.c index c052355..a65dbce 100644 --- a/contrib/examples/embeddable-wg-library/wireguard.c +++ b/contrib/examples/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) |