From aaa4fda5cf4d77d9800cbaaf98c639b3418648c6 Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Mon, 24 Aug 2020 12:19:33 +0200 Subject: deps: ntlmclient: provide platform-independent htonll implementation With the introduction of ntlmclient, we've started playing whac-a-mole with platforms to support the non-standard htonll function. Let's end this game once and for all by providing a generic implementation that's implemented via htonl(3P) and a endianness-check in CMake. --- deps/ntlmclient/CMakeLists.txt | 7 +++++++ deps/ntlmclient/compat.h | 39 ++++++++++++++------------------------- deps/ntlmclient/ntlm.c | 6 +++--- 3 files changed, 24 insertions(+), 28 deletions(-) diff --git a/deps/ntlmclient/CMakeLists.txt b/deps/ntlmclient/CMakeLists.txt index 5fbf0d0f4..1e7176802 100644 --- a/deps/ntlmclient/CMakeLists.txt +++ b/deps/ntlmclient/CMakeLists.txt @@ -1,3 +1,5 @@ +INCLUDE(TestBigEndian) + FILE(GLOB SRC_NTLMCLIENT "ntlm.c" "unicode_builtin.c" "util.c") LIST(SORT SRC_NTLMCLIENT) @@ -5,6 +7,11 @@ ADD_DEFINITIONS(-DNTLM_STATIC=1) DISABLE_WARNINGS(implicit-fallthrough) +TEST_BIG_ENDIAN(BIG_ENDIAN) +IF(BIG_ENDIAN) + ADD_DEFINITIONS(-DNTLM_BIG_ENDIAN) +ENDIF() + IF(USE_HTTPS STREQUAL "SecureTransport") ADD_DEFINITIONS(-DCRYPT_COMMONCRYPTO) SET(SRC_NTLMCLIENT_CRYPTO "crypt_commoncrypto.c") diff --git a/deps/ntlmclient/compat.h b/deps/ntlmclient/compat.h index f4d859aec..5b33b4e6b 100644 --- a/deps/ntlmclient/compat.h +++ b/deps/ntlmclient/compat.h @@ -21,31 +21,20 @@ # include #endif -#ifdef __linux__ -/* See man page endian(3) */ -# include -# define htonll htobe64 -#elif defined(__NetBSD__) || defined(__OpenBSD__) -/* See man page htobe64(3) */ -# include -# define htonll htobe64 -#elif defined(__FreeBSD__) -/* See man page bwaps64(9) */ -# include -# define htonll htobe64 -#elif defined(sun) || defined(__sun) -/* See man page byteorder(3SOCKET) */ -# include -# include -# include - -# if !defined(htonll) -# if defined(_BIG_ENDIAN) -# define htonll(x) (x) -# else -# define htonll(x) ((((uint64_t)htonl(x)) << 32) + htonl((uint64_t)(x) >> 32)) -# endif -# endif +#if defined(NTLM_BIG_ENDIAN) +static inline uint64_t ntlm_htonll(uint64_t value) +{ + return value; +} +#else + +# include + +static inline uint64_t ntlm_htonll(uint64_t value) +{ + return ((uint64_t)htonl(value) << 32) + htonl((uint64_t)value >> 32); +} + #endif #ifndef MIN diff --git a/deps/ntlmclient/ntlm.c b/deps/ntlmclient/ntlm.c index 74224bbea..40cf2cbfc 100644 --- a/deps/ntlmclient/ntlm.c +++ b/deps/ntlmclient/ntlm.c @@ -1125,7 +1125,7 @@ static bool generate_lm2_response(ntlm_client *ntlm, size_t lm2_len = 16; uint64_t local_nonce; - local_nonce = htonll(ntlm->nonce); + local_nonce = ntlm_htonll(ntlm->nonce); if (!ntlm_hmac_ctx_reset(ntlm->hmac_ctx) || !ntlm_hmac_md5_init(ntlm->hmac_ctx, @@ -1197,8 +1197,8 @@ static bool generate_ntlm2_response(ntlm_client *ntlm) /* the blob's integer values are in network byte order */ signature = htonl(0x01010000); - timestamp = htonll(ntlm->timestamp); - nonce = htonll(ntlm->nonce); + timestamp = ntlm_htonll(ntlm->timestamp); + nonce = ntlm_htonll(ntlm->nonce); /* construct the blob */ memcpy(&blob[0], &signature, 4); -- cgit v1.2.1