Skip to content

Commit

Permalink
byteswap.h is not present on macOS
Browse files Browse the repository at this point in the history
Projects like Chromium use a porting header to handle platform differences like these and a port.h is added to local include folder

Signed-off-by: kozyilmaz <kazim@monolytic.com>
  • Loading branch information
kozyilmaz committed May 12, 2024
1 parent 31e510b commit 8e91917
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 5 deletions.
26 changes: 26 additions & 0 deletions include/port.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifndef __MPC_LIB_PORT_H__
#define __MPC_LIB_PORT_H__

#ifdef __cplusplus
extern "C" {
#endif //__cplusplus

#if HAVE_BYTESWAP_H
#include <byteswap.h>
#else
// bswap_xx macros
#if defined(__APPLE__)
#include <libkern/OSByteOrder.h>
#define bswap_16(x) OSSwapInt16(x)
#define bswap_32(x) OSSwapInt32(x)
#define bswap_64(x) OSSwapInt64(x)
#else
#error bswap_xx macros should be defined
#endif
#endif

#ifdef __cplusplus
}
#endif //__cplusplus

#endif // __MPC_LIB_PORT_H__
2 changes: 1 addition & 1 deletion src/common/crypto/GFp_curve_algebra/GFp_curve_algebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <string.h>
#include <assert.h>
#include <byteswap.h>
#include "port.h"

#include <openssl/bn.h>
#include <openssl/err.h>
Expand Down
2 changes: 1 addition & 1 deletion src/common/crypto/ed25519_algebra/ed25519_algebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "crypto/keccak1600/keccak1600.h"
#include "curve25519.c"

#include <byteswap.h>
#include "port.h"

#include <openssl/bn.h>
#include <openssl/sha.h>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "crypto/zero_knowledge_proof/diffie_hellman_log.h"
#include "crypto/drng/drng.h"
#include <byteswap.h>
#include "port.h"
#include <string.h>
#include <openssl/sha.h>

Expand Down
2 changes: 1 addition & 1 deletion test/crypto/ed25519_algebra/tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <openssl/rand.h>
#include <openssl/bn.h>

#include <byteswap.h>
#include "port.h"
#include <string.h>

#include <tests/catch.hpp>
Expand Down
2 changes: 1 addition & 1 deletion test/crypto/secp256k1_algebra/tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <openssl/objects.h>
#include <openssl/rand.h>

#include <byteswap.h>
#include "port.h"
#include <string.h>

#include <tests/catch.hpp>
Expand Down

0 comments on commit 8e91917

Please sign in to comment.