summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2020-08-24 12:19:33 +0200
committerPatrick Steinhardt <ps@pks.im>2020-08-24 12:40:49 +0200
commitaaa4fda5cf4d77d9800cbaaf98c639b3418648c6 (patch)
treef172e6277d62b39a7259be72dabb7ebc8a046fcf
parentc71321a099373753c22055921c8f538afed5ebb6 (diff)
downloadlibgit2-pks/ntlmclicent-htonll-generic.tar.gz
deps: ntlmclient: provide platform-independent htonll implementationpks/ntlmclicent-htonll-generic
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.
-rw-r--r--deps/ntlmclient/CMakeLists.txt7
-rw-r--r--deps/ntlmclient/compat.h39
-rw-r--r--deps/ntlmclient/ntlm.c6
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 <stdbool.h>
#endif
-#ifdef __linux__
-/* See man page endian(3) */
-# include <endian.h>
-# define htonll htobe64
-#elif defined(__NetBSD__) || defined(__OpenBSD__)
-/* See man page htobe64(3) */
-# include <endian.h>
-# define htonll htobe64
-#elif defined(__FreeBSD__)
-/* See man page bwaps64(9) */
-# include <sys/endian.h>
-# define htonll htobe64
-#elif defined(sun) || defined(__sun)
-/* See man page byteorder(3SOCKET) */
-# include <sys/types.h>
-# include <netinet/in.h>
-# include <inttypes.h>
-
-# 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 <arpa/inet.h>
+
+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);