centos8上安装MP-SPDZ

运行环境安装

环境要求

Requirements
- GCC 5 or later (tested with up to 11) or LLVM/clang 5 or later (tested with up to 12). We recommend clang because it performs better.
- MPIR library, compiled with C++ support (use flag --enable-cxx when running configure). You can use make -j8 tldr to install it locally.
- libsodium library, tested against 1.0.18
- OpenSSL, tested against 1.1.1
- Boost.Asio with SSL support (libboost-dev on Ubuntu), tested against 1.71
- Boost.Thread for BMR (libboost-thread-dev on Ubuntu), tested against 1.71
- x86 or ARM 64-bit CPU (the latter tested with AWS Gravitron and Apple Silicon)
- Python 3.5 or later
- NTL library for homomorphic encryption (optional; tested with NTL 10.5)

python 3.5+ 安装,本地安装的是 python3.7(和本地虚拟机对应)

// requirements
sudo dnf install -y gcc openssl-devel bzip2-devel libffi-devel

// install python
cd /opt
sudo wget https://www.python.org/ftp/python/3.7.9/Python-3.7.12.tgz
sudo tar xzf Python-3.7.12.tgz
cd Python-3.7.12
sudo ./configure --enable-optimizations
sudo make altinstall
sudo rm Python-3.7.12.tgz

// 建立python软连接
ll /usr/local/bin | grep python
sudo ln -s /usr/local/bin/python3.7 /usr/bin/python
sudo ln -s /usr/local/bin/python3.7 /usr/bin/python3
// 如果python3存在,则删除python3,再重新进行软连接
sudo rm /usr/bin/python3

GCC安装,此处安装的是clang

参考:How To Install clang on CentOS 8

sudo dnf makecache --refresh
sudo dnf -y install clang

如果出现如下错误:

Last metadata expiration check: 0:08:51 ago on Tue 09 Aug 2022 03:01:52 PM CST.
Module yaml error: Unexpected key in data: static_context [line 9 col 3]
Module yaml error: Unexpected key in data: static_context [line 9 col 3]
Module yaml error: Unexpected key in data: static_context [line 9 col 3]
Module yaml error: Unexpected key in data: static_context [line 9 col 3]
Modular dependency problems:

 Problem 1: conflicting requests
  - nothing provides module(perl:5.26) needed by module perl-DBD-SQLite:1.58:8030020200716174729:3a70019f-0.x86_64
 Problem 2: conflicting requests
  - nothing provides module(perl:5.26) needed by module perl-DBI:1.641:8030020200716150652:1e4bbb35-0.x86_64
No match for argument: clang
Error: Unable to find a match: clang

解决方法参考:centos8 yum替换阿里源

libtool安装

sudo dnf makecache
sudo dnf install -y libtool.x86_64

yasm安装

cd /opt
sudo wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
sudo tar zxvf yasm-1.3.0.tar.gz
cd yasm-1.3.0
sudo ./configure
sudo make install 
cd .. && sudo rm yasm-1.3.0.tar.gz

libsodium library 安装

sudo dnf install -y libsodium-static.x86_64

OpenSSL 安装

// 查看是否已安装,由于本地已安装OpenSSL 1.1.1k ,跳过此步骤
openssl version -v

// Install C_rehash script
sudo yum install -y openssl-perl

Boost.Asio with SSL support, Boost.Thread for BMR 安装

截至到2022.7.7,centos8 最新版本是1.66

sudo dnf -y install boost

// 安装 boost.asio库,参考https://blog.csdn.net/qq_28648083/article/details/53465367

// 其下载地址:https://sourceforge.net/projects/boost/files/boost
// 打开F12,使用network选项卡,获得.tar.gz的下载地址
cd /opt
sudo wget https://jaist.dl.sourceforge.net/project/boost/boost/1.79.0/boost_1_79_0.tar.gz
sudo tar -zxvf  boost_1_79_0.tar.gz 
cd boost_1_79_0
sudo ./bootstrap.sh
sudo ./b2 install

安装好之后,仍然找不到头文件

sudo vi /etc/ld.so.conf.d/boost.asio.1.79.conf
// 输入如下字符串,保存退出
/usr/local/lib

// 使修改生效
sudo ldconfig

NTL 安装

install requirements

sudo dnf makecache --refresh
sudo dnf -y install gmp-devel

NTL download site: https://libntl.org/download.html

cd /opt
sudo wget https://libntl.org/ntl-11.5.1.tar.gz
sudo tar zxvf  ntl-11.5.1.tar.gz
cd ntl-11.5.1/src
sudo ./configure 
sudo make
sudo make check // 可以不进行
sudo make install
cd ../.. && sudo rm ntl-11.5.1.tar.gz

安装boost-system

sudo dnf -y install boost-system

MPIR安装

cd /path/to/your/MP-SPDZ
make clean
cd mpir && make clean && cd ..
rm ./local/* -rf

// 查看文件是否被删除干净
find ./ -type f | grep \\.o$
find ./ -type f | grep \\.so$
find ./ -type f | grep \\.x$
find ./ -type f | grep \\.d$
find ./ -type f | grep \\.a$
// 编译
make -j8 tldr 

如果出现./configure: Permission denied错误,设置可执行权限

chmod +x mpir/*.sh
chmod +x mpir/configure

如果出现../libtool: line 1766: ../mpn/m4-ccas: Permission denied错误,设置可执行权限

chmod +x mpir/mpn/m4-ccas

git安装

sudo dnf install git -y

编译运行测试环境

./compile.py tutorial
echo 1 2 3 4 > Player-Data/Input-P0-0
echo 1 2 3 4 > Player-Data/Input-P1-0
Scripts/mascot.sh tutorial

问题汇总

当python(指向python3.7.12)和python3(指向python3.6.8)版本不一致时就会出现如下问题,到最后呈现都没法运行。所以,出现问题时,一定要检查python、python3的版本。同时执行make clean删除历史。

使用mascot-party虚拟机出现的错误

libsodium.18.so找不到错误

具体错误如下:

./mascot-party.x: error while loading shared libraries: libSPDZ.so: cannot open shared object file: No such file or directory

使用ldd mascot-party.x查看 mascot-party.x引用的链接库信息如下:

        linux-vdso.so.1 (0x00007fff854c6000)
        libSPDZ.so => /home/baas/codes/mpc/MP-SPDZ/local/lib/libSPDZ.so (0x00007f36b7c4d000)
        libmpirxx.so.8 => /home/baas/codes/mpc/MP-SPDZ/local/lib/libmpirxx.so.8 (0x00007f36b7a48000)
        libmpir.so.23 => /home/baas/codes/mpc/MP-SPDZ/local/lib/libmpir.so.23 (0x00007f36b77d3000)
        libsodium.so.23 => /usr/local/lib/libsodium.so.23 (0x00007f36b757d000)
        libboost_system.so.1.79.0 => /usr/local/lib/libboost_system.so.1.79.0 (0x00007f36b737b000)
        libssl.so.1.1 => /lib64/libssl.so.1.1 (0x00007f36b70e7000)
        libcrypto.so.1.1 => /lib64/libcrypto.so.1.1 (0x00007f36b6bfe000)
        librt.so.1 => /lib64/librt.so.1 (0x00007f36b69f5000)
        libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007f36b6660000)
        libm.so.6 => /lib64/libm.so.6 (0x00007f36b62de000)
        libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f36b60c6000)
        libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f36b5ea6000)
        libc.so.6 => /lib64/libc.so.6 (0x00007f36b5ae4000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f36b7ff4000)
        libsodium.so.18 => not found
        libboost_system.so.1.58.0 => not found
        libssl.so.1.0.0 => not found
        libcrypto.so.1.0.0 => not found
        libz.so.1 => /lib64/libz.so.1 (0x00007f36b58cd000)
        libdl.so.2 => /lib64/libdl.so.2 (0x00007f36b56c9000)

而正确的链接库链接如下:

        linux-vdso.so.1 (0x00007fff4a15d000)
        libSPDZ.so => /home/baas/codes/mpc/MP-SPDZ/libSPDZ.so (0x00007f2e4827d000)
        libmpirxx.so.8 => /home/baas/codes/mpc/MP-SPDZ/local/lib/libmpirxx.so.8 (0x00007f2e48078000)
        libmpir.so.23 => /home/baas/codes/mpc/MP-SPDZ/local/lib/libmpir.so.23 (0x00007f2e47e03000)
        libsodium.so.23 => /lib64/libsodium.so.23 (0x00007f2e47bab000)
        libboost_system.so.1.79.0 => /usr/local/lib/libboost_system.so.1.79.0 (0x00007f2e479a9000)
        libssl.so.1.1 => /lib64/libssl.so.1.1 (0x00007f2e47715000)
        libcrypto.so.1.1 => /lib64/libcrypto.so.1.1 (0x00007f2e4722c000)
        librt.so.1 => /lib64/librt.so.1 (0x00007f2e47023000)
        libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007f2e46c8e000)
        libm.so.6 => /lib64/libm.so.6 (0x00007f2e4690c000)
        libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f2e466f4000)
        libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f2e464d4000)
        libc.so.6 => /lib64/libc.so.6 (0x00007f2e46112000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f2e48645000)
        libz.so.1 => /lib64/libz.so.1 (0x00007f2e45efb000)
        libdl.so.2 => /lib64/libdl.so.2 (0x00007f2e45cf7000)

通过对比,有如下几个库是重复、多余且找不到的:

        libsodium.so.18 => not found
        libboost_system.so.1.58.0 => not found
        libssl.so.1.0.0 => not found
        libcrypto.so.1.0.0 => not found

最终解决,发现make clean无法删除./local/lib目录下的libmpir.so,libmpirxx.so,libSPDZ.so文件,删除之后重新编译即可正常运行。

make clean
rm ./local/lib/*

libSPDZ.so找不到错误

重新编译一下:

make clean
rm CONFIG.mine
make -j 8 tldr

`.rodata.str1.8’ can not be used when making a PIE object; recompile with -fPIE

问题描述:

 g++ -o mascot-party.x -march=native -I./local/include -I./local/include -I./local/include -I./local/include -I./local/include -I./local/include -I./local/include -I./local/include -I./local/include -I./local/include -I./local/include -I./local/include -g -Wextra -Wall -O3 -I. -pthread    -DUSE_GF2N_LONG '-DPREP_DIR="Player-Data/"' '-DSSL_DIR="Player-Data/"'  -std=c++11 -Werror -fPIC -fPIE Machines/mascot-party.o OT/OTTripleSetup.o OT/BaseOT.o SimpleOT/libsimpleot.a libSPDZ.so Machines/SPDZ.o Machines/Tinier.o OT/MascotParams.o OT/BitDiagonal.o OT/OTExtensionWithMatrix.o OT/OTExtension.o -lmpirxx -lmpir -lsodium -Wl,-rpath -Wl,/home/verayy/codes/mpc/MP-SPDZ/local/lib -L/home/verayy/codes/mpc/MP-SPDZ/local/lib -Wl,-rpath -Wl,/home/verayy/codes/mpc/MP-SPDZ/local/lib -L/home/verayy/codes/mpc/MP-SPDZ/local/lib -Wl,-rpath -Wl,/home/baas/codes/mpc/MP-SPDZ/local/lib -L/home/baas/codes/mpc/MP-SPDZ/local/lib -Wl,-rpath -Wl,/home/baas/codes/mpc/MP-SPDZ/local/lib -L/home/baas/codes/mpc/MP-SPDZ/local/lib -Wl,-rpath -Wl,/home/baas/codes/mpc/MP-SPDZ/local/lib -L/home/baas/codes/mpc/MP-SPDZ/local/lib -Wl,-rpath -Wl,/home/baas/codes/mpc/MP-SPDZ/local/lib -L/home/baas/codes/mpc/MP-SPDZ/local/lib -Wl,-rpath -Wl,/home/server/yangyu/MP-SPDZ/local/lib -L/home/server/yangyu/MP-SPDZ/local/lib -Wl,-rpath -Wl,/home/server/yangyu/MP-SPDZ/local/lib -L/home/server/yangyu/MP-SPDZ/local/lib -Wl,-rpath -Wl,/home/server/yangyu/MP-SPDZ/local/lib -L/home/server/yangyu/MP-SPDZ/local/lib -Wl,-rpath -Wl,/home/server/yangyu/MP-SPDZ/local/lib -L/home/server/yangyu/MP-SPDZ/local/lib -Wl,-rpath -Wl,/home/server/yangyu/MP-SPDZ/local/lib -L/home/server/yangyu/MP-SPDZ/local/lib -Wl,-rpath -Wl,/home/server/yangyu/MP-SPDZ/local/lib -L/home/server/yangyu/MP-SPDZ/local/lib -lboost_system -lssl -lcrypto -lrt -Wl,-rpath -Wl,/home/server/yangyu/MP-SPDZ
/usr/bin/ld: SimpleOT/libsimpleot.a(ot_sender.o): relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a PIE object; recompile with -fPIE
/usr/bin/ld: SimpleOT/libsimpleot.a(ot_receiver.o): relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a PIE object; recompile with -fPIE
/usr/bin/ld: SimpleOT/libsimpleot.a(ge25519_unpack.o): relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIE
/usr/bin/ld: SimpleOT/libsimpleot.a(ge25519_scalarmult_base.o): relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIE
/usr/bin/ld: SimpleOT/libsimpleot.a(ge4x.o): relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIE
/usr/bin/ld: SimpleOT/libsimpleot.a(gfe4x.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a PIE object; recompile with -fPIE
/usr/bin/ld: SimpleOT/libsimpleot.a(ge4x_unpack_vartime.o): relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIE
/usr/bin/ld: SimpleOT/libsimpleot.a(Keccak-simple.o): relocation R_X86_64_32S against symbol `KeccakF_RoundConstants' can not be used when making a PIE object; recompile with -fPIE
/usr/bin/ld: SimpleOT/libsimpleot.a(randombytes.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a PIE object; recompile with -fPIE
collect2: error: ld returned 1 exit status

解决方法:

参考:https://ubuntuforums.org/showthread.php?t=2393181

As the error messages say, you need to try adding -fPIC to the C compiler flags and/or C++ compiler flags. If that does not work, try instead adding -fno-PIE -no-pie to the C compiler flags and C++ compiler flags.

How to do this will depend on the specific software.

删除旧文件

make clean
// mpir清除旧文件
cd mpir && make clean && cd ..
rm ./local/* -rf

// 查看文件是否被删除干净
find ./ -type f | grep \\.o$
find ./ -type f | grep \\.so$
find ./ -type f | grep \\.x$
find ./ -type f | grep \\.d$
find ./ -type f | grep \\.a$
// 如果有未删除干净的文件,则执行如下方法删除
find ./ -type f | grep \\.o$ | xargs rm -rf
find ./ -type f | grep \\.so$ | xargs rm -rf
find ./ -type f | grep \\.x$ | xargs rm -rf
find ./ -type f | grep \\.d$ | xargs rm -rf
find ./ -type f | grep \\.a$ | xargs rm -rf

如果还是不成功,则在Makefile文件的CFLAGS后增加 -fno-PIE -no-pie ,如下所示:

...
CFLAGS += -fPIC -fno-PIE -no-pie
...

另外,tldr、semi-party.x的库与hemi-party.x的库不一致,如果要编译hemi-party.x的库,就需要clean一下。

猜你喜欢

转载自blog.csdn.net/shuizhongmose/article/details/125674279