diff options
-rw-r--r-- | src/allowedips.c | 4 | ||||
-rw-r--r-- | src/crypto/include/zinc/blake2s.h | 9 | ||||
-rw-r--r-- | src/crypto/zinc/blake2s/blake2s.c | 20 | ||||
-rw-r--r-- | src/noise.c | 13 |
4 files changed, 19 insertions, 27 deletions
diff --git a/src/allowedips.c b/src/allowedips.c index b7dc387..f212afe 100644 --- a/src/allowedips.c +++ b/src/allowedips.c @@ -50,7 +50,7 @@ static void node_free_rcu(struct rcu_head *rcu) #define push_rcu(stack, p, len) ({ \ if (rcu_access_pointer(p)) { \ - WARN_ON(len >= 128); \ + WARN_ON(IS_ENABLED(DEBUG) && len >= 128); \ stack[len++] = rcu_dereference_raw(p); \ } \ true; \ @@ -109,7 +109,7 @@ walk_by_peer(struct allowedips_node __rcu *top, u8 bits, #define ref(p) rcu_access_pointer(p) #define deref(p) rcu_dereference_protected(*p, lockdep_is_held(lock)) #define push(p) ({ \ - WARN_ON(len >= 128); \ + WARN_ON(IS_ENABLED(DEBUG) && len >= 128); \ stack[len++] = p; \ }) static void walk_remove_by_peer(struct allowedips_node __rcu **top, diff --git a/src/crypto/include/zinc/blake2s.h b/src/crypto/include/zinc/blake2s.h index 3dbe4b5..701a08b 100644 --- a/src/crypto/include/zinc/blake2s.h +++ b/src/crypto/include/zinc/blake2s.h @@ -8,6 +8,7 @@ #include <linux/types.h> #include <linux/kernel.h> +#include <asm/bug.h> enum blake2s_lengths { BLAKE2S_BLOCK_SIZE = 64, @@ -36,11 +37,9 @@ static inline void blake2s(u8 *out, const u8 *in, const u8 *key, { struct blake2s_state state; -#ifdef DEBUG - BUG_ON((!in && inlen > 0) || !out || !outlen || - outlen > BLAKE2S_HASH_SIZE || keylen > BLAKE2S_KEY_SIZE || - (!key && keylen)); -#endif + WARN_ON(IS_ENABLED(DEBUG) && ((!in && inlen > 0) || !out || !outlen || + outlen > BLAKE2S_HASH_SIZE || keylen > BLAKE2S_KEY_SIZE || + (!key && keylen))); if (keylen) blake2s_init_key(&state, outlen, key, keylen); diff --git a/src/crypto/zinc/blake2s/blake2s.c b/src/crypto/zinc/blake2s/blake2s.c index abe7202..08d3947 100644 --- a/src/crypto/zinc/blake2s/blake2s.c +++ b/src/crypto/zinc/blake2s/blake2s.c @@ -86,9 +86,7 @@ void blake2s_init(struct blake2s_state *state, const size_t outlen) .depth = 1 }; -#ifdef CONFIG_ZINC_SELFTEST - BUG_ON(!outlen || outlen > BLAKE2S_HASH_SIZE); -#endif + WARN_ON(IS_ENABLED(DEBUG) && (!outlen || outlen > BLAKE2S_HASH_SIZE)); blake2s_init_param(state, ¶m); } EXPORT_SYMBOL(blake2s_init); @@ -102,10 +100,8 @@ void blake2s_init_key(struct blake2s_state *state, const size_t outlen, .depth = 1 }; u8 block[BLAKE2S_BLOCK_SIZE] = { 0 }; -#ifdef CONFIG_ZINC_SELFTEST - BUG_ON(!outlen || outlen > BLAKE2S_HASH_SIZE || !key || !keylen || - keylen > BLAKE2S_KEY_SIZE); -#endif + WARN_ON(IS_ENABLED(DEBUG) && (!outlen || outlen > BLAKE2S_HASH_SIZE || + !key || !keylen || keylen > BLAKE2S_KEY_SIZE)); blake2s_init_param(state, ¶m); memcpy(block, key, keylen); blake2s_update(state, block, BLAKE2S_BLOCK_SIZE); @@ -135,9 +131,8 @@ static inline void blake2s_compress(struct blake2s_state *state, u32 v[16]; int i; -#ifdef CONFIG_ZINC_SELFTEST - BUG_ON(nblocks > 1 && inc != BLAKE2S_BLOCK_SIZE); -#endif + WARN_ON(IS_ENABLED(DEBUG) && + (nblocks > 1 && inc != BLAKE2S_BLOCK_SIZE)); if (blake2s_compress_arch(state, block, nblocks, inc)) return; @@ -227,9 +222,8 @@ EXPORT_SYMBOL(blake2s_update); void blake2s_final(struct blake2s_state *state, u8 *out, const size_t outlen) { -#ifdef CONFIG_ZINC_SELFTEST - BUG_ON(!out || !outlen || outlen > BLAKE2S_HASH_SIZE); -#endif + WARN_ON(IS_ENABLED(DEBUG) && + (!out || !outlen || outlen > BLAKE2S_HASH_SIZE)); blake2s_set_lastblock(state); memset(state->buf + state->buflen, 0, BLAKE2S_BLOCK_SIZE - state->buflen); /* Padding */ diff --git a/src/noise.c b/src/noise.c index 814dc11..830858c 100644 --- a/src/noise.c +++ b/src/noise.c @@ -291,13 +291,12 @@ static void kdf(u8 *first_dst, u8 *second_dst, u8 *third_dst, const u8 *data, u8 output[BLAKE2S_HASH_SIZE + 1]; u8 secret[BLAKE2S_HASH_SIZE]; -#ifdef DEBUG - BUG_ON(first_len > BLAKE2S_HASH_SIZE || second_len > BLAKE2S_HASH_SIZE || - third_len > BLAKE2S_HASH_SIZE || - ((second_len || second_dst || third_len || third_dst) && - (!first_len || !first_dst)) || - ((third_len || third_dst) && (!second_len || !second_dst))); -#endif + WARN_ON(IS_ENABLED(DEBUG) && + (first_len > BLAKE2S_HASH_SIZE || second_len > BLAKE2S_HASH_SIZE || + third_len > BLAKE2S_HASH_SIZE || + ((second_len || second_dst || third_len || third_dst) && + (!first_len || !first_dst)) || + ((third_len || third_dst) && (!second_len || !second_dst)))); /* Extract entropy from data into secret */ blake2s_hmac(secret, data, chaining_key, BLAKE2S_HASH_SIZE, data_len, |