Skip to content

Commit 0591ed6

Browse files
committed
Move endianness macros into util.h
1 parent cc623d5 commit 0591ed6

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

src/hash_impl.h

Lines changed: 1 addition & 6 deletions
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,12 +28,6 @@
2728
(h) = t1 + t2; \
2829
} while(0)
2930

30-
#ifdef WORDS_BIGENDIAN
31-
#define BE32(x) (x)
32-
#else
33-
#define BE32(p) ((((p) & 0xFF) << 24) | (((p) & 0xFF00) << 8) | (((p) & 0xFF0000) >> 8) | (((p) & 0xFF000000) >> 24))
34-
#endif
35-
3631
static void secp256k1_sha256_initialize(secp256k1_sha256_t *hash) {
3732
hash->s[0] = 0x6a09e667ul;
3833
hash->s[1] = 0xbb67ae85ul;

src/util.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,21 @@ static SECP256K1_INLINE void *checked_malloc(const callback_t* cb, size_t size)
103103
SECP256K1_GNUC_EXT typedef unsigned __int128 uint128_t;
104104
#endif
105105

106+
#define BYTESWAP32(p) ((((p) & 0xFF) << 24) | (((p) & 0xFF00) << 8) | (((p) & 0xFF0000) >> 8) | (((p) & 0xFF000000) >> 24))
107+
#define BYTESWAP64(p) ((((p) & 0xFF) << 56) | (((p) & 0xFF00) << 40) | (((p) & 0xFF0000) << 24) | (((p) & 0xFF000000) << 8) | \
108+
(((p) & 0xFF00000000ull) >> 8) | (((p) & 0xFF0000000000ull) >> 24) | \
109+
(((p) & 0xFF000000000000ull) >> 40) | (((p) & 0xFF00000000000000ull) >> 56))
110+
111+
#ifdef WORDS_BIGENDIAN
112+
#define BE32(x) (x)
113+
#define BE64(x) (x)
114+
#define LE32(p) BYTESWAP32(p)
115+
#define LE64(p) BYTESWAP64(p)
116+
#else
117+
#define BE32(p) BYTESWAP32(p)
118+
#define BE64(p) BYTESWAP64(p)
119+
#define LE32(x) (x)
120+
#define LE64(x) (x)
121+
#endif
122+
106123
#endif

0 commit comments

Comments
 (0)