diff options
author | Thomas Voss <mail@thomasvoss.com> | 2024-08-26 09:13:25 +0200 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2024-08-26 09:16:04 +0200 |
commit | eba151c179fa55f74a1e492cf36513ee636954ed (patch) | |
tree | e2bc9fc0767c835a6433cc3cff70b5b51b59afa0 /src | |
parent | 008417a47ca478705fe1a72174d8e0816dc3fcaa (diff) |
Don’t violate strict aliasing
Diffstat (limited to 'src')
-rw-r--r-- | src/sha1-generic.c | 9 |
1 files changed, 7 insertions, 2 deletions
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 <string.h> + #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++) |