changeset 3451:211f0c9588c2 HEAD

Define I_BYTE_ORDER macro ourself because BYTE_ORDER can't seem to be relied on. Fixes SHA1 giving wrong checksums at least in Solaris/sparc.
author Timo Sirainen <tss@iki.fi>
date Thu, 30 Jun 2005 23:55:34 +0300
parents 5c92b51f2b38
children 09a585f5ad4b
files configure.in src/lib/printf-upper-bound.c src/lib/sha1.c
diffstat 3 files changed, 10 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/configure.in	Thu Jun 30 23:38:48 2005 +0300
+++ b/configure.in	Thu Jun 30 23:55:34 2005 +0300
@@ -1,4 +1,4 @@
-AC_INIT(dovecot, 1.0-test67, [dovecot@dovecot.org])
+AC_INIT(dovecot, 1.0-test73, [dovecot@dovecot.org])
 AC_CONFIG_SRCDIR([src])
 
 AC_CONFIG_HEADERS([config.h])
@@ -1317,9 +1317,10 @@
 AC_C_BIGENDIAN
 
 if test $ac_cv_c_bigendian = yes; then
+	AC_DEFINE_UNQUOTED(I_BYTE_ORDER, BIG_ENDIAN, Big endian CPU)
 	flags=0
-
 else
+	AC_DEFINE_UNQUOTED(I_BYTE_ORDER, LITTLE_ENDIAN, Little endian CPU)
 	flags=1
 fi
 
--- a/src/lib/printf-upper-bound.c	Thu Jun 30 23:38:48 2005 +0300
+++ b/src/lib/printf-upper-bound.c	Thu Jun 30 23:55:34 2005 +0300
@@ -25,7 +25,7 @@
 #define G_IEEE754_DOUBLE_BIAS   (1023)
 /* multiply with base2 exponent to get base10 exponent (nomal numbers) */
 #define G_LOG_2_BASE_10         (0.30102999566398119521)
-#if G_BYTE_ORDER == G_LITTLE_ENDIAN
+#if I_BYTE_ORDER == LITTLE_ENDIAN
 union _GDoubleIEEE754
 {
   double v_double;
@@ -36,7 +36,7 @@
     unsigned int sign : 1;
   } mpn;
 };
-#elif G_BYTE_ORDER == G_BIG_ENDIAN
+#elif I_BYTE_ORDER == BIG_ENDIAN
 union _GDoubleIEEE754
 {
   double v_double;
--- a/src/lib/sha1.c	Thu Jun 30 23:38:48 2005 +0300
+++ b/src/lib/sha1.c	Thu Jun 30 23:55:34 2005 +0300
@@ -38,15 +38,10 @@
 #include "sha1.h"
 #include "safe-memset.h"
 
-/* sanity check */
-#if BYTE_ORDER != BIG_ENDIAN
-# if BYTE_ORDER != LITTLE_ENDIAN
-#  define unsupported 1
-# endif
+#if I_BYTE_ORDER != LITTLE_ENDIAN && I_BYTE_ORDER != BIG_ENDIAN
+#  error unknown endian
 #endif
 
-#ifndef unsupported
-
 /* constant table */
 static uint32_t _K[] = { 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xca62c1d6 };
 #define	K(t)	_K[(t) / 20]
@@ -89,7 +84,7 @@
 	size_t t, s;
 	uint32_t	tmp;
 
-#if BYTE_ORDER == LITTLE_ENDIAN
+#if I_BYTE_ORDER == LITTLE_ENDIAN
 	struct sha1_ctxt tctxt;
 	memmove(&tctxt.m.b8[0], &ctxt->m.b8[0], 64);
 	ctxt->m.b8[0] = tctxt.m.b8[3]; ctxt->m.b8[1] = tctxt.m.b8[2];
@@ -198,7 +193,7 @@
 	memset(&ctxt->m.b8[padstart], 0, padlen - 8);
 	COUNT += (padlen - 8);
 	COUNT %= 64;
-#if BYTE_ORDER == BIG_ENDIAN
+#if I_BYTE_ORDER == BIG_ENDIAN
 	PUTPAD(ctxt->c.b8[0]); PUTPAD(ctxt->c.b8[1]);
 	PUTPAD(ctxt->c.b8[2]); PUTPAD(ctxt->c.b8[3]);
 	PUTPAD(ctxt->c.b8[4]); PUTPAD(ctxt->c.b8[5]);
@@ -244,7 +239,7 @@
 
 	digest = (uint8_t *)digest0;
 	sha1_pad(ctxt);
-#if BYTE_ORDER == BIG_ENDIAN
+#if I_BYTE_ORDER == BIG_ENDIAN
 	memmove(digest, &ctxt->h.b8[0], 20);
 #else
 	digest[0] = ctxt->h.b8[3]; digest[1] = ctxt->h.b8[2];
@@ -270,5 +265,3 @@
 	sha1_loop(&ctx, data, size);
 	sha1_result(&ctx, result);
 }
-
-#endif /*unsupported*/