From f3f1a805ceeaaaf904d848cdf8e5ce3785afd7a2 Mon Sep 17 00:00:00 2001 From: Mirek Kratochvil Date: Thu, 28 Apr 2016 12:18:35 +0200 Subject: [PATCH] cubehash_impl: support non-little-endian architectures --- src/cubehash_impl.h | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/cubehash_impl.h b/src/cubehash_impl.h index ff2e0bc..a9aab46 100644 --- a/src/cubehash_impl.h +++ b/src/cubehash_impl.h @@ -25,10 +25,6 @@ #include -#if __BYTE_ORDER__!=__ORDER_LITTLE_ENDIAN__ -#error "Only for little endian now, sorry." -#endif - #define ROT(a,b,n) (((a) << (b)) | ((a) >> (n - b))) #define i16(cmd) for(i=0;i<16;++i) cmd; @@ -86,7 +82,14 @@ public: int i; for (i = 0; i + 4 <= B; i += 4) +#if __BYTE_ORDER__==__ORDER_LITTLE_ENDIAN__ //allow a small speedup for LE architectures X[i / 4] ^= * (uint32_t*) &data[i]; +#else + X[i / 4] ^= (uint32_t) data[i] + | ( (uint32_t) data[i + 1]) << 8 + | ( (uint32_t) data[i + 2]) << 16 + | ( (uint32_t) data[i + 3]) << 24; +#endif for (; i < B; ++i) X[i / 4] ^= ( (uint32_t) (data[i])) << ( (i % 4) * 8); @@ -98,7 +101,14 @@ public: int i; for (i = 0; i + 4 <= n; i += 4) +#if __BYTE_ORDER__==__ORDER_LITTLE_ENDIAN__ X[i / 4] ^= * (uint32_t*) &data[i]; +#else + X[i / 4] ^= (uint32_t) data[i] + | ( (uint32_t) data[i + 1]) << 8 + | ( (uint32_t) data[i + 2]) << 16 + | ( (uint32_t) data[i + 3]) << 24; +#endif for (; i < n; ++i) X[i / 4] ^= ( (uint32_t) (data[i])) << ( (i % 4) * 8);