aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2018-02-14 18:35:35 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2018-02-14 18:35:35 +0100
commitacd8820e464a57fbf59b9cb5c26a9b9a844de79b (patch)
tree56531dee6f05e01bb88bd32af2f676e7a7138454
parentallowedips: indicate to clang-analyzer that trie is non-null (diff)
downloadwireguard-monolithic-historical-acd8820e464a57fbf59b9cb5c26a9b9a844de79b.tar.xz
wireguard-monolithic-historical-acd8820e464a57fbf59b9cb5c26a9b9a844de79b.zip
blake2s: use union instead of casting
This deals with alignment more easily and also helps squelch a clang-analyzer warning.
-rw-r--r--src/Makefile2
-rw-r--r--src/crypto/blake2s.c34
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 <linux/bug.h>
#include <asm/unaligned.h>
-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)