cryptobiu / libscapi

Comprehensive Open Source Library for Secure Multiparty Computation
MIT License
180 stars 66 forks source link

macOS support #25

Closed fabrice102 closed 6 years ago

fabrice102 commented 7 years ago

I've almost managed to compile libscapi on macOS (see pull requests #19, #20, #21, #22, #23, #24, #29). The only component which does not compile is BristolOTExtension because of SimpleOT.

More precisely, I get the following error:

fe25519_freeze.s:213:1: error: 32-bit absolute addressing is not supported in 64-bit mode

(file: lib/OTExtensionBristol/SimpleOT/fe25519_freeze.s).

I think the issue can be solved by following https://stackoverflow.com/a/25804623 and https://ghc.haskell.org/trac/ghc/wiki/Commentary/PositionIndependentCode (basically suffixing global constants by @GOTPCREL(%rip)). But I am not comfortable making the change, as I am not sure how to easily test that there is no regression (both for correctness and performance).

It is possible to compile libscapi without BristolOTExtension by creating an empty file compile-otextension-bristol.

(I have just managed to compile the library libscapi itself. I have not tested whether the resulting library is working on macOS.)

fabrice102 commented 7 years ago

After pull request #31, tests (in the folder https://github.com/cryptobiu/libscapi/tree/master/test) are now passing.

Remark: Some care should be taken on macOS with openssl. If installed with homebrew, it might be necessary to set LIBRARY_PATH=/usr/local/opt/openssl/lib:$LIBRARY_PATH.

fabrice102 commented 7 years ago

After pull request #35 and #36, libscapi_samples seems to behave the same way on macOS and on a fresh Ubuntu 16.04 VM, except for OTExtensionBristol (which needs to be disabled - see above) and for Yao (because of issue #37).

Note: on macOS, the library rt does not exist and the flag -lrt should be removed. Furthermore, the flag -lboost_thread might need to changed to -lboost_thread-mt.

liorko87 commented 7 years ago

@fabrice102 Thank you for your work! I will review your PR and submit them to the new branch Mac OS x

RahulRachuri commented 6 years ago

Hey,

While compiling libOTe, I ran into this error. /Users/rahul/Downloads/libscapi-master/build/libOTe/cryptoTools/cryptoTools/Crypto/AES.h:4:10: fatal error: 'openssl/evp.h' file not found

I am running macOS High Sierra 10.13.3. I have openssl installed on my system. Does someone know a fix for this?

fabrice102 commented 6 years ago

You need to install openssl with HomeBrew for example (brew install openssl), and then to modify accordingly the environment variables CPLUS_INCLUDE_PATH, ...

Concretely, you can add the following to ~/.bashrc, ~/.zshrc, or equivalent and restart your shell:

# openssl (for CMAKE)
export OPENSSL_ROOT_DIR=/usr/local/opt/openssl
# and when CMAKE is not used...
export C_INCLUDE_PATH=$OPENSSL_ROOT_DIR/include:$C_INCLUDE_PATH
export CPLUS_INCLUDE_PATH=$OPENSSL_ROOT_DIR/include:$CPLUS_INCLUDE_PATH
export LD_LIBRARY_PATH=$OPENSSL_ROOT_DIR/lib:$LD_LIBRARY_PATH
export LIBRARY_PATH=$OPENSSL_ROOT_DIR/lib:$LIBRARY_PATH

Note: If you are compiling other softwares that uses openssl with CMake, you should unset LD_LIBRARY_PATH and LIBRARY_PATH when compiling them, to avoid having issues with rpath and System Integrity Protection (e.g., when debugging these softwares using gdb).

RahulRachuri commented 6 years ago

Thanks, that worked! But then there is an error with boost,

/Users/rahul/Downloads/libscapi-master/build/libOTe/cryptoTools/cryptoTools/Network/Channel.h:354:22: fatal error: use of class template 'boost::asio::strand' requires template arguments boost::asio::strand mSendStrand, mRecvStrand;

I am using boost 1.66.0 (the latest version). I think this might be a problem with the latest version of boost.

fabrice102 commented 6 years ago

Try to use an older version of boost (1.65.0 or 1.60.0).

RahulRachuri commented 6 years ago

Thanks, I am on 1.60.0 right now. That error is resolved but,

ld: warning: directory not found for option '-L/Users/rahul/libscapi/install/lib' ld: library not found for -lboost_thread clang: fatal error: linker command failed with exit code 1 (use -v to see invocation)

This is what it throws after compiling 45% of libOTe. I think the fix is to change lboost_thread to lboost_thread-mt for Mac, but I'm not sure all the places where this change has to be made.

fabrice102 commented 6 years ago

The build system changed since last time I compiled libscapi. I guess that now you should change boost_thread in boost_thread-mt inside CMakeLists.txt.

RahulRachuri commented 6 years ago

I changed it to boost_thread-mt in the CMakeLists.txt files and then there was a linker error for which I changed line 6 in CMakeLists.txt file in libOTe/cryptoTools/frontend_cryptoTools to link_directories($ENV{HOME}/Downloads/libscapi-master/install/lib/)

But then it igonres the file with this error -

ld: warning: ld: warning: ld: warning: ignoring file /Users/rahul/Downloads/libscapi-master/install/lib/libcrypto.a, file was built for archive which is not the architecture being linked (x86_64): /Users/rahul/Downloads/libscapi-master/install/lib/libcrypto.aignoring file /Users/rahul/Downloads/libscapi-master/install/lib/libssl.a, file was built for archive which is not the architecture being linked (x86_64): /Users/rahul/Downloads/libscapi-master/install/lib/libssl.aignoring file ../thirdparty/linux/miracl/miracl/source/libmiracl.a, file was built for archive which is not the architecture being linked (x86_64): ../thirdparty/linux/miracl/miracl/source/libmiracl.a