diff options
author | David Bremner <david@tethera.net> | 2013-11-25 22:55:24 -0400 |
---|---|---|
committer | David Bremner <david@tethera.net> | 2013-11-27 07:43:29 -0400 |
commit | b9f0e6923d645a044f837d61a9343ea16d56504e (patch) | |
tree | e87b30e7f490038ce9db6768fe7e1b02e4d98de6 /lib | |
parent | 7f07bfd6d0189afcd9d260f6f560056dd3476f66 (diff) |
util: detect byte order
Unfortunately old versions of GCC and clang do not provide byte order
macros, so we re-invent them.
If UTIL_BYTE_ORDER is not defined or defined to 0, we fall back to
macros supported by recent versions of GCC and clang
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libsha1.c | 21 |
1 files changed, 7 insertions, 14 deletions
diff --git a/lib/libsha1.c b/lib/libsha1.c index 87c7c528..aaaa4eb2 100644 --- a/lib/libsha1.c +++ b/lib/libsha1.c @@ -34,7 +34,7 @@ */ #include <string.h> /* for memcpy() etc. */ - +#include "endian-util.h" #include "libsha1.h" #if defined(__cplusplus) @@ -49,20 +49,13 @@ extern "C" #define bswap_32(x) ((rotr32((x), 24) & 0x00ff00ff) | (rotr32((x), 8) & 0xff00ff00)) -/* The macros __BYTE_ORDER__ and __ORDER_*_ENDIAN__ are GNU C - * extensions. They are also supported by clang as of v3.2 */ - -#ifdef __BYTE_ORDER__ -# if (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) -# define bsw_32(p,n) \ - { int _i = (n); while(_i--) ((uint32_t*)p)[_i] = bswap_32(((uint32_t*)p)[_i]); } -# elif (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) -# define bsw_32(p,n) -# else -# error "unknown byte order" -# endif +#if (UTIL_BYTE_ORDER == UTIL_ORDER_LITTLE_ENDIAN) +# define bsw_32(p,n) \ + { int _i = (n); while(_i--) ((uint32_t*)p)[_i] = bswap_32(((uint32_t*)p)[_i]); } +#elif (UTIL_BYTE_ORDER == UTIL_ORDER_BIG_ENDIAN) +# define bsw_32(p,n) #else -# error "macro __BYTE_ORDER__ is not defined" +# error "Unsupported byte order" #endif #define SHA1_MASK (SHA1_BLOCK_SIZE - 1) |