From 9eaec6d8f5cba1a95c7072c95d0a13726352aaea Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Tue, 3 Oct 2017 06:18:45 +0200 Subject: global: satisfy bitshift pedantry Suggested-by: Sultan Alsawaf --- src/crypto/chacha20poly1305.c | 14 +++++++------- src/hashtables.h | 4 ++-- src/messages.h | 2 +- src/ratelimiter.c | 2 +- src/routingtable.c | 2 +- src/tests/qemu/init.c | 2 +- src/tools/containers.h | 16 ++++++++-------- src/uapi/wireguard.h | 6 +++--- 8 files changed, 24 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/src/crypto/chacha20poly1305.c b/src/crypto/chacha20poly1305.c index 9e74784..7227617 100644 --- a/src/crypto/chacha20poly1305.c +++ b/src/crypto/chacha20poly1305.c @@ -459,7 +459,7 @@ static void poly1305_simd_mult(u32 *a, const u32 *b) memset(m, 0, sizeof(m)); /* The poly1305 block function adds a hi-bit to the accumulator which * we don't need for key multiplication; compensate for it. */ - a[4] -= 1 << 24; + a[4] -= 1U << 24; poly1305_asm_block_sse2(a, m, b, 1); } @@ -523,7 +523,7 @@ static void poly1305_update(struct poly1305_ctx *ctx, const u8 *src, unsigned in poly1305_simd_blocks(ctx, ctx->buf, POLY1305_BLOCK_SIZE); else #endif - poly1305_generic_blocks(ctx, ctx->buf, POLY1305_BLOCK_SIZE, 1 << 24); + poly1305_generic_blocks(ctx, ctx->buf, POLY1305_BLOCK_SIZE, 1U << 24); ctx->buflen = 0; } } @@ -534,7 +534,7 @@ static void poly1305_update(struct poly1305_ctx *ctx, const u8 *src, unsigned in bytes = poly1305_simd_blocks(ctx, src, srclen); else #endif - bytes = poly1305_generic_blocks(ctx, src, srclen, 1 << 24); + bytes = poly1305_generic_blocks(ctx, src, srclen, 1U << 24); src += srclen - bytes; srclen = bytes; } @@ -574,10 +574,10 @@ static void poly1305_finish(struct poly1305_ctx *ctx, u8 *dst) /* compute h + -p */ g0 = h0 + 5; - g1 = h1 + (g0 >> 26); g0 &= 0x3ffffff; - g2 = h2 + (g1 >> 26); g1 &= 0x3ffffff; - g3 = h3 + (g2 >> 26); g2 &= 0x3ffffff; - g4 = h4 + (g3 >> 26) - (1 << 26); g3 &= 0x3ffffff; + g1 = h1 + (g0 >> 26); g0 &= 0x3ffffff; + g2 = h2 + (g1 >> 26); g1 &= 0x3ffffff; + g3 = h3 + (g2 >> 26); g2 &= 0x3ffffff; + g4 = h4 + (g3 >> 26) - (1U << 26); g3 &= 0x3ffffff; /* select h if h < p, or h + -p if h >= p */ mask = (g4 >> ((sizeof(u32) * 8) - 1)) - 1; diff --git a/src/hashtables.h b/src/hashtables.h index 2a178a0..e12bfd6 100644 --- a/src/hashtables.h +++ b/src/hashtables.h @@ -30,8 +30,8 @@ struct index_hashtable { }; enum index_hashtable_type { - INDEX_HASHTABLE_HANDSHAKE = (1 << 0), - INDEX_HASHTABLE_KEYPAIR = (1 << 1) + INDEX_HASHTABLE_HANDSHAKE = 1U << 0, + INDEX_HASHTABLE_KEYPAIR = 1U << 1 }; struct index_hashtable_entry { diff --git a/src/messages.h b/src/messages.h index acf248c..19488a6 100644 --- a/src/messages.h +++ b/src/messages.h @@ -46,7 +46,7 @@ enum limits { REKEY_AFTER_TIME = 120 * HZ, REJECT_AFTER_TIME = 180 * HZ, INITIATIONS_PER_SECOND = HZ / 50, - MAX_PEERS_PER_DEVICE = 1 << 20, + MAX_PEERS_PER_DEVICE = 1U << 20, KEEPALIVE_TIMEOUT = 10 * HZ, MAX_TIMER_HANDSHAKES = (90 * HZ) / REKEY_TIMEOUT, MAX_QUEUED_INCOMING_HANDSHAKES = 4096, /* TODO: replace this with DQL */ diff --git a/src/ratelimiter.c b/src/ratelimiter.c index c4281e1..0afcdac 100644 --- a/src/ratelimiter.c +++ b/src/ratelimiter.c @@ -150,7 +150,7 @@ int ratelimiter_init(void) * but what it shares in common is that it uses a massive hashtable. So, * we borrow their wisdom about good table sizes on different systems * dependent on RAM. This calculation here comes from there. */ - table_size = (totalram_pages > (1 << 30) / PAGE_SIZE) ? 8192 : max_t(unsigned long, 16, roundup_pow_of_two((totalram_pages << PAGE_SHIFT) / (1 << 14) / sizeof(struct hlist_head))); + table_size = (totalram_pages > (1U << 30) / PAGE_SIZE) ? 8192 : max_t(unsigned long, 16, roundup_pow_of_two((totalram_pages << PAGE_SHIFT) / (1U << 14) / sizeof(struct hlist_head))); max_entries = table_size * 8; table_v4 = kvzalloc(table_size * sizeof(struct hlist_head), GFP_KERNEL); diff --git a/src/routingtable.c b/src/routingtable.c index c4e343f..6fdad8a 100644 --- a/src/routingtable.c +++ b/src/routingtable.c @@ -14,7 +14,7 @@ struct routing_table_node { static inline void copy_and_assign_cidr(struct routing_table_node *node, const u8 *src, u8 cidr) { memcpy(node->bits, src, (cidr + 7) / 8); - node->bits[(cidr + 7) / 8 - 1] &= 0xff << ((8 - (cidr % 8)) % 8); + node->bits[(cidr + 7) / 8 - 1] &= 0xffU << ((8 - (cidr % 8)) % 8); node->cidr = cidr; node->bit_at_a = cidr / 8; node->bit_at_b = 7 - (cidr % 8); diff --git a/src/tests/qemu/init.c b/src/tests/qemu/init.c index 130fd0e..3d0c9de 100644 --- a/src/tests/qemu/init.c +++ b/src/tests/qemu/init.c @@ -26,7 +26,7 @@ __attribute__((noreturn)) static void poweroff(void) fflush(stderr); #if defined(__x86_64__) || defined(__i386__) ioperm(0x604, 2, 1); - outw(1 << 13, 0x604); + outw(1U << 13, 0x604); #else reboot(RB_POWER_OFF); #endif diff --git a/src/tools/containers.h b/src/tools/containers.h index 7ce09a9..2261b07 100644 --- a/src/tools/containers.h +++ b/src/tools/containers.h @@ -24,10 +24,10 @@ struct wgallowedip { }; enum { - WGPEER_REMOVE_ME = (1 << 0), - WGPEER_REPLACE_ALLOWEDIPS = (1 << 1), - WGPEER_HAS_PRESHARED_KEY = (1 << 2), - WGPEER_HAS_PERSISTENT_KEEPALIVE_INTERVAL = (1 << 3) + WGPEER_REMOVE_ME = 1U << 0, + WGPEER_REPLACE_ALLOWEDIPS = 1U << 1, + WGPEER_HAS_PRESHARED_KEY = 1U << 2, + WGPEER_HAS_PERSISTENT_KEEPALIVE_INTERVAL = 1U << 3 }; struct wgpeer { @@ -51,10 +51,10 @@ struct wgpeer { }; enum { - WGDEVICE_REPLACE_PEERS = (1 << 0), - WGDEVICE_HAS_PRIVATE_KEY = (1 << 1), - WGDEVICE_HAS_LISTEN_PORT = (1 << 2), - WGDEVICE_HAS_FWMARK = (1 << 3) + WGDEVICE_REPLACE_PEERS = 1U << 0, + WGDEVICE_HAS_PRIVATE_KEY = 1U << 1, + WGDEVICE_HAS_LISTEN_PORT = 1U << 2, + WGDEVICE_HAS_FWMARK = 1U << 3 }; enum { diff --git a/src/uapi/wireguard.h b/src/uapi/wireguard.h index 9c260be..5274c44 100644 --- a/src/uapi/wireguard.h +++ b/src/uapi/wireguard.h @@ -152,7 +152,7 @@ enum wg_cmd { #define WG_CMD_MAX (__WG_CMD_MAX - 1) enum wgdevice_flag { - WGDEVICE_F_REPLACE_PEERS = (1 << 0) + WGDEVICE_F_REPLACE_PEERS = 1U << 0 }; enum wgdevice_attribute { WGDEVICE_A_UNSPEC, @@ -169,8 +169,8 @@ enum wgdevice_attribute { #define WGDEVICE_A_MAX (__WGDEVICE_A_LAST - 1) enum wgpeer_flag { - WGPEER_F_REMOVE_ME = (1 << 0), - WGPEER_F_REPLACE_ALLOWEDIPS = (1 << 1) + WGPEER_F_REMOVE_ME = 1U << 0, + WGPEER_F_REPLACE_ALLOWEDIPS = 1U << 1 }; enum wgpeer_attribute { WGPEER_A_UNSPEC, -- cgit v1.2.3-59-g8ed1b