From 6bbcefa48bbb9fbb6ef11ebce750bbb6a2135a31 Mon Sep 17 00:00:00 2001 From: Theo Buehler Date: Tue, 11 Apr 2023 16:06:24 +0200 Subject: Import endianness compat from iked (via tobhe) --- include/compat/endian.h | 61 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/include/compat/endian.h b/include/compat/endian.h index cd85f5c..6dfe0b0 100644 --- a/include/compat/endian.h +++ b/include/compat/endian.h @@ -48,4 +48,65 @@ #endif #endif +#if defined(__APPLE__) && !defined(HAVE_ENDIAN_H) +#include +#define betoh16(x) OSSwapBigToHostInt16((x)) +#define htobe16(x) OSSwapHostToBigInt16((x)) +#define betoh32(x) OSSwapBigToHostInt32((x)) +#define htobe32(x) OSSwapHostToBigInt32(x) +#define htole64(x) OSSwapHostToLittleInt64(x) +#define htobe64(x) OSSwapHostToBigInt64(x) +#define letoh64(x) OSSwapLittleToHostInt64(x) +#define betoh64(x) OSSwapBigToHostInt64(x) +#endif /* __APPLE__ && !HAVE_ENDIAN_H */ + +#if defined(_WIN32) && !defined(HAVE_ENDIAN_H) +#include +#define betoh16(x) ntohs((x)) +#define htobe16(x) htons((x)) +#define betoh32(x) ntohl((x)) +#define htobe32(x) ntohl((x)) +#define betoh64(x) ntohll((x)) +#define htobe64(x) ntohll((x)) +#endif /* _WIN32 && !HAVE_ENDIAN_H */ + +#ifdef __linux__ +#if !defined(betoh16) +#define betoh16 be16toh +#endif +#if !defined(betoh32) +#define betoh32 be32toh +#endif +#if !defined(betoh64) +#define betoh64 be64toh +#endif +#endif /* __linux__ */ + +#if defined(__FreeBSD__) +#if !defined(HAVE_ENDIAN_H) +#include +#endif +#if !defined(betoh16) +#define betoh16 be16toh +#endif +#if !defined(betoh32) +#define betoh32 be32toh +#endif +#if !defined(betoh64) +#define betoh64 be64toh +#endif +#endif + +#if defined(__NetBSD__) +#if !defined(betoh16) +#define betoh16 be16toh +#endif +#if !defined(betoh32) +#define betoh32 be32toh +#endif +#if !defined(betoh64) +#define betoh64 be64toh +#endif +#endif + #endif -- cgit v1.2.3-55-g6feb From e61927441352a7ac4c51b9b8fc2164d1d236e2f3 Mon Sep 17 00:00:00 2001 From: Theo Buehler Date: Tue, 11 Apr 2023 16:18:17 +0200 Subject: Temporarily add sha512.c r1.27 as a patch --- patches/sha512.c.patch | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 patches/sha512.c.patch diff --git a/patches/sha512.c.patch b/patches/sha512.c.patch new file mode 100644 index 0000000..92cfdf4 --- /dev/null +++ b/patches/sha512.c.patch @@ -0,0 +1,35 @@ +diff -u -p -r1.29 -r1.28 +--- crypto/sha/sha512.c 11 Apr 2023 13:03:03 -0000 1.29 ++++ crypto/sha/sha512.c 11 Apr 2023 10:35:21 -0000 1.28 +@@ -546,28 +546,9 @@ SHA512_Final(unsigned char *md, SHA512_C + sha512_block_data_order(c, p, 1); + } + +- memset (p + n, 0, sizeof(c->u) - 16 - n); +-#if BYTE_ORDER == BIG_ENDIAN +- c->u.d[SHA_LBLOCK - 2] = c->Nh; +- c->u.d[SHA_LBLOCK - 1] = c->Nl; +-#else +- p[sizeof(c->u) - 1] = (unsigned char)(c->Nl); +- p[sizeof(c->u) - 2] = (unsigned char)(c->Nl >> 8); +- p[sizeof(c->u) - 3] = (unsigned char)(c->Nl >> 16); +- p[sizeof(c->u) - 4] = (unsigned char)(c->Nl >> 24); +- p[sizeof(c->u) - 5] = (unsigned char)(c->Nl >> 32); +- p[sizeof(c->u) - 6] = (unsigned char)(c->Nl >> 40); +- p[sizeof(c->u) - 7] = (unsigned char)(c->Nl >> 48); +- p[sizeof(c->u) - 8] = (unsigned char)(c->Nl >> 56); +- p[sizeof(c->u) - 9] = (unsigned char)(c->Nh); +- p[sizeof(c->u) - 10] = (unsigned char)(c->Nh >> 8); +- p[sizeof(c->u) - 11] = (unsigned char)(c->Nh >> 16); +- p[sizeof(c->u) - 12] = (unsigned char)(c->Nh >> 24); +- p[sizeof(c->u) - 13] = (unsigned char)(c->Nh >> 32); +- p[sizeof(c->u) - 14] = (unsigned char)(c->Nh >> 40); +- p[sizeof(c->u) - 15] = (unsigned char)(c->Nh >> 48); +- p[sizeof(c->u) - 16] = (unsigned char)(c->Nh >> 56); +-#endif ++ memset(p + n, 0, sizeof(c->u) - 16 - n); ++ c->u.d[SHA_LBLOCK - 2] = htobe64(c->Nh); ++ c->u.d[SHA_LBLOCK - 1] = htobe64(c->Nl); + + sha512_block_data_order(c, p, 1); + -- cgit v1.2.3-55-g6feb From 7f319186539ed6e6cf0e475cf84aef296b30b1a4 Mon Sep 17 00:00:00 2001 From: Theo Buehler Date: Tue, 11 Apr 2023 16:37:04 +0200 Subject: attempt to appease mingw32 --- include/compat/endian.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/include/compat/endian.h b/include/compat/endian.h index 6dfe0b0..ca3465d 100644 --- a/include/compat/endian.h +++ b/include/compat/endian.h @@ -62,11 +62,20 @@ #if defined(_WIN32) && !defined(HAVE_ENDIAN_H) #include + #define betoh16(x) ntohs((x)) #define htobe16(x) htons((x)) #define betoh32(x) ntohl((x)) #define htobe32(x) ntohl((x)) #define betoh64(x) ntohll((x)) + +#if !defined(ntohll) +#define ntohll(x) ((1==htonl(1)) ? (x) : ((uint64_t)ntohl((x) & 0xFFFFFFFF) << 32) | ntohl((x) >> 32)) +#endif +#if !defined(htonll) +#define htonll(x) ((1==ntohl(1)) ? (x) : ((uint64_t)htonl((x) & 0xFFFFFFFF) << 32) | htonl((x) >> 32)) +#endif + #define htobe64(x) ntohll((x)) #endif /* _WIN32 && !HAVE_ENDIAN_H */ -- cgit v1.2.3-55-g6feb From be58e25d2c6220ec7d299560facb1cf057dfb76d Mon Sep 17 00:00:00 2001 From: Theo Buehler Date: Tue, 11 Apr 2023 17:33:24 +0200 Subject: Revert "Temporarily add sha512.c r1.27 as a patch" This reverts commit e61927441352a7ac4c51b9b8fc2164d1d236e2f3. --- patches/sha512.c.patch | 35 ----------------------------------- 1 file changed, 35 deletions(-) delete mode 100644 patches/sha512.c.patch diff --git a/patches/sha512.c.patch b/patches/sha512.c.patch deleted file mode 100644 index 92cfdf4..0000000 --- a/patches/sha512.c.patch +++ /dev/null @@ -1,35 +0,0 @@ -diff -u -p -r1.29 -r1.28 ---- crypto/sha/sha512.c 11 Apr 2023 13:03:03 -0000 1.29 -+++ crypto/sha/sha512.c 11 Apr 2023 10:35:21 -0000 1.28 -@@ -546,28 +546,9 @@ SHA512_Final(unsigned char *md, SHA512_C - sha512_block_data_order(c, p, 1); - } - -- memset (p + n, 0, sizeof(c->u) - 16 - n); --#if BYTE_ORDER == BIG_ENDIAN -- c->u.d[SHA_LBLOCK - 2] = c->Nh; -- c->u.d[SHA_LBLOCK - 1] = c->Nl; --#else -- p[sizeof(c->u) - 1] = (unsigned char)(c->Nl); -- p[sizeof(c->u) - 2] = (unsigned char)(c->Nl >> 8); -- p[sizeof(c->u) - 3] = (unsigned char)(c->Nl >> 16); -- p[sizeof(c->u) - 4] = (unsigned char)(c->Nl >> 24); -- p[sizeof(c->u) - 5] = (unsigned char)(c->Nl >> 32); -- p[sizeof(c->u) - 6] = (unsigned char)(c->Nl >> 40); -- p[sizeof(c->u) - 7] = (unsigned char)(c->Nl >> 48); -- p[sizeof(c->u) - 8] = (unsigned char)(c->Nl >> 56); -- p[sizeof(c->u) - 9] = (unsigned char)(c->Nh); -- p[sizeof(c->u) - 10] = (unsigned char)(c->Nh >> 8); -- p[sizeof(c->u) - 11] = (unsigned char)(c->Nh >> 16); -- p[sizeof(c->u) - 12] = (unsigned char)(c->Nh >> 24); -- p[sizeof(c->u) - 13] = (unsigned char)(c->Nh >> 32); -- p[sizeof(c->u) - 14] = (unsigned char)(c->Nh >> 40); -- p[sizeof(c->u) - 15] = (unsigned char)(c->Nh >> 48); -- p[sizeof(c->u) - 16] = (unsigned char)(c->Nh >> 56); --#endif -+ memset(p + n, 0, sizeof(c->u) - 16 - n); -+ c->u.d[SHA_LBLOCK - 2] = htobe64(c->Nh); -+ c->u.d[SHA_LBLOCK - 1] = htobe64(c->Nl); - - sha512_block_data_order(c, p, 1); - -- cgit v1.2.3-55-g6feb