From 0677ba3c1ec30dd3a8aad8047e85081f4c09a6ff Mon Sep 17 00:00:00 2001 From: SODA Noriyuki Date: Fri, 30 Jun 2017 01:08:01 +0900 Subject: Big Endian Detection: fix breakage on *BSD & newlib MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In 33a694a ("Fix issues with a big endian platform", 2017-05-15) *BSD and newlib was broken because _BIG_ENDIAN is always defined, even on little-endian platforms. To fix this we need to also check the single-underscore version of BIG_ENDIAN & LITTLE_ENDIAN, but only do this if _LITTLE_ENDIAN is also defined. This makes sure that on Solaris we don't break where _BIG_ENDIAN is simply defined, not to any value (but _LITTLE_ENDIAN won't be). See http://src.illumos.org/source/xref/illumos-gate/usr/src/uts/common/sys/isa_defs.h#397 The https://github.com/cr-marcstevens/sha1collisiondetection/pull/34 pull request has a lot more details on the various issues involved, things that were tried (and not tried) etc. [Commit message & rebase by Ævar] --- lib/sha1.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/sha1.c b/lib/sha1.c index 260a3f1..a116893 100644 --- a/lib/sha1.c +++ b/lib/sha1.c @@ -67,6 +67,18 @@ #endif /* Not under GCC-alike or glibc */ +#elif defined(_BYTE_ORDER) && defined(_BIG_ENDIAN) && defined(_LITTLE_ENDIAN) +/* + * *BSD and newlib (embeded linux, cygwin, etc). + * the defined(_BIG_ENDIAN) && defined(_LITTLE_ENDIAN) part prevents + * this condition from matching with Solaris/sparc. + * (Solaris defines only one endian macro) + */ +#if _BYTE_ORDER == _BIG_ENDIAN +#define SHA1DC_BIGENDIAN +#endif + +/* Not under GCC-alike or glibc or *BSD or newlib */ #elif (defined(__ARMEB__) || defined(__THUMBEB__) || defined(__AARCH64EB__) || \ defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || \ defined(__sparc)) @@ -77,14 +89,14 @@ */ #define SHA1DC_BIGENDIAN -/* Not under GCC-alike or glibc or */ +/* Not under GCC-alike or glibc or *BSD or newlib or */ #elif defined(SHA1DC_ON_INTEL_LIKE_PROCESSOR) /* * As a last resort before we do anything else we're not 100% sure * about below, we blacklist specific processors here. We could add * more, see e.g. https://wiki.debian.org/ArchitectureSpecificsMemo */ -#else /* Not under GCC-alike or glibc or or */ +#else /* Not under GCC-alike or glibc or *BSD or newlib or or */ /* We do nothing more here for now */ /*#error "Uncomment this to see if you fall through all the detection"*/ -- cgit v1.2.3