From eba151c179fa55f74a1e492cf36513ee636954ed Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Mon, 26 Aug 2024 09:13:25 +0200 Subject: Don’t violate strict aliasing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/sha1-generic.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/sha1-generic.c') diff --git a/src/sha1-generic.c b/src/sha1-generic.c index d897a8f..600dcf5 100644 --- a/src/sha1-generic.c +++ b/src/sha1-generic.c @@ -1,3 +1,5 @@ +#include + #include "common.h" #include "sha1.h" #include "xendian.h" @@ -18,8 +20,11 @@ sha1hashblk(sha1_t *s, const uint8_t *blk) uint32_t w[80]; uint32_t a, b, c, d, e, tmp; - for (int i = 0; i < 16; i++) - w[i] = htobe32(((uint32_t *)blk)[i]); + for (int i = 0; i < 16; i++) { + uint32_t n; + memcpy(&n, blk + i*sizeof(n), sizeof(n)); + w[i] = htobe32(n); + } for (int i = 16; i < 32; i++) w[i] = rotl32(w[i-3] ^ w[i-8] ^ w[i-14] ^ w[i-16], 1); for (int i = 32; i < 80; i++) -- cgit v1.2.3