build: Switch to AC_C_BIGENDIAN defining WORD_BIGENDIAN We should use the autoconf macro instead of expecting the system to provide the endianness information, which many do not. [guillem@hadrons.org: - Use autoconf macro instead of gnulib one. - Slightly reword commit message. ] Signed-off-by: Guillem Jover <guillem@hadrons.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
diff --git a/configure.ac b/configure.ac
index 6cc811e..633605f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -31,9 +31,10 @@ AC_PROG_CC
# Checks for libraries.
# Checks for header files.
-AC_CHECK_HEADERS([sys/param.h sys/endian.h])
+AC_CHECK_HEADERS([sys/param.h])
# Checks for typedefs, structures, and compiler characteristics.
+AC_C_BIGENDIAN
AC_TYPE_OFF_T
AC_TYPE_SIZE_T
AC_TYPE_SSIZE_T
diff --git a/src/md4.c b/src/md4.c
index 25d4d95..fdb646c 100644
--- a/src/md4.c
+++ b/src/md4.c
@@ -158,7 +158,7 @@ MD4Transform(uint32_t state[4], const uint8_t block[MD4_BLOCK_LENGTH])
{
uint32_t a, b, c, d, in[MD4_BLOCK_LENGTH / 4];
-#if BYTE_ORDER == LITTLE_ENDIAN
+#ifndef WORDS_BIGENDIAN
memcpy(in, block, sizeof(in));
#else
for (a = 0; a < MD4_BLOCK_LENGTH / 4; a++) {
diff --git a/src/md5.c b/src/md5.c
index b3a0935..a6877bc 100644
--- a/src/md5.c
+++ b/src/md5.c
@@ -158,7 +158,7 @@ MD5Transform(uint32_t state[4], const uint8_t block[MD5_BLOCK_LENGTH])
{
uint32_t a, b, c, d, in[MD5_BLOCK_LENGTH / 4];
-#if BYTE_ORDER == LITTLE_ENDIAN
+#ifndef WORDS_BIGENDIAN
memcpy(in, block, sizeof(in));
#else
for (a = 0; a < MD5_BLOCK_LENGTH / 4; a++) {
diff --git a/src/rmd160.c b/src/rmd160.c
index 3f13243..e0904f9 100644
--- a/src/rmd160.c
+++ b/src/rmd160.c
@@ -31,11 +31,6 @@
#include <string.h>
#include <sys/types.h>
-#ifdef HAVE_SYS_ENDIAN_H
-#include <sys/endian.h>
-#else
-#include <endian.h>
-#endif
#include <rmd160.h>
#define PUT_64BIT_LE(cp, value) do { \
@@ -170,7 +165,7 @@ RMD160Transform(uint32_t state[5], const uint8_t block[RMD160_BLOCK_LENGTH])
{
uint32_t a, b, c, d, e, aa, bb, cc, dd, ee, t, x[16];
-#if BYTE_ORDER == LITTLE_ENDIAN
+#ifndef WORDS_BIGENDIAN
memcpy(x, block, RMD160_BLOCK_LENGTH);
#else
int i;
diff --git a/src/sha1.c b/src/sha1.c
index 19b9219..2f04b82 100644
--- a/src/sha1.c
+++ b/src/sha1.c
@@ -26,7 +26,7 @@
* blk0() and blk() perform the initial expand.
* I got the idea of expanding during the round function from SSLeay
*/
-#if BYTE_ORDER == LITTLE_ENDIAN
+#ifndef WORDS_BIGENDIAN
# define blk0(i) (block->l[i] = (rol(block->l[i],24)&0xFF00FF00) \
|(rol(block->l[i],8)&0x00FF00FF))
#else
diff --git a/src/sha2.c b/src/sha2.c
index 24a68e7..849ebbb 100644
--- a/src/sha2.c
+++ b/src/sha2.c
@@ -61,39 +61,6 @@
*
*/
-/*** SHA-256/384/512 Machine Architecture Definitions *****************/
-/*
- * BYTE_ORDER NOTE:
- *
- * Please make sure that your system defines BYTE_ORDER. If your
- * architecture is little-endian, make sure it also defines
- * LITTLE_ENDIAN and that the two (BYTE_ORDER and LITTLE_ENDIAN) are
- * equivilent.
- *
- * If your system does not define the above, then you can do so by
- * hand like this:
- *
- * #define LITTLE_ENDIAN 1234
- * #define BIG_ENDIAN 4321
- *
- * And for little-endian machines, add:
- *
- * #define BYTE_ORDER LITTLE_ENDIAN
- *
- * Or for big-endian machines:
- *
- * #define BYTE_ORDER BIG_ENDIAN
- *
- * The FreeBSD machine this was written on defines BYTE_ORDER
- * appropriately by including <sys/types.h> (which in turn includes
- * <machine/endian.h> where the appropriate definitions are actually
- * made).
- */
-#if !defined(BYTE_ORDER) || (BYTE_ORDER != LITTLE_ENDIAN && BYTE_ORDER != BIG_ENDIAN)
-#error Define BYTE_ORDER to be equal to either LITTLE_ENDIAN or BIG_ENDIAN
-#endif
-
-
/*** SHA-256/384/512 Various Length Definitions ***********************/
/* NOTE: Most of these are in sha2.h */
#define SHA256_SHORT_BLOCK_LENGTH (SHA256_BLOCK_LENGTH - 8)
@@ -545,7 +512,7 @@ SHA256Final(uint8_t digest[SHA256_DIGEST_LENGTH], SHA2_CTX *context)
/* If no digest buffer is passed, we don't bother doing this: */
if (digest != NULL) {
-#if BYTE_ORDER == LITTLE_ENDIAN
+#ifndef WORDS_BIGENDIAN
int i;
/* Convert TO host byte order */
@@ -827,7 +794,7 @@ SHA512Final(uint8_t digest[SHA512_DIGEST_LENGTH], SHA2_CTX *context)
/* If no digest buffer is passed, we don't bother doing this: */
if (digest != NULL) {
-#if BYTE_ORDER == LITTLE_ENDIAN
+#ifndef WORDS_BIGENDIAN
int i;
/* Convert TO host byte order */
@@ -864,7 +831,7 @@ SHA384Final(uint8_t digest[SHA384_DIGEST_LENGTH], SHA2_CTX *context)
/* If no digest buffer is passed, we don't bother doing this: */
if (digest != NULL) {
-#if BYTE_ORDER == LITTLE_ENDIAN
+#ifndef WORDS_BIGENDIAN
int i;
/* Convert TO host byte order */