|
16 | 16 |
|
17 | 17 | #include <assert.h> |
18 | 18 | #include <string.h> |
19 | | -#if defined(__GNUC__) && !defined(__MINGW32__) && !defined(__clang__) && !defined(__QNX__) |
20 | | -#include <endian.h> |
21 | | -#endif |
22 | 19 |
|
23 | 20 | #include "sha1.h" |
24 | 21 | #include "sha2.h" |
|
37 | 34 |
|
38 | 35 | static inline void write32_be(uint32_t n, uint8_t out[4]) |
39 | 36 | { |
40 | | -#if defined(__GNUC__) && __GNUC__ >= 4 && __BYTE_ORDER == __LITTLE_ENDIAN |
41 | | - *(uint32_t *)(out) = __builtin_bswap32(n); |
| 37 | +#if SQLITE_BYTEORDER==4321 |
| 38 | + memcpy(out, &n, 4); |
| 39 | +#elif SQLITE_BYTEORDER==1234 && GCC_VERSION>=4003000 |
| 40 | + u32 x = __builtin_bswap32(n); |
| 41 | + memcpy(out, &x, 4); |
| 42 | +#elif SQLITE_BYTEORDER==1234 && MSVC_VERSION>=1300 |
| 43 | + u32 x = _byteswap_ulong(n); |
| 44 | + memcpy(out, &x, 4); |
42 | 45 | #else |
43 | | - out[0] = (n >> 24) & 0xff; |
44 | | - out[1] = (n >> 16) & 0xff; |
45 | | - out[2] = (n >> 8) & 0xff; |
46 | | - out[3] = n & 0xff; |
| 46 | + out[0] = (n >> 24) & 0xFF; |
| 47 | + out[1] = (n >> 16) & 0xFF; |
| 48 | + out[2] = (n >> 8) & 0xFF; |
| 49 | + out[3] = (n >> 0) & 0xFF; |
47 | 50 | #endif |
48 | 51 | } |
49 | 52 |
|
50 | 53 | static inline void write64_be(uint64_t n, uint8_t out[8]) |
51 | 54 | { |
52 | | -#if defined(__GNUC__) && __GNUC__ >= 4 && __BYTE_ORDER == __LITTLE_ENDIAN |
53 | | - *(uint64_t *)(out) = __builtin_bswap64(n); |
| 55 | +#if SQLITE_BYTEORDER==1234 && GCC_VERSION>=4003000 |
| 56 | + n = __builtin_bswap64(n); |
| 57 | + memcpy(out, &n, 8); |
| 58 | +#elif SQLITE_BYTEORDER==1234 && MSVC_VERSION>=1300 |
| 59 | + n = _byteswap_uint64(n); |
| 60 | + memcpy(out, &n, 8); |
| 61 | +#elif SQLITE_BYTEORDER==4321 |
| 62 | + memcpy(out, &n, 8); |
54 | 63 | #else |
55 | | - write32_be((n >> 32) & 0xffffffff, out); |
56 | | - write32_be(n & 0xffffffff, out + 4); |
| 64 | + out[0] = (n >> 56) & 0xFF; |
| 65 | + out[1] = (n >> 48) & 0xFF; |
| 66 | + out[2] = (n >> 40) & 0xFF; |
| 67 | + out[3] = (n >> 32) & 0xFF; |
| 68 | + out[4] = (n >> 24) & 0xFF; |
| 69 | + out[5] = (n >> 16) & 0xFF; |
| 70 | + out[6] = (n >> 8) & 0xFF; |
| 71 | + out[7] = (n >> 0) & 0xFF; |
57 | 72 | #endif |
58 | 73 | } |
59 | 74 |
|
|
0 commit comments