Skip to content

Commit 979961c

Browse files
Merge #787: Use preprocessor macros instead of autoconf to detect endianness
0dccf98 Use preprocessor macros instead of autoconf to detect endianness (Tim Ruffing) Pull request description: This does not fix any particular issue but it's preferable to not rely on autoconf. This avoids endianness mess for users on BE hosts if they use their build without autoconf. The macros are carefully written to err on the side of the caution, e.g., we #error if the user manually configures a different endianness than what we detect. Supersedes #770 . ACKs for top commit: sipa: ACK 0dccf98 gmaxwell: ACK 0dccf98 Tree-SHA512: 6779458de5cb6eaef2ac37f9d4b8fa6c9b299f58f6e5b72f2b0d7e36c12ea06074e483acfb85085a147e0f4b51cd67d897f61a67250ec1cea284a0f7680eb2e8
2 parents 887bd1f + 0dccf98 commit 979961c

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

configure.ac

-2
Original file line numberDiff line numberDiff line change
@@ -421,8 +421,6 @@ if test x"$enable_module_recovery" = x"yes"; then
421421
AC_DEFINE(ENABLE_MODULE_RECOVERY, 1, [Define this symbol to enable the ECDSA pubkey recovery module])
422422
fi
423423

424-
AC_C_BIGENDIAN()
425-
426424
if test x"$use_external_asm" = x"yes"; then
427425
AC_DEFINE(USE_EXTERNAL_ASM, 1, [Define this symbol if an external (non-inline) assembly implementation is used])
428426
fi

src/hash_impl.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#define SECP256K1_HASH_IMPL_H
99

1010
#include "hash.h"
11+
#include "util.h"
1112

1213
#include <stdlib.h>
1314
#include <stdint.h>
@@ -27,9 +28,9 @@
2728
(h) = t1 + t2; \
2829
} while(0)
2930

30-
#ifdef WORDS_BIGENDIAN
31+
#if defined(SECP256K1_BIG_ENDIAN)
3132
#define BE32(x) (x)
32-
#else
33+
#elif defined(SECP256K1_LITTLE_ENDIAN)
3334
#define BE32(p) ((((p) & 0xFF) << 24) | (((p) & 0xFF00) << 8) | (((p) & 0xFF0000) >> 8) | (((p) & 0xFF000000) >> 24))
3435
#endif
3536

src/util.h

+14
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,20 @@ static SECP256K1_INLINE void *manual_alloc(void** prealloc_ptr, size_t alloc_siz
176176
# define SECP256K1_GNUC_EXT
177177
#endif
178178

179+
#if defined(__BYTE_ORDER__)
180+
# if defined(__ORDER_LITTLE_ENDIAN__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ && !defined(SECP256K1_LITTLE_ENDIAN)
181+
# define SECP256K1_LITTLE_ENDIAN
182+
# elif defined(__ORDER_BIG_ENDIAN__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ && !defined(SECP256K1_BIG_ENDIAN)
183+
# define SECP256K1_BIG_ENDIAN
184+
# endif
185+
#endif
186+
#if defined(_MSC_VER) && defined(_WIN32) && !defined(SECP256K1_LITTLE_ENDIAN)
187+
# define SECP256K1_LITTLE_ENDIAN
188+
#endif
189+
#if defined(SECP256K1_LITTLE_ENDIAN) == defined(SECP256K1_BIG_ENDIAN)
190+
# error Please make sure that either SECP256K1_LITTLE_ENDIAN or SECP256K1_BIG_ENDIAN is set, see src/util.h.
191+
#endif
192+
179193
/* Zero memory if flag == 1. Flag must be 0 or 1. Constant time. */
180194
static SECP256K1_INLINE void memczero(void *s, size_t len, int flag) {
181195
unsigned char *p = (unsigned char *)s;

0 commit comments

Comments
 (0)