From e4000ad6892061948b33727ab1b710e6d965514a Mon Sep 17 00:00:00 2001
From: cheloveck3-0 <cheloveck2.0@gmail.com>
Date: Wed, 23 Jan 2019 21:58:12 +0600
Subject: [PATCH] added header to macos for endian.h (#37)

Added header to macOS for endian.h
---
 crypto/sig_picnic/macos_specific_endian.h | 32 +++++++++++++++++++++++
 crypto/sig_picnic/picnic_impl.c           |  2 ++
 crypto/sig_picnic/sig_picnic.pri          |  3 ++-
 3 files changed, 36 insertions(+), 1 deletion(-)
 create mode 100644 crypto/sig_picnic/macos_specific_endian.h

diff --git a/crypto/sig_picnic/macos_specific_endian.h b/crypto/sig_picnic/macos_specific_endian.h
new file mode 100644
index 0000000..f7b6756
--- /dev/null
+++ b/crypto/sig_picnic/macos_specific_endian.h
@@ -0,0 +1,32 @@
+#ifndef MACOS_SPECIFIC_ENDIAN_H
+#define MACOS_SPECIFIC_ENDIAN_H
+
+/** compatibility header for endian.h
+ * This is a simple compatibility shim to convert
+ * BSD/Linux endian macros to the Mac OS X equivalents.
+ * It is public domain.
+ * */
+
+#ifndef __APPLE__
+    #warning "This header file (endian.h) is MacOS X specific.\n"
+#endif	/* __APPLE__ */
+
+#include <machine/endian.h>
+#include <libkern/OSByteOrder.h>
+
+#define htobe16(x) OSSwapHostToBigInt16(x)
+#define htole16(x) OSSwapHostToLittleInt16(x)
+#define be16toh(x) OSSwapBigToHostInt16(x)
+#define le16toh(x) OSSwapLittleToHostInt16(x)
+
+#define htobe32(x) OSSwapHostToBigInt32(x)
+#define htole32(x) OSSwapHostToLittleInt32(x)
+#define be32toh(x) OSSwapBigToHostInt32(x)
+#define le32toh(x) OSSwapLittleToHostInt32(x)
+
+#define htobe64(x) OSSwapHostToBigInt64(x)
+#define htole64(x) OSSwapHostToLittleInt64(x)
+#define be64toh(x) OSSwapBigToHostInt64(x)
+#define le64toh(x) OSSwapLittleToHostInt64(x)
+
+#endif // MACOS_SPECIFIC_ENDIAN_H
diff --git a/crypto/sig_picnic/picnic_impl.c b/crypto/sig_picnic/picnic_impl.c
index e1061f0..990a6da 100644
--- a/crypto/sig_picnic/picnic_impl.c
+++ b/crypto/sig_picnic/picnic_impl.c
@@ -20,6 +20,8 @@
 #if defined (__WIN32)
 	#include <Windows.h>
 	#include <bcrypt.h>
+#elif defined (__APPLE__)
+    #include "macos_specific_endian.h"
 #else
     #include <endian.h>
 #endif
diff --git a/crypto/sig_picnic/sig_picnic.pri b/crypto/sig_picnic/sig_picnic.pri
index 52fd381..f95cfdd 100644
--- a/crypto/sig_picnic/sig_picnic.pri
+++ b/crypto/sig_picnic/sig_picnic.pri
@@ -3,8 +3,9 @@ HEADERS += $$PWD/hash.h \
     $$PWD/picnic.h \
     $$PWD/picnic_impl.h \
     $$PWD/picnic_types.h \
-    $$PWD/platform.h \
+    $$PWD/platform.h
 
+macos { HEADERS += $$PWD/macos_specific_endian.h }
 
 SOURCES +=  $$PWD/hash.c \
     $$PWD/lowmc_constants.c \
-- 
GitLab