mpc4j简介
Multi-Party Computation for Java (
mpc4j
) is an efficient and easy-to-use Secure Multi-Party Computation (MPC), Homomorphic Encryption (HE) and Differential Privacy (DP) library mainly written in Java.mpc4j
aims to provide an academic library for researchers to study and develop MPC/HE/DP in a unified manner. As mpc4j
tries to provide state-of-the-art MPC/HE/DP implementations, researchers could leverage the library to have fair and quick comparisons between the new algorithms/protocols they proposed and existing ones.We note that
mpc4j
is mainly focused on research and mpc4j
assumes a very strong system model. Specifically, mpc4j
assumes never-crash nodes with a fully synchronized network. In practice, crash-recovery nodes with a partially synchronized network would be a reasonable system model. Aside from the system model, mpc4j
tries to integrate tools that are suitable to be used in the production environment. We emphasize that additional engineering problems need to be solved if you want to develop your own MPC/DP applications. A reasonable solution would be to implement communication APIs on your own, develop protocols by calling tools in mpc4j
, and referring protocol implementations in mpc4j
as a prototype.安装mpc4j-native-tool和mpc4j-native-fourq
安装好jdk8,和demo的版本对应:

安装工具和依赖
安装openssl和cmake 完成
安装gmp 未完成
这里m1-Ventura安装gmp-6.2.1失败,查了资料应该和操作系统版本有关,考虑升级一下系统
安装NTL 完成
安装MCL 完成
安装libsodium 完成
把java的环境变量弄好:
Go to the path of
mpc4j-native-fourq
, and run the following command to compile and install mpc4j-native-fourq
.Go to the path of
mpc4j-native-tool
, and run the following command to compile mpc4j-native-tool
.这里是安装成功了:

安装mpc4j-native-fhe
是用java去调度了seal 4.0的接口进行交互,因此需要安装seal。
Run the following command to compile and install SEAL v4.0.0.
编译fhe模块
Please follow the procedures presented in
mcp4j-native-tool
to correctly install Java and set JAVA_HOME
. Then, go to the path of mpc4j-native-fhe
, run the following command to compile mpc4j-native-fhe
.
配置idea
-Djava.library.path=/Users/zimablue/Desktop/Projects/mpc4j/mpc4j-native-tool/cmake-build-release:/Users/zimablue/Desktop/Projects/mpc4j/mpc4j-native-fhe/cmake-build-release
/Users/zimablue/Desktop/Projects/mpc4j/mpc4j-native-fhe/cmake-build-release
配置完以后可以正常去运行每个子模块的测试代码了:

使用该库遇到的问题
在test的时候,发现会有如下报错:
参考项目readme的Notes for Running on
aarch64
:java.lang.UnsatisfiedLinkError: /Users/zimablue/Desktop/Projects/mpc4j/mpc4j-native-tool/cmake-build-release/libmpc4j-native-tool.dylib: dlopen(/Users/zimablue/Desktop/Projects/mpc4j/mpc4j-native-tool/cmake-build-release/libmpc4j-native-tool.dylib, 0x0001): tried: '/Users/zimablue/Desktop/Projects/mpc4j/mpc4j-native-tool/cmake-build-release/libmpc4j-native-tool.dylib' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')), '/System/Volumes/Preboot/Cryptexes/OS/Users/zimablue/Desktop/Projects/mpc4j/mpc4j-native-tool/cmake-build-release/libmpc4j-native-tool.dylib' (no such file), '/Users/zimablue/Desktop/Projects/mpc4j/mpc4j-native-tool/cmake-build-release/libmpc4j-native-tool.dylib' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64'))
出现问题的原因:
安装的是1.8版本的x86-jdk
需要用到的是arm版本的1.7+的jdk
解决方法:
右键mpc4j选择open module settings,在project那里安装一个1.7的arm架构jdk,set一下就好了
版本更新
版本更新以后直接pull代码即可,但是native-tool部分要手动重新make一下。