From: Ulrik Sverdrup Date: Sun, 13 Jan 2013 15:24:11 +0000 (+0100) Subject: siphash: Use simple but misalignment-correct implementation of W64 X-Git-Url: http://git.ozlabs.org/?p=ccan;a=commitdiff_plain;h=bbfec6b1b466bf0000b47eb33f2c624871e0dbd2;hp=480b3117c39b91fcb6d39c60222232b7608f5507 siphash: Use simple but misalignment-correct implementation of W64 A simple implementation compiles very well with gcc and clang on ppc and x86, and will handle any-aligned input. --- diff --git a/ccan/siphash/siphash.c b/ccan/siphash/siphash.c index 93eac040..7f6706ca 100644 --- a/ccan/siphash/siphash.c +++ b/ccan/siphash/siphash.c @@ -2,6 +2,8 @@ #include +#include + #include "siphash.h" typedef uint64_t u64; @@ -23,8 +25,13 @@ enum sip_index { A=0, B=2, C=1, D=3, E=4 }; SIP_HALF_ROUND((W)[C], (W)[B], (W)[A], (W)[D], 17, 21); \ } while(0) -/* Load a 64-bit word as little endian */ -#define W64(S,I) (le64_to_cpu(*((u64 *)(S) + (I)))) + +static inline u64 W64(const void *p, size_t I) +{ + uint64_t x; + memcpy(&x, (char *)p + I*sizeof(x), sizeof(x)); + return le64_to_cpu(x); +} static void siphash_init(u64 v[5], const unsigned char key[16]) {