chiark / gitweb /
siphash24: fix memory alignment
authorDaniel Mack <daniel@zonque.org>
Mon, 16 Nov 2015 12:08:34 +0000 (13:08 +0100)
committerSven Eden <yamakuzure@gmx.net>
Wed, 26 Apr 2017 10:58:55 +0000 (12:58 +0200)
Use unaligned_read_le64() to access input buffer when reading complete
64-bit words.

This should fix memory traps on platforms with strict aliasing.

src/basic/siphash24.c

index fa94f80ae8ed49d239bfe1d2a6c2045665792511..c7c465e5cedf8adac525ce8a3affbe60ee5fa51c 100644 (file)
@@ -20,6 +20,7 @@
 #include "sparse-endian.h"
 
 #include "siphash24.h"
+#include "unaligned.h"
 #include "util.h"
 
 static inline uint64_t rotate_left(uint64_t x, uint8_t b) {
@@ -104,7 +105,7 @@ void siphash24_compress(const void *_in, size_t inlen, struct siphash *state) {
         end -= ( state->inlen % sizeof (uint64_t) );
 
         for ( ; in < end; in += 8 ) {
-                m = le64toh(*(le64_t*) in);
+                m = unaligned_read_le64(in);
 #ifdef DEBUG
                 printf("(%3zu) v0 %08x %08x\n", state->inlen, (uint32_t) (state->v0 >> 32), (uint32_t) state->v0);
                 printf("(%3zu) v1 %08x %08x\n", state->inlen, (uint32_t) (state->v1 >> 32), (uint32_t) state->v1);