From acd8820e464a57fbf59b9cb5c26a9b9a844de79b Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Wed, 14 Feb 2018 18:35:35 +0100 Subject: blake2s: use union instead of casting This deals with alignment more easily and also helps squelch a clang-analyzer warning. --- src/Makefile | 2 +- src/crypto/blake2s.c | 34 ++++++++++++++++------------------ 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/Makefile b/src/Makefile index 0193e10..c7ba400 100644 --- a/src/Makefile +++ b/src/Makefile @@ -73,7 +73,7 @@ style: $(KERNELDIR)/scripts/checkpatch.pl -f --max-line-length=4000 --codespell --color=always $(filter-out wireguard.mod.c,$(wildcard *.c)) $(wildcard *.h) check: clean - scan-build --view --keep-going $(MAKE) module tools CONFIG_WIREGUARD_DEBUG=y C=2 CF="-D__CHECK_ENDIAN__" + scan-build --html-title=WireGuard -maxloop 100 --view --keep-going $(MAKE) module tools CONFIG_WIREGUARD_DEBUG=y C=2 CF="-D__CHECK_ENDIAN__" coccicheck: clean @$(MAKE) -C $(KERNELDIR) M=$(PWD) CONFIG_WIREGUARD_DEBUG=y coccicheck MODE=report diff --git a/src/crypto/blake2s.c b/src/crypto/blake2s.c index 2fbaf09..1bb3cc1 100644 --- a/src/crypto/blake2s.c +++ b/src/crypto/blake2s.c @@ -13,18 +13,21 @@ #include #include -typedef struct { - u8 digest_length; - u8 key_length; - u8 fanout; - u8 depth; - u32 leaf_length; - u32 node_offset; - u16 xof_length; - u8 node_depth; - u8 inner_length; - u8 salt[8]; - u8 personal[8]; +typedef union { + struct { + u8 digest_length; + u8 key_length; + u8 fanout; + u8 depth; + u32 leaf_length; + u32 node_offset; + u16 xof_length; + u8 node_depth; + u8 inner_length; + u8 salt[8]; + u8 personal[8]; + }; + __le32 words[8]; } __packed blake2s_param; static const u32 blake2s_iv[8] = { @@ -65,16 +68,11 @@ static inline void blake2s_increment_counter(struct blake2s_state *state, const static inline void blake2s_init_param(struct blake2s_state *state, const blake2s_param *param) { - const __le32 *p; int i; memset(state, 0, sizeof(struct blake2s_state)); for (i = 0; i < 8; ++i) - state->h[i] = blake2s_iv[i]; - p = (const __le32 *)param; - /* IV XOR ParamBlock */ - for (i = 0; i < 8; ++i) - state->h[i] ^= le32_to_cpu(p[i]); + state->h[i] = blake2s_iv[i] ^ le32_to_cpu(param->words[i]); } void blake2s_init(struct blake2s_state *state, const size_t outlen) -- cgit v1.2.3-59-g8ed1b