]> git.ipfire.org Git - thirdparty/wireguard-tools.git/commitdiff
wg: encoding: be more paranoid
authorJason A. Donenfeld <Jason@zx2c4.com>
Sun, 15 Oct 2017 19:29:01 +0000 (21:29 +0200)
committerJason A. Donenfeld <Jason@zx2c4.com>
Tue, 17 Oct 2017 17:26:07 +0000 (19:26 +0200)
Needless, but overkill can be fun.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
src/encoding.c

index 3d5e94b8a023544c216dff71a2c0965bb56c200b..c407b57b96bdd1fa084c2c48cc48aade40d0b73e 100644 (file)
@@ -102,10 +102,10 @@ bool key_from_hex(uint8_t key[static WG_KEY_LEN], const char *hex)
 
 bool key_is_zero(const uint8_t key[static WG_KEY_LEN])
 {
-       uint8_t acc = 0;
+       volatile uint8_t acc = 0;
        for (unsigned int i = 0; i < WG_KEY_LEN; ++i) {
                acc |= key[i];
                __asm__ ("" : "=r" (acc) : "0" (acc));
        }
-       return acc == 0;
+       return 1 & ((acc - 1) >> 8);
 }