信息安全从业人员^_^
一个未入门de情报学胖子(邮箱:tenghm1986@163.com)
Toggle navigation
信息安全从业人员^_^
主页
About Me
归档
标签
MP-SPDZ性能测试Demo
2020-11-12 14:04:10
2806
0
0
heming
# 0.方案说明 单机版本(测试环境为172.16.13.103),电路的编译测试前已经准备好,执行阶段求和数据传输量不大(三方求和0.65,5方2.4M,7方6.7M) **results:** |类别|时间(执行)|comments| |:--|:--|:--| |3方求和|0.03s|编译时间1ms| |5方求和|0.095s|编译时间1ms| |7方求和|0.21s|编译时间2ms| |PSI(100)|5.25s|随机数,从文件读取,编译时间83ms| |PSI(1000)|519.48s|随机数,从文件读取,编译时间581ms| # 1.环境准备 ## 1.1 安装依赖 ``` sudo apt-get install automake build-essential git libboost-dev libboost-thread-dev libsodium-dev libssl-dev libtool m4 python texinfo yasm libntl-dev -y ``` ## 1.2 首次编译,安装依赖 ``` make -j 8 tldr ``` ## 1.3 3/5/7 多方求和情况 --- **tips:** BMR/config.h 修改此头文件,改成7 --- ### 1.3.1 demo 5方求和过程 > 程序 ``` a=sint.get_input_from(0) b=sint.get_input_from(1) c=sint.get_input_from(2) d=sint.get_input_from(3) e=sint.get_input_from(4) sum = a+b+c+d+e print_ln('5 sum =%s',sum.reveal()) ``` >编译 ``` python3 ./compile.py -B 32 3_sum python3 ./compile.py -B 32 5_sum python3 ./compile.py -B 32 7_sum python3 ./compile.py array make -j 8 shamir-bmr-party.x make -j 8 semi-party.x ``` >执行前生成相关证书 ``` Scripts/setup-ssl.sh 7 # 3代表参与方数目 ``` <center> ![1](https://leanote.com/api/file/getImage?fileId=5f43bd86ab644139c50017c1) </center> >准备数据 ``` echo 1 > Player-Data/Input-P0-0 echo 2 > Player-Data/Input-P1-0 echo 3 > Player-Data/Input-P2-0 echo 4 > Player-Data/Input-P3-0 echo 5 > Player-Data/Input-P4-0 echo 6 > Player-Data/Input-P5-0 echo 7 > Player-Data/Input-P6-0 ``` --- 默认数据准备如下:后缀sum 求和,后缀psi求交集 <center> ![数据准备](https://leanote.com/api/file/getImage?fileId=5f462c3cab644105f500179f) </center> --- > 执行(demo 运行5个数求和,3/7类似) ``` ./shamir-bmr-party.x -N 5 0 5_sum # diff terminal ./shamir-bmr-party.x -N 5 1 5_sum ./shamir-bmr-party.x -N 5 2 5_sum ./shamir-bmr-party.x -N 5 3 5_sum ./shamir-bmr-party.x -N 5 4 5_sum ``` > 3个求和(时间约为0.03s) <center> ![3](https://leanote.com/api/file/getImage?fileId=5f464293ab644105f500186f) </center> > 5个求和(时间0.095s) <center> ![5](https://leanote.com/api/file/getImage?fileId=5f4641acab644107f20018b3) </center> > 7个求和(时间约为0.22s) <center> ![7](https://leanote.com/api/file/getImage?fileId=5f464231ab644105f500186d) </center> # 2.PSI 求交集 >**psi程序**(A,B数组随机产生100个数,判断相等否) ``` from util import if_else from Compiler import types program.bit_length = 128 def compute_intersection(a, b): """ Naive quadratic private set intersection. Returns: secret Array with intersection (padded to len(a)), and secret Array of bits indicating whether Alice's input matches or not """ n = len(a) if n != len(b): raise CompilerError('Inconsistent lengths to compute_intersection') intersection = Array(n, sfix) is_match_at = Array(n, sfix) @for_range(n) def _(i): @for_range(n) def _(j): match = a[i] == b[j] is_match_at[i] += match intersection[i] = if_else(match, a[i], intersection[i]) # match * a[i] + (1 - match) * intersection[i] return intersection, is_match_at def set_intersection_example(a,b): """Naive private set intersection on two Arrays, followed by computing the size and average of the intersection""" print_ln('Running PSI example') intersection, is_match_at = compute_intersection(a,b) print_ln('Printing set intersection (0: not in intersection)') size = MemValue(sfix(0)) total = MemValue(sfix(0)) @for_range(n) def _(i): size.write(size + is_match_at[i]) total.write(total + intersection[i]) print_str('%s ', intersection[i].reveal()) print_ln('\nIntersection size: %s', size.reveal()) n = 5 a = Array(n, sfix) b = Array(n, sfix) @for_range_opt(n) def _(i): a[i] = sfix.get_input_from(0) @for_range_opt(n) def _(j): b[j] = sfix.get_input_from(1) print_ln('data is ok') set_intersection_example(a,b) ``` > 编译过程 ``` make -j8 semi-party python3 ./compile.py -B 64 psi python3 ./compile.py -B 32 array ``` ## PSI 随机数执行过程 > 执行过程 <center> ![psi](https://leanote.com/api/file/getImage?fileId=5f44ac70ab644107f2000660) </center> ## array-psi(从文件读取数组) > 修改程序Source/array.mpc(将42行n设为数组大小) <center> ![1](https://leanote.com/api/file/getImage?fileId=5f462a83ab644105f500177d) </center> >数据准备(准备数据,空格分隔) ``` echo 1 2 3 45 55 > Player-Data/Input-P0-0 echo 1 2 3 77 78 > Player-Data/Input-P1-0 ``` >重新编译array ``` python3 ./compile.py -B 32 array ``` >执行 ``` ./semi-party.x -N 2 -p 0 array # diff terminal ./semi-party.x -N 2 -p 1 array ``` > 长度为100两个数组求交集(5.24s) <center> ![100](https://leanote.com/api/file/getImage?fileId=5f463a77ab644105f500182c) </center> > 长度为1000两个数组求交集(519.5s) <center> ![1000](https://leanote.com/api/file/getImage?fileId=5f463f1dab644105f5001855) </center> # 2.编译时间 > psi(100) 编译时间(83ms) <center> ![1](https://leanote.com/api/file/getImage?fileId=5f4646acab644105f50018a4) </center> > psi(1000) 编译时间(581ms) <center> ![psi-1000](https://leanote.com/api/file/getImage?fileId=5f4647f3ab644105f50018b6) </center> > 3_sum(1ms) <center> ![2](https://leanote.com/api/file/getImage?fileId=5f4646bcab644107f200190b) </center> > 5_sum(1ms) <center> ![3](https://leanote.com/api/file/getImage?fileId=5f4646d6ab644107f200190d) </center> > 7_sum(2ms) <center> ![4](https://leanote.com/api/file/getImage?fileId=5f4646fbab644105f50018a6) </center>
上一篇:
云安全实用指南--第1章 原则与概念
下一篇:
GRPC编译过程
0
赞
2806 人读过
新浪微博
微信
腾讯微博
QQ空间
人人网
Please enable JavaScript to view the
comments powered by Disqus.
comments powered by
Disqus
文档导航