aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
authorGravatar David Bremner <david@tethera.net>2013-11-24 17:29:42 -0400
committerGravatar David Bremner <david@tethera.net>2013-11-25 07:55:54 -0400
commit20adfe39d7624150a5b337bb77a9647bb3def54b (patch)
treed05e142abc3069235a8a6f0c9374534601e531db /lib
parent89bf67fe41e3db270366a49be4f0a7afb07d0eae (diff)
lib: fix byte order test in libsha1.c
Previously PLATFORM_BYTE_ORDER and IS_LITTLE_ENDIAN were not defined, so the little endian code was always compiled in. This will have the effect that the "SHA1s" on big endian architectures will change (i.e. become actual sha1s). So someone re-indexing their database could conceivable lose tags on messages without a message-id header.
Diffstat (limited to 'lib')
-rw-r--r--lib/libsha1.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/lib/libsha1.c b/lib/libsha1.c
index 5d16f6ab..87c7c528 100644
--- a/lib/libsha1.c
+++ b/lib/libsha1.c
@@ -49,11 +49,20 @@ extern "C"
#define bswap_32(x) ((rotr32((x), 24) & 0x00ff00ff) | (rotr32((x), 8) & 0xff00ff00))
-#if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN)
-#define bsw_32(p,n) \
- { int _i = (n); while(_i--) ((uint32_t*)p)[_i] = bswap_32(((uint32_t*)p)[_i]); }
+/* 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
#else
-#define bsw_32(p,n)
+# error "macro __BYTE_ORDER__ is not defined"
#endif
#define SHA1_MASK (SHA1_BLOCK_SIZE - 1)