├── .dockerignore ├── .gitignore ├── .gitmodules ├── Announcement.md ├── BMR ├── AndJob.cpp ├── AndJob.h ├── BooleanCircuit.h ├── CommonParty.cpp ├── CommonParty.h ├── CommonParty.hpp ├── GarbledGate.cpp ├── GarbledGate.h ├── Gate.h ├── Key.cpp ├── Key.h ├── Party.cpp ├── Party.h ├── ProgramParty.hpp ├── RealGarbleWire.h ├── RealGarbleWire.hpp ├── RealProgramParty.h ├── RealProgramParty.hpp ├── Register.cpp ├── Register.h ├── Register.hpp ├── Register_inline.h ├── SpdzWire.h ├── TrustedParty.cpp ├── TrustedParty.h ├── Wire.h ├── common.h ├── config.h ├── msg_types.cpp ├── msg_types.h ├── network │ ├── Client.cpp │ ├── Client.h │ ├── Node.cpp │ ├── Node.h │ ├── Server.cpp │ ├── Server.h │ ├── common.h │ ├── utils.cpp │ └── utils.h ├── prf.h ├── proto_utils.cpp └── proto_utils.h ├── CONFIG ├── Compiler ├── DL │ ├── CK+48-data-full.py │ ├── CK_Plus_DataSet.py │ ├── GetAll-feature.py │ ├── LeNet-CIFAR100.py │ ├── LeNet-Ferplus.py │ ├── MNIST-ViT.py │ ├── VGG.py │ ├── VGG16-GETALL-feature.py │ ├── fer_utils │ │ ├── templates │ │ │ ├── dlib │ │ │ │ └── cnn_face_detector.dat │ │ │ └── haar_cascade │ │ │ │ └── frontal_face.xml │ │ ├── udata.py │ │ ├── ufile.py │ │ ├── uimage.py │ │ └── umath.py │ └── readme.md ├── GC │ ├── __init__.py │ ├── instructions.py │ ├── program.py │ └── types.py ├── GFA │ ├── NFGen │ │ ├── PerformanceModel │ │ │ ├── PrivPy_KMProfiler.pkl │ │ │ ├── PrivPy_kmProfiler.pkl │ │ │ ├── PsRepPrime_kmProfiler.pkl │ │ │ ├── PsRepRing_kmProfiler.pkl │ │ │ ├── Rep3_kmProfiler.pkl │ │ │ ├── RepPrime_kmProfiler.pkl │ │ │ ├── Shamir3_kmProfiler.pkl │ │ │ ├── __init__.py │ │ │ └── time_ops.py │ │ ├── __init__.py │ │ ├── fitter.py │ │ ├── funcs.py │ │ ├── main.py │ │ └── profiler.py │ └── presets.py ├── __init__.py ├── allocator.py ├── circuit.py ├── circuit_oram.py ├── comparison.py ├── compilerLib.py ├── config.py ├── cost_config.py ├── dataloader.py ├── dijkstra.py ├── ents.py ├── exceptions.py ├── floatingpoint.py ├── functional.py ├── gfapp.py ├── graph.py ├── graph_visualization.py ├── group_ops.py ├── gs.py ├── gtorch.py ├── instructions.py ├── instructions_base.py ├── joint_statistics.py ├── library.py ├── loan_fraud_framework.py ├── ml.py ├── mpc_math.py ├── nn.py ├── non_linear.py ├── onnxConverter │ ├── Ops │ │ ├── add.py │ │ ├── base.py │ │ ├── conv.py │ │ ├── loop.py │ │ └── split.py │ ├── constants.py │ ├── layer.py │ ├── model.py │ ├── onnxSpilter.py │ └── operations.py ├── optimizer.py ├── oram.py ├── path_oram.py ├── permutation.py ├── profiling_res │ ├── .gitignore │ └── 1.txt ├── profiling_visualization.py ├── program.py ├── sorting.py ├── sqrt_oram.py ├── tensor.py ├── tools.py ├── types.py ├── util.py ├── xgboost.py └── xgboost_inference.py ├── Dockerfile ├── ECDSA ├── CurveElement.cpp ├── CurveElement.h ├── EcdsaOptions.h ├── Fake-ECDSA.cpp ├── P256Element.cpp ├── P256Element.h ├── README.md ├── fake-spdz-ecdsa-party.cpp ├── hm-ecdsa-party.hpp ├── mal-rep-ecdsa-party.cpp ├── mal-shamir-ecdsa-party.cpp ├── mascot-ecdsa-party.cpp ├── ot-ecdsa-party.hpp ├── preprocessing.hpp ├── rep-ecdsa-party.cpp ├── semi-ecdsa-party.cpp ├── shamir-ecdsa-party.cpp └── sign.hpp ├── ExternalIO ├── Client.h ├── Client.hpp ├── README.md ├── bankers-bonus-client.cpp ├── bankers-bonus-client.py ├── client.py └── domains.py ├── FHE ├── AddableVector.h ├── AddableVector.hpp ├── Ciphertext.cpp ├── Ciphertext.h ├── Diagonalizer.cpp ├── Diagonalizer.h ├── DiscreteGauss.cpp ├── DiscreteGauss.h ├── FFT.cpp ├── FFT.h ├── FFT_Data.cpp ├── FFT_Data.h ├── FHE_Keys.cpp ├── FHE_Keys.h ├── FHE_Params.cpp ├── FHE_Params.h ├── Generator.h ├── Matrix.cpp ├── Matrix.h ├── NTL-Subs.cpp ├── NTL-Subs.h ├── NoiseBounds.cpp ├── NoiseBounds.h ├── P2Data.cpp ├── P2Data.h ├── PPData.cpp ├── PPData.h ├── Plaintext.cpp ├── Plaintext.h ├── QGroup.cpp ├── QGroup.h ├── Random_Coins.cpp ├── Random_Coins.h ├── Ring.cpp ├── Ring.h ├── Ring_Element.cpp ├── Ring_Element.h ├── Rq_Element.cpp ├── Rq_Element.h ├── Subroutines.cpp ├── Subroutines.h └── tools.h ├── FHEOffline ├── CutAndChooseMachine.cpp ├── CutAndChooseMachine.h ├── DataSetup.cpp ├── DataSetup.h ├── DataSetup.hpp ├── DistDecrypt.cpp ├── DistDecrypt.h ├── DistKeyGen.cpp ├── DistKeyGen.h ├── EncCommit.cpp ├── EncCommit.h ├── FHE-Subroutines.cpp ├── Multiplier.cpp ├── Multiplier.h ├── PairwiseGenerator.cpp ├── PairwiseGenerator.h ├── PairwiseMachine.cpp ├── PairwiseMachine.h ├── PairwiseSetup.cpp ├── PairwiseSetup.h ├── Producer.cpp ├── Producer.h ├── Proof.cpp ├── Proof.h ├── Prover.cpp ├── Prover.h ├── Reshare.cpp ├── Reshare.h ├── Sacrificing.cpp ├── Sacrificing.h ├── SimpleDistDecrypt.cpp ├── SimpleDistDecrypt.h ├── SimpleEncCommit.cpp ├── SimpleEncCommit.h ├── SimpleGenerator.cpp ├── SimpleGenerator.h ├── SimpleMachine.cpp ├── SimpleMachine.h ├── TemiSetup.cpp ├── TemiSetup.h ├── Verifier.cpp ├── Verifier.h └── config.h ├── GC ├── Access.h ├── ArgTuples.h ├── AtlasSecret.cpp ├── AtlasSecret.h ├── AtlasShare.h ├── BitAdder.h ├── BitAdder.hpp ├── BitPrepFiles.h ├── CcdPrep.h ├── CcdPrep.hpp ├── CcdSecret.h ├── CcdShare.h ├── Clear.h ├── DealerPrep.h ├── FakeSecret.cpp ├── FakeSecret.h ├── Instruction.cpp ├── Instruction.h ├── Instruction_inline.h ├── Machine.h ├── Machine.hpp ├── MaliciousCcdSecret.h ├── MaliciousCcdShare.h ├── MaliciousRepSecret.h ├── Memory.h ├── NoShare.h ├── PersonalPrep.h ├── PersonalPrep.hpp ├── PostSacriBin.cpp ├── PostSacriBin.h ├── PostSacriSecret.h ├── Processor.h ├── Processor.hpp ├── Program.h ├── Program.hpp ├── Rep4Secret.cpp ├── Rep4Secret.h ├── RepPrep.h ├── RepPrep.hpp ├── RuntimeBranching.h ├── Secret.h ├── Secret.hpp ├── Secret_inline.h ├── Semi.cpp ├── Semi.h ├── SemiHonestRepPrep.h ├── SemiPrep.cpp ├── SemiPrep.h ├── SemiSecret.h ├── SemiSecret.hpp ├── ShareParty.h ├── ShareParty.hpp ├── ShareSecret.h ├── ShareSecret.hpp ├── ShareThread.h ├── ShareThread.hpp ├── ShiftableTripleBuffer.h ├── Thread.h ├── Thread.hpp ├── ThreadMaster.h ├── ThreadMaster.hpp ├── TinierSecret.h ├── TinierShare.h ├── TinierSharePrep.h ├── TinierSharePrep.hpp ├── TinyMC.h ├── TinyPrep.hpp ├── TinySecret.h ├── TinyShare.h ├── VectorInput.h ├── VectorProtocol.h ├── VectorProtocol.hpp ├── config.h ├── instructions.h ├── square64.cpp └── square64.h ├── Garnet.jpeg ├── Garnet.png ├── GarnetUI ├── Dockerfile ├── Vue3-garnet-ui │ ├── .eslintrc.cjs │ ├── .gitignore │ ├── .prettierrc.json │ ├── .vscode │ │ └── extensions.json │ ├── README.md │ ├── index.html │ ├── npm │ ├── package-lock.json │ ├── package.json │ ├── pnpm-lock.yaml │ ├── public │ │ └── garnet.ico │ ├── src │ │ ├── App.vue │ │ ├── api │ │ │ ├── TaskDaraItem.ts │ │ │ ├── locateCompute.js │ │ │ ├── mpC.js │ │ │ ├── serverSet.js │ │ │ └── user.js │ │ ├── assets │ │ │ ├── Garnet.jpeg │ │ │ └── login_bg.jpg │ │ ├── main.js │ │ ├── router │ │ │ └── index.js │ │ ├── stores │ │ │ ├── index.js │ │ │ └── modules │ │ │ │ ├── counter.js │ │ │ │ └── user.js │ │ ├── utils │ │ │ └── request.js │ │ └── views │ │ │ ├── layout │ │ │ └── layoutContainer.vue │ │ │ ├── locate │ │ │ ├── locateCompute.vue │ │ │ └── locateTaskTable.vue │ │ │ ├── login │ │ │ └── loginPage.vue │ │ │ ├── mpc │ │ │ ├── jionTask.vue │ │ │ ├── mpC.vue │ │ │ └── taskTable.vue │ │ │ └── user │ │ │ ├── mpcCode.vue │ │ │ └── userData.vue │ └── vite.config.js ├── docker部署.md ├── env.sh ├── piplist ├── readme.md ├── start.sh └── ui │ ├── Model │ ├── __init__.py │ ├── admin.py │ ├── apps.py │ ├── models.py │ ├── serializers.py │ ├── tests.py │ └── views.py │ ├── manage.py │ ├── mpc.json │ ├── protocol.json │ ├── scripts │ ├── rehash.sh │ ├── run.sh │ └── ssl.sh │ ├── ui │ ├── Rtask.py │ ├── __init__.py │ ├── asgi.py │ ├── authentication.py │ ├── pagination.py │ ├── settings.py │ ├── urls.py │ ├── views │ │ ├── __init__.py │ │ ├── link.py │ │ ├── localTask.py │ │ ├── login.py │ │ ├── mpc.py │ │ ├── protocol.py │ │ ├── remotetask.py │ │ ├── servers.py │ │ ├── user.py │ │ └── userdata.py │ └── wsgi.py │ ├── uploads │ └── mpc │ │ ├── correction-supervision.mpc │ │ ├── drug_supervision.mpc │ │ ├── mnist1.mpc │ │ ├── mnist2.mpc │ │ └── mnist3.mpc │ └── utils │ └── common.py ├── Input └── .gitkeep ├── License.txt ├── MPLTS ├── CMakeLists.txt ├── INSTALL.md ├── LICENSE ├── README.md ├── Scripts │ ├── check.py │ ├── check_fig.py │ ├── run.py │ ├── test.py │ ├── test2.py │ └── test3.py ├── cmake │ └── FindCUDA.cmake ├── config.cmake ├── examples │ ├── batched_resnet.py │ ├── bert.py │ ├── enas.py │ ├── enas_arcs │ ├── example.py │ ├── inceptionv3.py │ ├── lenet.py │ ├── nasnet_a.py │ ├── nasnet_block.py │ ├── nasrnn.py │ ├── resnet18.py │ ├── resnet50.py │ ├── resnet_block.py │ └── resnext50.py ├── graph_subst.pb ├── graph_subst_ext.pb ├── graph_subst_full.pb ├── include │ └── taso │ │ ├── cuda_helper.h │ │ ├── dnnl_helper.h │ │ ├── ops.h │ │ └── substitution.h ├── python │ ├── setup.py │ └── taso │ │ ├── __init__.py │ │ └── _cython │ │ ├── CCore.pxd │ │ ├── core.cpp │ │ └── core.pyx ├── recompile.sh ├── requirements.txt ├── src │ ├── core │ │ ├── activation.cc │ │ ├── batchnorm.cc │ │ ├── broadcast_add.cc │ │ ├── cast.cc │ │ ├── concat.cc │ │ ├── constant.cc │ │ ├── conv2d.cc │ │ ├── element.cc │ │ ├── elementwise_unary.cc │ │ ├── enlarge.cc │ │ ├── fuse_conv_batchnorm.cc │ │ ├── fuse_conv_batchnorm_alpha_var.cc │ │ ├── fuse_conv_batchnorm_bias.cc │ │ ├── graph_to_trt.cc │ │ ├── matmul.cc │ │ ├── merge_gconv.cc │ │ ├── mul.cc │ │ ├── noop.cc │ │ ├── ops.cc │ │ ├── pad.cc │ │ ├── pool2d.cc │ │ ├── reduce.cc │ │ ├── reshape.cc │ │ ├── resize.cc │ │ ├── rules.proto │ │ ├── shape.cc │ │ ├── slice.cc │ │ ├── split.cc │ │ ├── squeeze.cc │ │ ├── substitution.cc │ │ ├── topk.cc │ │ ├── transpose.cc │ │ ├── unsqueeze.cc │ │ └── where.cc │ ├── cudnn │ │ ├── activation_kernel.cu │ │ ├── batchnorm_kernel.cu │ │ ├── broadcast_add_kernel.cu │ │ ├── cast_kernel.cu │ │ ├── concat_kernel.cu │ │ ├── constant_kernel.cu │ │ ├── conv2d_kernel.cu │ │ ├── cuda_helper.cu │ │ ├── element_kernel.cu │ │ ├── elementwise_unary_kernel.cu │ │ ├── enlarge_kernel.cu │ │ ├── fuse_conv_batchnorm_alpha_var_kernel.cu │ │ ├── fuse_conv_batchnorm_bias_kernel.cu │ │ ├── fuse_conv_batchnorm_kernel.cu │ │ ├── matmul_kernel.cu │ │ ├── merge_gconv_kernel.cu │ │ ├── mul_kernel.cu │ │ ├── ops_cudnn.cu │ │ ├── pad_kernel.cu │ │ ├── pool2d_kernel.cu │ │ ├── reduce_kernel.cu │ │ ├── reshape_kernel.cu │ │ ├── resize_kernel.cu │ │ ├── shape_kernel.cu │ │ ├── slice_kernel.cu │ │ ├── squeeze_kernel.cu │ │ ├── topk_kernel.cu │ │ ├── transpose_kernel.cu │ │ ├── unsqueeze_kernel.cu │ │ └── where_kernel.cu │ ├── dnnl │ │ ├── activation_mkl.cc │ │ ├── batchnorm_mkl.cc │ │ ├── broadcast_add_mkl.cc │ │ ├── cast_mkl.cc │ │ ├── concat_mkl.cc │ │ ├── constant_mkl.cc │ │ ├── conv2d_mkl.cc │ │ ├── dnnl_helper.cc │ │ ├── element_mkl.cc │ │ ├── elementwise_unary_mkl.cc │ │ ├── enlarge_mkl.cc │ │ ├── fuse_conv_batchnorm_alpha_var_mkl.cc │ │ ├── fuse_conv_batchnorm_bias_mkl.cc │ │ ├── fuse_conv_batchnorm_mkl.cc │ │ ├── matmul_mkl.cc │ │ ├── merge_gconv_mkl.cc │ │ ├── mul_mkl.cc │ │ ├── ops_mkl.cc │ │ ├── pad_mkl.cc │ │ ├── pool2d_mkl.cc │ │ ├── reduce_mkl.cc │ │ ├── reshape_mkl.cc │ │ ├── resize_mkl.cc │ │ ├── shape_mkl.cc │ │ ├── slice_mkl.cc │ │ ├── squeeze_mkl.cc │ │ ├── topk_mkl.cc │ │ ├── transpose_mkl.cc │ │ ├── unsqueeze_mkl.cc │ │ └── where_mkl.cc │ └── generator │ │ ├── compile.sh │ │ ├── generator │ │ ├── generator.cc │ │ ├── graph_subst.pb │ │ ├── rules.pb.cc │ │ └── rules.pb.h └── verify │ ├── graph_subst.pb │ ├── rules_pb2.py │ ├── validate_axioms.py │ └── verify.py ├── Machines ├── ANN.cpp ├── Atlas.hpp ├── Fss.hpp ├── K-means.cpp ├── MalRep.hpp ├── OTMachine.cpp ├── OTMachine.h ├── OText_main.cpp ├── OutputCheck.h ├── Player-Online.cpp ├── Rep.hpp ├── Rep4.hpp ├── RepRing.hpp ├── SPDZ.cpp ├── SPDZ.hpp ├── SPDZ2^64+48.cpp ├── SPDZ2^64+64.cpp ├── SPDZ2^72+48.cpp ├── SPDZ2^72+64.cpp ├── SPDZ2k.cpp ├── SPDZ2k.hpp ├── Semi.hpp ├── Semi2k.hpp ├── ShamirMachine.h ├── ShamirMachine.hpp ├── Tinier.cpp ├── TreeInferenceClient.h ├── TreeInferenceClient.hpp ├── TreeInferenceServer.h ├── TreeInferenceServer.hpp ├── TripleMachine.cpp ├── bmr-program-party.cpp ├── bmr-program-tparty.cpp ├── brain-party.cpp ├── ccd-party.cpp ├── chaigear-party.cpp ├── cowgear-offline.cpp ├── cowgear-party.cpp ├── dealer-ring-party.cpp ├── emulate.cpp ├── fss-ring-party.cpp ├── hemi-party.cpp ├── highgear-party.cpp ├── knn-party-offline.cpp ├── knn-party.cpp ├── kona.cpp ├── lowgear-party.cpp ├── mal-rep-bmr-party.cpp ├── mal-rss-with-conversion-party.cpp ├── mal-shamir-bmr-party.cpp ├── mal-shamir-offline.cpp ├── malicious-ccd-party.cpp ├── malicious-rep-bin-party.cpp ├── malicious-rep-field-party.cpp ├── malicious-rep-ring-party.cpp ├── malicious-shamir-party.cpp ├── mama-party.cpp ├── mascot-offline.cpp ├── mascot-party.cpp ├── no-party.cpp ├── ps-rep-bin-party.cpp ├── ps-rep-field-party.cpp ├── ps-rep-ring-party.cpp ├── real-bmr-party.cpp ├── rep-bmr-party.cpp ├── rep4-ring-party.cpp ├── replicated-bin-party.cpp ├── replicated-field-party.cpp ├── replicated-ring-party.cpp ├── rss-with-conversion-party.cpp ├── secknn.cpp ├── semi-bin-party.cpp ├── semi-bmr-party.cpp ├── semi-party.cpp ├── semi2k-party.cpp ├── semi2k-with-conversion-party.cpp ├── shamir-bmr-party.cpp ├── shamir-party.cpp ├── sml-party.cpp ├── soho-party.cpp ├── spdz2k-party.cpp ├── sy-rep-field-party.cpp ├── sy-rep-ring-party.cpp ├── sy-shamir-party.cpp ├── temi-party.cpp ├── tinier-party.cpp ├── tiny-party.cpp ├── tree-inference.cpp ├── vss-field-party.cpp ├── vss-field-party.h ├── vss-field-party.hpp ├── vss-party.cpp └── yao-party.cpp ├── Makefile ├── Math ├── Bit.cpp ├── Bit.h ├── BitVec.h ├── FixedVec.h ├── Integer.h ├── Integer.hpp ├── Setup.cpp ├── Setup.h ├── Setup.hpp ├── Square.cpp ├── Square.h ├── Square.hpp ├── ValueInterface.h ├── Z2k.h ├── Z2k.hpp ├── Zp_Data.cpp ├── Zp_Data.h ├── bigint.cpp ├── bigint.h ├── bigint.hpp ├── config.h ├── field_types.h ├── fixint.h ├── gf2n.cpp ├── gf2n.h ├── gf2nlong.cpp ├── gf2nlong.h ├── gfp.h ├── gfp.hpp ├── gfpvar.cpp ├── gfpvar.h ├── modp.h ├── modp.hpp ├── mpn_fixed.h └── square128.cpp ├── Networking ├── AllButLastPlayer.h ├── CryptoPlayer.cpp ├── CryptoPlayer.h ├── Exchanger.h ├── Player.cpp ├── Player.h ├── PlayerBuffer.h ├── PlayerCtSocket.h ├── Receiver.cpp ├── Receiver.h ├── Sender.cpp ├── Sender.h ├── Server.cpp ├── Server.h ├── ServerSocket.cpp ├── ServerSocket.h ├── data.h ├── sockets.cpp ├── sockets.h └── ssl_sockets.h ├── OT ├── BaseOT.cpp ├── BaseOT.h ├── BitDiagonal.cpp ├── BitDiagonal.h ├── BitMatrix.h ├── BitMatrix.hpp ├── MamaRectangle.h ├── MascotParams.cpp ├── MascotParams.h ├── NPartyTripleGenerator.h ├── NPartyTripleGenerator.hpp ├── OTCorrelator.hpp ├── OTExtension.cpp ├── OTExtension.h ├── OTExtensionWithMatrix.cpp ├── OTExtensionWithMatrix.h ├── OTMultiplier.h ├── OTMultiplier.hpp ├── OTTripleSetup.cpp ├── OTTripleSetup.h ├── OTVole.h ├── OTVole.hpp ├── Rectangle.h ├── Rectangle.hpp ├── Row.h ├── Row.hpp ├── Tools.h ├── Triple.hpp ├── TripleMachine.h └── config.h ├── Output └── .gitkeep ├── Player-Data └── readme.txt ├── Processor ├── BaseMachine.cpp ├── BaseMachine.h ├── Binary_File_IO.h ├── Binary_File_IO.hpp ├── Conv2dTuple.h ├── DataPositions.cpp ├── Data_Files.h ├── Data_Files.hpp ├── DummyProtocol.h ├── ExternalClients.cpp ├── ExternalClients.h ├── FieldMachine.h ├── FieldMachine.hpp ├── FixInput.cpp ├── FixInput.h ├── FloatInput.cpp ├── FloatInput.h ├── HonestMajorityMachine.cpp ├── HonestMajorityMachine.h ├── Input.h ├── Input.hpp ├── InputTuple.h ├── Instruction.cpp ├── Instruction.h ├── Instruction.hpp ├── Instructions_for_big_domain.h ├── IntInput.h ├── IntInput.hpp ├── Machine.h ├── Machine.hpp ├── MatmulsTuple.h ├── MatmulsmTuple.h ├── Memory.h ├── Memory.hpp ├── NoFilePrep.h ├── OfflineMachine.h ├── OfflineMachine.hpp ├── Online-Thread.h ├── Online-Thread.hpp ├── OnlineMachine.h ├── OnlineMachine.hpp ├── OnlineOptions.cpp ├── OnlineOptions.h ├── OnlineOptions.hpp ├── PrepBase.cpp ├── PrepBase.h ├── PrivateOutput.h ├── PrivateOutput.hpp ├── Processor.h ├── Processor.hpp ├── ProcessorBase.cpp ├── ProcessorBase.h ├── ProcessorBase.hpp ├── Program.cpp ├── Program.h ├── RingMachine.h ├── RingMachine.hpp ├── RingOptions.cpp ├── RingOptions.h ├── SpecificPrivateOutput.h ├── StrInput.cpp ├── StrInput.h ├── ThreadJob.h ├── ThreadQueue.cpp ├── ThreadQueue.h ├── ThreadQueues.cpp ├── ThreadQueues.h ├── TruncPrTuple.h ├── config.h └── instructions.h ├── Programs ├── Profiling-data │ └── program-protocol └── Source │ ├── Linear-ReLU-Test.mpc │ ├── ViT-MNIST-Test.mpc │ ├── adult.mpc │ ├── aes.mpc │ ├── aes_circuit.mpc │ ├── autograd_MPCFormer.mpc │ ├── autograd_alexnet_train_adam.mpc │ ├── autograd_alexnet_train_sgd.mpc │ ├── autograd_bert.mpc │ ├── autograd_dense.mpc │ ├── autograd_densenet.mpc │ ├── autograd_dev.mpc │ ├── autograd_gpt.mpc │ ├── autograd_lenet.mpc │ ├── autograd_lenet_modified.mpc │ ├── autograd_lenet_train_adam.mpc │ ├── autograd_lenet_train_sgd.mpc │ ├── autograd_linear.mpc │ ├── autograd_logistic.mpc │ ├── autograd_logistic_dpsgd.mpc │ ├── autograd_mobilenetv3.mpc │ ├── autograd_preacresnet.mpc │ ├── autograd_resnet.mpc │ ├── autograd_rnn.mpc │ ├── autograd_shufflenetv2.mpc │ ├── autograd_transformer.mpc │ ├── autograd_vgg_train_adam.mpc │ ├── autograd_vgg_train_sgd.mpc │ ├── bankers_bonus.mpc │ ├── bench-dt.mpc │ ├── benchmark_conv.mpc │ ├── benchmark_mobilenet.mpc │ ├── benchmark_net.mpc │ ├── benchmark_secureNN.mpc │ ├── benchmark_sops_fixed_length.mpc │ ├── benchmark_sops_fixed_num_sops.mpc │ ├── bio.mpc │ ├── blink.mpc │ ├── correction-supervision.mpc │ ├── davex-decision-tree.mpc │ ├── davex-dt-inference.mpc │ ├── dijkstra_example.mpc │ ├── drug_supervision.mpc │ ├── dt_adult.mpc │ ├── ents_accuracy.mpc │ ├── ents_efficiency.mpc │ ├── falcon_alex.mpc │ ├── gale-shapley_tutorial.mpc │ ├── gc_and.mpc │ ├── gc_oram.mpc │ ├── htmac.mpc │ ├── idash_predict.mpc │ ├── idash_train.mpc │ ├── keras_cifar_lenet.mpc │ ├── keras_mnist_dense.mpc │ ├── keras_mnist_dense_predict.mpc │ ├── keras_mnist_lenet.mpc │ ├── keras_mnist_lenet_predict.mpc │ ├── l2h_comparison.mpc │ ├── l2h_multiplication.mpc │ ├── loan_fraud_analysis.mpc │ ├── loan_fraud_xgboost.mpc │ ├── logistic_regression.mpc │ ├── logreg.mpc │ ├── mini_matmul.mpc │ ├── mnist1.mpc │ ├── mnist2.mpc │ ├── mnist3.mpc │ ├── mnist_49.mpc │ ├── mnist_A.mpc │ ├── mnist_full_A.mpc │ ├── mnist_full_B.mpc │ ├── mnist_full_C.mpc │ ├── mnist_full_D.mpc │ ├── mnist_logreg.mpc │ ├── mul_test.mpc │ ├── oram_tutorial.mpc │ ├── prep_aes.mpc │ ├── prf_leg.mpc │ ├── prf_mimc.mpc │ ├── regression.mpc │ ├── spect.mpc │ ├── ss_psi_test.mpc │ ├── temp-poplar-accuracy.mpc │ ├── test.mpc │ ├── test2.mpc │ ├── test_args.mpc │ ├── test_autograd.mpc │ ├── test_autograd_function.mpc │ ├── test_autograd_mul.mpc │ ├── test_autograd_zrs.mpc │ ├── test_broadcast.mpc │ ├── test_conv2d.mpc │ ├── test_dataframe.mpc │ ├── test_double.mpc │ ├── test_flow_optimization.mpc │ ├── test_gc.mpc │ ├── test_gfa.mpc │ ├── test_gfa_preset.mpc │ ├── test_gopt.mpc │ ├── test_ins_merge.mpc │ ├── test_joint_statistics.mpc │ ├── test_joint_statistics2.mpc │ ├── test_matmul_merge.mpc │ ├── test_mpsi.mpc │ ├── test_onnx.mpc │ ├── test_order.mpc │ ├── test_permute.mpc │ ├── test_psi.mpc │ ├── test_psu.mpc │ ├── test_sbitfix.mpc │ ├── test_sbitint.mpc │ ├── test_sfix.mpc │ ├── test_spline_2.mpc │ ├── test_str.mpc │ ├── test_t.mpc │ ├── test_tanh.mpc │ ├── test_thread_mul.mpc │ ├── test_torch.mpc │ ├── test_vssfield.mpc │ ├── test_x+r.mpc │ ├── testvss.mpc │ ├── tf.mpc │ ├── torch_ckplus48_lenet_selected.mpc │ ├── torch_lenet_fine-tuning.mpc │ ├── tpmpc_tutorial.mpc │ ├── tutorial.mpc │ ├── txy.mpc │ ├── vickrey.mpc │ ├── xgboost-inference-mal.mpc │ ├── xgboost-inference-test.mpc │ ├── xgboost-inference.mpc │ └── xgboost.mpc ├── Protocols ├── Atlas.h ├── Atlas.hpp ├── AtlasPrep.h ├── AtlasShare.h ├── Beaver.h ├── Beaver.hpp ├── BrainPrep.h ├── BrainPrep.hpp ├── BrainShare.h ├── ChaiGearPrep.h ├── ChaiGearPrep.hpp ├── ChaiGearShare.h ├── CowGearOptions.cpp ├── CowGearOptions.h ├── CowGearPrep.h ├── CowGearPrep.hpp ├── CowGearShare.h ├── DabitSacrifice.h ├── DabitSacrifice.hpp ├── Dealer.h ├── DealerInput.h ├── DealerInput.hpp ├── DealerMC.h ├── DealerMC.hpp ├── DealerMatrixPrep.h ├── DealerMatrixPrep.hpp ├── DealerPrep.h ├── DealerPrep.hpp ├── DealerShare.h ├── FakeInput.h ├── FakeMC.h ├── FakePrep.h ├── FakeProtocol.h ├── FakeShare.h ├── FakeShare.hpp ├── Fss.h ├── Fss.hpp ├── Fss3Prep.h ├── Fss3Prep.hpp ├── Fss3Share.h ├── Fss3Share2k.h ├── Hemi.h ├── Hemi.hpp ├── HemiMatrixPrep.h ├── HemiMatrixPrep.hpp ├── HemiOptions.h ├── HemiPrep.h ├── HemiPrep.hpp ├── HemiShare.h ├── HighGearKeyGen.cpp ├── HighGearKeyGen.h ├── HighGearKeyGen.hpp ├── HighGearShare.h ├── LimitedPrep.h ├── LimitedPrep.hpp ├── LowGearKeyGen.cpp ├── LowGearKeyGen.h ├── LowGearKeyGen.hpp ├── LowGearShare.h ├── MAC_Check.h ├── MAC_Check.hpp ├── MAC_Check_Base.h ├── MAC_Check_Base.hpp ├── MalRepRingOptions.cpp ├── MalRepRingOptions.h ├── MalRepRingPrep.h ├── MalRepRingPrep.hpp ├── MalRepRingShare.h ├── MalRepRingShare128.h ├── MaliciousRep3Share.h ├── MaliciousRepMC.h ├── MaliciousRepMC.hpp ├── MaliciousRepPO.h ├── MaliciousRepPO.hpp ├── MaliciousRepPrep.h ├── MaliciousRepPrep.hpp ├── MaliciousRingPrep.hpp ├── MaliciousShamirMC.h ├── MaliciousShamirMC.hpp ├── MaliciousShamirPO.h ├── MaliciousShamirPO.hpp ├── MaliciousShamirShare.h ├── MamaPrep.h ├── MamaPrep.hpp ├── MamaShare.h ├── MascotPrep.h ├── MascotPrep.hpp ├── NoLivePrep.h ├── NoProtocol.h ├── NoShare.h ├── PostSacriRepFieldShare.h ├── PostSacriRepRingShare.h ├── PostSacrifice.h ├── PostSacrifice.hpp ├── ProtocolSet.h ├── ProtocolSetup.h ├── Rep3Share.h ├── Rep3Share128.h ├── Rep3Share2k.h ├── Rep3Shuffler.h ├── Rep3Shuffler.hpp ├── Rep4.h ├── Rep4.hpp ├── Rep4Input.h ├── Rep4Input.hpp ├── Rep4MC.h ├── Rep4MC.hpp ├── Rep4Prep.h ├── Rep4Prep.hpp ├── Rep4Share.h ├── Rep4Share2k.h ├── RepRingOnlyEdabitPrep.h ├── RepRingOnlyEdabitPrep.hpp ├── Replicated.h ├── Replicated.hpp ├── ReplicatedInput.h ├── ReplicatedInput.hpp ├── ReplicatedMC.h ├── ReplicatedMC.hpp ├── ReplicatedPO.h ├── ReplicatedPO.hpp ├── ReplicatedPrep.h ├── ReplicatedPrep.hpp ├── RingOnlyPrep.h ├── RingOnlyPrep.hpp ├── SPDZ.h ├── SPDZ2k.h ├── SecureML.h ├── SecureShuffle.h ├── SecureShuffle.hpp ├── Semi.h ├── Semi2kShare.h ├── Semi2kShare128.h ├── SemiInput.h ├── SemiInput.hpp ├── SemiMC.h ├── SemiMC.hpp ├── SemiPrep.h ├── SemiPrep.hpp ├── SemiPrep2k.h ├── SemiRep3Prep.h ├── SemiShare.h ├── Shamir.h ├── Shamir.hpp ├── ShamirInput.h ├── ShamirInput.hpp ├── ShamirMC.h ├── ShamirMC.hpp ├── ShamirShare.h ├── Share.h ├── Share.hpp ├── ShareInterface.cpp ├── ShareInterface.h ├── ShareMatrix.h ├── ShareVector.h ├── ShareVector.hpp ├── ShuffleSacrifice.h ├── ShuffleSacrifice.hpp ├── SmlMatrixPrep.h ├── SmlShare.h ├── SohoPrep.h ├── SohoPrep.hpp ├── SohoShare.h ├── Spdz2kPrep.h ├── Spdz2kPrep.hpp ├── Spdz2kShare.h ├── SpdzWise.h ├── SpdzWise.hpp ├── SpdzWiseInput.h ├── SpdzWiseInput.hpp ├── SpdzWiseMC.h ├── SpdzWisePrep.h ├── SpdzWisePrep.hpp ├── SpdzWiseRing.h ├── SpdzWiseRing.hpp ├── SpdzWiseRingPrep.h ├── SpdzWiseRingShare.h ├── SpdzWiseShare.h ├── SpdzWiseShare.hpp ├── SquarePrep.h ├── TemiPrep.h ├── TemiPrep.hpp ├── TemiShare.h ├── Vss.h ├── Vss2kShare.h ├── VssFieldInput.h ├── VssFieldInput.hpp ├── VssFieldMC.h ├── VssFieldMC.hpp ├── VssFieldPrep.h ├── VssFieldShare.h ├── VssInput.h ├── VssInput.hpp ├── VssMC.h ├── VssMC.hpp ├── VssMatrixPrep.h ├── VssPrep.h ├── config.h ├── dabit.h ├── edabit.h ├── fake-stuff.h ├── fake-stuff.hpp └── mac_key.hpp ├── README-CN.md ├── README.md ├── Scripts ├── PSI-Test │ ├── check_psi.py │ ├── generate_fake_data.py │ ├── plain_psi.py │ ├── run_mpsi.sh │ └── run_psi.sh ├── accuracy_data_for_ents.py ├── adult_prepare.py ├── atlas.sh ├── bmr-program-run-remote.sh ├── bmr-program-run.sh ├── brain.sh ├── build.sh ├── ccd.sh ├── chaigear.sh ├── community_correction_data_process.py ├── compile-for-emulation.sh ├── convert.sh ├── court_correction_data_process.py ├── cowgear.sh ├── data_prepare_for_xgboost.py ├── dealer-ring.sh ├── decompile.py ├── direct_compilation_example.py ├── download.sh ├── drug_process.py ├── efficiency_data_for_ents.py ├── emulate-append.sh ├── emulate.sh ├── fake-spdz-real-bmr.sh ├── fixed-rep-to-float.py ├── fixed-rep-to-raw.py ├── fss-ring.sh ├── generate-cert.sh ├── hemi.sh ├── highgear.sh ├── loan_data_generator.py ├── lowgear.sh ├── mal-ccd.sh ├── mal-rep-bin.sh ├── mal-rep-bmr.sh ├── mal-rep-field.sh ├── mal-rep-ring.sh ├── mal-rss-with-conversion.sh ├── mal-shamir-bmr.sh ├── mal-shamir.sh ├── mama.sh ├── mascot.sh ├── memory-usage.py ├── prep-usage.py ├── process-tf.py ├── profiling-5models.py ├── profiling-5models.sh ├── profiling-v-2m4p.py ├── profiling-v.py ├── ps-rep-bin.sh ├── ps-rep-field.sh ├── ps-rep-ring.sh ├── real-bmr.sh ├── rep-bmr.sh ├── rep-field.sh ├── rep4-ring.sh ├── replicated.sh ├── ring-only-online.sh ├── ring.sh ├── rss-with-conversion.sh ├── run-common.sh ├── run-online.sh ├── semi-bin.sh ├── semi-bmr.sh ├── semi.sh ├── semi2k-with-conversion.sh ├── semi2k.sh ├── setup-clients.sh ├── setup-online.sh ├── setup-ssl.sh ├── shamir-bmr.sh ├── shamir.sh ├── sml.sh ├── soho.sh ├── spdz2k.sh ├── sy-rep-field.sh ├── sy-rep-ring.sh ├── sy-shamir.sh ├── temi.sh ├── test_ecdsa.sh ├── test_flow_optimization.sh ├── test_streaming.sh ├── test_tutorial.sh ├── tinier.sh ├── tiny.sh ├── tldr.sh ├── vss-field.sh ├── vss.sh ├── wan.sh └── yao.sh ├── Tools ├── BitVector.cpp ├── BitVector.h ├── Buffer.cpp ├── Buffer.h ├── Bundle.h ├── CheckVector.h ├── Commit.cpp ├── Commit.h ├── Coordinator.cpp ├── Coordinator.h ├── Exceptions.cpp ├── Exceptions.h ├── ExecutionStats.cpp ├── ExecutionStats.h ├── FixedVector.h ├── FlexBuffer.cpp ├── FlexBuffer.h ├── Hash.cpp ├── Hash.h ├── Lock.cpp ├── Lock.h ├── MMO.h ├── MMO.hpp ├── MemoryUsage.h ├── NetworkOptions.cpp ├── NetworkOptions.h ├── OfflineMachineBase.cpp ├── OfflineMachineBase.h ├── PointerVector.h ├── Signal.cpp ├── Signal.h ├── Subroutines.cpp ├── Subroutines.h ├── Subroutines.hpp ├── SwitchableOutput.h ├── TimerWithComm.cpp ├── TimerWithComm.h ├── WaitQueue.h ├── Waksman.cpp ├── Waksman.h ├── Worker.h ├── aes-arm.h ├── aes-ni.cpp ├── aes.cpp ├── aes.h ├── avx_memcpy.h ├── benchmarking.cpp ├── benchmarking.h ├── callgrind.h ├── cpu_support.h ├── ezOptionParser-MIT-LICENSE ├── ezOptionParser.h ├── int.h ├── intrinsics.h ├── mkpath.cpp ├── mkpath.h ├── names.cpp ├── oct.h ├── octetStream.cpp ├── octetStream.h ├── parse.h ├── pprint.h ├── random.cpp ├── random.h ├── time-func.cpp └── time-func.h ├── Tools_PSI ├── OKVS.cpp ├── OKVS.h ├── PRF.h ├── SimpleIndex.cpp └── SimpleIndex.h ├── Utils ├── Check-Offline-Z2k.cpp ├── Check-Offline.cpp ├── Fake-Offline.cpp ├── Server.cpp ├── binary-example.cpp ├── check-passive.cpp ├── cnc-offline.cpp ├── default-prime-length.cpp ├── galois-degree.cpp ├── gauss_test │ ├── generate_noise │ └── generate_noise.cpp ├── gc-emulate.cpp ├── gen_input_f2n.cpp ├── gen_input_fp.cpp ├── generate_data.py ├── he-example.cpp ├── hyper.cpp ├── l2h-example.cpp ├── mixed-example.cpp ├── ot-offline.cpp ├── pairwise-offline.cpp ├── paper-example.cpp ├── prime.cpp ├── simple-offline.cpp ├── spdz2-offline.cpp └── stream-fake-mascot-triples.cpp ├── Yao ├── YaoAndJob.h ├── YaoCommon.h ├── YaoCommon.hpp ├── YaoEvalInput.h ├── YaoEvalMaster.cpp ├── YaoEvalMaster.h ├── YaoEvalWire.cpp ├── YaoEvalWire.h ├── YaoEvaluator.cpp ├── YaoEvaluator.h ├── YaoGarbleInput.h ├── YaoGarbleMaster.cpp ├── YaoGarbleMaster.h ├── YaoGarbleWire.cpp ├── YaoGarbleWire.h ├── YaoGarbler.cpp ├── YaoGarbler.h ├── YaoGate.cpp ├── YaoGate.h ├── YaoHalfGate.cpp ├── YaoHalfGate.h ├── YaoPlayer.cpp ├── YaoPlayer.h ├── YaoWire.h ├── YaoWire.hpp └── config.h ├── azure-pipelines.yml ├── bin ├── README.md ├── boost-license.txt ├── glibc-license.txt ├── libsodium-license.txt ├── mpir-license.txt ├── ntl-license.txt └── openssl-license.txt ├── compile.py ├── doc ├── .gitignore ├── Compiler.rst ├── Doxyfile ├── Makefile ├── _static │ └── custom.css ├── add-protocol.rst ├── compilation.rst ├── conf.py ├── gen-instructions.py ├── gen-readme.sh ├── homomorphic-encryption.rst ├── index.rst ├── instructions.rst ├── io.rst ├── low-level.rst ├── machine-learning.rst ├── networking.rst ├── non-linear.rst ├── preprocessing.rst ├── requirements.txt └── troubleshooting.rst ├── docs ├── PSI.md ├── ann.md ├── autograd.md ├── dataframe.md ├── dpsgd.md ├── figs │ ├── psi-align.svg │ └── psi.svg ├── fss.md ├── joint_statistics.md ├── joint_statistics2.md ├── knn.md ├── mPSI.md ├── mpts.md ├── nfgen.md ├── pretrain.md ├── profiling.md ├── ruyi.md ├── secureML.md ├── ss-psi.md ├── ss-psu.md ├── string.md ├── transformer.md ├── vss.md ├── xgboost-inference.md └── xgboost-training.md ├── mixed ├── requirements.txt └── setup.py /.dockerignore: -------------------------------------------------------------------------------- 1 | .git 2 | *.md 3 | *.png 4 | *.jpeg -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "SimpleOT"] 2 | path = deps/SimpleOT 3 | url = https://github.com/mkskeller/SimpleOT 4 | [submodule "mpir"] 5 | path = deps/mpir 6 | url = https://github.com/wbhart/mpir 7 | [submodule "Programs/Circuits"] 8 | path = Programs/Circuits 9 | url = https://github.com/mkskeller/bristol-fashion 10 | [submodule "simde"] 11 | path = deps/simde 12 | url = https://github.com/simd-everywhere/simde 13 | [submodule "deps/libOTe"] 14 | path = deps/libOTe 15 | url = https://github.com/mkskeller/softspoken-implementation 16 | [submodule "deps/SimplestOT_C"] 17 | path = deps/SimplestOT_C 18 | url = https://github.com/mkskeller/SimplestOT_C 19 | -------------------------------------------------------------------------------- /BMR/BooleanCircuit.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __BOOLEAN_CIRCUIT__ 3 | #define __BOOLEAN_CIRCUIT__ 4 | 5 | #include "Party.h" 6 | 7 | #define MSG_KEYS_HEADER_SZ (16) 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /BMR/Key.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Key.cpp 3 | * 4 | */ 5 | 6 | 7 | #include 8 | #include "Key.h" 9 | 10 | ostream& operator<<(ostream& o, const Key& key) 11 | { 12 | return o << key.r; 13 | } 14 | 15 | ostream& operator<<(ostream& o, const __m128i& x) { 16 | o.fill('0'); 17 | o << hex << noshowbase; 18 | for (int i = 0; i < 2; i++) 19 | { 20 | o.width(16); 21 | o << ((int64_t*)&x)[1-i]; 22 | } 23 | o << dec; 24 | return o; 25 | } 26 | -------------------------------------------------------------------------------- /BMR/Register_inline.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Register_inline.h 3 | * 4 | */ 5 | 6 | #ifndef BMR_REGISTER_INLINE_H_ 7 | #define BMR_REGISTER_INLINE_H_ 8 | 9 | #include "CommonParty.h" 10 | #include "Party.h" 11 | 12 | inline Register::Register() : 13 | garbled_entry(CommonParty::s().get_n_parties()), external(NO_SIGNAL), 14 | mask(NO_SIGNAL), keys(CommonParty::s().get_n_parties()) 15 | { 16 | } 17 | 18 | #endif /* BMR_REGISTER_INLINE_H_ */ 19 | -------------------------------------------------------------------------------- /BMR/SpdzWire.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SpdzWire.h 3 | * 4 | */ 5 | 6 | #ifndef BMR_SPDZWIRE_H_ 7 | #define BMR_SPDZWIRE_H_ 8 | 9 | #include "Protocols/Share.h" 10 | #include "Key.h" 11 | 12 | template 13 | class DualWire 14 | { 15 | public: 16 | T mask; 17 | Key my_keys[2]; 18 | 19 | DualWire() 20 | { 21 | my_keys[0] = 0; 22 | my_keys[1] = 0; 23 | } 24 | 25 | void pack(octetStream& os) const 26 | { 27 | mask.pack(os); 28 | os.serialize(my_keys); 29 | } 30 | void unpack(octetStream& os, size_t wanted_size) 31 | { 32 | (void)wanted_size; 33 | mask.unpack(os); 34 | os.unserialize(my_keys); 35 | } 36 | }; 37 | 38 | typedef DualWire> SpdzWire; 39 | 40 | #endif /* BMR_SPDZWIRE_H_ */ 41 | -------------------------------------------------------------------------------- /BMR/Wire.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __WIRE_H__ 3 | #define __WIRE_H__ 4 | 5 | #include 6 | 7 | #include "Key.h" 8 | #include "common.h" 9 | 10 | class Gate; 11 | 12 | #define NO_SIGNAL (2) //since this is a boolean circuit, valid values are either 0 or 1. 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /BMR/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * config.h 3 | * 4 | */ 5 | 6 | #ifndef BMR_CONFIG_H_ 7 | #define BMR_CONFIG_H_ 8 | 9 | // change number of parties here or omit to allow any number 10 | //#define N_PARTIES 2 11 | #define MAX_N_PARTIES 3 12 | 13 | #define MAX_INLINE 14 | 15 | //#define SIGNAL_CHECK 16 | //#define DEBUG_MASK 17 | 18 | #endif /* BMR_CONFIG_H_ */ 19 | -------------------------------------------------------------------------------- /BMR/msg_types.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * msg_types.cpp 3 | * 4 | */ 5 | 6 | #include "msg_types.h" 7 | 8 | #define X(NAME) #NAME, 9 | 10 | const char* message_type_names[] = { 11 | MESSAGE_TYPES 12 | }; 13 | 14 | #undef X 15 | -------------------------------------------------------------------------------- /BMR/msg_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * msg_types.h 3 | * 4 | */ 5 | 6 | #ifndef PROTOCOL_INC_MSG_TYPES_H_ 7 | #define PROTOCOL_INC_MSG_TYPES_H_ 8 | 9 | 10 | #define MESSAGE_TYPES \ 11 | X(TYPE_KEYS) \ 12 | X(TYPE_MASK_INPUTS) \ 13 | X(TYPE_MASK_OUTPUT) \ 14 | X(TYPE_PRF_OUTPUTS) \ 15 | X(TYPE_GARBLED_CIRCUIT) \ 16 | X(TYPE_LAUNCH_ONLINE) \ 17 | X(TYPE_RECEIVED_GC) \ 18 | X(TYPE_SPDZ_WIRES) \ 19 | X(TYPE_DELTA) \ 20 | X(TYPE_NEXT) \ 21 | X(TYPE_DONE) \ 22 | X(TYPE_MAX) \ 23 | 24 | 25 | #define X(NAME) NAME, 26 | 27 | typedef enum { 28 | MESSAGE_TYPES 29 | } MSG_TYPE; 30 | 31 | #undef X 32 | 33 | extern const char* message_type_names[]; 34 | 35 | #endif /* PROTOCOL_INC_MSG_TYPES_H_ */ 36 | -------------------------------------------------------------------------------- /BMR/network/common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * common.h 3 | * 4 | */ 5 | 6 | #ifndef NETWORK_INC_COMMON_H_ 7 | #define NETWORK_INC_COMMON_H_ 8 | 9 | #include 10 | #include 11 | 12 | //#include "utils.h" 13 | 14 | /* 15 | * To change the buffer sizes in the kernel 16 | # echo 'net.core.wmem_max=12582912' >> /etc/sysctl.conf 17 | # echo 'net.core.rmem_max=12582912' >> /etc/sysctl.conf 18 | */ 19 | const int NETWORK_BUFFER_SIZE = 20000000; 20 | 21 | typedef struct { 22 | std::string ip; 23 | int port; 24 | } endpoint_t; 25 | 26 | #endif /* NETWORK_INC_COMMON_H_ */ 27 | -------------------------------------------------------------------------------- /BMR/network/utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * utils.h 3 | * 4 | */ 5 | 6 | #ifndef NETWORK_TEST_UTILS_H_ 7 | #define NETWORK_TEST_UTILS_H_ 8 | 9 | 10 | char cs(char* msg, unsigned int len, char result=0); 11 | 12 | void phex (const void *addr, int len); 13 | 14 | #endif /* NETWORK_TEST_UTILS_H_ */ 15 | -------------------------------------------------------------------------------- /BMR/prf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * prf.h 3 | * 4 | */ 5 | 6 | #ifndef PROTOCOL_INC_PRF_H_ 7 | #define PROTOCOL_INC_PRF_H_ 8 | 9 | #include "Key.h" 10 | 11 | #include "Tools/aes.h" 12 | 13 | inline void PRF_chunk(const Key& key, char* input, char* output, int number) 14 | { 15 | __m128i* in = (__m128i*)input; 16 | __m128i* out = (__m128i*)output; 17 | __m128i rd_key[15]; 18 | aes_128_schedule((octet*) rd_key, (unsigned char*)&key.r); 19 | switch (number) 20 | { 21 | case 2: 22 | ecb_aes_128_encrypt<2>(out, in, (octet*)rd_key); 23 | break; 24 | case 3: 25 | ecb_aes_128_encrypt<3>(out, in, (octet*)rd_key); 26 | break; 27 | default: 28 | for (int i = 0; i < number; i++) 29 | ecb_aes_128_encrypt<1>(&out[i], &in[i], (octet*)rd_key); 30 | break; 31 | } 32 | } 33 | 34 | #endif /* PROTOCOL_INC_PRF_H_ */ 35 | -------------------------------------------------------------------------------- /BMR/proto_utils.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * utils.cpp 3 | * 4 | */ 5 | 6 | 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | //#include 13 | #include 14 | 15 | #include "proto_utils.h" 16 | 17 | void fill_message_type(void* buffer, MSG_TYPE type) 18 | { 19 | memcpy(buffer, &type, sizeof(MSG_TYPE)); 20 | } 21 | 22 | void fill_message_type(SendBuffer& buffer, MSG_TYPE type) 23 | { 24 | buffer.serialize(type); 25 | } 26 | -------------------------------------------------------------------------------- /BMR/proto_utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * utils.h 3 | * 4 | */ 5 | 6 | #ifndef PROTO_UTILS_H_ 7 | #define PROTO_UTILS_H_ 8 | 9 | #include "msg_types.h" 10 | #include 11 | #include 12 | #include 13 | #include 14 | using namespace std; 15 | 16 | #include "Tools/avx_memcpy.h" 17 | #include "Tools/FlexBuffer.h" 18 | 19 | #define LOOPBACK_STR "LOOPBACK" 20 | 21 | class SendBuffer; 22 | 23 | void fill_message_type(void* buffer, MSG_TYPE type); 24 | void fill_message_type(SendBuffer& buffer, MSG_TYPE type); 25 | 26 | void phex (const void *addr, int len); 27 | 28 | 29 | inline void phex(const FlexBuffer& buffer) { phex(buffer.data(), buffer.size()); } 30 | 31 | #endif /* NETWORK_TEST_UTILS_H_ */ 32 | -------------------------------------------------------------------------------- /Compiler/DL/fer_utils/templates/dlib/cnn_face_detector.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FudanMPL/Garnet/89af954fd61628990a0e6faa9a29d9d5e4b17667/Compiler/DL/fer_utils/templates/dlib/cnn_face_detector.dat -------------------------------------------------------------------------------- /Compiler/DL/readme.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FudanMPL/Garnet/89af954fd61628990a0e6faa9a29d9d5e4b17667/Compiler/DL/readme.md -------------------------------------------------------------------------------- /Compiler/GC/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FudanMPL/Garnet/89af954fd61628990a0e6faa9a29d9d5e4b17667/Compiler/GC/__init__.py -------------------------------------------------------------------------------- /Compiler/GC/program.py: -------------------------------------------------------------------------------- 1 | from Compiler import types, instructions 2 | 3 | class Program(object): 4 | def __init__(self, progname): 5 | types.program = self 6 | instructions.program = self 7 | self.curr_tape = None 8 | exec(compile(open(progname).read(), progname, 'exec')) 9 | def malloc(self, *args): 10 | pass 11 | -------------------------------------------------------------------------------- /Compiler/GFA/NFGen/PerformanceModel/PrivPy_KMProfiler.pkl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FudanMPL/Garnet/89af954fd61628990a0e6faa9a29d9d5e4b17667/Compiler/GFA/NFGen/PerformanceModel/PrivPy_KMProfiler.pkl -------------------------------------------------------------------------------- /Compiler/GFA/NFGen/PerformanceModel/PrivPy_kmProfiler.pkl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FudanMPL/Garnet/89af954fd61628990a0e6faa9a29d9d5e4b17667/Compiler/GFA/NFGen/PerformanceModel/PrivPy_kmProfiler.pkl -------------------------------------------------------------------------------- /Compiler/GFA/NFGen/PerformanceModel/PsRepPrime_kmProfiler.pkl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FudanMPL/Garnet/89af954fd61628990a0e6faa9a29d9d5e4b17667/Compiler/GFA/NFGen/PerformanceModel/PsRepPrime_kmProfiler.pkl -------------------------------------------------------------------------------- /Compiler/GFA/NFGen/PerformanceModel/PsRepRing_kmProfiler.pkl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FudanMPL/Garnet/89af954fd61628990a0e6faa9a29d9d5e4b17667/Compiler/GFA/NFGen/PerformanceModel/PsRepRing_kmProfiler.pkl -------------------------------------------------------------------------------- /Compiler/GFA/NFGen/PerformanceModel/Rep3_kmProfiler.pkl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FudanMPL/Garnet/89af954fd61628990a0e6faa9a29d9d5e4b17667/Compiler/GFA/NFGen/PerformanceModel/Rep3_kmProfiler.pkl -------------------------------------------------------------------------------- /Compiler/GFA/NFGen/PerformanceModel/RepPrime_kmProfiler.pkl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FudanMPL/Garnet/89af954fd61628990a0e6faa9a29d9d5e4b17667/Compiler/GFA/NFGen/PerformanceModel/RepPrime_kmProfiler.pkl -------------------------------------------------------------------------------- /Compiler/GFA/NFGen/PerformanceModel/Shamir3_kmProfiler.pkl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FudanMPL/Garnet/89af954fd61628990a0e6faa9a29d9d5e4b17667/Compiler/GFA/NFGen/PerformanceModel/Shamir3_kmProfiler.pkl -------------------------------------------------------------------------------- /Compiler/GFA/NFGen/PerformanceModel/__init__.py: -------------------------------------------------------------------------------- 1 | __all__ = ['time_ops'] -------------------------------------------------------------------------------- /Compiler/GFA/NFGen/__init__.py: -------------------------------------------------------------------------------- 1 | __all__ = ['config', 'data_preprocess', 'profiler', 'fitter', 'funcs', 'analysis', 'funcs_2d', 'main', 'code_generator', 'PerformanceModel', 'CodeTemplet'] -------------------------------------------------------------------------------- /Compiler/__init__.py: -------------------------------------------------------------------------------- 1 | from . import compilerLib, program, instructions, types, library, floatingpoint 2 | from .GC import types as GC_types 3 | import inspect 4 | from .config import * 5 | -------------------------------------------------------------------------------- /Compiler/exceptions.py: -------------------------------------------------------------------------------- 1 | class CompilerError(Exception): 2 | """Base class for compiler exceptions.""" 3 | pass 4 | 5 | class RegisterOverflowError(CompilerError): 6 | pass 7 | 8 | class MemoryOverflowError(CompilerError): 9 | pass 10 | 11 | class ArgumentError(CompilerError): 12 | """ Exception raised for errors in instruction argument parsing. """ 13 | def __init__(self, arg, msg): 14 | self.arg = arg 15 | self.msg = msg 16 | 17 | class VectorMismatch(CompilerError): 18 | pass 19 | -------------------------------------------------------------------------------- /Compiler/onnxConverter/constants.py: -------------------------------------------------------------------------------- 1 | import Compiler.nn as nn 2 | # from Compiler.nn.modules.conv import _ConvNd 3 | from onnx2pytorch.operations import ( 4 | BatchNormWrapper, 5 | InstanceNormWrapper, 6 | Loop, 7 | LSTMWrapper, 8 | Split, 9 | TopK, 10 | ) 11 | 12 | from Compiler.onnxConverter.Ops import split 13 | 14 | COMPOSITE_LAYERS = (nn.Sequential,) 15 | # MULTIOUTPUT_LAYERS = (nn.MaxPool2d, Loop, LSTMWrapper, split.Split, TopK) 16 | MULTIOUTPUT_LAYERS = (Loop, LSTMWrapper, split.Split, TopK) 17 | STANDARD_LAYERS = ( 18 | # _ConvNd, 19 | BatchNormWrapper, 20 | InstanceNormWrapper, 21 | LSTMWrapper, 22 | nn.Linear, 23 | ) 24 | -------------------------------------------------------------------------------- /Compiler/profiling_res/.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore everything in this directory 2 | *.pdf 3 | #Except this file -------------------------------------------------------------------------------- /Compiler/profiling_res/1.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FudanMPL/Garnet/89af954fd61628990a0e6faa9a29d9d5e4b17667/Compiler/profiling_res/1.txt -------------------------------------------------------------------------------- /Compiler/tools.py: -------------------------------------------------------------------------------- 1 | import itertools 2 | 3 | class chain(object): 4 | def __init__(self, *args): 5 | self.args = args 6 | def __iter__(self): 7 | return itertools.chain(*self.args) 8 | 9 | class cycle(object): 10 | def __init__(self, *args): 11 | self.args = args 12 | def __iter__(self): 13 | return itertools.cycle(*self.args) 14 | -------------------------------------------------------------------------------- /ECDSA/Fake-ECDSA.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Fake-ECDSA.cpp 3 | * 4 | */ 5 | 6 | #include "ECDSA/P256Element.h" 7 | #include "Tools/mkpath.h" 8 | #include "GC/TinierSecret.h" 9 | 10 | #include "Protocols/fake-stuff.hpp" 11 | #include "Protocols/Share.hpp" 12 | #include "Processor/Data_Files.hpp" 13 | #include "Math/gfp.hpp" 14 | 15 | int main() 16 | { 17 | P256Element::init(); 18 | P256Element::Scalar key; 19 | string prefix = PREP_DIR "ECDSA/"; 20 | mkdir_p(prefix.c_str()); 21 | write_online_setup(prefix, P256Element::Scalar::pr()); 22 | generate_mac_keys>(key, 2, prefix); 23 | make_mult_triples>(key, 2, 1000, false, prefix); 24 | make_inverse>(key, 2, 1000, false, prefix); 25 | P256Element::finish(); 26 | } 27 | -------------------------------------------------------------------------------- /ECDSA/mal-rep-ecdsa-party.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * mal-rep-ecdsa-party.cpp 3 | * 4 | */ 5 | 6 | #include "Protocols/MaliciousRep3Share.h" 7 | 8 | #include "hm-ecdsa-party.hpp" 9 | 10 | int main(int argc, const char** argv) 11 | { 12 | run(argc, argv); 13 | } 14 | -------------------------------------------------------------------------------- /ECDSA/mal-shamir-ecdsa-party.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * mal-shamir-ecdsa-party.cpp 3 | * 4 | */ 5 | 6 | #include "Protocols/MaliciousShamirShare.h" 7 | 8 | #include "Protocols/Shamir.hpp" 9 | #include "Protocols/ShamirInput.hpp" 10 | 11 | #include "hm-ecdsa-party.hpp" 12 | 13 | int main(int argc, const char** argv) 14 | { 15 | ez::ezOptionParser opt; 16 | ShamirOptions(opt, argc, argv); 17 | run(argc, argv); 18 | } 19 | -------------------------------------------------------------------------------- /ECDSA/mascot-ecdsa-party.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * fake-spdz-ecdsa-party.cpp 3 | * 4 | */ 5 | 6 | #define NO_MIXED_CIRCUITS 7 | 8 | #define NO_SECURITY_CHECK 9 | 10 | #include "GC/TinierSecret.h" 11 | #include "GC/TinyMC.h" 12 | #include "GC/VectorInput.h" 13 | 14 | #include "Protocols/Share.hpp" 15 | #include "Protocols/MAC_Check.hpp" 16 | #include "GC/Secret.hpp" 17 | #include "GC/TinierSharePrep.hpp" 18 | #include "ot-ecdsa-party.hpp" 19 | 20 | #include 21 | 22 | int main(int argc, const char** argv) 23 | { 24 | run(argc, argv); 25 | } 26 | -------------------------------------------------------------------------------- /ECDSA/rep-ecdsa-party.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * mal-rep-ecdsa-party.cpp 3 | * 4 | */ 5 | 6 | #include "Protocols/Rep3Share.h" 7 | 8 | #include "hm-ecdsa-party.hpp" 9 | 10 | int main(int argc, const char** argv) 11 | { 12 | run(argc, argv); 13 | } 14 | -------------------------------------------------------------------------------- /ECDSA/semi-ecdsa-party.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * fake-spdz-ecdsa-party.cpp 3 | * 4 | */ 5 | 6 | #include "GC/SemiSecret.h" 7 | #include "GC/SemiPrep.h" 8 | 9 | #include "Protocols/SemiMC.hpp" 10 | #include "Protocols/SemiPrep.hpp" 11 | #include "Protocols/SemiInput.hpp" 12 | #include "Protocols/MAC_Check_Base.hpp" 13 | #include "GC/SemiSecret.hpp" 14 | #include "ot-ecdsa-party.hpp" 15 | 16 | #include 17 | 18 | int main(int argc, const char** argv) 19 | { 20 | run(argc, argv); 21 | } 22 | -------------------------------------------------------------------------------- /ECDSA/shamir-ecdsa-party.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * mal-shamir-ecdsa-party.cpp 3 | * 4 | */ 5 | 6 | #include "Protocols/ShamirShare.h" 7 | 8 | #include "Protocols/Shamir.hpp" 9 | #include "Protocols/ShamirInput.hpp" 10 | 11 | #include "hm-ecdsa-party.hpp" 12 | 13 | int main(int argc, const char** argv) 14 | { 15 | ez::ezOptionParser opt; 16 | ShamirOptions(opt, argc, argv); 17 | run(argc, argv); 18 | } 19 | -------------------------------------------------------------------------------- /FHE/AddableVector.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * AddableVector.cpp 3 | * 4 | */ 5 | 6 | #include "AddableVector.h" 7 | #include "Rq_Element.h" 8 | #include "FHE_Keys.h" 9 | #include "P2Data.h" 10 | 11 | template 12 | AddableVector AddableVector::mul_by_X_i(int j, 13 | const FHE_PK& pk) const 14 | { 15 | int phi_m = this->size(); 16 | assert(phi_m == pk.get_params().phi_m()); 17 | AddableVector res(phi_m); 18 | for (int i = 0; i < phi_m; i++) 19 | { 20 | int k = j + i, s = 1; 21 | while (k >= phi_m) 22 | { 23 | k -= phi_m; 24 | s = -s; 25 | } 26 | if (s == 1) 27 | { 28 | res[k] = (*this)[i]; 29 | } 30 | else 31 | { 32 | res[k] = -(*this)[i]; 33 | } 34 | } 35 | return res; 36 | } 37 | -------------------------------------------------------------------------------- /FHE/Random_Coins.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Random_Coins.h" 3 | #include "FHE_Keys.h" 4 | 5 | Int_Random_Coins::Int_Random_Coins(const FHE_PK& pk) : 6 | Int_Random_Coins(pk.get_params()) 7 | { 8 | } 9 | 10 | Random_Coins::Random_Coins(const FHE_PK& pk) : 11 | Random_Coins(pk.get_params()) 12 | { 13 | } 14 | 15 | void add(Random_Coins& ans,const Random_Coins& x,const Random_Coins& y) 16 | { 17 | if (x.params!=y.params) { throw params_mismatch(); } 18 | if (ans.params!=y.params) { throw params_mismatch(); } 19 | 20 | add(ans.uu,x.uu,y.uu); 21 | add(ans.vv,x.vv,y.vv); 22 | add(ans.ww,x.ww,y.ww); 23 | } 24 | 25 | -------------------------------------------------------------------------------- /FHE/Ring.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Ring.h" 3 | #include "Tools/Exceptions.h" 4 | 5 | void Ring::pack(octetStream& o) const 6 | { 7 | o.store(mm); 8 | if (((mm - 1) & mm) != 0) 9 | { 10 | o.store(phim); 11 | o.store(pi); 12 | o.store(pi_inv); 13 | o.store(poly); 14 | } 15 | } 16 | 17 | void Ring::unpack(octetStream& o) 18 | { 19 | o.get(mm); 20 | if (((mm - 1) & mm) != 0) 21 | { 22 | o.get(phim); 23 | o.get(pi); 24 | o.get(pi_inv); 25 | o.get(poly); 26 | } 27 | else if (mm != 0) 28 | init(*this, mm); 29 | } 30 | 31 | bool Ring::operator !=(const Ring& other) const 32 | { 33 | if (mm != other.mm or phim != other.phim or pi != other.pi 34 | or pi_inv != other.pi_inv or poly != other.poly) 35 | return true; 36 | else 37 | return false; 38 | } 39 | -------------------------------------------------------------------------------- /FHE/tools.h: -------------------------------------------------------------------------------- 1 | /* 2 | * tools.h 3 | * 4 | */ 5 | 6 | #ifndef FHE_TOOLS_H_ 7 | #define FHE_TOOLS_H_ 8 | 9 | #include 10 | using namespace std; 11 | 12 | template 13 | T sum(const vector& summands) 14 | { 15 | T res = summands[0]; 16 | for (size_t i = 1; i < summands.size(); i++) 17 | res += summands[i]; 18 | return res; 19 | } 20 | 21 | #endif /* FHE_TOOLS_H_ */ 22 | -------------------------------------------------------------------------------- /FHEOffline/CutAndChooseMachine.h: -------------------------------------------------------------------------------- 1 | /* 2 | * CutAndChooseMachine.h 3 | * 4 | */ 5 | 6 | #ifndef FHEOFFLINE_CUTANDCHOOSEMACHINE_H_ 7 | #define FHEOFFLINE_CUTANDCHOOSEMACHINE_H_ 8 | 9 | #include "FHEOffline/SimpleMachine.h" 10 | 11 | class CutAndChooseMachine : public MultiplicativeMachine 12 | { 13 | bool covert; 14 | 15 | template 16 | GeneratorBase* new_generator(int i); 17 | 18 | public: 19 | CutAndChooseMachine(int argc, const char** argv); 20 | 21 | int get_covert() const { return sec; } 22 | }; 23 | 24 | #endif /* FHEOFFLINE_CUTANDCHOOSEMACHINE_H_ */ 25 | -------------------------------------------------------------------------------- /FHEOffline/SimpleDistDecrypt.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SimpleDistDecrypt.h 3 | * 4 | */ 5 | 6 | #ifndef FHEOFFLINE_SIMPLEDISTDECRYPT_H_ 7 | #define FHEOFFLINE_SIMPLEDISTDECRYPT_H_ 8 | 9 | #include "FHEOffline/DistDecrypt.h" 10 | #include "FHEOffline/DataSetup.h" 11 | 12 | template 13 | class SimpleDistDecrypt : public DistDecrypt 14 | { 15 | public: 16 | SimpleDistDecrypt(const Player& P, const PartSetup& setup) : 17 | DistDecrypt(P, setup.sk, setup.pk, setup.FieldD) {} 18 | 19 | void intermediate_step(); 20 | void reshare(Plaintext& m, 21 | const Ciphertext& cm, 22 | EncCommitBase& EC); 23 | Plaintext_ reshare(const Ciphertext& cm); 24 | }; 25 | 26 | #endif /* FHEOFFLINE_SIMPLEDISTDECRYPT_H_ */ 27 | -------------------------------------------------------------------------------- /FHEOffline/TemiSetup.h: -------------------------------------------------------------------------------- 1 | /* 2 | * TemiSetup.h 3 | * 4 | */ 5 | 6 | #ifndef FHEOFFLINE_TEMISETUP_H_ 7 | #define FHEOFFLINE_TEMISETUP_H_ 8 | 9 | #include "FHE/FHE_Keys.h" 10 | #include "FHEOffline/SimpleMachine.h" 11 | 12 | template 13 | class TemiSetup : public PartSetup 14 | { 15 | public: 16 | static string name() 17 | { 18 | return "TemiParams"; 19 | } 20 | 21 | static string protocol_name(int) 22 | { 23 | return "Temi"; 24 | } 25 | 26 | TemiSetup(); 27 | 28 | void secure_init(Player& P, int plaintext_length); 29 | void generate(Player& P, MachineBase&, int plaintext_length, int sec); 30 | 31 | void key_and_mac_generation(Player& P, MachineBase&, int, true_type); 32 | }; 33 | 34 | #endif /* FHEOFFLINE_TEMISETUP_H_ */ 35 | -------------------------------------------------------------------------------- /FHEOffline/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * config.h 3 | * 4 | */ 5 | 6 | #ifndef FHEOFFLINE_CONFIG_H_ 7 | #define FHEOFFLINE_CONFIG_H_ 8 | 9 | #ifndef LESS_MEM_MORE_ALLOC 10 | #define LESS_ALLOC_MORE_MEM 11 | #endif 12 | 13 | #ifndef COMP_SEC 14 | #define COMP_SEC 128 15 | #endif 16 | 17 | #endif /* FHEOFFLINE_CONFIG_H_ */ 18 | -------------------------------------------------------------------------------- /GC/AtlasSecret.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * AtlasSecret.cpp 3 | * 4 | */ 5 | 6 | #include "AtlasSecret.h" 7 | #include "TinyMC.h" 8 | 9 | #include "Protocols/Shamir.hpp" 10 | #include "Protocols/ShamirMC.hpp" 11 | #include "Protocols/MAC_Check_Base.hpp" 12 | #include "Secret.hpp" 13 | 14 | namespace GC 15 | { 16 | 17 | typename AtlasSecret::MC* AtlasSecret::new_mc(typename AtlasSecret::mac_key_type mac_key) 18 | { 19 | return new MC(mac_key); 20 | } 21 | 22 | AtlasShare::AtlasShare(const AtlasSecret& other) : 23 | AtlasShare(other.get_bit(0)) 24 | { 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /GC/CcdPrep.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * CcdPrep.hpp 3 | * 4 | */ 5 | 6 | #ifndef GC_CCDPREP_HPP_ 7 | #define GC_CCDPREP_HPP_ 8 | 9 | #include "CcdPrep.h" 10 | 11 | #include "Processor/Processor.hpp" 12 | 13 | namespace GC 14 | { 15 | 16 | template 17 | CcdPrep::~CcdPrep() 18 | { 19 | if (part_proc) 20 | delete part_proc; 21 | } 22 | 23 | template 24 | void CcdPrep::set_protocol(typename T::Protocol& protocol) 25 | { 26 | auto& thread = ShareThread::s(); 27 | assert(thread.MC); 28 | 29 | if (part_proc) 30 | { 31 | assert(&part_proc->MC == &thread.MC->get_part_MC()); 32 | assert(&part_proc->P == &protocol.get_part().P); 33 | return; 34 | } 35 | 36 | part_proc = new SubProcessor( 37 | thread.MC->get_part_MC(), part_prep, protocol.get_part().P); 38 | } 39 | 40 | } 41 | 42 | #endif /* GC_CCDPREP_HPP_ */ 43 | -------------------------------------------------------------------------------- /GC/Clear.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Clear.h 3 | * 4 | */ 5 | 6 | #ifndef GC_CLEAR_H_ 7 | #define GC_CLEAR_H_ 8 | 9 | #include "Math/Integer.h" 10 | 11 | namespace GC 12 | { 13 | 14 | class Clear : public Integer 15 | { 16 | public: 17 | static string type_string() { return "clear"; } 18 | 19 | Clear() : Integer() {} 20 | Clear(long a) : Integer(a) {} 21 | Clear(const IntBase& x) { IntBase::operator=(x); } 22 | 23 | void xor_(const Clear& x, const Clear& y) { a = x.a ^ y.a; } 24 | void xor_(const Clear& x, long y) { a = x.a ^ y; } 25 | }; 26 | 27 | } /* namespace GC */ 28 | 29 | #endif /* GC_CLEAR_H_ */ 30 | -------------------------------------------------------------------------------- /GC/Instruction_inline.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Instruction_inline.h 3 | * 4 | */ 5 | 6 | #ifndef GC_INSTRUCTION_INLINE_H_ 7 | #define GC_INSTRUCTION_INLINE_H_ 8 | 9 | #include "BMR/config.h" 10 | 11 | #ifdef MAX_INLINE 12 | #define MAYBE_INLINE inline 13 | #else 14 | #define MAYBE_INLINE 15 | #endif 16 | 17 | namespace GC { 18 | 19 | #include "instructions.h" 20 | 21 | template 22 | inline bool fallback_code(const Instruction& instruction, Processor& processor) 23 | { 24 | (void)processor; 25 | cout << "Undefined instruction " << showbase << hex 26 | << instruction.get_opcode() << endl << dec; 27 | return true; 28 | } 29 | 30 | } /* namespace GC */ 31 | 32 | #endif /* GC_INSTRUCTION_INLINE_H_ */ 33 | -------------------------------------------------------------------------------- /GC/PersonalPrep.h: -------------------------------------------------------------------------------- 1 | /* 2 | * PersonalPrep.h 3 | * 4 | */ 5 | 6 | #ifndef GC_PERSONALPREP_H_ 7 | #define GC_PERSONALPREP_H_ 8 | 9 | #include "Protocols/ReplicatedPrep.h" 10 | #include "ShareThread.h" 11 | 12 | namespace GC 13 | { 14 | 15 | template 16 | class PersonalPrep : public BufferPrep 17 | { 18 | protected: 19 | static const int SECURE = -1; 20 | 21 | const int input_player; 22 | 23 | void buffer_personal_triples(); 24 | 25 | public: 26 | PersonalPrep(DataPositions& usage, int input_player); 27 | 28 | void buffer_personal_triples(size_t n, ThreadQueues* queues = 0); 29 | void buffer_personal_triples(vector>& triples, size_t begin, 30 | size_t end); 31 | }; 32 | 33 | } 34 | 35 | #endif /* GC_PERSONALPREP_H_ */ 36 | -------------------------------------------------------------------------------- /GC/PostSacriSecret.h: -------------------------------------------------------------------------------- 1 | /* 2 | * AbfllnowShare.h 3 | * 4 | */ 5 | 6 | #ifndef GC_POSTSACRISECRET_H_ 7 | #define GC_POSTSACRISECRET_H_ 8 | 9 | #include "MaliciousRepSecret.h" 10 | 11 | namespace GC 12 | { 13 | 14 | class PostSacriBin; 15 | 16 | class PostSacriSecret : public MalRepSecretBase 17 | { 18 | typedef PostSacriSecret This; 19 | typedef MalRepSecretBase super; 20 | 21 | public: 22 | typedef PostSacriBin Protocol; 23 | 24 | PostSacriSecret() 25 | { 26 | } 27 | 28 | template 29 | PostSacriSecret(const T& other) : 30 | super(other) 31 | { 32 | } 33 | }; 34 | 35 | } 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /GC/Rep4Secret.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Rep4Secret.cpp 3 | * 4 | */ 5 | 6 | #ifndef GC_REP4SECRET_CPP_ 7 | #define GC_REP4SECRET_CPP_ 8 | 9 | #include "Rep4Secret.h" 10 | 11 | #include "ShareSecret.hpp" 12 | #include "ShareThread.hpp" 13 | #include "Protocols/Rep4MC.hpp" 14 | 15 | namespace GC 16 | { 17 | 18 | void Rep4Secret::load_clear(int n, const Integer& x) 19 | { 20 | this->check_length(n, x); 21 | *this = constant(x, ShareThread::s().P->my_num()); 22 | } 23 | 24 | } 25 | 26 | #endif /* GC_REP4SECRET_CPP_ */ 27 | -------------------------------------------------------------------------------- /GC/RuntimeBranching.h: -------------------------------------------------------------------------------- 1 | /* 2 | * RuntimeBranching.h 3 | * 4 | */ 5 | 6 | #ifndef GC_RUNTIMEBRANCHING_H_ 7 | #define GC_RUNTIMEBRANCHING_H_ 8 | 9 | namespace GC 10 | { 11 | 12 | class RuntimeBranching 13 | { 14 | bool tainted; 15 | 16 | public: 17 | RuntimeBranching() : tainted(true) 18 | { 19 | } 20 | 21 | void untaint() 22 | { 23 | bool was_tainted = tainted; 24 | tainted = false; 25 | if (was_tainted) 26 | throw needs_cleaning(); 27 | else 28 | taint(); 29 | } 30 | void taint() 31 | { 32 | tainted = true; 33 | } 34 | 35 | bool is_tainted() 36 | { 37 | return tainted; 38 | } 39 | }; 40 | 41 | } /* namespace GC */ 42 | 43 | #endif /* GC_RUNTIMEBRANCHING_H_ */ 44 | -------------------------------------------------------------------------------- /GC/Semi.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Semi.h 3 | * 4 | */ 5 | 6 | #ifndef GC_SEMI_H_ 7 | #define GC_SEMI_H_ 8 | 9 | #include "Protocols/Beaver.h" 10 | #include "SemiSecret.h" 11 | 12 | namespace GC 13 | { 14 | 15 | class Semi : public Beaver 16 | { 17 | typedef Beaver super; 18 | 19 | public: 20 | Semi(Player& P) : 21 | super(P) 22 | { 23 | } 24 | 25 | void prepare_mult(const SemiSecret& x, const SemiSecret& y, int n, 26 | bool repeat); 27 | }; 28 | 29 | } /* namespace GC */ 30 | 31 | #endif /* GC_SEMI_H_ */ 32 | -------------------------------------------------------------------------------- /GC/SemiHonestRepPrep.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ReplicatedPrep.h 3 | * 4 | */ 5 | 6 | #ifndef GC_SEMIHONESTREPPREP_H_ 7 | #define GC_SEMIHONESTREPPREP_H_ 8 | 9 | #include "RepPrep.h" 10 | #include "ShareSecret.h" 11 | 12 | namespace GC 13 | { 14 | 15 | class SemiHonestRepPrep : public RepPrep 16 | { 17 | public: 18 | SemiHonestRepPrep(DataPositions& usage, bool = false) : 19 | RepPrep(usage) 20 | { 21 | } 22 | 23 | void buffer_triples() { throw not_implemented(); } 24 | }; 25 | 26 | } /* namespace GC */ 27 | 28 | #endif /* GC_SEMIHONESTREPPREP_H_ */ 29 | -------------------------------------------------------------------------------- /GC/VectorProtocol.h: -------------------------------------------------------------------------------- 1 | /* 2 | * VectorProtocol.h 3 | * 4 | */ 5 | 6 | #ifndef GC_VECTORPROTOCOL_H_ 7 | #define GC_VECTORPROTOCOL_H_ 8 | 9 | #include "Protocols/Replicated.h" 10 | 11 | namespace GC 12 | { 13 | 14 | template 15 | class VectorProtocol : public ProtocolBase 16 | { 17 | typename T::part_type::Protocol part_protocol; 18 | 19 | public: 20 | Player& P; 21 | 22 | VectorProtocol(Player& P); 23 | 24 | void init(Preprocessing& prep, typename T::MAC_Check& MC); 25 | 26 | void init_mul(); 27 | void prepare_mul(const T& x, const T& y, int n = -1); 28 | void exchange(); 29 | void finalize_mult(T& res, int n = -1); 30 | T finalize_mul(int n = -1); 31 | 32 | typename T::part_type::Protocol& get_part() 33 | { 34 | return part_protocol; 35 | } 36 | }; 37 | 38 | } /* namespace GC */ 39 | 40 | #endif /* GC_VECTORPROTOCOL_H_ */ 41 | -------------------------------------------------------------------------------- /GC/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * config.h 3 | * 4 | */ 5 | 6 | #ifndef GC_CONFIG_H_ 7 | #define GC_CONFIG_H_ 8 | 9 | //#define CHECK_SIZE 10 | 11 | //#define COUNT_INSTRUCTIONS 12 | 13 | //#define CHECK_SIZE 14 | 15 | #endif /* GC_CONFIG_H_ */ 16 | -------------------------------------------------------------------------------- /GC/square64.h: -------------------------------------------------------------------------------- 1 | /* 2 | * square64.h 3 | * 4 | */ 5 | 6 | #ifndef GC_SQUARE64_H_ 7 | #define GC_SQUARE64_H_ 8 | 9 | #include 10 | #include 11 | #include "Tools/int.h" 12 | #include "Tools/intrinsics.h" 13 | 14 | union square64 15 | { 16 | __m256i quadrows[16]; 17 | __m128i doublerows[32]; 18 | int64_t rows[64]; 19 | int32_t halfrows[128][2]; 20 | octet bytes[64][8]; 21 | 22 | square64() 23 | { 24 | memset(bytes, 0, sizeof(bytes)); 25 | } 26 | 27 | bool get_bit(int x, int y) 28 | { return (bytes[x][y/8] >> (y % 8)) & 1; } 29 | 30 | void transpose(int n_rows, int n_cols); 31 | 32 | bool operator!=(const square64& other); 33 | 34 | void print(); 35 | }; 36 | 37 | #endif /* GC_SQUARE64_H_ */ 38 | -------------------------------------------------------------------------------- /Garnet.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FudanMPL/Garnet/89af954fd61628990a0e6faa9a29d9d5e4b17667/Garnet.jpeg -------------------------------------------------------------------------------- /Garnet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FudanMPL/Garnet/89af954fd61628990a0e6faa9a29d9d5e4b17667/Garnet.png -------------------------------------------------------------------------------- /GarnetUI/Dockerfile: -------------------------------------------------------------------------------- 1 | # 目前来说 封装好的镜像名为 garnet3.14 v1.0 2 | # 目前这一个版本只编译了两方的虚拟机 3 | # 拉区镜像 4 | FROM zengwen0318/garnet3.14:v1.0 5 | 6 | # 设置环境变量 7 | ENV HostName="garnet173" 8 | ENV HostAddress="10.176.34.173" 9 | 10 | 11 | # 复制启动脚本到容器中 12 | COPY start.sh /usr/local/bin/start.sh 13 | 14 | # 添加可执行权限 15 | RUN chmod +x /usr/local/bin/start.sh 16 | 17 | # 指定启动命令 18 | CMD ["/usr/local/bin/start.sh"] 19 | -------------------------------------------------------------------------------- /GarnetUI/Vue3-garnet-ui/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | pnpm-debug.log* 8 | lerna-debug.log* 9 | 10 | node_modules 11 | .DS_Store 12 | dist 13 | dist-ssr 14 | coverage 15 | *.local 16 | 17 | /cypress/videos/ 18 | /cypress/screenshots/ 19 | 20 | # Editor directories and files 21 | .vscode/* 22 | !.vscode/extensions.json 23 | .idea 24 | *.suo 25 | *.ntvs* 26 | *.njsproj 27 | *.sln 28 | *.sw? 29 | -------------------------------------------------------------------------------- /GarnetUI/Vue3-garnet-ui/.prettierrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/prettierrc", 3 | "semi": false, 4 | "tabWidth": 2, 5 | "singleQuote": true, 6 | "printWidth": 100, 7 | "trailingComma": "none" 8 | } -------------------------------------------------------------------------------- /GarnetUI/Vue3-garnet-ui/.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "Vue.volar", 4 | "Vue.vscode-typescript-vue-plugin", 5 | "dbaeumer.vscode-eslint", 6 | "esbenp.prettier-vscode" 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /GarnetUI/Vue3-garnet-ui/README.md: -------------------------------------------------------------------------------- 1 | # Vue3-garent-ui 2 | 3 | This template should help get you started developing with Vue 3 in Vite. 4 | 5 | ## Recommended IDE Setup 6 | 7 | [VSCode](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur) + [TypeScript Vue Plugin (Volar)](https://marketplace.visualstudio.com/items?itemName=Vue.vscode-typescript-vue-plugin). 8 | 9 | ## Customize configuration 10 | 11 | See [Vite Configuration Reference](https://vitejs.dev/config/). 12 | 13 | ## Project Setup 14 | 15 | ```sh 16 | pnpm install 17 | ``` 18 | 19 | ### Compile and Hot-Reload for Development 20 | 21 | ```sh 22 | pnpm dev 23 | ``` 24 | 25 | ### Compile and Minify for Production 26 | 27 | ```sh 28 | pnpm build 29 | ``` 30 | 31 | ### Lint with [ESLint](https://eslint.org/) 32 | 33 | ```sh 34 | pnpm lint 35 | ``` 36 | -------------------------------------------------------------------------------- /GarnetUI/Vue3-garnet-ui/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Garnet 8 | 9 | 10 |
11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /GarnetUI/Vue3-garnet-ui/npm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FudanMPL/Garnet/89af954fd61628990a0e6faa9a29d9d5e4b17667/GarnetUI/Vue3-garnet-ui/npm -------------------------------------------------------------------------------- /GarnetUI/Vue3-garnet-ui/public/garnet.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FudanMPL/Garnet/89af954fd61628990a0e6faa9a29d9d5e4b17667/GarnetUI/Vue3-garnet-ui/public/garnet.ico -------------------------------------------------------------------------------- /GarnetUI/Vue3-garnet-ui/src/App.vue: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /GarnetUI/Vue3-garnet-ui/src/api/TaskDaraItem.ts: -------------------------------------------------------------------------------- 1 | // types.ts 2 | export interface TaskDataItem { 3 | index: string; 4 | data: string; 5 | task: string; 6 | } 7 | -------------------------------------------------------------------------------- /GarnetUI/Vue3-garnet-ui/src/api/serverSet.js: -------------------------------------------------------------------------------- 1 | import request from '@/utils/request' 2 | //连接 3 | export const userLinkServer = ({ ip, port }) => 4 | request.post('/link/metadata/send/', { 5 | ip, 6 | port 7 | }) 8 | -------------------------------------------------------------------------------- /GarnetUI/Vue3-garnet-ui/src/assets/Garnet.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FudanMPL/Garnet/89af954fd61628990a0e6faa9a29d9d5e4b17667/GarnetUI/Vue3-garnet-ui/src/assets/Garnet.jpeg -------------------------------------------------------------------------------- /GarnetUI/Vue3-garnet-ui/src/assets/login_bg.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FudanMPL/Garnet/89af954fd61628990a0e6faa9a29d9d5e4b17667/GarnetUI/Vue3-garnet-ui/src/assets/login_bg.jpg -------------------------------------------------------------------------------- /GarnetUI/Vue3-garnet-ui/src/main.js: -------------------------------------------------------------------------------- 1 | import { createApp } from 'vue' 2 | 3 | import App from './App.vue' 4 | import router from './router' 5 | import pinia from '@/stores/index' 6 | // import VueMeta from 'vue-meta' 7 | 8 | const app = createApp(App) 9 | 10 | app.use(pinia) 11 | app.use(router) 12 | // app.use(VueMeta) 13 | 14 | app.mount('#app') 15 | -------------------------------------------------------------------------------- /GarnetUI/Vue3-garnet-ui/src/stores/index.js: -------------------------------------------------------------------------------- 1 | import { createPinia } from 'pinia' 2 | import persist from 'pinia-plugin-persistedstate' 3 | 4 | const pinia = createPinia().use(persist) 5 | pinia.use(persist) 6 | 7 | export default pinia 8 | 9 | import { useUserStore } from './modules/user' 10 | export { useUserStore } 11 | -------------------------------------------------------------------------------- /GarnetUI/Vue3-garnet-ui/src/stores/modules/counter.js: -------------------------------------------------------------------------------- 1 | import { ref, computed } from 'vue' 2 | import { defineStore } from 'pinia' 3 | 4 | export const useCounterStore = defineStore('counter', () => { 5 | const count = ref(0) 6 | const doubleCount = computed(() => count.value * 2) 7 | function increment() { 8 | count.value++ 9 | } 10 | 11 | return { count, doubleCount, increment } 12 | }) 13 | -------------------------------------------------------------------------------- /GarnetUI/Vue3-garnet-ui/vite.config.js: -------------------------------------------------------------------------------- 1 | import { fileURLToPath, URL } from 'node:url' 2 | 3 | import { defineConfig } from 'vite' 4 | import vue from '@vitejs/plugin-vue' 5 | import AutoImport from 'unplugin-auto-import/vite' 6 | import Components from 'unplugin-vue-components/vite' 7 | import { ElementPlusResolver } from 'unplugin-vue-components/resolvers' 8 | 9 | export default defineConfig({ 10 | // server: { 11 | // host: '10.176.34.171', 12 | // port: 8889, 13 | // open: true 14 | // }, 15 | plugins: [ 16 | vue(), 17 | AutoImport({ 18 | resolvers: [ElementPlusResolver()] 19 | }), 20 | Components({ 21 | resolvers: [ElementPlusResolver()] 22 | }) 23 | ], 24 | resolve: { 25 | alias: { 26 | '@': fileURLToPath(new URL('./src', import.meta.url)) 27 | } 28 | } 29 | }) 30 | -------------------------------------------------------------------------------- /GarnetUI/env.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 从环境变量中读取四个变量 4 | HostName=${HostName:-"GarnetUI"} 5 | HostAddress=${HostAddress:-"localhost"} 6 | HostPort=${HostPort:-8000} 7 | GarnetPath=${GarnetPath:-"/Garnet"} 8 | 9 | # 修改ui/ui/settings.py文件 10 | sed -i "s|GARNETPATH = .*|GARNETPATH = \"$GarnetPath\"|" ui/ui/settings.py 11 | sed -i "s|NAME = .*|NAME = \"$HostName\"|" ui/ui/settings.py 12 | sed -i "s|IPADDRESS = .*|IPADDRESS = \"$HostAddress\"|" ui/ui/settings.py 13 | sed -i "s|PORT = .*|PORT = $HostPort|" ui/ui/settings.py 14 | 15 | # 修改Vue3-garnet-ui/src/utils/request.js文件 16 | sed -i "6s|const baseURL = .*|const baseURL = 'http://$HostAddress:$HostPort/api/'|" Vue3-garnet-ui/src/utils/request.js 17 | 18 | -------------------------------------------------------------------------------- /GarnetUI/start.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 激活虚拟环境 4 | source /root/miniconda3/bin/activate py310 5 | # 进入目录并执行命令 6 | cd Garnet/GarnetUI 7 | chmod +x env.sh 8 | bash env.sh 9 | cd Vue3-garnet-ui 10 | pnpm dev --host 0.0.0.0 --port 9000 & 11 | cd ../ 12 | python3 ui/manage.py runserver 0.0.0.0:8000 & 13 | python3 ui/manage.py qcluster & 14 | # 保持容器运行 15 | while true; do 16 | sleep 10 17 | done 18 | -------------------------------------------------------------------------------- /GarnetUI/ui/Model/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FudanMPL/Garnet/89af954fd61628990a0e6faa9a29d9d5e4b17667/GarnetUI/ui/Model/__init__.py -------------------------------------------------------------------------------- /GarnetUI/ui/Model/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | # Register your models here. 4 | -------------------------------------------------------------------------------- /GarnetUI/ui/Model/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class ModelConfig(AppConfig): 5 | default_auto_field = 'django.db.models.BigAutoField' 6 | name = 'Model' 7 | -------------------------------------------------------------------------------- /GarnetUI/ui/Model/views.py: -------------------------------------------------------------------------------- 1 | from django.shortcuts import render 2 | 3 | # Create your views here. 4 | -------------------------------------------------------------------------------- /GarnetUI/ui/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """Django's command-line utility for administrative tasks.""" 3 | 4 | import os 5 | import sys 6 | 7 | 8 | def main(): 9 | """Run administrative tasks.""" 10 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ui.settings") 11 | try: 12 | from django.core.management import execute_from_command_line 13 | except ImportError as exc: 14 | raise ImportError( 15 | "Couldn't import Django. Are you sure it's installed and " 16 | "available on your PYTHONPATH environment variable? Did you " 17 | "forget to activate a virtual environment?" 18 | ) from exc 19 | execute_from_command_line(sys.argv) 20 | 21 | 22 | if __name__ == "__main__": 23 | main() 24 | -------------------------------------------------------------------------------- /GarnetUI/ui/scripts/rehash.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ssl_dir=$1 4 | garnet=$2 5 | 6 | 7 | rm $garnet/Player-Data/*.pem 8 | rm $garnet/Player-Data/*.key 9 | rm $garnet/Player-Data/server.name 10 | part=$3 11 | local_name=$4 12 | cp $ssl_dir/$local_name.key $garnet/Player-Data/P$part.key 13 | paramCount=$# 14 | 15 | for (( i = 5; i <= paramCount; i+=2 )); do 16 | p=${!i} 17 | ii=$(($i+1)) 18 | n=${!ii} 19 | cp $ssl_dir/$n.pem $garnet/Player-Data/P$p.pem 20 | echo $n >> $garnet/Player-Data/server.name 21 | done 22 | c_rehash $garnet/Player-Data -------------------------------------------------------------------------------- /GarnetUI/ui/scripts/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | source .venv/bin/activate 4 | cd $1 5 | echo ${@:2} 6 | ${@:2} -------------------------------------------------------------------------------- /GarnetUI/ui/scripts/ssl.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # brew-installed OpenSSL on MacOS 4 | PATH=/usr/local/opt/openssl/bin:$PATH 5 | 6 | name=${1:-"local"} 7 | ssl_dir=${2:-"uploads/ssl"} 8 | 9 | test -e $ssl_dir || mkdir $ssl_dir 10 | 11 | openssl req -newkey rsa -nodes -x509 -out $ssl_dir/$name.pem -keyout $ssl_dir/$name.key -subj "/CN=$name" > /dev/null 12 | -------------------------------------------------------------------------------- /GarnetUI/ui/ui/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FudanMPL/Garnet/89af954fd61628990a0e6faa9a29d9d5e4b17667/GarnetUI/ui/ui/__init__.py -------------------------------------------------------------------------------- /GarnetUI/ui/ui/asgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | ASGI config for ui project. 3 | 4 | It exposes the ASGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/4.2/howto/deployment/asgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.asgi import get_asgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ui.settings') 15 | 16 | application = get_asgi_application() 17 | -------------------------------------------------------------------------------- /GarnetUI/ui/ui/pagination.py: -------------------------------------------------------------------------------- 1 | from rest_framework.pagination import PageNumberPagination 2 | 3 | 4 | class PagePagination(PageNumberPagination): 5 | page_size = 2 # 每页显示多少条 6 | page_size_query_param = "size" # URL中每页显示条数的参数 7 | page_query_param = "page" # URL中页码的参数 8 | max_page_size = None # 最大页码数限制 9 | -------------------------------------------------------------------------------- /GarnetUI/ui/ui/views/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FudanMPL/Garnet/89af954fd61628990a0e6faa9a29d9d5e4b17667/GarnetUI/ui/ui/views/__init__.py -------------------------------------------------------------------------------- /GarnetUI/ui/ui/views/protocol.py: -------------------------------------------------------------------------------- 1 | from Model.models import Protocol 2 | from Model.serializers import ProtocolModelSerializer 3 | from rest_framework.viewsets import ModelViewSet 4 | 5 | from ..authentication import UserAuthentication 6 | from ..pagination import PagePagination 7 | 8 | 9 | class ProtocolSets(ModelViewSet): 10 | queryset = Protocol.objects.all() 11 | serializer_class = ProtocolModelSerializer 12 | authentication_classes = [UserAuthentication] 13 | pagination_class = PagePagination 14 | -------------------------------------------------------------------------------- /GarnetUI/ui/ui/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for ui project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/4.2/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ui.settings') 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /Input/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FudanMPL/Garnet/89af954fd61628990a0e6faa9a29d9d5e4b17667/Input/.gitkeep -------------------------------------------------------------------------------- /MPLTS/Scripts/test2.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import matplotlib.pyplot as plt 3 | import time 4 | import sys 5 | 6 | data = np.loadtxt('ts.data') 7 | 8 | labels = ['round_online', 'comm_bits_online', 'round_total', 'comm_bits_total', 'MPTS-cost'] 9 | cols = {} 10 | 11 | for i in range(0,5): 12 | cols[labels[i]] = data[:,i] 13 | 14 | for label in labels: 15 | print(label, min(cols[label]) / cols[label][0]) -------------------------------------------------------------------------------- /MPLTS/Scripts/test3.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import matplotlib.pyplot as plt 3 | 4 | data_base = np.loadtxt('MPLTS/Scripts/base.data') 5 | data_opt = np.loadtxt('MPLTS/Scripts/opt.data') 6 | 7 | cost_base = data_base[:,4] 8 | cost_opt = data_opt[:,4] 9 | 10 | bestcost_base = [min(cost_base[:i+1]) for i in range(len(cost_base))] 11 | bestcost_opt = [min(cost_opt[:i+1]) for i in range(len(cost_opt))] 12 | 13 | plt.figure(figsize=(10, 6)) 14 | plt.plot(bestcost_base, label='base') 15 | plt.plot(bestcost_opt, label='opt') 16 | 17 | plt.xlabel('searching graphs') 18 | plt.ylabel('opt % of origin graph') 19 | plt.legend() 20 | 21 | plt.savefig('MPLTS/Scripts/prune.png') 22 | plt.close() -------------------------------------------------------------------------------- /MPLTS/config.cmake: -------------------------------------------------------------------------------- 1 | set(USE_CUDA ON) 2 | set(USE_CUDNN ON) 3 | set(USE_DNNL OFF) 4 | set(BUILD_CPP_EXAMPLES OFF) -------------------------------------------------------------------------------- /MPLTS/examples/example.py: -------------------------------------------------------------------------------- 1 | import taso 2 | import onnx 3 | 4 | d = 32 5 | 6 | #Build DNN model 7 | graph = taso.new_graph() 8 | input1 = graph.new_input(dims=(1,d,10,10)) 9 | input2 = graph.new_input(dims=(1,d,10,10)) 10 | 11 | w00 = graph.new_weight(dims=(d,d,3,3)) 12 | w01 = graph.new_weight(dims=(d,d,1,1)) 13 | 14 | path1 = input1 15 | path1 = graph.conv2d(input=path1, weight=w00, strides=(1,1), padding="SAME") 16 | path1 = graph.conv2d(input=path1, weight=w01, strides=(1,1), padding="SAME") 17 | 18 | output = graph.relu(path1) 19 | 20 | onnx_model = taso.export_onnx(graph) 21 | onnx.save(onnx_model, "example.onnx") 22 | 23 | # graph = taso.optimize(graph, alpha=1e9, input_size=(1,32,10,10)) 24 | graph = taso.optimize(graph, alpha=1e9, input_size=(1,d,10,10), inMPL=True) 25 | 26 | onnx_model = taso.export_onnx(graph) 27 | onnx.save(onnx_model, "example_opt.onnx") -------------------------------------------------------------------------------- /MPLTS/graph_subst.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FudanMPL/Garnet/89af954fd61628990a0e6faa9a29d9d5e4b17667/MPLTS/graph_subst.pb -------------------------------------------------------------------------------- /MPLTS/graph_subst_ext.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FudanMPL/Garnet/89af954fd61628990a0e6faa9a29d9d5e4b17667/MPLTS/graph_subst_ext.pb -------------------------------------------------------------------------------- /MPLTS/graph_subst_full.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FudanMPL/Garnet/89af954fd61628990a0e6faa9a29d9d5e4b17667/MPLTS/graph_subst_full.pb -------------------------------------------------------------------------------- /MPLTS/recompile.sh: -------------------------------------------------------------------------------- 1 | current_dir=$(pwd) 2 | 3 | if [ -d "$current_dir/MPLTS" ]; then 4 | cd MPLTS 5 | fi 6 | 7 | sudo rm -rf build 8 | mkdir build 9 | cd build 10 | cmake .. 11 | sudo make install -j 8 12 | 13 | cd ../python 14 | python setup.py install 15 | 16 | sudo cp /usr/local/lib/libtaso_runtime.so /home/lx/anaconda3/envs/Garnet/lib/ -------------------------------------------------------------------------------- /MPLTS/requirements.txt: -------------------------------------------------------------------------------- 1 | torchaudio 2 | onnx2pytorch 3 | cython==0.29.32 -------------------------------------------------------------------------------- /MPLTS/src/core/rules.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | package GraphSubst; 4 | 5 | message Parameter { 6 | required int32 key = 1; 7 | required int32 value = 2; 8 | } 9 | 10 | message Tensor { 11 | required int32 opId = 1; 12 | required int32 tsId = 2; 13 | } 14 | 15 | message Operator { 16 | required int32 type = 1; 17 | repeated Tensor input = 2; 18 | repeated Parameter para = 3; 19 | } 20 | 21 | message MapOutput { 22 | required int32 srcOpId = 1; 23 | required int32 dstOpId = 2; 24 | required int32 srcTsId = 3; 25 | required int32 dstTsId = 4; 26 | } 27 | 28 | message Rule { 29 | repeated Operator srcOp = 1; 30 | repeated Operator dstOp = 2; 31 | repeated MapOutput mappedOutput = 3; 32 | } 33 | 34 | message RuleCollection { 35 | repeated Rule rule = 1; 36 | } 37 | -------------------------------------------------------------------------------- /MPLTS/src/generator/compile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | g++ generator.cc rules.pb.cc -o generator -I/usr/local/include -L/usr/local/lib -lprotobuf -std=c++11 -pthread -O2 3 | -------------------------------------------------------------------------------- /MPLTS/src/generator/generator: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FudanMPL/Garnet/89af954fd61628990a0e6faa9a29d9d5e4b17667/MPLTS/src/generator/generator -------------------------------------------------------------------------------- /MPLTS/src/generator/graph_subst.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FudanMPL/Garnet/89af954fd61628990a0e6faa9a29d9d5e4b17667/MPLTS/src/generator/graph_subst.pb -------------------------------------------------------------------------------- /MPLTS/verify/graph_subst.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FudanMPL/Garnet/89af954fd61628990a0e6faa9a29d9d5e4b17667/MPLTS/verify/graph_subst.pb -------------------------------------------------------------------------------- /Machines/Atlas.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Atlas.hpp 3 | * 4 | */ 5 | 6 | #ifndef MACHINES_ATLAS_HPP_ 7 | #define MACHINES_ATLAS_HPP_ 8 | 9 | #include "Protocols/AtlasShare.h" 10 | #include "Protocols/AtlasPrep.h" 11 | #include "GC/AtlasSecret.h" 12 | 13 | #include "ShamirMachine.hpp" 14 | #include "Protocols/Atlas.hpp" 15 | 16 | #endif /* MACHINES_ATLAS_HPP_ */ 17 | -------------------------------------------------------------------------------- /Machines/Fss.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Fss.hpp 3 | * 4 | */ 5 | 6 | #ifndef MACHINES_FSS_HPP_ 7 | #define MACHINES_FSS_HPP_ 8 | 9 | #include "Protocols/MalRepRingPrep.h" 10 | #include "Protocols/SemiRep3Prep.h" 11 | #include "GC/SemiHonestRepPrep.h" 12 | 13 | #include "Processor/Data_Files.hpp" 14 | #include "Processor/Instruction.hpp" 15 | #include "Processor/Machine.hpp" 16 | #include "Protocols/MAC_Check_Base.hpp" 17 | #include "Protocols/Fss.hpp" 18 | #include "Protocols/Spdz2kPrep.hpp" 19 | #include "Protocols/ReplicatedMC.hpp" 20 | #include "Math/Z2k.hpp" 21 | #include "GC/RepPrep.hpp" 22 | #include "GC/ThreadMaster.hpp" 23 | 24 | 25 | #endif /* MACHINES_FSS_HPP_ */ -------------------------------------------------------------------------------- /Machines/MalRep.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * MalRep.hpp 3 | * 4 | */ 5 | 6 | #ifndef MACHINES_MALREP_HPP_ 7 | #define MACHINES_MALREP_HPP_ 8 | 9 | #include "Protocols/MalRepRingPrep.hpp" 10 | #include "Protocols/MaliciousRepPrep.hpp" 11 | #include "Protocols/MaliciousRepMC.hpp" 12 | #include "Protocols/Beaver.hpp" 13 | #include "Rep.hpp" 14 | 15 | #endif /* MACHINES_MALREP_HPP_ */ 16 | -------------------------------------------------------------------------------- /Machines/OTMachine.h: -------------------------------------------------------------------------------- 1 | /* 2 | * OTMachine.h 3 | * 4 | */ 5 | 6 | #ifndef OT_OTMACHINE_H_ 7 | #define OT_OTMACHINE_H_ 8 | 9 | #include "OT/OTExtension.h" 10 | #include "Tools/ezOptionParser.h" 11 | 12 | class OTMachine 13 | { 14 | ez::ezOptionParser opt; 15 | OT_ROLE ot_role; 16 | 17 | public: 18 | int my_num, portnum_base, nthreads, nloops, nsubloops, nbase; 19 | long nOTs; 20 | bool passive; 21 | TwoPartyPlayer* P; 22 | BitVector baseReceiverInput; 23 | BaseOT* bot_; 24 | vector N; 25 | 26 | OTMachine(int argc, const char** argv); 27 | ~OTMachine(); 28 | void run(); 29 | }; 30 | 31 | #endif /* OT_OTMACHINE_H_ */ 32 | -------------------------------------------------------------------------------- /Machines/OText_main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OText_main.cpp 3 | * 4 | */ 5 | 6 | #include "OTMachine.h" 7 | 8 | int main(int argc, const char** argv) 9 | { 10 | OTMachine(argc, argv).run(); 11 | } 12 | -------------------------------------------------------------------------------- /Machines/OutputCheck.h: -------------------------------------------------------------------------------- 1 | /* 2 | * check.h 3 | * 4 | */ 5 | 6 | #ifndef OT_OUTPUTCHECK_H_ 7 | #define OT_OUTPUTCHECK_H_ 8 | 9 | #include "Math/Setup.h" 10 | 11 | #define RECEIVER_INPUT PREP_DIR "OT-receiver%d-input" 12 | #define RECEIVER_OUTPUT PREP_DIR "OT-receiver%d-output" 13 | #define SENDER_OUTPUT PREP_DIR "OT-sender%d-output%d" 14 | 15 | #endif /* OT_OUTPUTCHECK_H_ */ 16 | -------------------------------------------------------------------------------- /Machines/Player-Online.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Player-Online.cpp 3 | * 4 | */ 5 | 6 | #include "Processor/config.h" 7 | #include "Protocols/Share.h" 8 | #include "GC/TinierSecret.h" 9 | #include "Math/gfp.hpp" 10 | #include "Processor/FieldMachine.h" 11 | 12 | int main(int argc, const char** argv) 13 | { 14 | ez::ezOptionParser opt; 15 | DishonestMajorityFieldMachine(argc, argv, opt, false); 16 | } 17 | -------------------------------------------------------------------------------- /Machines/Rep.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Rep.cpp 3 | * 4 | */ 5 | 6 | #include "Protocols/MalRepRingPrep.h" 7 | #include "Protocols/SemiRep3Prep.h" 8 | #include "GC/SemiHonestRepPrep.h" 9 | 10 | #include "Processor/Data_Files.hpp" 11 | #include "Processor/Instruction.hpp" 12 | #include "Processor/Machine.hpp" 13 | #include "Protocols/MAC_Check_Base.hpp" 14 | #include "Protocols/Beaver.hpp" 15 | #include "Protocols/Spdz2kPrep.hpp" 16 | #include "Protocols/ReplicatedMC.hpp" 17 | #include "Protocols/Rep3Shuffler.hpp" 18 | #include "Math/Z2k.hpp" 19 | #include "GC/ShareSecret.hpp" 20 | #include "GC/RepPrep.hpp" 21 | #include "GC/ThreadMaster.hpp" 22 | -------------------------------------------------------------------------------- /Machines/Rep4.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Rep4.hpp 3 | * 4 | */ 5 | 6 | #ifndef MACHINES_REP4_HPP_ 7 | #define MACHINES_REP4_HPP_ 8 | 9 | #include "GC/Rep4Secret.h" 10 | #include "Protocols/Rep4Share2k.h" 11 | #include "Protocols/Rep4Prep.h" 12 | #include "Protocols/Rep4.hpp" 13 | #include "Protocols/Rep4MC.hpp" 14 | #include "Protocols/Rep4Input.hpp" 15 | #include "Protocols/Rep4Prep.hpp" 16 | 17 | #endif /* MACHINES_REP4_HPP_ */ 18 | -------------------------------------------------------------------------------- /Machines/RepRing.hpp: -------------------------------------------------------------------------------- 1 | #include "Rep.hpp" 2 | #include "Protocols/Spdz2kPrep.hpp" 3 | #include "Protocols/RepRingOnlyEdabitPrep.hpp" 4 | -------------------------------------------------------------------------------- /Machines/SPDZ.cpp: -------------------------------------------------------------------------------- 1 | #include "SPDZ.hpp" 2 | 3 | #include "Protocols/MascotPrep.hpp" 4 | #include "Processor/FieldMachine.hpp" 5 | #include "Math/gfp.hpp" 6 | 7 | template class FieldMachine; 8 | -------------------------------------------------------------------------------- /Machines/SPDZ2^64+48.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDZ2^(64+48).cpp 3 | * 4 | */ 5 | 6 | #include "SPDZ2k.hpp" 7 | 8 | template class Machine, Share>; 9 | -------------------------------------------------------------------------------- /Machines/SPDZ2^64+64.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDZ2^(64+48).cpp 3 | * 4 | */ 5 | 6 | #include "SPDZ2k.hpp" 7 | 8 | template class Machine, Share>; 9 | -------------------------------------------------------------------------------- /Machines/SPDZ2^72+48.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDZ2^(64+48).cpp 3 | * 4 | */ 5 | 6 | #include "SPDZ2k.hpp" 7 | 8 | template class Machine, Share>; 9 | -------------------------------------------------------------------------------- /Machines/SPDZ2^72+64.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDZ2^(64+48).cpp 3 | * 4 | */ 5 | 6 | #include "SPDZ2k.hpp" 7 | 8 | template class Machine, Share>; 9 | -------------------------------------------------------------------------------- /Machines/SPDZ2k.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDZ2k.cpp 3 | * 4 | */ 5 | 6 | #include "SPDZ2k.hpp" 7 | 8 | #ifdef RING_SIZE 9 | template class Machine, Share>; 10 | #endif 11 | -------------------------------------------------------------------------------- /Machines/SPDZ2k.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDZ2k.cpp 3 | * 4 | */ 5 | 6 | #include "Protocols/Spdz2kShare.h" 7 | #include "Protocols/Spdz2kPrep.h" 8 | #include "Protocols/SPDZ2k.h" 9 | 10 | #include "GC/TinySecret.h" 11 | #include "GC/TinyMC.h" 12 | #include "GC/TinierSecret.h" 13 | #include "GC/VectorInput.h" 14 | 15 | #include "Processor/Data_Files.hpp" 16 | #include "Processor/Instruction.hpp" 17 | #include "Processor/Machine.hpp" 18 | #include "Protocols/MAC_Check.hpp" 19 | #include "Protocols/fake-stuff.hpp" 20 | #include "Protocols/Beaver.hpp" 21 | #include "Protocols/Share.hpp" 22 | #include "Math/Z2k.hpp" 23 | 24 | #include "Protocols/MascotPrep.hpp" 25 | #include "Protocols/Spdz2kPrep.hpp" 26 | 27 | #include "GC/ShareParty.h" 28 | #include "GC/ShareSecret.h" 29 | #include "GC/Secret.hpp" 30 | #include "GC/TinierSharePrep.h" 31 | #include "GC/CcdPrep.h" 32 | 33 | #include "GC/VectorProtocol.hpp" 34 | -------------------------------------------------------------------------------- /Machines/Semi.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Semi.cpp 3 | * 4 | */ 5 | 6 | #include "Protocols/SemiShare.h" 7 | #include "Math/gf2n.h" 8 | #include "Protocols/SemiMC.h" 9 | #include "Protocols/VssMC.h" 10 | #include "Protocols/VssFieldMC.h" 11 | #include "Protocols/SemiPrep.h" 12 | 13 | #include "Processor/Data_Files.hpp" 14 | #include "Processor/Instruction.hpp" 15 | #include "Processor/Machine.hpp" 16 | #include "Protocols/MascotPrep.hpp" 17 | #include "Protocols/SemiPrep.hpp" 18 | #include "Protocols/SemiInput.hpp" 19 | #include "Protocols/VssInput.hpp" 20 | #include "Protocols/VssFieldInput.hpp" 21 | #include "Protocols/MAC_Check_Base.hpp" 22 | #include "Protocols/MAC_Check.hpp" 23 | #include "Protocols/SemiMC.hpp" 24 | #include "Protocols/VssMC.hpp" 25 | #include "Protocols/VssFieldMC.hpp" 26 | #include "Protocols/Beaver.hpp" 27 | #include "Protocols/MalRepRingPrep.hpp" 28 | #include "GC/SemiSecret.hpp" 29 | -------------------------------------------------------------------------------- /Machines/Semi2k.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Semi2.hpp 3 | * 4 | */ 5 | 6 | #ifndef MACHINES_SEMI2K_HPP_ 7 | #define MACHINES_SEMI2K_HPP_ 8 | 9 | #include "Protocols/Semi2kShare.h" 10 | #include "Protocols/SemiPrep2k.h" 11 | 12 | #include "Semi.hpp" 13 | #include "Protocols/RepRingOnlyEdabitPrep.hpp" 14 | 15 | #endif /* MACHINES_SEMI2K_HPP_ */ 16 | -------------------------------------------------------------------------------- /Machines/ShamirMachine.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ShamirMachine.h 3 | * 4 | */ 5 | 6 | #ifndef MACHINES_SHAMIRMACHINE_H_ 7 | #define MACHINES_SHAMIRMACHINE_H_ 8 | 9 | #include "Tools/ezOptionParser.h" 10 | 11 | class ShamirOptions 12 | { 13 | public: 14 | static ShamirOptions singleton; 15 | static ShamirOptions& s(); 16 | 17 | int nparties; 18 | int threshold; 19 | 20 | ShamirOptions(int nparties = 3, int threshold = 1); 21 | ShamirOptions(ez::ezOptionParser& opt, int argc, const char** argv); 22 | 23 | void set_threshold(ez::ezOptionParser& opt); 24 | }; 25 | 26 | class ShamirMachine : public ShamirOptions 27 | { 28 | }; 29 | 30 | template class T> 31 | class ShamirMachineSpec 32 | { 33 | public: 34 | ShamirMachineSpec(int argc, const char** argv); 35 | }; 36 | 37 | #endif /* MACHINES_SHAMIRMACHINE_H_ */ 38 | -------------------------------------------------------------------------------- /Machines/Tinier.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Tinier.cpp 3 | * 4 | */ 5 | 6 | #include "GC/TinyMC.h" 7 | #include "GC/TinierSecret.h" 8 | #include "GC/VectorInput.h" 9 | 10 | #include "GC/ShareParty.hpp" 11 | #include "GC/Secret.hpp" 12 | #include "GC/TinyPrep.hpp" 13 | #include "GC/ShareSecret.hpp" 14 | #include "GC/TinierSharePrep.hpp" 15 | #include "GC/CcdPrep.hpp" 16 | #include "GC/PersonalPrep.hpp" 17 | 18 | //template class GC::ShareParty>; 19 | template class GC::CcdPrep>; 20 | template class Preprocessing>; 21 | template class GC::TinierSharePrep>; 22 | template class GC::ShareSecret>; 23 | template class TripleShuffleSacrifice>; 24 | -------------------------------------------------------------------------------- /Machines/bmr-program-party.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * bmr-program-party.cpp 3 | * 4 | */ 5 | 6 | #include "BMR/Party.h" 7 | 8 | int main(int argc, const char** argv) 9 | { 10 | FakeProgramParty party(argc, argv); 11 | party.Start(); 12 | } 13 | -------------------------------------------------------------------------------- /Machines/bmr-program-tparty.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * bmr-program-tparty.cpp 3 | * 4 | */ 5 | 6 | #include "BMR/TrustedParty.h" 7 | 8 | int main(int argc, char** argv) 9 | { 10 | TrustedProgramParty party(argc, argv); 11 | party.Start(); 12 | } 13 | -------------------------------------------------------------------------------- /Machines/brain-party.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * brain-party.cpp 3 | * 4 | */ 5 | 6 | #include "Protocols/BrainShare.h" 7 | #include "Protocols/MaliciousRep3Share.h" 8 | #include "Processor/RingOptions.h" 9 | 10 | #include "Processor/RingMachine.hpp" 11 | #include "Protocols/BrainPrep.hpp" 12 | #include "Machines/RepRing.hpp" 13 | #include "Machines/MalRep.hpp" 14 | #include "Math/gfp.hpp" 15 | 16 | int main(int argc, const char** argv) 17 | { 18 | ez::ezOptionParser opt; 19 | HonestMajorityRingMachineWithSecurity(argc, 20 | argv, opt); 21 | } 22 | -------------------------------------------------------------------------------- /Machines/ccd-party.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ccd-party.cpp 3 | * 4 | */ 5 | 6 | #include "GC/CcdSecret.h" 7 | #include "GC/TinyMC.h" 8 | #include "GC/CcdPrep.h" 9 | #include "GC/VectorInput.h" 10 | 11 | #include "GC/ShareParty.hpp" 12 | #include "GC/ShareSecret.hpp" 13 | #include "GC/ThreadMaster.hpp" 14 | #include "GC/Secret.hpp" 15 | #include "GC/CcdPrep.hpp" 16 | #include "Machines/ShamirMachine.hpp" 17 | 18 | int main(int argc, const char** argv) 19 | { 20 | gf2n_::init_field(8); 21 | ez::ezOptionParser opt; 22 | ShamirOptions::singleton = {opt, argc, argv}; 23 | assert(ShamirOptions::singleton.nparties < (1 << gf2n_::length())); 24 | GC::ShareParty>>(argc, argv, opt); 25 | } 26 | -------------------------------------------------------------------------------- /Machines/chaigear-party.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * chaigear-party.cpp 3 | * 4 | */ 5 | 6 | #include "Protocols/ChaiGearShare.h" 7 | 8 | #include "SPDZ.hpp" 9 | #include "Protocols/ChaiGearPrep.hpp" 10 | #include "Processor/FieldMachine.hpp" 11 | #include "Math/gfp.hpp" 12 | 13 | int main(int argc, const char** argv) 14 | { 15 | ez::ezOptionParser opt; 16 | CowGearOptions::singleton = CowGearOptions(opt, argc, argv); 17 | DishonestMajorityFieldMachine( 18 | argc, argv, opt); 19 | } 20 | -------------------------------------------------------------------------------- /Machines/cowgear-offline.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * cowgear-offline.cpp 3 | * 4 | */ 5 | 6 | #include "SPDZ.hpp" 7 | #include "Math/gfp.hpp" 8 | #include "Protocols/CowGearShare.h" 9 | #include "Protocols/CowGearOptions.h" 10 | #include "Protocols/CowGearPrep.hpp" 11 | #include "Processor/FieldMachine.hpp" 12 | #include "Processor/OfflineMachine.hpp" 13 | 14 | int main(int argc, const char** argv) 15 | { 16 | ez::ezOptionParser opt; 17 | CowGearOptions::singleton = CowGearOptions(opt, argc, argv); 18 | DishonestMajorityFieldMachine>(argc, argv, opt); 20 | } 21 | -------------------------------------------------------------------------------- /Machines/cowgear-party.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * cowgear-party.cpp 3 | * 4 | */ 5 | 6 | #include "Protocols/CowGearShare.h" 7 | #include "Protocols/CowGearPrep.h" 8 | #include "Protocols/CowGearOptions.h" 9 | 10 | #include "FHE/FHE_Params.h" 11 | #include "FHE/FFT_Data.h" 12 | #include "FHE/NTL-Subs.h" 13 | 14 | #include "GC/TinierSecret.h" 15 | #include "GC/TinyMC.h" 16 | 17 | #include "SPDZ.hpp" 18 | 19 | #include "Protocols/CowGearPrep.hpp" 20 | #include "Processor/FieldMachine.hpp" 21 | #include "Math/gfp.hpp" 22 | 23 | int main(int argc, const char** argv) 24 | { 25 | ez::ezOptionParser opt; 26 | CowGearOptions::singleton = CowGearOptions(opt, argc, argv); 27 | DishonestMajorityFieldMachine(argc, argv, opt); 28 | } 29 | -------------------------------------------------------------------------------- /Machines/fss-ring-party.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * replicated-ring-party.cpp 3 | * 4 | */ 5 | 6 | 7 | 8 | #include "Protocols/Rep3Share2k.h" 9 | #include "Protocols/Fss3Prep.h" 10 | #include "Protocols/Fss3Prep.hpp" 11 | #include "Protocols/Fss.h" 12 | #include "Protocols/Fss.hpp" 13 | #include "Protocols/Fss3Share.h" 14 | #include "Protocols/Fss3Share2k.h" 15 | #include "Processor/RingOptions.h" 16 | #include "Math/Integer.h" 17 | #include "Machines/RepRing.hpp" 18 | #include "Processor/RingMachine.hpp" 19 | 20 | int main(int argc, const char** argv) 21 | { 22 | HonestMajorityRingMachine(argc, argv); 23 | } 24 | -------------------------------------------------------------------------------- /Machines/highgear-party.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * highgear-party.cpp 3 | * 4 | */ 5 | 6 | #include "Protocols/HighGearShare.h" 7 | 8 | #include "SPDZ.hpp" 9 | #include "Protocols/ChaiGearPrep.hpp" 10 | 11 | int main(int argc, const char** argv) 12 | { 13 | ez::ezOptionParser opt; 14 | CowGearOptions::singleton = CowGearOptions(opt, argc, argv, false); 15 | DishonestMajorityFieldMachine(argc, argv, opt); 16 | } 17 | -------------------------------------------------------------------------------- /Machines/lowgear-party.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * lowgear-party.cpp 3 | * 4 | */ 5 | 6 | #include "Protocols/LowGearShare.h" 7 | 8 | #include "SPDZ.hpp" 9 | #include "Protocols/CowGearPrep.hpp" 10 | 11 | int main(int argc, const char** argv) 12 | { 13 | ez::ezOptionParser opt; 14 | CowGearOptions::singleton = CowGearOptions(opt, argc, argv, false); 15 | DishonestMajorityFieldMachine(argc, argv, opt); 16 | } 17 | -------------------------------------------------------------------------------- /Machines/mal-rep-bmr-party.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * mal-rep-shamir-party.cpp 3 | * 4 | */ 5 | 6 | #include "Protocols/MaliciousRep3Share.h" 7 | 8 | #include "BMR/RealProgramParty.hpp" 9 | #include "Machines/Rep.hpp" 10 | #include "Machines/MalRep.hpp" 11 | 12 | int main(int argc, const char** argv) 13 | { 14 | RealProgramParty>(argc, argv); 15 | } 16 | -------------------------------------------------------------------------------- /Machines/mal-rss-with-conversion-party.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * mal-rep-ring-party.cpp 3 | * 4 | */ 5 | #define BIG_DOMAIN_FOR_RING 6 | #define BigDomainShare MalRepRingShare128 7 | #define BIG_DOMAIN_USE_RSS 8 | 9 | 10 | #include "Protocols/MalRepRingShare.h" 11 | #include "Protocols/MalRepRingOptions.h" 12 | #include "Processor/RingMachine.hpp" 13 | #include "Processor/RingOptions.h" 14 | #include "Machines/RepRing.hpp" 15 | #include "Machines/MalRep.hpp" 16 | 17 | 18 | int main(int argc, const char** argv) 19 | { 20 | ez::ezOptionParser opt; 21 | MalRepRingOptions::singleton = MalRepRingOptions(opt, argc, argv); 22 | HonestMajorityRingMachineWithSecurity(argc, argv, opt); 23 | } 24 | -------------------------------------------------------------------------------- /Machines/mal-shamir-bmr-party.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * mal-shamir-bmr-party.cpp 3 | * 4 | */ 5 | 6 | #include "BMR/RealProgramParty.hpp" 7 | #include "Machines/ShamirMachine.hpp" 8 | #include "Math/Z2k.hpp" 9 | #include "Machines/MalRep.hpp" 10 | 11 | int main(int argc, const char** argv) 12 | { 13 | ez::ezOptionParser opt; 14 | ShamirOptions::singleton = {opt, argc, argv}; 15 | RealProgramParty>(argc, argv); 16 | } 17 | -------------------------------------------------------------------------------- /Machines/mal-shamir-offline.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * mal-shamir-offline.cpp 3 | * 4 | */ 5 | 6 | #include "ShamirMachine.hpp" 7 | #include "MalRep.hpp" 8 | #include "Processor/OfflineMachine.hpp" 9 | 10 | int main(int argc, const char** argv) 11 | { 12 | auto& opts = ShamirOptions::singleton; 13 | ez::ezOptionParser opt; 14 | opts = {opt, argc, argv}; 15 | HonestMajorityFieldMachine>(argc, argv, opt, 17 | opts.nparties); 18 | } 19 | -------------------------------------------------------------------------------- /Machines/malicious-ccd-party.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ccd-party.cpp 3 | * 4 | */ 5 | 6 | #include "GC/MaliciousCcdSecret.h" 7 | #include "GC/TinyMC.h" 8 | #include "GC/CcdPrep.h" 9 | #include "GC/VectorInput.h" 10 | 11 | #include "GC/ShareParty.hpp" 12 | #include "GC/ShareSecret.hpp" 13 | #include "GC/ThreadMaster.hpp" 14 | #include "GC/Secret.hpp" 15 | #include "GC/CcdPrep.hpp" 16 | #include "Machines/ShamirMachine.hpp" 17 | #include "Machines/MalRep.hpp" 18 | 19 | int main(int argc, const char** argv) 20 | { 21 | ez::ezOptionParser opt; 22 | ShamirOptions::singleton = {opt, argc, argv}; 23 | OnlineOptions opts(opt, argc, argv); 24 | gf2n_short::init_minimum(opts.security_parameter); 25 | GC::ShareParty>(argc, argv, opt); 26 | } 27 | -------------------------------------------------------------------------------- /Machines/malicious-rep-bin-party.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * malicious-rep-bin-party.cpp 3 | * 4 | */ 5 | 6 | #include "GC/ShareParty.h" 7 | #include "GC/ShareParty.hpp" 8 | #include "GC/ShareSecret.hpp" 9 | #include "GC/MaliciousRepSecret.h" 10 | #include "GC/RepPrep.h" 11 | 12 | #include "GC/Machine.hpp" 13 | #include "GC/Processor.hpp" 14 | #include "GC/Program.hpp" 15 | #include "GC/Thread.hpp" 16 | #include "GC/ThreadMaster.hpp" 17 | #include "GC/RepPrep.hpp" 18 | 19 | #include "Processor/Instruction.hpp" 20 | #include "Protocols/MaliciousRepMC.hpp" 21 | #include "Protocols/MAC_Check_Base.hpp" 22 | #include "Protocols/Beaver.hpp" 23 | 24 | int main(int argc, const char** argv) 25 | { 26 | GC::simple_binary_main(argc, argv); 27 | } 28 | -------------------------------------------------------------------------------- /Machines/malicious-rep-field-party.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * malicious-rep-field-party.cpp 3 | * 4 | */ 5 | 6 | #include "Protocols/MaliciousRep3Share.h" 7 | #include "Processor/FieldMachine.hpp" 8 | #include "Machines/Rep.hpp" 9 | #include "Machines/MalRep.hpp" 10 | #include "Math/gfp.hpp" 11 | 12 | int main(int argc, const char** argv) 13 | { 14 | HonestMajorityFieldMachine(argc, argv); 15 | } 16 | -------------------------------------------------------------------------------- /Machines/malicious-rep-ring-party.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * mal-rep-ring-party.cpp 3 | * 4 | */ 5 | 6 | #include "Protocols/MalRepRingShare.h" 7 | #include "Protocols/MalRepRingOptions.h" 8 | #include "Processor/RingMachine.hpp" 9 | #include "Processor/RingOptions.h" 10 | #include "Machines/RepRing.hpp" 11 | #include "Machines/MalRep.hpp" 12 | 13 | int main(int argc, const char** argv) 14 | { 15 | ez::ezOptionParser opt; 16 | MalRepRingOptions::singleton = MalRepRingOptions(opt, argc, argv); 17 | HonestMajorityRingMachineWithSecurity(argc, argv, opt); 18 | } 19 | -------------------------------------------------------------------------------- /Machines/malicious-shamir-party.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * malicious-shamir-party.cpp 3 | * 4 | */ 5 | 6 | #include "Machines/ShamirMachine.h" 7 | #include "Protocols/MaliciousShamirShare.h" 8 | #include "Machines/MalRep.hpp" 9 | 10 | #include "ShamirMachine.hpp" 11 | 12 | int main(int argc, const char** argv) 13 | { 14 | ShamirMachineSpec(argc, argv); 15 | } 16 | -------------------------------------------------------------------------------- /Machines/mascot-offline.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * mascot-offline.cpp 3 | * 4 | */ 5 | 6 | #include "GC/TinierSecret.h" 7 | 8 | #include "SPDZ.hpp" 9 | #include "Math/gfp.hpp" 10 | #include "Processor/FieldMachine.hpp" 11 | #include "Processor/OfflineMachine.hpp" 12 | #include "Protocols/MascotPrep.hpp" 13 | 14 | int main(int argc, const char** argv) 15 | { 16 | ez::ezOptionParser opt; 17 | DishonestMajorityFieldMachine>(argc, argv, opt); 19 | } 20 | -------------------------------------------------------------------------------- /Machines/mascot-party.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Math/gfp.hpp" 3 | #include "GC/TinierSecret.h" 4 | #include "Processor/FieldMachine.h" 5 | 6 | int main(int argc, const char** argv) 7 | { 8 | ez::ezOptionParser opt; 9 | DishonestMajorityFieldMachine(argc, argv, opt); 10 | } 11 | -------------------------------------------------------------------------------- /Machines/no-party.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * no-party.cpp 3 | * 4 | */ 5 | 6 | #include "Protocols/NoShare.h" 7 | 8 | #include "Processor/OnlineMachine.hpp" 9 | #include "Processor/Machine.hpp" 10 | #include "Protocols/Replicated.hpp" 11 | #include "Protocols/MalRepRingPrep.hpp" 12 | #include "Protocols/ReplicatedPrep.hpp" 13 | #include "Protocols/MAC_Check_Base.hpp" 14 | #include "Math/gfp.hpp" 15 | #include "Math/Z2k.hpp" 16 | 17 | int main(int argc, const char** argv) 18 | { 19 | ez::ezOptionParser opt; 20 | OnlineOptions::singleton = {opt, argc, argv}; 21 | OnlineMachine machine(argc, argv, opt, OnlineOptions::singleton); 22 | OnlineOptions::singleton.finalize(opt, argc, argv); 23 | machine.start_networking(); 24 | // use primes of length 65 to 128 for arithmetic computation 25 | machine.run>, NoShare>(); 26 | } 27 | -------------------------------------------------------------------------------- /Machines/ps-rep-bin-party.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * abfllnow-party.cpp 3 | * 4 | */ 5 | 6 | #include "GC/PostSacriBin.h" 7 | #include "GC/PostSacriSecret.h" 8 | #include "GC/RepPrep.h" 9 | 10 | #include "GC/ShareParty.hpp" 11 | #include "GC/RepPrep.hpp" 12 | #include "Protocols/MaliciousRepMC.hpp" 13 | 14 | int main(int argc, const char** argv) 15 | { 16 | GC::simple_binary_main(argc, argv); 17 | } 18 | -------------------------------------------------------------------------------- /Machines/ps-rep-field-party.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ps-rep-field-party.cpp 3 | * 4 | */ 5 | 6 | #include "Protocols/PostSacriRepFieldShare.h" 7 | #include "Processor/FieldMachine.hpp" 8 | #include "Machines/Rep.hpp" 9 | #include "Machines/MalRep.hpp" 10 | #include "Protocols/PostSacrifice.hpp" 11 | #include "Math/gfp.hpp" 12 | 13 | int main(int argc, const char** argv) 14 | { 15 | HonestMajorityFieldMachine(argc, argv); 16 | } 17 | -------------------------------------------------------------------------------- /Machines/ps-rep-ring-party.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * mal-rep-ring-party.cpp 3 | * 4 | */ 5 | 6 | #include "Protocols/PostSacriRepRingShare.h" 7 | #include "Protocols/PostSacriRepFieldShare.h" 8 | #include "Processor/RingMachine.hpp" 9 | #include "Processor/RingOptions.h" 10 | #include "Machines/RepRing.hpp" 11 | #include "Machines/MalRep.hpp" 12 | #include "Protocols/PostSacrifice.hpp" 13 | 14 | int main(int argc, const char** argv) 15 | { 16 | ez::ezOptionParser opt; 17 | HonestMajorityRingMachineWithSecurity(argc, argv, opt); 19 | } 20 | -------------------------------------------------------------------------------- /Machines/real-bmr-party.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * real-bmr-party.cpp 3 | * 4 | */ 5 | 6 | #define NO_MIXED_CIRCUITS 7 | 8 | #include "BMR/RealProgramParty.hpp" 9 | #include "Machines/SPDZ.hpp" 10 | #include "Protocols/MascotPrep.hpp" 11 | 12 | int main(int argc, const char** argv) 13 | { 14 | RealProgramParty>(argc, argv); 15 | } 16 | -------------------------------------------------------------------------------- /Machines/rep-bmr-party.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * rep-bmr-party.cpp 3 | * 4 | */ 5 | 6 | #include "BMR/RealProgramParty.hpp" 7 | #include "Machines/Rep.hpp" 8 | 9 | int main(int argc, const char** argv) 10 | { 11 | RealProgramParty>(argc, argv); 12 | } 13 | -------------------------------------------------------------------------------- /Machines/rep4-ring-party.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * rep4-party.cpp 3 | * 4 | */ 5 | 6 | #include "Protocols/Rep4Share2k.h" 7 | #include "Protocols/Rep4Share.h" 8 | #include "Protocols/Rep4MC.h" 9 | #include "Math/Z2k.h" 10 | #include "Math/gf2n.h" 11 | #include "Tools/ezOptionParser.h" 12 | #include "GC/Rep4Secret.h" 13 | #include "Processor/RingOptions.h" 14 | 15 | #include "Processor/RingMachine.hpp" 16 | #include "Protocols/RepRingOnlyEdabitPrep.hpp" 17 | #include "Protocols/Rep4Input.hpp" 18 | #include "Protocols/Rep4Prep.hpp" 19 | #include "Protocols/Rep4MC.hpp" 20 | #include "Protocols/Rep4.hpp" 21 | #include "GC/BitAdder.hpp" 22 | #include "Math/Z2k.hpp" 23 | #include "Rep.hpp" 24 | 25 | int main(int argc, const char** argv) 26 | { 27 | HonestMajorityRingMachine(argc, argv, 4); 28 | } 29 | -------------------------------------------------------------------------------- /Machines/replicated-bin-party.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * replicated-party.cpp 3 | * 4 | */ 5 | 6 | #include "GC/ShareParty.h" 7 | #include "GC/SemiHonestRepPrep.h" 8 | 9 | #include "GC/ShareParty.hpp" 10 | #include "GC/ShareSecret.hpp" 11 | #include "GC/Machine.hpp" 12 | #include "GC/Processor.hpp" 13 | #include "GC/Program.hpp" 14 | #include "GC/Thread.hpp" 15 | #include "GC/ThreadMaster.hpp" 16 | #include "GC/RepPrep.hpp" 17 | 18 | #include "Processor/Instruction.hpp" 19 | #include "Protocols/MaliciousRepMC.hpp" 20 | #include "Protocols/MAC_Check_Base.hpp" 21 | #include "Protocols/Beaver.hpp" 22 | 23 | int main(int argc, const char** argv) 24 | { 25 | GC::simple_binary_main(argc, argv); 26 | } 27 | -------------------------------------------------------------------------------- /Machines/replicated-field-party.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * replicated-field-party.cpp 3 | * 4 | */ 5 | 6 | #include "Math/gfp.hpp" 7 | #include "Processor/FieldMachine.hpp" 8 | #include "Machines/Rep.hpp" 9 | 10 | int main(int argc, const char** argv) 11 | { 12 | HonestMajorityFieldMachine(argc, argv); 13 | } 14 | -------------------------------------------------------------------------------- /Machines/replicated-ring-party.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * replicated-ring-party.cpp 3 | * 4 | */ 5 | 6 | 7 | #include "Protocols/Rep3Share2k.h" 8 | #include "Processor/RingOptions.h" 9 | #include "Math/Integer.h" 10 | #include "Machines/RepRing.hpp" 11 | #include "Processor/RingMachine.hpp" 12 | 13 | 14 | int main(int argc, const char** argv) 15 | { 16 | HonestMajorityRingMachine(argc, argv); 17 | } 18 | -------------------------------------------------------------------------------- /Machines/rss-with-conversion-party.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * replicated-ring-party.cpp 3 | * 4 | */ 5 | #define BIG_DOMAIN_FOR_RING 6 | #define BIG_DOMAIN_USE_RSS 7 | #define BigDomainShare Rep3Share128 8 | 9 | #include "Protocols/Rep3Share2k.h" 10 | #include "Protocols/Rep3Share128.h" 11 | #include "Processor/RingOptions.h" 12 | #include "Math/Integer.h" 13 | #include "Machines/RepRing.hpp" 14 | #include "Processor/RingMachine.hpp" 15 | 16 | 17 | int main(int argc, const char** argv) 18 | { 19 | HonestMajorityRingMachine(argc, argv); 20 | } 21 | -------------------------------------------------------------------------------- /Machines/semi-bin-party.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * semi-bin-party.cpp 3 | * 4 | */ 5 | 6 | #include "GC/ShareParty.h" 7 | #include "GC/SemiSecret.h" 8 | 9 | #include "GC/ShareParty.hpp" 10 | #include "GC/ShareSecret.hpp" 11 | 12 | #include "GC/Machine.hpp" 13 | #include "GC/Program.hpp" 14 | #include "GC/Thread.hpp" 15 | #include "GC/ThreadMaster.hpp" 16 | #include "GC/Processor.hpp" 17 | #include "GC/SemiSecret.hpp" 18 | #include "Protocols/MAC_Check_Base.hpp" 19 | #include "Protocols/SemiMC.hpp" 20 | #include "Protocols/SemiInput.hpp" 21 | #include "Protocols/ReplicatedInput.hpp" 22 | #include "Processor/Instruction.hpp" 23 | #include "Processor/Input.hpp" 24 | 25 | int main(int argc, const char** argv) 26 | { 27 | GC::simple_binary_main(argc, argv); 28 | } 29 | -------------------------------------------------------------------------------- /Machines/semi-bmr-party.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * semi-bmr-party.cpp 3 | * 4 | */ 5 | 6 | #include "BMR/RealProgramParty.hpp" 7 | #include "Machines/Semi.hpp" 8 | 9 | int main(int argc, const char** argv) 10 | { 11 | RealProgramParty>(argc, argv); 12 | } 13 | -------------------------------------------------------------------------------- /Machines/semi-party.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * semi-party.cpp 3 | * 4 | */ 5 | 6 | #include "Math/gfp.h" 7 | #include "Protocols/SemiShare.h" 8 | #include "Tools/SwitchableOutput.h" 9 | #include "GC/SemiPrep.h" 10 | 11 | #include "Processor/FieldMachine.hpp" 12 | #include "Semi.hpp" 13 | #include "GC/ShareSecret.hpp" 14 | #include "Math/gfp.hpp" 15 | 16 | int main(int argc, const char** argv) 17 | { 18 | ez::ezOptionParser opt; 19 | DishonestMajorityFieldMachine(argc, argv, opt); 20 | } 21 | -------------------------------------------------------------------------------- /Machines/semi2k-party.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * semi2k-party.cpp 3 | * 4 | */ 5 | 6 | #include "Protocols/Semi2kShare.h" 7 | #include "Protocols/SemiPrep2k.h" 8 | #include "Math/gf2n.h" 9 | #include "Processor/RingOptions.h" 10 | #include "GC/SemiPrep.h" 11 | 12 | #include "Semi.hpp" 13 | #include "GC/ShareSecret.hpp" 14 | #include "Protocols/RepRingOnlyEdabitPrep.hpp" 15 | #include "Processor/RingMachine.hpp" 16 | 17 | int main(int argc, const char** argv) 18 | { 19 | ez::ezOptionParser opt; 20 | DishonestMajorityRingMachine(argc, argv, opt); 21 | } 22 | -------------------------------------------------------------------------------- /Machines/semi2k-with-conversion-party.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * semi2k-party.cpp 3 | * 4 | */ 5 | 6 | #define BIG_DOMAIN_FOR_RING 7 | #define BIG_DOMAIN_USE_SEMI 8 | #define BigDomainShare Semi2kShare128 9 | 10 | #include "Protocols/Semi2kShare128.h" 11 | #include "Protocols/Semi2kShare.h" 12 | #include "Protocols/SemiPrep2k.h" 13 | #include "Math/gf2n.h" 14 | #include "Processor/RingOptions.h" 15 | #include "GC/SemiPrep.h" 16 | 17 | #include "Semi.hpp" 18 | #include "GC/ShareSecret.hpp" 19 | #include "Protocols/RepRingOnlyEdabitPrep.hpp" 20 | #include "Processor/RingMachine.hpp" 21 | 22 | int main(int argc, const char** argv) 23 | { 24 | ez::ezOptionParser opt; 25 | DishonestMajorityRingMachine(argc, argv, opt); 26 | } 27 | -------------------------------------------------------------------------------- /Machines/shamir-bmr-party.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * shamir-bmr-party.cpp 3 | * 4 | */ 5 | 6 | #include "BMR/RealProgramParty.hpp" 7 | #include "Machines/ShamirMachine.hpp" 8 | #include "Math/Z2k.hpp" 9 | 10 | int main(int argc, const char** argv) 11 | { 12 | ez::ezOptionParser opt; 13 | ShamirOptions::singleton = {opt, argc, argv}; 14 | RealProgramParty>(argc, argv); 15 | } 16 | -------------------------------------------------------------------------------- /Machines/shamir-party.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * shamir-party.cpp 3 | * 4 | */ 5 | 6 | #include "Machines/ShamirMachine.h" 7 | #include "Protocols/ShamirShare.h" 8 | 9 | #include "ShamirMachine.hpp" 10 | 11 | int main(int argc, const char** argv) 12 | { 13 | ShamirMachineSpec(argc, argv); 14 | } 15 | -------------------------------------------------------------------------------- /Machines/vss-field-party.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * vss-field-party.cpp 3 | * 4 | */ 5 | 6 | #include "Math/gfp.hpp" 7 | #include "Processor/FieldMachine.hpp" 8 | #include "Machines/Semi.hpp" 9 | #include "Machines/vss-field-party.h" 10 | #include "Machines/vss-field-party.hpp" 11 | #include "Protocols/Vss.h" 12 | #include "Protocols/VssFieldShare.h" 13 | 14 | int main(int argc, const char** argv) 15 | { 16 | VssFieldMachineSpec(argc, argv); 17 | } -------------------------------------------------------------------------------- /Machines/vss-party.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Vss2k-party.cpp 3 | * 4 | */ 5 | 6 | #include "Protocols/Vss2kShare.h" 7 | #include "Protocols/SemiPrep2k.h" 8 | #include "Math/gf2n.h" 9 | #include "Processor/RingOptions.h" 10 | #include "GC/SemiPrep.h" 11 | #include "Semi.hpp" 12 | #include "GC/ShareSecret.hpp" 13 | #include "Protocols/RepRingOnlyEdabitPrep.hpp" 14 | #include "Processor/RingMachine.hpp" 15 | 16 | int main(int argc, const char** argv) 17 | { 18 | ez::ezOptionParser opt; 19 | HonestMajorityRingMachine(argc, argv, opt); 20 | } -------------------------------------------------------------------------------- /Machines/yao-party.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * yao-player.cpp 3 | * 4 | */ 5 | 6 | #include "Yao/YaoPlayer.h" 7 | 8 | int main(int argc, const char** argv) 9 | { 10 | YaoPlayer(argc, argv); 11 | } 12 | -------------------------------------------------------------------------------- /Math/Bit.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Bit.cpp 3 | * 4 | */ 5 | 6 | #include "Bit.h" 7 | #include "gf2n.h" 8 | 9 | template 10 | Bit::Bit(const gf2n_& other) : 11 | super(other.get_bit(0)) 12 | { 13 | assert(other.is_one() or other.is_zero()); 14 | } 15 | 16 | template Bit::Bit(const gf2n_& other); 17 | template Bit::Bit(const gf2n_& other); 18 | -------------------------------------------------------------------------------- /Math/Square.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Square.cpp 3 | * 4 | */ 5 | 6 | #include "Square.h" 7 | #include "BitVec.h" 8 | #include "gf2n.h" 9 | #include "gfp.h" 10 | 11 | template<> 12 | void Square::to(gf2n_short& result, false_type) 13 | { 14 | int128 sum; 15 | for (int i = 0; i < gf2n_short::degree(); i++) 16 | sum ^= int128(rows[i].get()) << i; 17 | result = sum; 18 | } 19 | 20 | template<> 21 | void Square::to(BitVec& result, false_type) 22 | { 23 | result = 0; 24 | for (int i = 0; i < N_ROWS; i++) 25 | result ^= ((rows[i] >> i) & 1) << i; 26 | } 27 | -------------------------------------------------------------------------------- /Math/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * config.h 3 | * 4 | */ 5 | 6 | #ifndef MATH_CONFIG_H_ 7 | #define MATH_CONFIG_H_ 8 | 9 | //#define MAX_MOD_SZ 6 10 | 11 | #endif /* MATH_CONFIG_H_ */ 12 | -------------------------------------------------------------------------------- /Math/field_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * types.h 3 | * 4 | */ 5 | 6 | #ifndef MATH_FIELD_TYPES_H_ 7 | #define MATH_FIELD_TYPES_H_ 8 | 9 | 10 | enum DataFieldType { DATA_INT, DATA_GF2N, DATA_GF2, N_DATA_FIELD_TYPE }; 11 | 12 | enum Dtype 13 | { 14 | DATA_TRIPLE, 15 | DATA_SQUARE, 16 | DATA_BIT, 17 | DATA_INVERSE, 18 | DATA_DABIT, 19 | DATA_MIXED, 20 | N_DTYPE, 21 | }; 22 | 23 | #endif /* MATH_FIELD_TYPES_H_ */ 24 | -------------------------------------------------------------------------------- /Networking/PlayerBuffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * PlayerBuffer.h 3 | * 4 | */ 5 | 6 | #ifndef NETWORKING_PLAYERBUFFER_H_ 7 | #define NETWORKING_PLAYERBUFFER_H_ 8 | 9 | #include "Tools/int.h" 10 | 11 | class PlayerBuffer 12 | { 13 | public: 14 | octet* data; 15 | size_t size; 16 | 17 | PlayerBuffer(octet* data, size_t size) : 18 | data(data), size(size) 19 | { 20 | } 21 | }; 22 | 23 | #endif /* NETWORKING_PLAYERBUFFER_H_ */ 24 | -------------------------------------------------------------------------------- /OT/BitDiagonal.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Diagonal.cpp 3 | * 4 | */ 5 | 6 | #include 7 | 8 | void BitDiagonal::pack(octetStream& os) const 9 | { 10 | for (int i = 0; i < N_ROWS; i++) 11 | os.store_int(rows[i].get_bit(i), 1); 12 | } 13 | 14 | void BitDiagonal::unpack(octetStream& os) 15 | { 16 | *this = {}; 17 | for (int i = 0; i < N_ROWS; i++) 18 | rows[i] = os.get_int(1) << i; 19 | } 20 | -------------------------------------------------------------------------------- /OT/BitDiagonal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Diagonal.h 3 | * 4 | */ 5 | 6 | #ifndef OT_BITDIAGONAL_H_ 7 | #define OT_BITDIAGONAL_H_ 8 | 9 | #include "Math/Square.h" 10 | #include "Math/BitVec.h" 11 | 12 | class BitDiagonal : public Square 13 | { 14 | public: 15 | static int size() 16 | { 17 | return 8 * BitVec::size(); 18 | } 19 | 20 | void pack(octetStream& os) const; 21 | void unpack(octetStream& os); 22 | }; 23 | 24 | #endif /* OT_BITDIAGONAL_H_ */ 25 | -------------------------------------------------------------------------------- /OT/MascotParams.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * TripleMachine.cpp 3 | * 4 | */ 5 | 6 | #include "MascotParams.h" 7 | 8 | MascotParams::MascotParams() 9 | { 10 | generateMACs = true; 11 | amplify = true; 12 | check = true; 13 | correlation_check = true; 14 | generateBits = false; 15 | use_extension = true; 16 | fewer_rounds = false; 17 | fiat_shamir = false; 18 | timerclear(&start); 19 | } 20 | 21 | void MascotParams::set_passive() 22 | { 23 | generateMACs = amplify = check = correlation_check = false; 24 | } 25 | -------------------------------------------------------------------------------- /OT/MascotParams.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MascotParams.h 3 | * 4 | */ 5 | 6 | #ifndef OT_MASCOTPARAMS_H_ 7 | #define OT_MASCOTPARAMS_H_ 8 | 9 | #include "Tools/OfflineMachineBase.h" 10 | 11 | class MascotParams : virtual public OfflineParams 12 | { 13 | public: 14 | string prep_data_dir; 15 | bool generateMACs; 16 | bool amplify; 17 | bool check; 18 | bool correlation_check; 19 | bool generateBits; 20 | bool use_extension; 21 | bool fewer_rounds; 22 | bool fiat_shamir; 23 | struct timeval start, stop; 24 | 25 | MascotParams(); 26 | 27 | void set_passive(); 28 | }; 29 | 30 | #endif /* OT_MASCOTPARAMS_H_ */ 31 | -------------------------------------------------------------------------------- /OT/Tools.h: -------------------------------------------------------------------------------- 1 | #ifndef _OTTOOLS 2 | #define _OTTOOLS 3 | 4 | //#if defined(__SSE2__) 5 | /* 6 | * Convert __m128i to string of type T 7 | */ 8 | template 9 | string __m128i_toString(const __m128i var) { 10 | stringstream sstr; 11 | sstr << hex; 12 | const T* values = (const T*) &var; 13 | if (sizeof(T) == 1) { 14 | for (unsigned int i = 0; i < sizeof(__m128i); i++) { 15 | sstr << (int) values[i] << " "; 16 | } 17 | } else { 18 | for (unsigned int i = 0; i < sizeof(__m128i) / sizeof(T); i++) { 19 | sstr << values[i] << " "; 20 | } 21 | } 22 | return sstr.str(); 23 | } 24 | //#endif 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /OT/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * config.h 3 | * 4 | */ 5 | 6 | #ifndef OT_CONFIG_H_ 7 | #define OT_CONFIG_H_ 8 | 9 | #define USE_OPT_VOLE 1 10 | #define NUM_VOLE_CHALLENGES 3 11 | 12 | #endif /* OT_CONFIG_H_ */ 13 | -------------------------------------------------------------------------------- /Output/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FudanMPL/Garnet/89af954fd61628990a0e6faa9a29d9d5e4b17667/Output/.gitkeep -------------------------------------------------------------------------------- /Player-Data/readme.txt: -------------------------------------------------------------------------------- 1 | 该文件夹下存放用于MPC计算的输入数据 2 | -------------------------------------------------------------------------------- /Processor/FixInput.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * FixInput.cpp 3 | * 4 | */ 5 | 6 | #include "FixInput.h" 7 | 8 | #include 9 | 10 | template<> 11 | void FixInput_::read(std::istream& in, const int* params) 12 | { 13 | double x; 14 | in >> x; 15 | 16 | items[0] = x * exp2(*params); 17 | } 18 | 19 | template<> 20 | void FixInput_::read(std::istream& in, const int* params) 21 | { 22 | #ifdef HIGH_PREC_INPUT 23 | mpf_class x; 24 | in >> x; 25 | items[0] = x << *params; 26 | #else 27 | double x; 28 | in >> x; 29 | items[0] = x * exp2(*params); 30 | #endif 31 | } -------------------------------------------------------------------------------- /Processor/FixInput.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FixInput.h 3 | * 4 | */ 5 | 6 | #ifndef PROCESSOR_FIXINPUT_H_ 7 | #define PROCESSOR_FIXINPUT_H_ 8 | 9 | #include 10 | 11 | #include "Math/bigint.h" 12 | #include "Math/Integer.h" 13 | 14 | template 15 | class FixInput_ 16 | { 17 | public: 18 | const static int N_DEST = 1; 19 | const static int N_PARAM = 1; 20 | const static char* NAME; 21 | 22 | const static int TYPE = 1; 23 | 24 | T items[N_DEST]; 25 | 26 | void read(std::istream& in, const int* params); 27 | }; 28 | 29 | template 30 | const char* FixInput_::NAME = "real number"; 31 | 32 | #ifdef LOW_PREC_INPUT 33 | typedef FixInput_ FixInput; 34 | #else 35 | typedef FixInput_ FixInput; 36 | #endif 37 | 38 | #endif /* PROCESSOR_FIXINPUT_H_ */ 39 | -------------------------------------------------------------------------------- /Processor/FloatInput.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * FloatInput.cpp 3 | * 4 | */ 5 | 6 | #include "FloatInput.h" 7 | 8 | #include 9 | 10 | const char* FloatInput::NAME = "real number"; 11 | 12 | void FloatInput::read(std::istream& in, const int* params) 13 | { 14 | double x; 15 | in >> x; 16 | int exp; 17 | double mant = fabs(frexp(x, &exp)); 18 | 19 | items[0] = round(mant * (1LL << *params)); 20 | items[1] = exp - *params; 21 | items[2] = (x == 0); 22 | items[3] = (x < 0); 23 | } -------------------------------------------------------------------------------- /Processor/FloatInput.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FloatInput.h 3 | * 4 | */ 5 | 6 | #ifndef PROCESSOR_FLOATINPUT_H_ 7 | #define PROCESSOR_FLOATINPUT_H_ 8 | 9 | #include "Math/bigint.h" 10 | 11 | #include 12 | 13 | class FloatInput 14 | { 15 | public: 16 | const static int N_DEST = 4; 17 | const static int N_PARAM = 1; 18 | const static char* NAME; 19 | 20 | const static int TYPE = 2; 21 | 22 | long items[N_DEST]; 23 | 24 | void read(std::istream& in, const int* params); 25 | }; 26 | 27 | #endif /* PROCESSOR_FLOATINPUT_H_ */ 28 | -------------------------------------------------------------------------------- /Processor/HonestMajorityMachine.h: -------------------------------------------------------------------------------- 1 | /* 2 | * DishonestMajorityMachine.h 3 | * 4 | */ 5 | 6 | #ifndef PROCESSOR_HONESTMAJORITYMACHINE_H_ 7 | #define PROCESSOR_HONESTMAJORITYMACHINE_H_ 8 | 9 | #include "OnlineMachine.h" 10 | 11 | class HonestMajorityMachine : public OnlineMachine 12 | { 13 | public: 14 | HonestMajorityMachine(int argc, const char** argv, ez::ezOptionParser& opt, 15 | OnlineOptions& online_opts, int n_players = 3); 16 | 17 | template 18 | HonestMajorityMachine(int argc, const char** argv, ez::ezOptionParser& opt, 19 | OnlineOptions& online_opts, V, int nplayers) : 20 | HonestMajorityMachine(argc, argv, opt, online_opts, nplayers) 21 | { 22 | } 23 | }; 24 | 25 | #endif /* PROCESSOR_HONESTMAJORITYMACHINE_H_ */ 26 | -------------------------------------------------------------------------------- /Processor/IntInput.h: -------------------------------------------------------------------------------- 1 | /* 2 | * IntInput.h 3 | * 4 | */ 5 | 6 | #ifndef PROCESSOR_INTINPUT_H_ 7 | #define PROCESSOR_INTINPUT_H_ 8 | 9 | #include 10 | 11 | template 12 | class IntInput 13 | { 14 | public: 15 | const static int N_DEST = 1; 16 | const static int N_PARAM = 0; 17 | const static char* NAME; 18 | 19 | const static int TYPE = 0; 20 | 21 | T items[N_DEST]; 22 | 23 | void read(std::istream& in, const int* params); 24 | }; 25 | 26 | #endif /* PROCESSOR_INTINPUT_H_ */ 27 | -------------------------------------------------------------------------------- /Processor/IntInput.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * IntInput.cpp 3 | * 4 | */ 5 | 6 | #ifndef PROCESSOR_INTINPUT_HPP_ 7 | #define PROCESSOR_INTINPUT_HPP_ 8 | 9 | #include "IntInput.h" 10 | 11 | template 12 | const char* IntInput::NAME = "integer"; 13 | 14 | template 15 | void IntInput::read(std::istream& in, const int*) 16 | { 17 | in >> items[0]; 18 | } 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /Processor/MatmulsTuple.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MatmulsTuple.h 3 | * 4 | */ 5 | 6 | #ifndef PROCESSOR_MATMULSTUPLE_H_ 7 | #define PROCESSOR_MATMULSTUPLE_H_ 8 | 9 | #include 10 | using namespace std; 11 | 12 | class MatmulsTuple 13 | { 14 | public: 15 | int dim[3]; 16 | int a, b, c; 17 | vector>> lengths; 18 | 19 | MatmulsTuple(const vector& args, int start); 20 | 21 | template 22 | void pre(const vector& source, vector& S, typename T::Protocol& protocol); 23 | template 24 | void post(vector& S, typename T::Protocol& protocol); 25 | 26 | template 27 | void run_matrix(SubProcessor& processor); 28 | }; 29 | 30 | #endif /* PROCESSOR_MATMULSMTUPLE_H_ */ -------------------------------------------------------------------------------- /Processor/MatmulsmTuple.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MatmulsmTuple.h 3 | * 4 | */ 5 | 6 | #ifndef PROCESSOR_MATMULSMTUPLE_H_ 7 | #define PROCESSOR_MATMULSMTUPLE_H_ 8 | 9 | #include 10 | 11 | using namespace std; 12 | 13 | class MatmulsmTuple 14 | { 15 | public: 16 | int dim[9]; 17 | long a, b; 18 | int c; 19 | vector>> lengths; 20 | 21 | MatmulsmTuple(const vector& args, ArithmeticProcessor* Proc, int start); 22 | 23 | template 24 | void pre(const vector& source, ArithmeticProcessor* Proc, typename T::Protocol& protocol); 25 | template 26 | void post(vector& S, typename T::Protocol& protocol); 27 | 28 | template 29 | void run_matrix(SubProcessor& processor, CheckVector& source); 30 | }; 31 | 32 | #endif /* PROCESSOR_MATMULSMTUPLE_H_ */ -------------------------------------------------------------------------------- /Processor/NoFilePrep.h: -------------------------------------------------------------------------------- 1 | /* 2 | * NoFilePrep.h 3 | * 4 | */ 5 | 6 | #ifndef PROCESSOR_NOFILEPREP_H_ 7 | #define PROCESSOR_NOFILEPREP_H_ 8 | 9 | #include "Data_Files.h" 10 | 11 | template 12 | class NoFilePrep : public Preprocessing 13 | { 14 | public: 15 | NoFilePrep(int, int, const string&, DataPositions& usage, int = -1) : 16 | Preprocessing(usage) 17 | { 18 | throw runtime_error("preprocessing from file disabled"); 19 | } 20 | }; 21 | 22 | #endif /* PROCESSOR_NOFILEPREP_H_ */ 23 | -------------------------------------------------------------------------------- /Processor/PrivateOutput.h: -------------------------------------------------------------------------------- 1 | /* 2 | * PrivateOutput.h 3 | * 4 | */ 5 | 6 | #ifndef PROCESSOR_PRIVATEOUTPUT_H_ 7 | #define PROCESSOR_PRIVATEOUTPUT_H_ 8 | 9 | #include 10 | using namespace std; 11 | 12 | template class SubProcessor; 13 | 14 | template 15 | class PrivateOutput 16 | { 17 | typedef typename T::open_type open_type; 18 | 19 | SubProcessor& proc; 20 | typename T::MAC_Check MC; 21 | deque masks; 22 | 23 | public: 24 | PrivateOutput(SubProcessor& proc); 25 | ~PrivateOutput(); 26 | 27 | void prepare_sending(const T& source, int player); 28 | void exchange(); 29 | typename T::clear finalize(int player); 30 | }; 31 | 32 | #endif /* PROCESSOR_PRIVATEOUTPUT_H_ */ 33 | -------------------------------------------------------------------------------- /Processor/RingOptions.h: -------------------------------------------------------------------------------- 1 | /* 2 | * RingOptions.h 3 | * 4 | */ 5 | 6 | #ifndef PROCESSOR_RINGOPTIONS_H_ 7 | #define PROCESSOR_RINGOPTIONS_H_ 8 | 9 | #include "Tools/ezOptionParser.h" 10 | #include 11 | using namespace std; 12 | 13 | class RingOptions 14 | { 15 | bool R_is_set; 16 | 17 | public: 18 | int R; 19 | 20 | RingOptions(ez::ezOptionParser& opt, int argc, const char** argv); 21 | 22 | int ring_size_from_opts_or_schedule(string progname); 23 | }; 24 | 25 | #endif /* PROCESSOR_RINGOPTIONS_H_ */ 26 | -------------------------------------------------------------------------------- /Processor/StrInput.h: -------------------------------------------------------------------------------- 1 | /* 2 | * StrInput.h 3 | * 4 | */ 5 | 6 | #ifndef PROCESSOR_STRINPUT_H_ 7 | #define PROCESSOR_STRINPUT_H_ 8 | 9 | #include 10 | 11 | #include "Math/bigint.h" 12 | #include "Math/Integer.h" 13 | 14 | template 15 | class StrInput_ 16 | { 17 | public: 18 | const static int N_DEST = 1; 19 | const static int N_PARAM = 0; 20 | const static char* NAME; 21 | 22 | const static int TYPE = 3; 23 | 24 | T items[N_DEST]; 25 | 26 | void read(std::istream& in, const int* params); 27 | }; 28 | 29 | template 30 | const char* StrInput_::NAME = "real number"; 31 | 32 | #ifdef LOW_PREC_INP 33 | typedef StrInput_ StrInput; 34 | #else 35 | typedef StrInput_ StrInput; 36 | #endif 37 | 38 | #endif /* PROCESSOR_STRINPUT_H_ */ 39 | -------------------------------------------------------------------------------- /Processor/ThreadQueue.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ThreadQueue.h 3 | * 4 | */ 5 | 6 | #ifndef PROCESSOR_THREADQUEUE_H_ 7 | #define PROCESSOR_THREADQUEUE_H_ 8 | 9 | #include "ThreadJob.h" 10 | 11 | class ThreadQueue 12 | { 13 | WaitQueue in, out; 14 | Lock lock; 15 | int left; 16 | NamedCommStats comm_stats; 17 | 18 | public: 19 | ThreadQueue() : 20 | left(0) 21 | { 22 | } 23 | 24 | bool available() 25 | { 26 | return left == 0; 27 | } 28 | 29 | void schedule(const ThreadJob& job); 30 | ThreadJob next(); 31 | void finished(const ThreadJob& job); 32 | void finished(const ThreadJob& job, const NamedCommStats& comm_stats); 33 | ThreadJob result(); 34 | 35 | void set_comm_stats(const NamedCommStats& new_comm_stats); 36 | NamedCommStats get_comm_stats(); 37 | }; 38 | 39 | #endif /* PROCESSOR_THREADQUEUE_H_ */ 40 | -------------------------------------------------------------------------------- /Processor/ThreadQueues.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ThreadQueues.h 3 | * 4 | */ 5 | 6 | #ifndef PROCESSOR_THREADQUEUES_H_ 7 | #define PROCESSOR_THREADQUEUES_H_ 8 | 9 | #include "Tools/WaitQueue.h" 10 | #include "ThreadJob.h" 11 | #include "ThreadQueue.h" 12 | 13 | class ThreadQueues : 14 | public vector 15 | { 16 | vector available; 17 | 18 | public: 19 | int find_available(); 20 | int get_n_per_thread(int n_items, int granularity = 1); 21 | // expects that the last slice is done by the caller 22 | int distribute(ThreadJob job, int n_items, int base = 0, 23 | int granularity = 1); 24 | int distribute_no_setup(ThreadJob job, int n_items, int base = 0, 25 | int granularity = 1, const vector* supplies = 0); 26 | void wrap_up(ThreadJob job); 27 | }; 28 | 29 | #endif /* PROCESSOR_THREADQUEUES_H_ */ 30 | -------------------------------------------------------------------------------- /Processor/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * config.h 3 | * 4 | */ 5 | 6 | #ifndef PROCESSOR_CONFIG_H_ 7 | #define PROCESSOR_CONFIG_H_ 8 | 9 | #ifdef REPLICATED 10 | #error REPLICATED flag is obsolete 11 | #endif 12 | 13 | #endif /* PROCESSOR_CONFIG_H_ */ 14 | -------------------------------------------------------------------------------- /Programs/Profiling-data/program-protocol: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FudanMPL/Garnet/89af954fd61628990a0e6faa9a29d9d5e4b17667/Programs/Profiling-data/program-protocol -------------------------------------------------------------------------------- /Programs/Source/Linear-ReLU-Test.mpc: -------------------------------------------------------------------------------- 1 | program.options_from_args() 2 | program.use_trunc_pr = True 3 | program.use_split(3) 4 | from Compiler import ml 5 | L=ml.Linear_Relu([1,2]) 6 | M=MultiArray([1,2], cint) 7 | A=MultiArray([1,2], sfix) 8 | M[0][0]=1 9 | M[0][1]=0 10 | A[0][0]=-1.0 11 | A[0][1]=-2.0 12 | L.set_mask(M) 13 | L.debug_output=True 14 | L.X=A 15 | L._forward() -------------------------------------------------------------------------------- /Programs/Source/aes_circuit.mpc: -------------------------------------------------------------------------------- 1 | from circuit import Circuit 2 | sb128 = sbits.get_type(128) 3 | key = sb128(0x2b7e151628aed2a6abf7158809cf4f3c) 4 | plaintext = sb128(0x6bc1bee22e409f96e93d7e117393172a) 5 | n = 1000 6 | aes128 = Circuit('aes_128') 7 | ciphertexts = aes128(sbitvec([key] * n), sbitvec([plaintext] * n)) 8 | ciphertexts.elements()[n - 1].reveal().print_reg() 9 | -------------------------------------------------------------------------------- /Programs/Source/bench-dt.mpc: -------------------------------------------------------------------------------- 1 | binary = 'binary' in program.args 2 | 3 | program.set_bit_length(32) 4 | 5 | n_train = int(program.args[1]) 6 | m = int(program.args[2]) 7 | 8 | try: 9 | n_levels = int(program.args[3]) 10 | except: 11 | n_levels = 1 12 | 13 | try: 14 | n_threads = int(program.args[4]) 15 | except: 16 | n_threads = None 17 | 18 | train = sint.Array(n_train), sint.Matrix(m, n_train) 19 | 20 | import decision_tree, util 21 | 22 | decision_tree.max_leaves = 2000 23 | 24 | if 'nearest' in program.args: 25 | sfix.round_nearest = True 26 | 27 | layers = decision_tree.TreeTrainer( 28 | train[1], train[0], n_levels, binary=binary, n_threads=n_threads).train() 29 | 30 | #decision_tree.output_decision_tree(layers) 31 | 32 | #decision_tree.test_decision_tree('foo', layers, *train) 33 | -------------------------------------------------------------------------------- /Programs/Source/davex-dt-inference.mpc: -------------------------------------------------------------------------------- 1 | import ents, util, math 2 | 3 | 4 | m = int(program.args[1]) # 特征+标签数 5 | test_samples = int(program.args[2]) # 测试样本数 6 | ents.label_number = int(program.args[3]) # 标签种类数 7 | ents.tree_h = int(program.args[4]) # 树高 8 | 9 | n_threads = 4 # 最大线程数 10 | 11 | program.use_split(2) 12 | program.use_trunc_pr=True 13 | 14 | label = sint.Array(test_samples) 15 | feature = sfix.Matrix(m -1 , test_samples) 16 | 17 | count = 0 18 | 19 | for i in range(test_samples): 20 | for j in range(0, m-1): 21 | feature[j][i] = sfix.get_input_from(1) 22 | label[i] = sint.get_input_from(1) 23 | 24 | 25 | 26 | 27 | 28 | dt = ents.DecisionTree( 29 | feature, label, ents.tree_h) 30 | 31 | dt.input_from(0) 32 | 33 | 34 | dt.predict_all(feature, label) 35 | 36 | 37 | -------------------------------------------------------------------------------- /Programs/Source/dt_adult.mpc: -------------------------------------------------------------------------------- 1 | program.use_trunc_pr=True 2 | m = 6 3 | n_train = 32561 4 | n_test = 16281 5 | attr_lengths = None 6 | 7 | 8 | try: 9 | n_threads = int(program.args[2]) 10 | except: 11 | n_threads = None 12 | 13 | 14 | 15 | train = sint.Array(n_train), sint.Matrix(m, n_train) 16 | test = sint.Array(n_test), sint.Matrix(m, n_test) 17 | 18 | for x in train + test: 19 | x.input_from(0) 20 | 21 | 22 | import decision_tree, util 23 | 24 | 25 | 26 | trainer = decision_tree.TreeTrainer( 27 | train[1], train[0], int(program.args[1]), attr_lengths=attr_lengths, 28 | n_threads=n_threads) 29 | trainer.debug_selection = 'debug_selection' in program.args 30 | trainer.debug_gini = True 31 | layers = trainer.train_with_testing(*test) 32 | 33 | #decision_tree.output_decision_tree(layers) 34 | -------------------------------------------------------------------------------- /Programs/Source/gale-shapley_tutorial.mpc: -------------------------------------------------------------------------------- 1 | from Compiler import gs 2 | from Compiler.path_oram import OptimalORAM 3 | 4 | mm = gs.Matchmaker(50, oram_type=OptimalORAM) 5 | mm.init_hard() 6 | mm.match() 7 | -------------------------------------------------------------------------------- /Programs/Source/gc_and.mpc: -------------------------------------------------------------------------------- 1 | from Compiler.GC.types import sbits, sbit, cbits 2 | 3 | 4 | import random 5 | 6 | n = 4096 7 | m = 1 8 | 9 | if len(program.args) > 1: 10 | n = int(program.args[1]) 11 | 12 | if len(program.args) > 2: 13 | m = int(program.args[2]) 14 | 15 | pack = min(n, 50) 16 | n = (n + pack - 1) // pack 17 | 18 | a = sbit(1) 19 | b = sbit.get_type(pack)(1) 20 | 21 | start_timer(1) 22 | @for_range(m) 23 | def f(_): 24 | for i in range(n): 25 | a * b 26 | stop_timer(1) 27 | -------------------------------------------------------------------------------- /Programs/Source/gc_oram.mpc: -------------------------------------------------------------------------------- 1 | prog = program 2 | 3 | prog.options.binary = -1 4 | 5 | from Compiler.GC.types import * 6 | from Compiler.GC.instructions import * 7 | 8 | bits.unit = 64 9 | 10 | from Compiler.circuit_oram import * 11 | from Compiler import circuit_oram 12 | 13 | import oram 14 | oram.n_threads = 1 15 | oram.n_threads_for_tree = 1 16 | 17 | # ORAM/array size 18 | n = 1000000 19 | 20 | # some parameters 21 | oram.max_demux_bits = 0 22 | circuit_oram.threshold = 128 23 | 24 | # Circuit ORAM 25 | oram_type = AtLeastOneRecursionPackedCircuitORAM 26 | 27 | # linear scan (no ORAM) 28 | #oram_type = LinearORAM 29 | 30 | oram = test_oram(oram_type, n, value_type=sbits, iterations=3) 31 | -------------------------------------------------------------------------------- /Programs/Source/l2h_comparison.mpc: -------------------------------------------------------------------------------- 1 | res = sint.load_mem(0) < sint.load_mem(1) 2 | res.store_in_mem(3) 3 | print_ln('comparison in VM: %s', res.reveal()) 4 | -------------------------------------------------------------------------------- /Programs/Source/l2h_multiplication.mpc: -------------------------------------------------------------------------------- 1 | (sint.load_mem(0) * sint.load_mem(1)).store_in_mem(2) 2 | -------------------------------------------------------------------------------- /Programs/Source/loan_fraud_xgboost.mpc: -------------------------------------------------------------------------------- 1 | 2 | m = 4 # 特征数 3 | n_train = 100 # 训练样本数量 4 | h = 3 # 树高 5 | tree_number = 3 # 树的数量 6 | 7 | n_threads = 4 # 最大线程数 8 | learning_rate = 0.5 # 学习率 9 | 10 | program.use_trunc_pr=True 11 | import xgboost, util, math 12 | 13 | xgboost.learning_rate = learning_rate 14 | train = sfix.Array(n_train), sint.Matrix(m, n_train) 15 | 16 | 17 | for x in train: 18 | x.input_from(0) 19 | 20 | trainer = xgboost.XGBoost( 21 | train[1], train[0], h=h, tree_number=tree_number, attr_lengths=None, 22 | n_threads=n_threads) 23 | trainer.fit() 24 | 25 | 26 | 27 | trainer.reveal_and_print() -------------------------------------------------------------------------------- /Programs/Source/mul_test.mpc: -------------------------------------------------------------------------------- 1 | a = sfix.Matrix(10, 10) 2 | b = sfix.Matrix(10, 10) 3 | #a.input_from(0) 4 | #b.input_from(0) 5 | c = a * b 6 | #for i in range(0,1): 7 | # for j in range(0,1): 8 | # print_ln("c = %s", c[i][j].reveal()) 9 | 10 | #a = sint(-1244112) 11 | #b = sint(-1111111) 12 | #c = a <= b 13 | #print_ln("c = %s", c.reveal()) 14 | -------------------------------------------------------------------------------- /Programs/Source/oram_tutorial.mpc: -------------------------------------------------------------------------------- 1 | from oram import OptimalORAM 2 | 3 | array = OptimalORAM(10000) 4 | array[1] = 1 5 | print_ln('%s', array[1].reveal()) 6 | -------------------------------------------------------------------------------- /Programs/Source/ss_psi_test.mpc: -------------------------------------------------------------------------------- 1 | table0 = sint.Matrix(3, 4) # 第0方的数据量为3行4列 2 | table1 = sint.Matrix(4, 3) # 第1方的数据量为4行3列 3 | 4 | for x in table0: 5 | x.input_from(0) 6 | 7 | for x in table1: 8 | x.input_from(1) 9 | 10 | 11 | merge_table, n = ss_psi_merge(table0, table1) 12 | 13 | 14 | -------------------------------------------------------------------------------- /Programs/Source/test2.mpc: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | 4 | ca = 5 5 | cb = 15 6 | cc = 25 7 | cr = 15 8 | 9 | 10 | 11 | a = cfix(ca) 12 | b = cfix(cb) 13 | c = cfix(cc) 14 | r = cfix(cr) 15 | x = sfix(10) 16 | 17 | reveal_val = (x+r).reveal() 18 | f = sfix(-3 * ca * cr + cb) 19 | g = sfix(3 * ca * cr * cr - 2 * cb * cr + cc) 20 | h = sfix(- ca * cr * cr * cr + cb * cr * cr - cc * cr) 21 | 22 | original = a * x * x * x + b * x * x + c * x 23 | optimize = a * reveal_val * reveal_val * reveal_val + f * reveal_val * reveal_val + g * reveal_val + h 24 | print_ln("original is %s, optimize is %s", original.reveal(), optimize.reveal()) 25 | -------------------------------------------------------------------------------- /Programs/Source/test_flow_optimization.mpc: -------------------------------------------------------------------------------- 1 | n = 10 ** 7 2 | a = regint.Array(n) 3 | b = regint.Array(n) 4 | 5 | for i in range(n): 6 | if i > 1000: 7 | a[i] = i 8 | 9 | if i < 1000: 10 | b[i] = -1 11 | else: 12 | b[i] = 2 * i 13 | 14 | def test(a, index, value): 15 | print_ln('expected %s got %s at %s', value, a[index], index) 16 | crash(a[index] != value) 17 | 18 | test(a, 999, 0) 19 | test(b, 999, -1) 20 | test(a, 10000, 10000) 21 | test(b, 10000, 20000) 22 | test(a, 1000000, 1000000) 23 | test(b, 1000000, 2000000) 24 | -------------------------------------------------------------------------------- /Programs/Source/test_gfa.mpc: -------------------------------------------------------------------------------- 1 | import sympy as sp 2 | import Compiler.mpc_math 3 | from gfapp import GFA 4 | import numpy as np 5 | 6 | sfix.set_precision(31, 63) 7 | 8 | # target function. 9 | @GFA(10, 31, 63, (-10,10)) 10 | def mysigmoid(x): 11 | return 1 / ((1 + sp.exp(-x))) 12 | 13 | print_ln('using GFA sigmoid') 14 | for i in range(-5, 5): 15 | actual = mysigmoid(sfix(i)) 16 | expected = 1 / ((1 + np.exp(-i))) 17 | print_ln('expected %s, got %s', str(expected), actual.reveal()) 18 | 19 | -------------------------------------------------------------------------------- /Programs/Source/test_gfa_preset.mpc: -------------------------------------------------------------------------------- 1 | from GFA.presets import sigmoid 2 | from GFA.presets import tanh 3 | from GFA.presets import soft_plus 4 | from GFA.presets import elu 5 | from GFA.presets import selu 6 | from GFA.presets import gelu 7 | from GFA.presets import snormal_dis 8 | 9 | sfix.set_precision(44, 96) 10 | sigmoid(sfix(0)) 11 | tanh(sfix(0)) 12 | soft_plus(sfix(0)) 13 | elu(sfix(0)) 14 | selu(sfix(0)) 15 | gelu(sfix(0)) 16 | snormal_dis(sfix(0)) -------------------------------------------------------------------------------- /Programs/Source/test_gopt.mpc: -------------------------------------------------------------------------------- 1 | from tensor import Tensor,autograd_function 2 | import functional as F 3 | from Compiler.types import * 4 | 5 | sfix.set_precision(30, 60) 6 | cfix.set_precision(30, 60) 7 | 8 | @for_range_opt(30) 9 | def _(i): 10 | x = MultiArray([1, 1], sfix) 11 | # x = Array(1, sfix) 12 | x.assign_vector(sfix(i)) 13 | input = Tensor(x, req_grad = True) 14 | 15 | out1 = F.gelu(input, approximate='tanh') 16 | out2 = input.relu() 17 | out3 = out1 - out2 18 | 19 | print_ln('======================') 20 | x.print_reveal_nested() 21 | out1.value.print_reveal_nested() 22 | out2.value.print_reveal_nested() 23 | out3.value.print_reveal_nested() 24 | 25 | -------------------------------------------------------------------------------- /Programs/Source/test_ins_merge.mpc: -------------------------------------------------------------------------------- 1 | from Compiler.types import * 2 | from Compiler.instructions import * 3 | 4 | x = MultiArray([2,2,2,2], sfix) 5 | for i in range(0,2): 6 | for j in range(0,2): 7 | for k in range(0, 2): 8 | for q in range(0, 2): 9 | x[i][j][k][q] = sfix(((i*j*k*q+i+j+k+q)%101)*1e-2) 10 | # x.print_reveal_nested() 11 | 12 | y = MultiArray([2,2,2,2], sfix) 13 | for i in range(0,2): 14 | for j in range(0,2): 15 | for k in range(0, 2): 16 | for q in range(0, 2): 17 | y[i][j][k][q] = sfix((i+j+k+q)) 18 | y.print_reveal_nested() 19 | 20 | for i in range(0,10): 21 | x[:] = x[:] - i * y[:] 22 | # break_point() 23 | # z.print_reveal_nested() 24 | # @for_range(5) 25 | # def _(i): 26 | # c = x.get_vector(i, 1) + y.get_vector(i, 1) 27 | # c.reveal() 28 | 29 | -------------------------------------------------------------------------------- /Programs/Source/test_joint_statistics.mpc: -------------------------------------------------------------------------------- 1 | from Compiler.types import Array 2 | import joint_statistics 3 | 4 | a = Array(10, sfix) 5 | for i in range(10): 6 | if i < 5: 7 | a[i] = i + 1 8 | elif i == 8: 9 | a[i] = 7 10 | else: 11 | a[i] = 6 12 | print_ln("%s ", a[i].reveal()) 13 | 14 | a_mean = a.mean().reveal() 15 | a_median = a.median().reveal() 16 | a_mode = a.mode().reveal() 17 | print_ln("%s",a_mean) 18 | print_ln("%s",a_median) 19 | print_ln("%s",a_mode) 20 | for i in range(10): 21 | print_ln("%s ", a[i].reveal()) -------------------------------------------------------------------------------- /Programs/Source/test_joint_statistics2.mpc: -------------------------------------------------------------------------------- 1 | from Compiler.types import Array 2 | import joint_statistics 3 | 4 | a = Array(10, sfix) 5 | for i in range(10): 6 | if i < 5: 7 | a[i] = i + 1 8 | elif i == 8: 9 | a[i] = 7 10 | else: 11 | a[i] = 6 12 | print_ln("%s ", a[i].reveal()) 13 | 14 | a_square = a.square().reveal(); 15 | for i in range(10): 16 | print_ln("%s",a_square[i]) 17 | a_variance = a.variance().reveal(); 18 | print_ln("%s",a_variance) 19 | a_std_dev = a.std_dev().reveal(); 20 | print_ln("%s",a_std_dev) -------------------------------------------------------------------------------- /Programs/Source/test_matmul_merge.mpc: -------------------------------------------------------------------------------- 1 | 2 | 3 | #program.use_trunc_pr = True 4 | 5 | A = sfix.Matrix(9, 4) 6 | B = sfix.Matrix(4, 9) 7 | C = sfix.Matrix(9, 9) 8 | 9 | 10 | for i in range(A.total_size()): 11 | A.assign_vector(sfix(i), i) 12 | 13 | for i in range(B.total_size()): 14 | B.assign_vector(sfix(i), i) 15 | 16 | for i in range(C.total_size()): 17 | C.assign_vector(sfix(i), i) 18 | 19 | 20 | C.assign_vector(A.direct_mul(B)) 21 | -------------------------------------------------------------------------------- /Programs/Source/test_mpsi.mpc: -------------------------------------------------------------------------------- 1 | n = 3 2 | 3 | print_str("begin psi\n") 4 | 5 | start_timer(1) 6 | mPSI(n) 7 | stop_timer(1) 8 | 9 | print_str("end psi\n") -------------------------------------------------------------------------------- /Programs/Source/test_onnx.mpc: -------------------------------------------------------------------------------- 1 | from Compiler.tensor import Tensor, reset_gloabal_store, reset_op_id 2 | import onnx 3 | from Compiler.library import * 4 | from Compiler.types import * 5 | program.use_trunc_pr = True 6 | 7 | from Compiler.onnxConverter.model import ConvertModel 8 | onnx_model = onnx.load("example.onnx") 9 | model = ConvertModel(onnx_model) 10 | print(model) 11 | 12 | x = MultiArray([1,32,10,10], sfix) 13 | @for_range(x.total_size()) 14 | def _(i): 15 | x.assign_vector(sfix(i/10), i) 16 | input = Tensor(x) 17 | y= model(input) -------------------------------------------------------------------------------- /Programs/Source/test_order.mpc: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | order = 8 4 | x = sfix(2) 5 | x_order = sfix.Array(order+1) 6 | x_order[0] = sfix(0) 7 | x_order[1] = x 8 | pre = 1 9 | cur = 2 10 | for i in range (math.ceil(math.log2(order))+1): 11 | for j in range(pre + 1, cur + 1): 12 | x_order[j] = x_order[:][pre] * x_order[:][j - pre] 13 | pre = cur 14 | cur = min(cur*2, order) 15 | 16 | #for i in range(order+1): 17 | # print_ln("%s order of x is %s", i, x_order[:][i].reveal()) -------------------------------------------------------------------------------- /Programs/Source/test_permute.mpc: -------------------------------------------------------------------------------- 1 | program.options_from_args() 2 | i = 3 3 | j = 3 4 | k = 5 5 | training_samples = MultiArray([i, j, k], sfix) 6 | tmp =1 7 | for x in range(i): 8 | for y in range(j): 9 | for z in range(k): 10 | indices = (x,y,z) 11 | sss = sfix(tmp) 12 | training_samples.assign_vector_by_indices(sss, *indices) 13 | tmp += 1 14 | 15 | training_samples.print_reveal_nested() 16 | tmp = training_samples.mean(dim = 0) 17 | tmp.print_reveal_nested() 18 | -------------------------------------------------------------------------------- /Programs/Source/test_psi.mpc: -------------------------------------------------------------------------------- 1 | f0 = 7 2 | f1 = 7 3 | n = 8 4 | 5 | print_str("begin psi") 6 | print_str("\n") 7 | 8 | val,num = PSI(n,f0,f1) 9 | 10 | print_str("num of intersection:") 11 | print_int(num) 12 | print_str("\n") 13 | 14 | print_ln("result=%s",val.reveal()) -------------------------------------------------------------------------------- /Programs/Source/test_psu.mpc: -------------------------------------------------------------------------------- 1 | table0 = sint.Matrix(3, 1) 2 | table1 = sint.Matrix(4, 1) 3 | 4 | for x in table0: 5 | x.input_from(0) # 从第0方读入数据 6 | 7 | for x in table1: 8 | x.input_from(1) # 从第1方读入数据 9 | 10 | union_id, flag_id = ss_psu(table0, table1) # 进行PSU并合并两个数据表 -------------------------------------------------------------------------------- /Programs/Source/test_sfix.mpc: -------------------------------------------------------------------------------- 1 | import Compiler.mpc_math 2 | import random 3 | import math 4 | 5 | n = 100 6 | cnt = 0 7 | 8 | for i in range(n): 9 | a = sfix.get_random(-1000,1000) 10 | b = sfix.get_random(-1000,1000) 11 | c = (a > b) 12 | clear_a = a.reveal() 13 | clear_b = b.reveal() 14 | d = (clear_a > clear_b) 15 | if(c.reveal() != d): 16 | print_ln("c is %s , a-b is %s", c.reveal(), (a-b).reveal()) -------------------------------------------------------------------------------- /Programs/Source/test_tanh.mpc: -------------------------------------------------------------------------------- 1 | import Compiler.mpc_math 2 | from gfapp import GFA 3 | 4 | def test(actual, expected): 5 | 6 | # you can reveal a number in order to print it 7 | 8 | actual = actual.reveal() 9 | print_ln('expected %s, got %s', expected, actual) 10 | 11 | 12 | sfix.set_precision(32, 96) 13 | 14 | a = [-0.964, -0.761, 0.000, 0.761, 0.964] 15 | 16 | mytanh = GFA('tanh') 17 | for i in range(0, 5): 18 | test(mytanh.At(sfix(i-2)) ,a[i]) 19 | -------------------------------------------------------------------------------- /Programs/Source/test_vssfield.mpc: -------------------------------------------------------------------------------- 1 | print_ln('result: %s', sint(123).reveal()) 2 | 3 | a=sint.get_input_from(0) 4 | b=sint.get_input_from(1) 5 | c=sint.get_input_from(2) 6 | sum=a+b+c 7 | print_ln('a=%s, b=%s, c=%s', a.reveal(), b.reveal(), c.reveal()) 8 | print_ln('Results=%s',sum.reveal()) 9 | 10 | e = a * c 11 | print_ln('a*c=%s', e.reveal()) 12 | 13 | f = (a < b) 14 | print_ln('a B[i] -------------------------------------------------------------------------------- /Programs/Source/xgboost-inference-mal.mpc: -------------------------------------------------------------------------------- 1 | m = 4 # 特征数 2 | h = 2 # 树高 3 | tree_number = 3 # 树的数量 4 | n_threads = 1 # 最大线程数 5 | test_samples = 51 # 测试样本数 6 | 7 | program.use_edabit(True) 8 | import xgboost_inference, util, math 9 | 10 | test = sfix.Array(test_samples), sint.Matrix(m, test_samples) 11 | 12 | for x in test: 13 | x.input_from(1) 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | inference = xgboost_inference.XGBoostInference( 23 | h=h, tree_number=tree_number, n_threads=n_threads, attribute_number=m, test_sample_number=test_samples) 24 | 25 | inference.input_from(0) 26 | 27 | 28 | inference.test(test[1], test[0]) 29 | 30 | 31 | -------------------------------------------------------------------------------- /Programs/Source/xgboost-inference-test.mpc: -------------------------------------------------------------------------------- 1 | m = 4 # 特征数 2 | h = 2 # 树高 3 | tree_number = 3 # 树的数量 4 | n_threads = 4 # 最大线程数 5 | test_samples = 51 # 测试样本数 6 | attribute_max_values = [ # 各个特征的最大值,用于在两方同态加密下使用 7 | 100, 8 | 100, 9 | 100, 10 | 100 11 | ] 12 | 13 | 14 | program.use_trunc_pr=True 15 | import xgboost, util, math 16 | 17 | test = sfix.Array(test_samples), sint.Matrix(m, test_samples) 18 | 19 | for x in test: 20 | x.input_from(1) 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | trainer = xgboost.XGBoost( 30 | h=h, tree_number=tree_number, n_threads=n_threads, attribute_number=m, attribute_max_values=attribute_max_values, test_sample_number=test_samples) 31 | 32 | trainer.input_from(0) 33 | 34 | 35 | trainer.test(test[1], test[0]) 36 | 37 | 38 | -------------------------------------------------------------------------------- /Programs/Source/xgboost-inference.mpc: -------------------------------------------------------------------------------- 1 | m = 4 # 特征数 2 | h = 2 # 树高 3 | tree_number = 3 # 树的数量 4 | n_threads = 1 # 最大线程数 5 | test_samples = 51 # 测试样本数 6 | attribute_max_values = [ # 各个特征的最大值,用于在两方同态加密下使用 7 | 100, 8 | 100, 9 | 100, 10 | 100 11 | ] 12 | 13 | 14 | program.use_split(3) 15 | program.use_trunc_pr=True 16 | import xgboost_inference, util, math 17 | 18 | test = sfix.Array(test_samples), sint.Matrix(m, test_samples) 19 | 20 | for x in test: 21 | x.input_from(1) 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | inference = xgboost_inference.XGBoostInference( 31 | h=h, tree_number=tree_number, n_threads=n_threads, attribute_number=m, test_sample_number=test_samples, attribute_max_values=attribute_max_values) 32 | 33 | inference.input_from(0) 34 | 35 | 36 | inference.test(test[1], test[0]) 37 | 38 | 39 | -------------------------------------------------------------------------------- /Programs/Source/xgboost.mpc: -------------------------------------------------------------------------------- 1 | 2 | m = 4 # 特征数 3 | n_train = 99 # 训练样本数量 4 | n_test = 51 # 测试样本数量 5 | h = 4 # 树高 6 | tree_number = 5 # 树的数量 7 | n_threads = 4 # 最大线程数 8 | learning_rate = 0.5 # 学习率 9 | 10 | program.use_trunc_pr=True 11 | import xgboost, util, math 12 | 13 | xgboost.learning_rate = learning_rate 14 | train = sfix.Array(n_train), sint.Matrix(m, n_train) 15 | test = sfix.Array(n_test), sint.Matrix(m, n_test) 16 | 17 | for x in train + test: 18 | x.input_from(0) 19 | print_ln("x = %s",x.reveal()) 20 | 21 | trainer = xgboost.XGBoost( 22 | train[1], train[0], h=h, tree_number=tree_number, attr_lengths=None, 23 | n_threads=n_threads) 24 | trainer.fit() 25 | trainer.test(test[1], test[0]) 26 | 27 | 28 | trainer.reveal_and_print() -------------------------------------------------------------------------------- /Protocols/BrainPrep.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BrainPrep.h 3 | * 4 | */ 5 | 6 | #ifndef PROTOCOLS_BRAINPREP_H_ 7 | #define PROTOCOLS_BRAINPREP_H_ 8 | 9 | #include "ReplicatedPrep.h" 10 | #include "Protocols/BrainShare.h" 11 | 12 | template 13 | class BrainPrep : public MaliciousRingPrep 14 | { 15 | typedef gfp_<2, (T::Z_BITS + 66) / 64> gfp2; 16 | 17 | public: 18 | static void basic_setup(Player&); 19 | 20 | BrainPrep(SubProcessor* proc, DataPositions& usage) : 21 | BufferPrep(usage), BitPrep(proc, usage), 22 | RingPrep(proc, usage), 23 | MaliciousDabitOnlyPrep(proc, usage), 24 | MaliciousRingPrep(proc, usage) 25 | { 26 | } 27 | 28 | void buffer_triples(); 29 | void buffer_inputs(int player); 30 | }; 31 | 32 | #endif /* PROTOCOLS_BRAINPREP_H_ */ 33 | -------------------------------------------------------------------------------- /Protocols/CowGearOptions.h: -------------------------------------------------------------------------------- 1 | /* 2 | * CowGearOptions.h 3 | * 4 | */ 5 | 6 | #ifndef PROTOCOLS_COWGEAROPTIONS_H_ 7 | #define PROTOCOLS_COWGEAROPTIONS_H_ 8 | 9 | #include "Tools/ezOptionParser.h" 10 | 11 | class CowGearOptions 12 | { 13 | bool use_top_gear; 14 | 15 | public: 16 | static CowGearOptions singleton; 17 | 18 | int covert_security; 19 | 20 | CowGearOptions(bool covert = true); 21 | CowGearOptions(ez::ezOptionParser& opt, int argc, const char** argv, 22 | bool covert = true); 23 | 24 | bool top_gear() 25 | { 26 | return use_top_gear; 27 | } 28 | 29 | void set_top_gear(bool use) 30 | { 31 | use_top_gear = use; 32 | } 33 | }; 34 | 35 | #endif /* PROTOCOLS_COWGEAROPTIONS_H_ */ 36 | -------------------------------------------------------------------------------- /Protocols/Dealer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Dealer.h 3 | * 4 | */ 5 | 6 | #ifndef PROTOCOLS_DEALER_H_ 7 | #define PROTOCOLS_DEALER_H_ 8 | 9 | #include "Beaver.h" 10 | 11 | template 12 | class Dealer : public Beaver 13 | { 14 | SeededPRNG G; 15 | 16 | public: 17 | Dealer(Player& P) : 18 | Beaver(P) 19 | { 20 | } 21 | 22 | T get_random() 23 | { 24 | if (T::real_shares(this->P)) 25 | return G.get(); 26 | else 27 | return {}; 28 | } 29 | 30 | vector get_relevant_players() 31 | { 32 | return vector(1, this->P.num_players() - 1); 33 | } 34 | }; 35 | 36 | #endif /* PROTOCOLS_DEALER_H_ */ 37 | -------------------------------------------------------------------------------- /Protocols/DealerMatrixPrep.h: -------------------------------------------------------------------------------- 1 | /* 2 | * DealerMatrixPrep.h 3 | * 4 | */ 5 | 6 | #ifndef PROTOCOLS_DEALERMATRIXPREP_H_ 7 | #define PROTOCOLS_DEALERMATRIXPREP_H_ 8 | 9 | #include "ShareMatrix.h" 10 | 11 | template 12 | class DealerMatrixPrep : public BufferPrep> 13 | { 14 | typedef BufferPrep> super; 15 | typedef typename T::LivePrep LivePrep; 16 | 17 | int n_rows, n_inner, n_cols; 18 | 19 | LivePrep* prep; 20 | 21 | public: 22 | DealerMatrixPrep(int n_rows, int n_inner, int n_cols, 23 | typename T::LivePrep&, DataPositions& usage); 24 | 25 | void set_protocol(typename ShareMatrix::Protocol&) 26 | { 27 | } 28 | 29 | void buffer_triples(); 30 | }; 31 | 32 | #endif /* PROTOCOLS_DEALERMATRIXPREP_H_ */ 33 | -------------------------------------------------------------------------------- /Protocols/FakeMC.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FakeMC.h 3 | * 4 | */ 5 | 6 | #ifndef PROTOCOLS_FAKEMC_H_ 7 | #define PROTOCOLS_FAKEMC_H_ 8 | 9 | #include "MAC_Check_Base.h" 10 | 11 | template 12 | class FakeMC : public MAC_Check_Base 13 | { 14 | public: 15 | FakeMC(typename T::mac_key_type, int = 0, int = 0) 16 | { 17 | } 18 | 19 | void exchange(const Player&) 20 | { 21 | for (auto& x : this->secrets) 22 | this->values.push_back(x); 23 | } 24 | 25 | FakeMC& get_part_MC() 26 | { 27 | return *this; 28 | } 29 | }; 30 | 31 | #endif /* PROTOCOLS_FAKEMC_H_ */ 32 | -------------------------------------------------------------------------------- /Protocols/HighGearKeyGen.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * KeyGen.cpp 3 | * 4 | */ 5 | 6 | #include "FHEOffline/DataSetup.h" 7 | #include "Processor/OnlineOptions.h" 8 | 9 | #include "Protocols/HighGearKeyGen.hpp" 10 | 11 | template<> 12 | void PartSetup::key_and_mac_generation(Player& P, 13 | MachineBase& machine, int, false_type) 14 | { 15 | HighGearKeyGen<0, 0>(P, params).run(*this, machine); 16 | } 17 | 18 | template<> 19 | void PartSetup::key_and_mac_generation(Player& P, MachineBase& machine, 20 | int, false_type) 21 | { 22 | HighGearKeyGen<0, 0>(P, params).run(*this, machine); 23 | } 24 | -------------------------------------------------------------------------------- /Protocols/LimitedPrep.h: -------------------------------------------------------------------------------- 1 | /* 2 | * LimitedPrep.h 3 | * 4 | */ 5 | 6 | #ifndef PROTOCOLS_LIMITEDPREP_H_ 7 | #define PROTOCOLS_LIMITEDPREP_H_ 8 | 9 | #include "ReplicatedPrep.h" 10 | 11 | template 12 | class LimitedPrep : public BufferPrep 13 | { 14 | DataPositions usage; 15 | 16 | void buffer_triples() { throw ran_out(); } 17 | void buffer_squares() { throw ran_out(); } 18 | void buffer_inverses() { throw ran_out(); } 19 | void buffer_bits() { throw ran_out(); } 20 | 21 | public: 22 | LimitedPrep(); 23 | ~LimitedPrep(); 24 | 25 | void set_protocol(typename T::Protocol& protocol); 26 | }; 27 | 28 | #endif /* PROTOCOLS_LIMITEDPREP_H_ */ 29 | -------------------------------------------------------------------------------- /Protocols/LimitedPrep.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * LimitedPrep.cpp 3 | * 4 | */ 5 | 6 | #ifndef PROTOCOLS_LIMITEDPREP_HPP 7 | #define PROTOCOLS_LIMITEDPREP_HPP 8 | 9 | #include "LimitedPrep.h" 10 | 11 | template 12 | LimitedPrep::LimitedPrep() : 13 | BufferPrep(usage) 14 | { 15 | } 16 | 17 | template 18 | LimitedPrep::~LimitedPrep() 19 | { 20 | #ifdef VERBOSE 21 | if (not this->triples.empty()) 22 | cerr << "Triples left" << endl; 23 | #endif 24 | } 25 | 26 | template 27 | void LimitedPrep::set_protocol(typename T::Protocol& protocol) 28 | { 29 | usage.set_num_players(protocol.P.num_players()); 30 | } 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /Protocols/LowGearKeyGen.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * LowGearKeyGen.cpp 3 | * 4 | */ 5 | 6 | #include "FHEOffline/DataSetup.h" 7 | #include "Processor/OnlineOptions.h" 8 | 9 | #include "Protocols/LowGearKeyGen.hpp" 10 | 11 | template<> 12 | void PairwiseSetup::key_and_mac_generation(Player& P, 13 | PairwiseMachine& machine, int, false_type) 14 | { 15 | LowGearKeyGen<0>(P, machine, params).run(*this); 16 | } 17 | 18 | template<> 19 | void PairwiseSetup::key_and_mac_generation(Player& P, 20 | PairwiseMachine& machine, int, false_type) 21 | { 22 | LowGearKeyGen<0>(P, machine, params).run(*this); 23 | } 24 | -------------------------------------------------------------------------------- /Protocols/MalRepRingOptions.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * MalRepRingOptions.cpp 3 | * 4 | */ 5 | 6 | #include "MalRepRingOptions.h" 7 | 8 | MalRepRingOptions MalRepRingOptions::singleton; 9 | 10 | MalRepRingOptions::MalRepRingOptions() 11 | { 12 | shuffle = false; 13 | } 14 | 15 | MalRepRingOptions::MalRepRingOptions(ez::ezOptionParser& opt, int argc, 16 | const char** argv) : MalRepRingOptions() 17 | { 18 | opt.add( 19 | "", // Default. 20 | 0, // Required? 21 | 0, // Number of args expected. 22 | 0, // Delimiter if expecting multiple args. 23 | "Shuffle sacrifice (default: disabled)", // Help description. 24 | "-SH", // Flag token. 25 | "--shuffle" // Flag token. 26 | ); 27 | opt.parse(argc, argv); 28 | shuffle = opt.isSet("-SH"); 29 | opt.resetArgs(); 30 | } 31 | -------------------------------------------------------------------------------- /Protocols/MalRepRingOptions.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MalRepRingOptions.h 3 | * 4 | */ 5 | 6 | #ifndef PROTOCOLS_MALREPRINGOPTIONS_H_ 7 | #define PROTOCOLS_MALREPRINGOPTIONS_H_ 8 | 9 | #include "Tools/ezOptionParser.h" 10 | 11 | class MalRepRingOptions 12 | { 13 | public: 14 | static MalRepRingOptions singleton; 15 | 16 | bool shuffle; 17 | 18 | MalRepRingOptions(); 19 | MalRepRingOptions(ez::ezOptionParser& opt, int argc, const char** argv); 20 | }; 21 | 22 | #endif /* PROTOCOLS_MALREPRINGOPTIONS_H_ */ 23 | -------------------------------------------------------------------------------- /Protocols/MaliciousRepPO.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MaliciousRepPO.h 3 | * 4 | */ 5 | 6 | #ifndef PROTOCOLS_MALICIOUSREPPO_H_ 7 | #define PROTOCOLS_MALICIOUSREPPO_H_ 8 | 9 | #include "Networking/Player.h" 10 | 11 | template 12 | class MaliciousRepPO 13 | { 14 | protected: 15 | Player& P; 16 | octetStream to_send; 17 | octetStream to_receive[2]; 18 | PointerVector secrets; 19 | 20 | public: 21 | MaliciousRepPO(Player& P); 22 | virtual ~MaliciousRepPO() {} 23 | 24 | void prepare_sending(const T& secret, int player); 25 | virtual void send(int player); 26 | virtual void receive(); 27 | typename T::clear finalize(const T& secret); 28 | typename T::clear finalize(); 29 | }; 30 | 31 | #endif /* PROTOCOLS_MALICIOUSREPPO_H_ */ 32 | -------------------------------------------------------------------------------- /Protocols/MaliciousShamirPO.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MaliciousShamirPO.h 3 | * 4 | */ 5 | 6 | #ifndef PROTOCOLS_MALICIOUSSHAMIRPO_H_ 7 | #define PROTOCOLS_MALICIOUSSHAMIRPO_H_ 8 | 9 | template 10 | class MaliciousShamirPO 11 | { 12 | protected: 13 | Player& P; 14 | 15 | octetStream to_send; 16 | vector to_receive; 17 | 18 | vector shares; 19 | typename T::Direct_MC MC; 20 | 21 | public: 22 | MaliciousShamirPO(Player& P); 23 | 24 | void prepare_sending(const T& secret, int player); 25 | void send(int player); 26 | void receive(); 27 | typename T::clear finalize(const T& secret); 28 | }; 29 | 30 | #endif /* PROTOCOLS_MALICIOUSSHAMIRPO_H_ */ 31 | -------------------------------------------------------------------------------- /Protocols/MamaPrep.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MamaPrep.h 3 | * 4 | */ 5 | 6 | #ifndef PROTOCOLS_MAMAPREP_H_ 7 | #define PROTOCOLS_MAMAPREP_H_ 8 | 9 | #include "MascotPrep.h" 10 | 11 | /** 12 | * MASCOT triple generation with multiple MACs 13 | */ 14 | template 15 | class MamaPrep : public MascotInputPrep, public MaliciousRingPrep 16 | { 17 | public: 18 | static void basic_setup(Player&) {}; 19 | static void teardown() {}; 20 | 21 | MamaPrep(SubProcessor* proc, DataPositions& usage); 22 | 23 | void buffer_triples(); 24 | }; 25 | 26 | #endif /* PROTOCOLS_MAMAPREP_H_ */ 27 | -------------------------------------------------------------------------------- /Protocols/Rep3Shuffler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Rep3Shuffler.h 3 | * 4 | */ 5 | 6 | #ifndef PROTOCOLS_REP3SHUFFLER_H_ 7 | #define PROTOCOLS_REP3SHUFFLER_H_ 8 | 9 | template 10 | class Rep3Shuffler 11 | { 12 | SubProcessor& proc; 13 | 14 | vector, 2>> shuffles; 15 | 16 | public: 17 | Rep3Shuffler(vector& a, size_t n, int unit_size, size_t output_base, 18 | size_t input_base, SubProcessor& proc); 19 | 20 | Rep3Shuffler(SubProcessor& proc); 21 | 22 | int generate(int n_shuffle); 23 | 24 | void apply(vector& a, size_t n, int unit_size, size_t output_base, 25 | size_t input_base, int handle, bool reverse); 26 | 27 | void inverse_permutation(vector& stack, size_t n, size_t output_base, 28 | size_t input_base); 29 | 30 | void del(int handle); 31 | }; 32 | 33 | #endif /* PROTOCOLS_REP3SHUFFLER_H_ */ 34 | -------------------------------------------------------------------------------- /Protocols/Rep4MC.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Rep4MC.h 3 | * 4 | */ 5 | 6 | #ifndef PROTOCOLS_REP4MC_H_ 7 | #define PROTOCOLS_REP4MC_H_ 8 | 9 | #include "MAC_Check_Base.h" 10 | 11 | template 12 | class Rep4MC : public MAC_Check_Base 13 | { 14 | Hash check_hash, receive_hash; 15 | 16 | public: 17 | Rep4MC(typename T::mac_key_type = {}, int = 0, int = 0) 18 | { 19 | } 20 | 21 | void exchange(const Player& P); 22 | void Check(const Player& P); 23 | 24 | Rep4MC& get_part_MC() 25 | { 26 | return *this; 27 | } 28 | }; 29 | 30 | #endif /* PROTOCOLS_REP4MC_H_ */ 31 | -------------------------------------------------------------------------------- /Protocols/ReplicatedPO.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ReplicatedPO.h 3 | * 4 | */ 5 | 6 | #ifndef PROTOCOLS_REPLICATEDPO_H_ 7 | #define PROTOCOLS_REPLICATEDPO_H_ 8 | 9 | #include "MaliciousRepPO.h" 10 | 11 | template 12 | class ReplicatedPO : public MaliciousRepPO 13 | { 14 | public: 15 | ReplicatedPO(Player& P) : 16 | MaliciousRepPO(P) 17 | { 18 | } 19 | 20 | void send(int player); 21 | void receive(); 22 | }; 23 | 24 | #endif /* PROTOCOLS_REPLICATEDPO_H_ */ 25 | -------------------------------------------------------------------------------- /Protocols/ReplicatedPO.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ReplicatedPO.cpp 3 | * 4 | */ 5 | 6 | #ifndef PROTOCOLS_REPLICATEDPO_HPP_ 7 | #define PROTOCOLS_REPLICATEDPO_HPP_ 8 | 9 | #include "ReplicatedPO.h" 10 | 11 | #include "MaliciousRepPO.hpp" 12 | 13 | template 14 | void ReplicatedPO::send(int player) 15 | { 16 | if (this->P.get_offset(player) == 2) 17 | this->P.send_to(player, this->to_send); 18 | } 19 | 20 | template 21 | void ReplicatedPO::receive() 22 | { 23 | this->P.receive_relative(1, this->to_receive[0]); 24 | } 25 | 26 | #endif /* PROTOCOLS_REPLICATEDPO_HPP_ */ -------------------------------------------------------------------------------- /Protocols/RingOnlyPrep.h: -------------------------------------------------------------------------------- 1 | /* 2 | * RingOnlyPrep.h 3 | * 4 | */ 5 | 6 | #ifndef PROTOCOLS_RINGONLYPREP_H_ 7 | #define PROTOCOLS_RINGONLYPREP_H_ 8 | 9 | #include "ReplicatedPrep.h" 10 | 11 | /** 12 | * Semi-honest daBit generation for computation modulo a power of two 13 | */ 14 | template 15 | class RingOnlyPrep : public virtual RingPrep 16 | { 17 | protected: 18 | RingOnlyPrep(SubProcessor* proc, DataPositions& usage) : 19 | BufferPrep(usage), BitPrep(proc, usage), 20 | RingPrep(proc, usage) 21 | { 22 | } 23 | 24 | void buffer_dabits_from_bits_without_check(vector>& dabits, 25 | int buffer_size, ThreadQueues* queues); 26 | }; 27 | 28 | #endif /* PROTOCOLS_RINGONLYPREP_H_ */ 29 | -------------------------------------------------------------------------------- /Protocols/SPDZ.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Multiplication.h 3 | * 4 | */ 5 | 6 | #ifndef PROTOCOLS_SPDZ_H_ 7 | #define PROTOCOLS_SPDZ_H_ 8 | 9 | #include "Beaver.h" 10 | 11 | #include 12 | using namespace std; 13 | 14 | template class SubProcessor; 15 | template class Share; 16 | class Player; 17 | 18 | /** 19 | * SPDZ protocol 20 | */ 21 | template 22 | class SPDZ : public Beaver 23 | { 24 | public: 25 | SPDZ(Player& P) : Beaver(P) 26 | { 27 | } 28 | 29 | static void assign(typename T::open_type& share, 30 | const typename T::open_type& clear, int my_num) 31 | { 32 | if (my_num == 0) 33 | share = clear; 34 | else 35 | share = 0; 36 | } 37 | 38 | int get_n_relevant_players() 39 | { 40 | return this->P.num_players(); 41 | } 42 | }; 43 | 44 | #endif /* PROTOCOLS_SPDZ_H_ */ 45 | -------------------------------------------------------------------------------- /Protocols/SPDZ2k.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDZ2k.h 3 | * 4 | */ 5 | 6 | #ifndef PROTOCOLS_SPDZ2K_H_ 7 | #define PROTOCOLS_SPDZ2K_H_ 8 | 9 | #include "SPDZ.h" 10 | 11 | template 12 | class SPDZ2k : public SPDZ 13 | { 14 | public: 15 | SPDZ2k(Player& P) : 16 | SPDZ(P) 17 | { 18 | } 19 | 20 | void exchange() 21 | { 22 | for (size_t i = 0; i < this->shares.size(); i++) 23 | this->MC->set_random_element({}); 24 | SPDZ::exchange(); 25 | } 26 | }; 27 | 28 | #endif /* PROTOCOLS_SPDZ2K_H_ */ 29 | -------------------------------------------------------------------------------- /Protocols/SemiPrep.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SemiPrep.h 3 | * 4 | */ 5 | 6 | #ifndef PROTOCOLS_SEMIPREP_H_ 7 | #define PROTOCOLS_SEMIPREP_H_ 8 | 9 | #include "MascotPrep.h" 10 | 11 | template class HemiPrep; 12 | 13 | /** 14 | * Semi-honest triple generation based on oblivious transfer 15 | */ 16 | template 17 | class SemiPrep : public virtual OTPrep, public virtual SemiHonestRingPrep 18 | { 19 | friend class HemiPrep; 20 | 21 | public: 22 | SemiPrep(SubProcessor* proc, DataPositions& usage); 23 | 24 | void buffer_triples(); 25 | 26 | void buffer_dabits(ThreadQueues* queues); 27 | 28 | void get_one_no_count(Dtype dtype, T& a); 29 | 30 | bool bits_from_dabits(); 31 | }; 32 | 33 | #endif /* PROTOCOLS_SEMIPREP_H_ */ 34 | -------------------------------------------------------------------------------- /Protocols/ShareInterface.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ShareInterface.cpp 3 | * 4 | */ 5 | 6 | #include "ShareInterface.h" 7 | 8 | const int ShareInterface::default_length; 9 | 10 | const false_type ShareInterface::triple_matmul; 11 | -------------------------------------------------------------------------------- /Protocols/ShareVector.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ShareVector.cpp 3 | * 4 | */ 5 | 6 | #include "ShareVector.h" 7 | #include "FHE/FFT.h" 8 | 9 | template 10 | void ShareVector::fft(const FFT_Data& fftd) 11 | { 12 | array, 2> data; 13 | for (auto& share : *this) 14 | { 15 | data[0].push_back({share.get_share(), fftd.get_prD()}); 16 | data[1].push_back({share.get_mac(), fftd.get_prD()}); 17 | } 18 | 19 | for (auto& x : data) 20 | { 21 | if (fftd.get_twop() == 0) 22 | FFT_Iter2(x, fftd.phi_m(), fftd.get_root(0), fftd.get_prD()); 23 | else 24 | FFT_non_power_of_two(x, x, fftd); 25 | } 26 | 27 | for (int i = 0; i < fftd.phi_m(); i++) 28 | { 29 | typedef typename U::clear clear; 30 | (*this)[i] = {clear(data[0][i], fftd.get_prD()), clear(data[1][i], fftd.get_prD())}; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Protocols/SohoPrep.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SohoPrep.h 3 | * 4 | */ 5 | 6 | #ifndef PROTOCOLS_SOHOPREP_H_ 7 | #define PROTOCOLS_SOHOPREP_H_ 8 | 9 | /** 10 | * Semi-honest preprocessing with somewhat homomorphic encryption 11 | */ 12 | template 13 | class SohoPrep : public SemiHonestRingPrep 14 | { 15 | typedef typename T::clear::FD FD; 16 | 17 | static PartSetup* setup; 18 | static Lock lock; 19 | 20 | public: 21 | static void basic_setup(Player& P); 22 | static void teardown(); 23 | 24 | SohoPrep(SubProcessor* proc, DataPositions& usage) : 25 | BufferPrep(usage), 26 | BitPrep(proc, usage), RingPrep(proc, usage), 27 | SemiHonestRingPrep(proc, usage) 28 | { 29 | } 30 | 31 | void buffer_triples(); 32 | void buffer_squares(); 33 | void buffer_bits(); 34 | }; 35 | 36 | #endif /* PROTOCOLS_SOHOPREP_H_ */ 37 | -------------------------------------------------------------------------------- /Protocols/SohoShare.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SohoShare.h 3 | * 4 | */ 5 | 6 | #ifndef PROTOCOLS_SOHOSHARE_H_ 7 | #define PROTOCOLS_SOHOSHARE_H_ 8 | 9 | #include "SemiShare.h" 10 | 11 | template class SohoPrep; 12 | 13 | template 14 | class SohoShare : public SemiShare 15 | { 16 | typedef SohoShare This; 17 | typedef SemiShare super; 18 | 19 | public: 20 | typedef SemiMC MAC_Check; 21 | typedef DirectSemiMC Direct_MC; 22 | typedef SemiInput Input; 23 | typedef ::PrivateOutput PrivateOutput; 24 | typedef SPDZ Protocol; 25 | typedef SohoPrep LivePrep; 26 | 27 | static const bool needs_ot = false; 28 | 29 | SohoShare() 30 | { 31 | } 32 | 33 | template 34 | SohoShare(const U& other) : 35 | super(other) 36 | { 37 | } 38 | }; 39 | 40 | #endif /* PROTOCOLS_SOHOSHARE_H_ */ 41 | -------------------------------------------------------------------------------- /Protocols/SquarePrep.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SquarePrep.h 3 | * 4 | */ 5 | 6 | #ifndef PROTOCOLS_SQUAREPREP_H_ 7 | #define PROTOCOLS_SQUAREPREP_H_ 8 | 9 | #include "ReplicatedPrep.h" 10 | 11 | template 12 | void generate_squares(vector>& squares, int n_squares, 13 | U* protocol); 14 | 15 | template 16 | class SquarePrep : public BufferPrep 17 | { 18 | void buffer_triples() 19 | { 20 | throw runtime_error("no triples here"); 21 | } 22 | 23 | void buffer_squares() 24 | { 25 | generate_squares(this->squares, this->buffer_size, 26 | &this->proc->protocol); 27 | } 28 | 29 | public: 30 | SquarePrep(DataPositions& usage) : 31 | BufferPrep(usage) 32 | { 33 | } 34 | 35 | void set_protocol(typename T::Protocol&) 36 | { 37 | } 38 | }; 39 | 40 | #endif /* PROTOCOLS_SQUAREPREP_H_ */ 41 | -------------------------------------------------------------------------------- /Protocols/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * config.h 3 | * 4 | */ 5 | 6 | #ifndef PROTOCOLS_CONFIG_H_ 7 | #define PROTOCOLS_CONFIG_H_ 8 | 9 | #ifndef DEFAULT_SECURITY 10 | #define DEFAULT_SECURITY 40 11 | #endif 12 | 13 | #endif /* PROTOCOLS_CONFIG_H_ */ 14 | -------------------------------------------------------------------------------- /Scripts/PSI-Test/run_mpsi.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | param=$1 4 | 5 | case $param in 6 | "c") 7 | ./compile.py -F 64 test_mpsi 8 | ;; 9 | "x") 10 | sudo make -j 8 replicated-ring-party.x 11 | ;; 12 | "0") 13 | sudo ./replicated-ring-party.x -I 0 test_mpsi 14 | ;; 15 | "1") 16 | sudo ./replicated-ring-party.x -I 1 test_mpsi 17 | ;; 18 | "2") 19 | sudo ./replicated-ring-party.x -I 2 test_mpsi 20 | ;; 21 | "t") 22 | sudo bash Scripts/semi2k.sh test_psi > Scripts/PSI-Test/out.txt 23 | esac -------------------------------------------------------------------------------- /Scripts/PSI-Test/run_psi.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | param=$1 4 | 5 | case $param in 6 | "c") 7 | sudo ./compile.py -F 64 test_psi -v -C -K psi_cisc 8 | ;; 9 | "r") 10 | sudo ./compile.py -F 64 test_psi 11 | ;; 12 | "x") 13 | sudo make -j 8 semi2k-party.x 14 | ;; 15 | "0") 16 | sudo ./semi2k-party.x -N 2 -p 0 test_psi 17 | ;; 18 | "1") 19 | sudo ./semi2k-party.x -N 2 -p 1 test_psi 20 | ;; 21 | "t") 22 | sudo bash Scripts/semi2k.sh test_psi > Scripts/PSI-Test/out.txt 23 | esac -------------------------------------------------------------------------------- /Scripts/atlas.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | HERE=$(cd `dirname $0`; pwd) 4 | SPDZROOT=$HERE/.. 5 | 6 | export PLAYERS=${PLAYERS:-3} 7 | 8 | if test "$THRESHOLD"; then 9 | t="-T $THRESHOLD" 10 | fi 11 | 12 | . $HERE/run-common.sh 13 | 14 | run_player atlas-party.x $* $t || exit 1 15 | -------------------------------------------------------------------------------- /Scripts/brain.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | HERE=$(cd `dirname $0`; pwd) 4 | SPDZROOT=$HERE/.. 5 | 6 | export PLAYERS=3 7 | 8 | . $HERE/run-common.sh 9 | 10 | run_player brain-party.x $* || exit 1 11 | -------------------------------------------------------------------------------- /Scripts/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | function build 4 | { 5 | echo ARCH = $1 >> CONFIG.mine 6 | echo GDEBUG = >> CONFIG.mine 7 | root=`pwd` 8 | cd deps/libOTe 9 | rm -R out 10 | python3 build.py --install=$root/local -- -DENABLE_SOFTSPOKEN_OT=ON -DBUILD_SHARED_LIBS=0 -DCMAKE_INSTALL_LIBDIR=lib $3 11 | cd $root 12 | make clean 13 | rm -R static 14 | mkdir static 15 | make -j 4 static-release || exit 1 16 | mkdir bin 17 | dest=bin/`uname`-$2 18 | rm -R $dest 19 | mv static $dest 20 | strip $dest/* 21 | } 22 | 23 | make deps/libOTe/libOTe 24 | 25 | echo AVX_OT = 0 >> CONFIG.mine 26 | build '-maes -mpclmul -DCHECK_AES -DCHECK_PCLMUL -DCHECK_AVX' amd64 -DENABLE_AVX=OFF 27 | 28 | echo AVX_OT = 1 >> CONFIG.mine 29 | build '-msse4.1 -maes -mpclmul -mavx -mavx2 -mbmi2 -madx -DCHECK_ADX' avx2 -DENABLE_AVX=ON 30 | -------------------------------------------------------------------------------- /Scripts/ccd.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | HERE=$(cd `dirname $0`; pwd) 4 | SPDZROOT=$HERE/.. 5 | 6 | export PLAYERS=${PLAYERS:-3} 7 | 8 | . $HERE/run-common.sh 9 | 10 | run_player ccd-party.x $* || exit 1 11 | -------------------------------------------------------------------------------- /Scripts/chaigear.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | HERE=$(cd `dirname $0`; pwd) 4 | SPDZROOT=$HERE/.. 5 | 6 | . $HERE/run-common.sh 7 | 8 | run_player chaigear-party.x $* || exit 1 9 | -------------------------------------------------------------------------------- /Scripts/compile-for-emulation.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | pypy3 ./compile.py -CDR 64 -K '' $* 4 | -------------------------------------------------------------------------------- /Scripts/convert.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | Scripts/adult_prepare.py mixed 4 | 5 | out_dir=Player-Data 6 | test -e $out_dir || mkdir $out_dir 7 | 8 | cp mixed $out_dir/Input-P0-0 9 | -------------------------------------------------------------------------------- /Scripts/cowgear.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | HERE=$(cd `dirname $0`; pwd) 4 | SPDZROOT=$HERE/.. 5 | 6 | . $HERE/run-common.sh 7 | 8 | run_player cowgear-party.x $* || exit 1 9 | -------------------------------------------------------------------------------- /Scripts/data_prepare_for_xgboost.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | import csv 3 | import sys 4 | import pandas as pd 5 | 6 | data_name = sys.argv[1] 7 | 8 | 9 | output_data = [] 10 | for suffix in 'train', 'test': 11 | file_name = './Data/%s_%s.csv' % (data_name, suffix) 12 | data = pd.read_csv(file_name, header=None) 13 | data = data.transpose() 14 | x = data[:-1] 15 | y = data[-1:] 16 | x = x.astype("int") 17 | y = y.astype("int") 18 | output_data = output_data + y.values.tolist() 19 | output_data = output_data + x.values.tolist() 20 | 21 | 22 | print("file:", file_name) 23 | print('items:', len(x.columns)) 24 | print('attributes:', len(data) - 1) 25 | 26 | 27 | 28 | output_file = open("./Player-Data/Input-P0-0", 'w') 29 | 30 | for line in output_data: 31 | output_file.write(" ".join(str(i) for i in line)) 32 | output_file.write("\n") 33 | output_file.close() -------------------------------------------------------------------------------- /Scripts/dealer-ring.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | HERE=$(cd `dirname $0`; pwd) 4 | SPDZROOT=$HERE/.. 5 | 6 | export PLAYERS=${PLAYERS:-3} 7 | 8 | . $HERE/run-common.sh 9 | 10 | run_player dealer-ring-party.x $* || exit 1 11 | -------------------------------------------------------------------------------- /Scripts/decompile.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import sys, os 4 | 5 | sys.path.append('.') 6 | 7 | from Compiler.instructions_base import Instruction 8 | from Compiler.program import * 9 | 10 | if len(sys.argv) <= 1: 11 | print('Usage: %s ' % sys.argv[0]) 12 | 13 | for tapename in Program.read_tapes(sys.argv[1]): 14 | with open('Programs/Bytecode/%s.asm' % tapename, 'w') as out: 15 | for i, inst in enumerate(Tape.read_instructions(tapename)): 16 | print(inst, '#', i, file=out) 17 | -------------------------------------------------------------------------------- /Scripts/direct_compilation_example.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import sys, os 4 | sys.path.append(os.curdir) 5 | 6 | from Compiler.program import Program, defaults 7 | 8 | opts = defaults() 9 | opts.ring = 64 10 | 11 | prog = Program(['direct_compilation'], opts) 12 | 13 | from Compiler.library import print_ln 14 | from Compiler.types import sint 15 | 16 | print_ln('%s', (sint(0) < sint(1)).reveal()) 17 | 18 | prog.finalize() 19 | 20 | import subprocess 21 | subprocess.run(['./emulate.x', 'direct_compilation']) 22 | -------------------------------------------------------------------------------- /Scripts/download.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | wget -nc -q https://archive.ics.uci.edu/ml/machine-learning-databases/adult/adult.{data,test} || exit 1 4 | -------------------------------------------------------------------------------- /Scripts/emulate-append.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | . $(dirname $0)/run-common.sh 4 | prog=${1%.sch} 5 | prog=${prog##*/} 6 | shift 7 | $prefix ./emulate.x $prog $* 2>&1 | tee -a logs/emulate-append-$prog 8 | -------------------------------------------------------------------------------- /Scripts/emulate.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | . $(dirname $0)/run-common.sh 4 | prog=${1%.sch} 5 | prog=${prog##*/} 6 | shift 7 | $prefix ./emulate.x $prog $* 2>&1 | tee logs/emulate-$prog 8 | -------------------------------------------------------------------------------- /Scripts/fake-spdz-real-bmr.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | HERE=$(cd `dirname $0`; pwd) 4 | SPDZROOT=$HERE/.. 5 | 6 | . $HERE/run-common.sh 7 | 8 | run_player real-bmr-party.x $* -F || exit 1 9 | -------------------------------------------------------------------------------- /Scripts/fixed-rep-to-float.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import sys, operator 4 | 5 | try: 6 | f = int(sys.argv[2]) 7 | except: 8 | f = 12 9 | 10 | try: 11 | filename = sys.argv[3] 12 | except: 13 | filename = 'Player-Data/Input-P0-0' 14 | 15 | out = open(filename, 'w') 16 | 17 | for line in open(sys.argv[1]): 18 | line = (line.strip()) 19 | if line: 20 | x = (line.split(' ')) 21 | out.write(' '.join(str(int(xx) / 2**f) for xx in x)) 22 | out.write('\n') 23 | -------------------------------------------------------------------------------- /Scripts/fixed-rep-to-raw.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import sys, operator, struct 4 | 5 | try: 6 | filename = sys.argv[3] 7 | except: 8 | filename = 'Player-Data/Private-Input-0' 9 | 10 | out = open(filename, 'bw') 11 | 12 | for line in open(sys.argv[1]): 13 | line = (line.strip()) 14 | if line: 15 | x = (line.split(' ')) 16 | for xx in x: 17 | out.write(struct.pack('' % sys.argv[0]) 13 | 14 | res = collections.defaultdict(lambda: 0) 15 | m = 0 16 | 17 | tapename = next(Program.read_tapes(sys.argv[1])) 18 | res = Tape.ReqNum() 19 | for inst in Tape.read_instructions(tapename): 20 | res.update(inst.get_usage()) 21 | 22 | for x in res.pretty(): 23 | print(x) 24 | -------------------------------------------------------------------------------- /Scripts/ps-rep-bin.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | HERE=$(cd `dirname $0`; pwd) 4 | SPDZROOT=$HERE/.. 5 | 6 | export PLAYERS=3 7 | 8 | . $HERE/run-common.sh 9 | 10 | run_player ps-rep-bin-party.x $* || exit 1 11 | -------------------------------------------------------------------------------- /Scripts/ps-rep-field.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | HERE=$(cd `dirname $0`; pwd) 4 | SPDZROOT=$HERE/.. 5 | 6 | export PLAYERS=3 7 | 8 | . $HERE/run-common.sh 9 | 10 | run_player ps-rep-field-party.x $* || exit 1 11 | -------------------------------------------------------------------------------- /Scripts/ps-rep-ring.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | HERE=$(cd `dirname $0`; pwd) 4 | SPDZROOT=$HERE/.. 5 | 6 | export PLAYERS=3 7 | 8 | . $HERE/run-common.sh 9 | 10 | run_player ps-rep-ring-party.x $* || exit 1 11 | -------------------------------------------------------------------------------- /Scripts/real-bmr.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | HERE=$(cd `dirname $0`; pwd) 4 | SPDZROOT=$HERE/.. 5 | 6 | . $HERE/run-common.sh 7 | 8 | run_player real-bmr-party.x $* || exit 1 9 | -------------------------------------------------------------------------------- /Scripts/rep-bmr.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | HERE=$(cd `dirname $0`; pwd) 4 | SPDZROOT=$HERE/.. 5 | 6 | export PLAYERS=${PLAYERS:-3} 7 | 8 | . $HERE/run-common.sh 9 | 10 | run_player rep-bmr-party.x $* || exit 1 11 | -------------------------------------------------------------------------------- /Scripts/rep-field.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | HERE=$(cd `dirname $0`; pwd) 4 | SPDZROOT=$HERE/.. 5 | 6 | export PLAYERS=3 7 | 8 | . $HERE/run-common.sh 9 | 10 | run_player replicated-field-party.x $* || exit 1 11 | -------------------------------------------------------------------------------- /Scripts/rep4-ring.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | HERE=$(cd `dirname $0`; pwd) 4 | SPDZROOT=$HERE/.. 5 | 6 | export PLAYERS=4 7 | 8 | . $HERE/run-common.sh 9 | 10 | run_player rep4-ring-party.x $* || exit 1 11 | -------------------------------------------------------------------------------- /Scripts/replicated.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | HERE=$(cd `dirname $0`; pwd) 4 | SPDZROOT=$HERE/.. 5 | 6 | export PLAYERS=3 7 | 8 | . $HERE/run-common.sh 9 | 10 | run_player replicated-bin-party.x $* || exit 1 11 | -------------------------------------------------------------------------------- /Scripts/ring-only-online.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | HERE=$(cd `dirname $0`; pwd) 4 | SPDZROOT=$HERE/.. 5 | 6 | export PLAYERS=3 7 | 8 | . $HERE/run-common.sh 9 | 10 | run_player replicated-ring-party.x -F $* || exit 1 11 | -------------------------------------------------------------------------------- /Scripts/ring.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | HERE=$(cd `dirname $0`; pwd) 4 | SPDZROOT=$HERE/.. 5 | 6 | export PLAYERS=3 7 | 8 | . $HERE/run-common.sh 9 | 10 | run_player replicated-ring-party.x $* || exit 1 11 | -------------------------------------------------------------------------------- /Scripts/rss-with-conversion.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | HERE=$(cd `dirname $0`; pwd) 4 | SPDZROOT=$HERE/.. 5 | 6 | export PLAYERS=3 7 | 8 | . $HERE/run-common.sh 9 | 10 | run_player rss-with-conversion-party.x $* || exit 1 11 | -------------------------------------------------------------------------------- /Scripts/run-online.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | HERE=$(cd `dirname $0`; pwd) 4 | SPDZROOT=$HERE/.. 5 | 6 | . $HERE/run-common.sh 7 | 8 | run_player Player-Online.x $* || exit 1 9 | -------------------------------------------------------------------------------- /Scripts/semi-bin.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | HERE=$(cd `dirname $0`; pwd) 4 | SPDZROOT=$HERE/.. 5 | 6 | . $HERE/run-common.sh 7 | 8 | run_player semi-bin-party.x $* || exit 1 9 | -------------------------------------------------------------------------------- /Scripts/semi-bmr.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | HERE=$(cd `dirname $0`; pwd) 4 | SPDZROOT=$HERE/.. 5 | 6 | . $HERE/run-common.sh 7 | 8 | run_player semi-bmr-party.x $* || exit 1 9 | -------------------------------------------------------------------------------- /Scripts/semi.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | HERE=$(cd `dirname $0`; pwd) 4 | SPDZROOT=$HERE/.. 5 | 6 | . $HERE/run-common.sh 7 | 8 | run_player semi-party.x $* || exit 1 9 | -------------------------------------------------------------------------------- /Scripts/semi2k-with-conversion.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | HERE=$(cd `dirname $0`; pwd) 4 | SPDZROOT=$HERE/.. 5 | 6 | . $HERE/run-common.sh 7 | 8 | run_player semi2k-with-conversion-party.x $* || exit 1 9 | -------------------------------------------------------------------------------- /Scripts/semi2k.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | HERE=$(cd `dirname $0`; pwd) 4 | SPDZROOT=$HERE/.. 5 | 6 | . $HERE/run-common.sh 7 | 8 | run_player semi2k-party.x $* || exit 1 9 | -------------------------------------------------------------------------------- /Scripts/setup-clients.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | n=$1 4 | 5 | test -e Player-Data || mkdir Player-Data 6 | 7 | echo Setting up SSL for $n parties 8 | 9 | for i in `seq 0 $[n-1]`; do 10 | openssl req -newkey rsa -nodes -x509 -out Player-Data/C$i.pem -keyout Player-Data/C$i.key -subj "/CN=C$i" 11 | done 12 | 13 | c_rehash Player-Data 14 | -------------------------------------------------------------------------------- /Scripts/setup-ssl.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # brew-installed OpenSSL on MacOS 4 | PATH=/usr/local/opt/openssl/bin:$PATH 5 | 6 | n=${1:-4} 7 | ssl_dir=${2:-"Player-Data"} 8 | 9 | test -e $ssl_dir || mkdir $ssl_dir 10 | 11 | echo Setting up SSL for $n parties 12 | 13 | for i in `seq 0 $[n-1]`; do 14 | openssl req -newkey rsa -nodes -x509 -out $ssl_dir/P$i.pem -keyout $ssl_dir/P$i.key -subj "/CN=P$i" 15 | done 16 | 17 | c_rehash $ssl_dir -------------------------------------------------------------------------------- /Scripts/shamir-bmr.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | HERE=$(cd `dirname $0`; pwd) 4 | SPDZROOT=$HERE/.. 5 | 6 | export PLAYERS=${PLAYERS:-3} 7 | 8 | . $HERE/run-common.sh 9 | 10 | run_player shamir-bmr-party.x $* || exit 1 11 | -------------------------------------------------------------------------------- /Scripts/shamir.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | HERE=$(cd `dirname $0`; pwd) 4 | SPDZROOT=$HERE/.. 5 | 6 | export PLAYERS=${PLAYERS:-3} 7 | 8 | if test "$THRESHOLD"; then 9 | t="-T $THRESHOLD" 10 | fi 11 | 12 | . $HERE/run-common.sh 13 | 14 | run_player shamir-party.x $* $t || exit 1 15 | -------------------------------------------------------------------------------- /Scripts/sml.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | HERE=$(cd `dirname $0`; pwd) 4 | SPDZROOT=$HERE/.. 5 | 6 | . $HERE/run-common.sh 7 | 8 | run_player sml-party.x $* || exit 1 9 | -------------------------------------------------------------------------------- /Scripts/soho.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | HERE=$(cd `dirname $0`; pwd) 4 | SPDZROOT=$HERE/.. 5 | 6 | . $HERE/run-common.sh 7 | 8 | run_player soho-party.x $* || exit 1 9 | -------------------------------------------------------------------------------- /Scripts/spdz2k.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | HERE=$(cd `dirname $0`; pwd) 4 | SPDZROOT=$HERE/.. 5 | 6 | . $HERE/run-common.sh 7 | 8 | run_player spdz2k-party.x $* || exit 1 9 | -------------------------------------------------------------------------------- /Scripts/sy-rep-field.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | HERE=$(cd `dirname $0`; pwd) 4 | SPDZROOT=$HERE/.. 5 | 6 | export PLAYERS=3 7 | 8 | . $HERE/run-common.sh 9 | 10 | run_player sy-rep-field-party.x $* || exit 1 11 | -------------------------------------------------------------------------------- /Scripts/sy-rep-ring.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | HERE=$(cd `dirname $0`; pwd) 4 | SPDZROOT=$HERE/.. 5 | 6 | export PLAYERS=3 7 | 8 | . $HERE/run-common.sh 9 | 10 | run_player sy-rep-ring-party.x $* || exit 1 11 | -------------------------------------------------------------------------------- /Scripts/sy-shamir.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | HERE=$(cd `dirname $0`; pwd) 4 | SPDZROOT=$HERE/.. 5 | 6 | export PLAYERS=${PLAYERS:-3} 7 | 8 | . $HERE/run-common.sh 9 | 10 | run_player sy-shamir-party.x $* || exit 1 11 | -------------------------------------------------------------------------------- /Scripts/temi.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | HERE=$(cd `dirname $0`; pwd) 4 | SPDZROOT=$HERE/.. 5 | 6 | . $HERE/run-common.sh 7 | 8 | run_player temi-party.x $* || exit 1 9 | -------------------------------------------------------------------------------- /Scripts/test_ecdsa.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | echo SECURE = -DINSECURE >> CONFIG.mine 4 | touch ECDSA/Fake-ECDSA.cpp 5 | 6 | make -j4 ecdsa Fake-ECDSA.x secure.x 7 | 8 | run() 9 | { 10 | port=$[RANDOM+1024] 11 | if ! { 12 | for j in $(seq 0 $2); do 13 | ./$1-ecdsa-party.x -p $j 1 2>/dev/null & true 14 | done 15 | wait 16 | } | grep "Online checking"; then 17 | exit 1 18 | fi 19 | } 20 | 21 | for i in rep mal-rep shamir mal-shamir; do 22 | run $i 2 23 | done 24 | 25 | for i in semi mascot; do 26 | run $i 1 27 | done 28 | 29 | if ! ./secure.x; then 30 | ./Fake-ECDSA.x 31 | run fake-spdz 1 32 | fi 33 | -------------------------------------------------------------------------------- /Scripts/test_flow_optimization.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ./compile.py -l test_flow_optimization || exit 1 4 | Scripts/rep-field.sh test_flow_optimization || exit 1 5 | -------------------------------------------------------------------------------- /Scripts/test_streaming.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | make stream-fake-mascot-triples.x 4 | ./compile.py test_thread_mul || exit 1 5 | 6 | rm Player-Data/2-p-128/Triples-p-P?-T? 7 | mkdir Player-Data/2-p-128 8 | 9 | for i in 0 1; do 10 | for j in 0 1 2; do 11 | mknod Player-Data/2-p-128/Triples-p-P$i-T$j p || exit 1 12 | done 13 | done 14 | 15 | ./stream-fake-mascot-triples.x & 16 | 17 | Scripts/mascot.sh test_thread_mul -f || exit 1 18 | 19 | ./stream-fake-mascot-triples.x & 20 | 21 | Scripts/mascot.sh test_thread_mul -f || exit 1 22 | -------------------------------------------------------------------------------- /Scripts/tinier.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | HERE=$(cd `dirname $0`; pwd) 4 | SPDZROOT=$HERE/.. 5 | 6 | . $HERE/run-common.sh 7 | 8 | run_player tinier-party.x $* || exit 1 9 | -------------------------------------------------------------------------------- /Scripts/tiny.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | HERE=$(cd `dirname $0`; pwd) 4 | SPDZROOT=$HERE/.. 5 | 6 | . $HERE/run-common.sh 7 | 8 | run_player tiny-party.x $* || exit 1 9 | -------------------------------------------------------------------------------- /Scripts/vss-field.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | HERE=$(cd `dirname $0`; pwd) 4 | SPDZROOT=$HERE/.. 5 | 6 | export PLAYERS=3 7 | 8 | . $HERE/run-common.sh 9 | 10 | run_player vss-field-party.x -ND 0 -NA 2 -NP 1 $* || exit 1 -------------------------------------------------------------------------------- /Scripts/vss.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | HERE=$(cd `dirname $0`; pwd) 4 | SPDZROOT=$HERE/.. 5 | 6 | export PLAYERS=3 7 | 8 | . $HERE/run-common.sh 9 | 10 | run_player vss-party.x $* || exit 1 11 | -------------------------------------------------------------------------------- /Scripts/yao.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | HERE=$(cd `dirname $0`; pwd) 4 | SPDZROOT=$HERE/.. 5 | 6 | . $HERE/run-common.sh 7 | 8 | run_player yao-party.x $* || exit 1 9 | -------------------------------------------------------------------------------- /Tools/CheckVector.h: -------------------------------------------------------------------------------- 1 | /* 2 | * CheckVector.h 3 | * 4 | */ 5 | 6 | #ifndef TOOLS_CHECKVECTOR_H_ 7 | #define TOOLS_CHECKVECTOR_H_ 8 | 9 | #include 10 | using namespace std; 11 | 12 | template 13 | class CheckVector : public vector 14 | { 15 | public: 16 | CheckVector() : vector() {} 17 | CheckVector(size_t size) : vector(size) {} 18 | CheckVector(size_t size, const T& def) : vector(size, def) {} 19 | #ifdef CHECK_SIZE 20 | T& operator[](size_t i) { return this->at(i); } 21 | const T& operator[](size_t i) const { return this->at(i); } 22 | #else 23 | T& at(size_t i) { return (*this)[i]; } 24 | const T& at(size_t i) const { return (*this)[i]; } 25 | #endif 26 | }; 27 | 28 | #endif /* TOOLS_CHECKVECTOR_H_ */ 29 | -------------------------------------------------------------------------------- /Tools/Coordinator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Coordinator.h 3 | * 4 | */ 5 | 6 | #ifndef TOOLS_COORDINATOR_H_ 7 | #define TOOLS_COORDINATOR_H_ 8 | 9 | #include "Networking/Player.h" 10 | #include "Signal.h" 11 | #include "Lock.h" 12 | 13 | class Coordinator 14 | { 15 | PlainPlayer P; 16 | 17 | WaitQueue in; 18 | 19 | pthread_t thread; 20 | 21 | map waiting; 22 | 23 | map> signals; 24 | 25 | Lock lock; 26 | 27 | WaitQueue done; 28 | 29 | double waited; 30 | 31 | static void* run_thread(void* coordinator); 32 | 33 | public: 34 | Coordinator(const Names& N, string type_name); 35 | ~Coordinator(); 36 | 37 | void run(); 38 | 39 | void wait(const string& id); 40 | void finished(); 41 | }; 42 | 43 | #endif /* TOOLS_COORDINATOR_H_ */ 44 | -------------------------------------------------------------------------------- /Tools/ExecutionStats.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ExecutionsStats.h 3 | * 4 | */ 5 | 6 | #ifndef TOOLS_EXECUTIONSTATS_H_ 7 | #define TOOLS_EXECUTIONSTATS_H_ 8 | 9 | #include 10 | using namespace std; 11 | 12 | class ExecutionStats : public map 13 | { 14 | public: 15 | ExecutionStats& operator+=(const ExecutionStats& other); 16 | 17 | void print(); 18 | }; 19 | 20 | #endif /* TOOLS_EXECUTIONSTATS_H_ */ 21 | -------------------------------------------------------------------------------- /Tools/Lock.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Lock.cpp 3 | * 4 | */ 5 | 6 | #include 7 | 8 | Lock::Lock() 9 | { 10 | pthread_mutex_init(&mutex, 0); 11 | } 12 | 13 | Lock::~Lock() 14 | { 15 | pthread_mutex_destroy(&mutex); 16 | } 17 | 18 | void Lock::lock() 19 | { 20 | pthread_mutex_lock(&mutex); 21 | } 22 | 23 | void Lock::unlock() 24 | { 25 | pthread_mutex_unlock(&mutex); 26 | } 27 | -------------------------------------------------------------------------------- /Tools/Lock.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Lock.h 3 | * 4 | */ 5 | 6 | #ifndef TOOLS_LOCK_H_ 7 | #define TOOLS_LOCK_H_ 8 | 9 | #include 10 | 11 | class Lock 12 | { 13 | pthread_mutex_t mutex; 14 | public: 15 | Lock(); 16 | virtual ~Lock(); 17 | 18 | void lock(); 19 | void unlock(); 20 | }; 21 | 22 | #endif /* TOOLS_LOCK_H_ */ 23 | -------------------------------------------------------------------------------- /Tools/NetworkOptions.h: -------------------------------------------------------------------------------- 1 | /* 2 | * NetworkOptions.h 3 | * 4 | */ 5 | 6 | #ifndef TOOLS_NETWORKOPTIONS_H_ 7 | #define TOOLS_NETWORKOPTIONS_H_ 8 | 9 | #include "ezOptionParser.h" 10 | #include "Networking/Server.h" 11 | #include "Networking/Player.h" 12 | 13 | #include 14 | 15 | class NetworkOptions 16 | { 17 | public: 18 | int portnum_base; 19 | std::string hostname; 20 | 21 | NetworkOptions(ez::ezOptionParser& opt, int argc, const char** argv); 22 | }; 23 | 24 | class NetworkOptionsWithNumber : public NetworkOptions 25 | { 26 | public: 27 | int nplayers; 28 | std::string ip_filename; 29 | 30 | NetworkOptionsWithNumber(ez::ezOptionParser& opt, int argc, 31 | const char** argv, int default_nplayers, bool variable_nplayers); 32 | 33 | Server* start_networking(Names& N, int my_num); 34 | }; 35 | 36 | #endif /* TOOLS_NETWORKOPTIONS_H_ */ 37 | -------------------------------------------------------------------------------- /Tools/Signal.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Signal.cpp 3 | * 4 | */ 5 | 6 | #include "Signal.h" 7 | 8 | Signal::Signal() 9 | { 10 | pthread_mutex_init(&mutex, 0); 11 | pthread_cond_init(&cond, 0); 12 | } 13 | 14 | Signal::~Signal() 15 | { 16 | pthread_mutex_destroy(&mutex); 17 | pthread_cond_destroy(&cond); 18 | } 19 | 20 | void Signal::lock() 21 | { 22 | pthread_mutex_lock(&mutex); 23 | } 24 | 25 | void Signal::unlock() 26 | { 27 | pthread_mutex_unlock(&mutex); 28 | } 29 | 30 | void Signal::wait() 31 | { 32 | pthread_cond_wait(&cond, &mutex); 33 | } 34 | 35 | int Signal::wait(int seconds) 36 | { 37 | timespec ts; 38 | clock_gettime(CLOCK_REALTIME, &ts); 39 | ts.tv_sec += seconds; 40 | return pthread_cond_timedwait(&cond, &mutex, &ts); 41 | } 42 | 43 | void Signal::broadcast() 44 | { 45 | pthread_cond_broadcast(&cond); 46 | } 47 | -------------------------------------------------------------------------------- /Tools/Signal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Signal.h 3 | * 4 | */ 5 | 6 | #ifndef TOOLS_SIGNAL_H_ 7 | #define TOOLS_SIGNAL_H_ 8 | 9 | #include 10 | 11 | class Signal 12 | { 13 | pthread_mutex_t mutex; 14 | pthread_cond_t cond; 15 | 16 | public: 17 | Signal(); 18 | virtual ~Signal(); 19 | void lock(); 20 | void unlock(); 21 | void wait(); 22 | int wait(int seconds); 23 | void broadcast(); 24 | }; 25 | 26 | #endif /* TOOLS_SIGNAL_H_ */ 27 | -------------------------------------------------------------------------------- /Tools/TimerWithComm.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * TimerWithComm.cpp 3 | * 4 | */ 5 | 6 | #include "TimerWithComm.h" 7 | 8 | void TimerWithComm::start(const NamedCommStats& stats) 9 | { 10 | Timer::start(); 11 | last_stats = stats; 12 | } 13 | 14 | void TimerWithComm::stop(const NamedCommStats& stats) 15 | { 16 | Timer::stop(); 17 | total_stats += stats - last_stats; 18 | } 19 | 20 | double TimerWithComm::mb_sent() 21 | { 22 | return total_stats.sent * 1e-6; 23 | } 24 | -------------------------------------------------------------------------------- /Tools/TimerWithComm.h: -------------------------------------------------------------------------------- 1 | /* 2 | * TimerWithComm.h 3 | * 4 | */ 5 | 6 | #ifndef TOOLS_TIMERWITHCOMM_H_ 7 | #define TOOLS_TIMERWITHCOMM_H_ 8 | 9 | #include "time-func.h" 10 | #include "Networking/Player.h" 11 | 12 | class TimerWithComm : public Timer 13 | { 14 | NamedCommStats total_stats, last_stats; 15 | 16 | public: 17 | void start(const NamedCommStats& stats = {}); 18 | void stop(const NamedCommStats& stats = {}); 19 | 20 | double mb_sent(); 21 | }; 22 | 23 | #endif /* TOOLS_TIMERWITHCOMM_H_ */ 24 | -------------------------------------------------------------------------------- /Tools/Waksman.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Waksman.h 3 | * 4 | */ 5 | 6 | #ifndef TOOLS_WAKSMAN_H_ 7 | #define TOOLS_WAKSMAN_H_ 8 | 9 | #include 10 | using namespace std; 11 | 12 | class Waksman 13 | { 14 | int n_elements; 15 | int nr; 16 | 17 | public: 18 | static vector> configure(const vector& perm); 19 | 20 | Waksman(int n_elements); 21 | 22 | size_t n_rounds() const 23 | { 24 | return nr; 25 | } 26 | 27 | bool matters(int i, int j) const 28 | { 29 | int block = n_elements >> i; 30 | return (block == 2) or j % block != block / 2; 31 | } 32 | 33 | bool is_double(int i, int j) 34 | { 35 | return (i == (nr - 1) and j % 2 == 1); 36 | } 37 | 38 | size_t n_bits() const 39 | { 40 | return nr * n_elements - n_elements + 1; 41 | } 42 | }; 43 | 44 | #endif /* TOOLS_WAKSMAN_H_ */ 45 | -------------------------------------------------------------------------------- /Tools/benchmarking.h: -------------------------------------------------------------------------------- 1 | /* 2 | * benchmarking.h 3 | * 4 | */ 5 | 6 | #ifndef TOOLS_BENCHMARKING_H_ 7 | #define TOOLS_BENCHMARKING_H_ 8 | 9 | #include 10 | #include 11 | #include 12 | using namespace std; 13 | 14 | // call before insecure benchmarking functionality 15 | void insecure(string message, bool warning = true); 16 | 17 | void insecure_fake(bool warning = true); 18 | 19 | #endif /* TOOLS_BENCHMARKING_H_ */ 20 | -------------------------------------------------------------------------------- /Tools/callgrind.h: -------------------------------------------------------------------------------- 1 | /* 2 | * callgrind.h 3 | * 4 | */ 5 | 6 | #ifndef TOOLS_CALLGRIND_H_ 7 | #define TOOLS_CALLGRIND_H_ 8 | 9 | #ifdef USE_CALLGRIND 10 | #include 11 | #else 12 | #define CALLGRIND_START_INSTRUMENTATION 13 | #define CALLGRIND_STOP_INSTRUMENTATION 14 | #define CALLGRIND_DUMP_STATS 15 | #endif 16 | 17 | #endif /* TOOLS_CALLGRIND_H_ */ 18 | -------------------------------------------------------------------------------- /Tools/intrinsics.h: -------------------------------------------------------------------------------- 1 | /* 2 | * intrinsics.h 3 | * 4 | */ 5 | 6 | #ifndef TOOLS_INTRINSICS_H_ 7 | #define TOOLS_INTRINSICS_H_ 8 | 9 | #ifdef __x86_64__ 10 | #include 11 | #include 12 | #else 13 | #ifdef __aarch64__ 14 | #define SIMDE_X86_AVX_ENABLE_NATIVE_ALIASES 15 | #define SIMDE_X86_AVX2_ENABLE_NATIVE_ALIASES 16 | #define SIMDE_X86_SSE2_ENABLE_NATIVE_ALIASES 17 | #define SIMDE_X86_SSE4_1_ENABLE_NATIVE_ALIASES 18 | #define SIMDE_X86_PCLMUL_ENABLE_NATIVE_ALIASES 19 | #include "simde/simde/x86/avx2.h" 20 | #include "simde/simde/x86/clmul.h" 21 | #include "aes-arm.h" 22 | #endif 23 | #endif 24 | 25 | #endif /* TOOLS_INTRINSICS_H_ */ 26 | -------------------------------------------------------------------------------- /Tools/mkpath.h: -------------------------------------------------------------------------------- 1 | #ifndef TOOLS_MKPATH_H_ 2 | #define TOOLS_MKPATH_H_ 3 | 4 | // mkdir -p, from https://gist.github.com/JonathonReinhart/8c0d90191c38af2dcadb102c4e202950 5 | int mkdir_p(const char *path); 6 | 7 | #endif /* TOOLS_MKPATH_H_ */ 8 | -------------------------------------------------------------------------------- /Tools/names.cpp: -------------------------------------------------------------------------------- 1 | #include "Processor/Data_Files.h" 2 | 3 | const char* DataPositions::dtype_names[N_DTYPE + 1] = 4 | { "Triples", "Squares", "Bits", "Inverses", 5 | "daBits", "Mixed triples", "None" }; 6 | -------------------------------------------------------------------------------- /Tools/oct.h: -------------------------------------------------------------------------------- 1 | #ifndef TOOLS_OCT_H_ 2 | #define TOOLS_OCT_H_ 3 | 4 | typedef unsigned char octet; 5 | 6 | inline void PRINT_OCTET(const octet* bytes, size_t size) { 7 | for (size_t i = 0; i < size; ++i) 8 | cout << hex << (int) bytes[i]; 9 | cout << flush << endl; 10 | } 11 | 12 | inline bool OCTETS_EQUAL(const octet* left, const octet* right, int size) { 13 | for (int i = 0; i < size; ++i) 14 | if (left[i] != right[i]) 15 | return false; 16 | return true; 17 | } 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /Tools/pprint.h: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | inline void pprint_bytes(const char *label, unsigned char *bytes, int len) 8 | { 9 | cout << label << ": "; 10 | for (int j = 0; j < len; j++) 11 | cout << setfill('0') << setw(2) << hex << (int) bytes[j]; 12 | cout << dec << endl; 13 | } 14 | -------------------------------------------------------------------------------- /Tools_PSI/OKVS.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FudanMPL/Garnet/89af954fd61628990a0e6faa9a29d9d5e4b17667/Tools_PSI/OKVS.cpp -------------------------------------------------------------------------------- /Utils/Server.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Server.cpp 3 | * 4 | */ 5 | 6 | #include "Networking/Server.h" 7 | 8 | int main(int argc, char** argv) 9 | { 10 | Server(argc, argv).start(); 11 | } 12 | -------------------------------------------------------------------------------- /Utils/cnc-offline.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * cnc-offline.cpp 3 | * 4 | */ 5 | 6 | #include "FHEOffline/CutAndChooseMachine.h" 7 | 8 | int main(int argc, const char** argv) 9 | { 10 | CutAndChooseMachine(argc, argv).run(); 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /Utils/default-prime-length.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * default-prime-length.cpp 3 | * 4 | */ 5 | 6 | #include "Math/gfp.h" 7 | 8 | int main() 9 | { 10 | std::cout << gfp0::MAX_N_BITS << endl; 11 | } 12 | -------------------------------------------------------------------------------- /Utils/galois-degree.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * galois-degree.cpp 3 | * 4 | */ 5 | 6 | #include "Math/gf2n.h" 7 | 8 | int main() 9 | { 10 | cout << gf2n::default_degree() << endl; 11 | } 12 | -------------------------------------------------------------------------------- /Utils/gauss_test/generate_noise: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FudanMPL/Garnet/89af954fd61628990a0e6faa9a29d9d5e4b17667/Utils/gauss_test/generate_noise -------------------------------------------------------------------------------- /Utils/gen_input_f2n.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "Math/gf2n.h" 4 | #include "Tools/Buffer.h" 5 | 6 | using namespace std; 7 | 8 | int main() { 9 | ifstream cin("gf2n_vals.in"); 10 | ofstream cout("gf2n_vals.out"); 11 | 12 | gf2n::init_field(gf2n::default_degree()); 13 | 14 | int n; cin >> n; 15 | for (int i = 0; i < n; ++i) { 16 | gf2n x; cin >> x; 17 | cerr << "value is: " << x << "\n"; 18 | x.output(cout,false); 19 | } 20 | n = -(n % BUFFER_SIZE) + BUFFER_SIZE; 21 | cerr << "Adding " << n << " zeros to match buffer size" << endl; 22 | for (int i = 0; i < n; i++) 23 | gf2n(0).output(cout, false); 24 | 25 | cin.close(); 26 | cout.close(); 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /Utils/hyper.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * hyper.cpp 3 | * 4 | */ 5 | 6 | #include "Math/gfpvar.h" 7 | 8 | #include "Protocols/Shamir.hpp" 9 | 10 | int main(int argc, char** argv) 11 | { 12 | assert(argc > 2); 13 | gfpvar::init_field(argv[3]); 14 | vector> hyper; 15 | int t = atoi(argv[1]); 16 | int n = atoi(argv[2]); 17 | Shamir>::get_hyper(hyper, t, n); 18 | octetStream os; 19 | os.store(hyper); 20 | ofstream out(Shamir>::hyper_filename(t, n)); 21 | os.output(out); 22 | } 23 | -------------------------------------------------------------------------------- /Utils/ot-offline.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OT-Offline.cpp 3 | * 4 | */ 5 | 6 | #include "OT/NPartyTripleGenerator.h" 7 | #include "OT/TripleMachine.h" 8 | 9 | int main(int argc, const char** argv) 10 | { 11 | TripleMachine(argc, argv).run(); 12 | } 13 | -------------------------------------------------------------------------------- /Utils/pairwise-offline.cpp: -------------------------------------------------------------------------------- 1 | #include "FHEOffline/PairwiseMachine.h" 2 | #include "Tools/callgrind.h" 3 | 4 | int main(int argc, const char** argv) 5 | { 6 | CALLGRIND_STOP_INSTRUMENTATION; 7 | RealPairwiseMachine machine(argc, argv); 8 | CALLGRIND_START_INSTRUMENTATION; 9 | machine.run(); 10 | } 11 | -------------------------------------------------------------------------------- /Utils/prime.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * prime.cpp 3 | * 4 | */ 5 | 6 | #include "Math/gfp.h" 7 | #include "Math/Setup.h" 8 | 9 | int main(int argc, char** argv) 10 | { 11 | int lgp = gfp0::size_in_bits(); 12 | if (argc > 1) 13 | lgp = atoi(argv[1]); 14 | if (argc > 2) 15 | cout << generate_prime(lgp, 1 << atoi(argv[2])) << endl; 16 | else 17 | cout << SPDZ_Data_Setup_Primes(lgp) << endl; 18 | } 19 | -------------------------------------------------------------------------------- /Utils/simple-offline.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * simple-offline.cpp 3 | * 4 | */ 5 | 6 | #include 7 | #include "Tools/callgrind.h" 8 | 9 | int main(int argc, const char** argv) 10 | { 11 | CALLGRIND_STOP_INSTRUMENTATION; 12 | SimpleMachine machine(argc, argv); 13 | CALLGRIND_START_INSTRUMENTATION; 14 | machine.run(); 15 | } 16 | -------------------------------------------------------------------------------- /Yao/YaoCommon.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * YaoCommon.cpp 3 | * 4 | */ 5 | 6 | #include "YaoCommon.h" 7 | 8 | template 9 | vector > YaoCommon::get_splits(const vector& args, 10 | int threshold, int total) 11 | { 12 | vector> res; 13 | size_t max_gates_per_thread = max(threshold / 2, 14 | (total + get_n_worker_threads() - 1) / get_n_worker_threads()); 15 | size_t i_gate = 0; 16 | for (auto it = args.begin(); it < args.end(); it += 4) 17 | { 18 | i_gate += *it; 19 | auto end = it + 4; 20 | if (i_gate >= max_gates_per_thread or end >= args.end()) 21 | { 22 | res.push_back({{i_gate, size_t(end - args.begin())}}); 23 | i_gate = 0; 24 | } 25 | } 26 | return res; 27 | } 28 | -------------------------------------------------------------------------------- /Yao/YaoEvalInput.h: -------------------------------------------------------------------------------- 1 | /* 2 | * YaoEvalInput.h 3 | * 4 | */ 5 | 6 | #ifndef YAO_YAOEVALINPUT_H_ 7 | #define YAO_YAOEVALINPUT_H_ 8 | 9 | #include "YaoEvaluator.h" 10 | 11 | class YaoEvalInput 12 | { 13 | public: 14 | YaoEvaluator& evaluator; 15 | BitVector inputs; 16 | int i_bit; 17 | octetStream os; 18 | 19 | YaoEvalInput() : 20 | evaluator(YaoEvaluator::s()) 21 | { 22 | inputs.resize(0); 23 | i_bit = 0; 24 | } 25 | 26 | void exchange() 27 | { 28 | evaluator.ot_ext.extend_correlated(inputs.size(), inputs); 29 | evaluator.player.receive(os); 30 | } 31 | }; 32 | 33 | #endif /* YAO_YAOEVALINPUT_H_ */ 34 | -------------------------------------------------------------------------------- /Yao/YaoEvalMaster.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * YaoEvalMaster.cpp 3 | * 4 | */ 5 | 6 | #include "YaoEvalMaster.h" 7 | #include "YaoEvaluator.h" 8 | 9 | #include "GC/Machine.hpp" 10 | #include "GC/Program.hpp" 11 | #include "GC/Processor.hpp" 12 | #include "GC/Secret.hpp" 13 | #include "GC/Thread.hpp" 14 | #include "GC/ThreadMaster.hpp" 15 | #include "Processor/Instruction.hpp" 16 | #include "YaoWire.hpp" 17 | 18 | YaoEvalMaster::YaoEvalMaster(bool continuous, OnlineOptions& opts) : 19 | ThreadMaster>(opts), continuous(continuous) 20 | { 21 | } 22 | 23 | GC::Thread>* YaoEvalMaster::new_thread(int i) 24 | { 25 | return new YaoEvaluator(i, *this); 26 | } 27 | -------------------------------------------------------------------------------- /Yao/YaoEvalMaster.h: -------------------------------------------------------------------------------- 1 | /* 2 | * YaoEvalMaster.h 3 | * 4 | */ 5 | 6 | #ifndef YAO_YAOEVALMASTER_H_ 7 | #define YAO_YAOEVALMASTER_H_ 8 | 9 | #include "GC/ThreadMaster.h" 10 | #include "GC/Secret.h" 11 | #include "YaoEvalWire.h" 12 | 13 | class YaoEvalMaster : public GC::ThreadMaster> 14 | { 15 | public: 16 | bool continuous; 17 | 18 | YaoEvalMaster(bool continuous, OnlineOptions& opts); 19 | 20 | GC::Thread>* new_thread(int i); 21 | }; 22 | 23 | #endif /* YAO_YAOEVALMASTER_H_ */ 24 | -------------------------------------------------------------------------------- /Yao/YaoGarbleInput.h: -------------------------------------------------------------------------------- 1 | /* 2 | * YaoGarbleInput.h 3 | * 4 | */ 5 | 6 | #ifndef YAO_YAOGARBLEINPUT_H_ 7 | #define YAO_YAOGARBLEINPUT_H_ 8 | 9 | #include "YaoGarbler.h" 10 | 11 | class YaoGarbleWire; 12 | 13 | class YaoGarbleInput 14 | { 15 | public: 16 | YaoGarbler& garbler; 17 | 18 | YaoGarbleInput() : 19 | garbler(YaoGarbler::s()) 20 | { 21 | } 22 | 23 | void exchange() 24 | { 25 | garbler.receiver_input_keys.push_back({}); 26 | } 27 | }; 28 | 29 | #endif /* YAO_YAOGARBLEINPUT_H_ */ 30 | -------------------------------------------------------------------------------- /Yao/YaoGarbleMaster.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * YaoGarbleMaster.cpp 3 | * 4 | */ 5 | 6 | #include "YaoGarbleMaster.h" 7 | #include "YaoGarbler.h" 8 | 9 | #include "GC/Machine.hpp" 10 | #include "GC/Program.hpp" 11 | #include "GC/Processor.hpp" 12 | #include "GC/Secret.hpp" 13 | #include "GC/Thread.hpp" 14 | #include "GC/ThreadMaster.hpp" 15 | #include "Processor/Instruction.hpp" 16 | #include "YaoWire.hpp" 17 | 18 | YaoGarbleMaster::YaoGarbleMaster(bool continuous, OnlineOptions& opts, int threshold) : 19 | super(opts), continuous(continuous), threshold(threshold) 20 | { 21 | PRNG G; 22 | G.ReSeed(); 23 | delta = G.get_doubleword(); 24 | delta.set_signal(1); 25 | } 26 | 27 | GC::Thread>* YaoGarbleMaster::new_thread(int i) 28 | { 29 | return new YaoGarbler(i, *this); 30 | } 31 | -------------------------------------------------------------------------------- /Yao/YaoGarbleMaster.h: -------------------------------------------------------------------------------- 1 | /* 2 | * YaoGarbleMaster.h 3 | * 4 | */ 5 | 6 | #ifndef YAO_YAOGARBLEMASTER_H_ 7 | #define YAO_YAOGARBLEMASTER_H_ 8 | 9 | #include "GC/ThreadMaster.h" 10 | #include "GC/Secret.h" 11 | #include "YaoGarbleWire.h" 12 | #include "Processor/OnlineOptions.h" 13 | 14 | class YaoGarbleMaster : public GC::ThreadMaster> 15 | { 16 | typedef GC::ThreadMaster> super; 17 | 18 | Key delta; 19 | 20 | public: 21 | bool continuous; 22 | int threshold; 23 | 24 | YaoGarbleMaster(bool continuous, OnlineOptions& opts, int threshold = 1024); 25 | 26 | GC::Thread>* new_thread(int i); 27 | 28 | Key get_delta() 29 | { 30 | return delta; 31 | } 32 | }; 33 | 34 | #endif /* YAO_YAOGARBLEMASTER_H_ */ 35 | -------------------------------------------------------------------------------- /Yao/YaoPlayer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * YaoPlayer.h 3 | * 4 | */ 5 | 6 | #ifndef YAO_YAOPLAYER_H_ 7 | #define YAO_YAOPLAYER_H_ 8 | 9 | #include "Networking/Player.h" 10 | #include "Networking/Server.h" 11 | 12 | class YaoPlayer 13 | { 14 | string progname; 15 | Names N; 16 | 17 | public: 18 | YaoPlayer(int argc, const char** argv); 19 | ~YaoPlayer(); 20 | }; 21 | 22 | #endif /* YAO_YAOPLAYER_H_ */ 23 | -------------------------------------------------------------------------------- /Yao/YaoWire.h: -------------------------------------------------------------------------------- 1 | /* 2 | * YaoWire.h 3 | * 4 | */ 5 | 6 | #ifndef YAO_YAOWIRE_H_ 7 | #define YAO_YAOWIRE_H_ 8 | 9 | #include "BMR/Key.h" 10 | #include "BMR/Register.h" 11 | 12 | class YaoWire : public Phase 13 | { 14 | protected: 15 | Key key_; 16 | 17 | public: 18 | static int threshold(int) { return 1; } 19 | 20 | template 21 | static void xors(GC::Processor& processor, const vector& args); 22 | template 23 | static void xors(GC::Processor& processor, const vector& args, 24 | size_t start, size_t end); 25 | 26 | template 27 | static void andm(GC::Processor& processor, 28 | const BaseInstruction& instruction); 29 | 30 | void XOR(const YaoWire& left, const YaoWire& right) 31 | { 32 | key_ = left.key_ ^ right.key_; 33 | } 34 | 35 | template 36 | void other_input(T&, int) {} 37 | }; 38 | 39 | #endif /* YAO_YAOWIRE_H_ */ 40 | -------------------------------------------------------------------------------- /Yao/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * config.h 3 | * 4 | */ 5 | 6 | #ifndef YAO_CONFIG_H_ 7 | #define YAO_CONFIG_H_ 8 | 9 | //#define DEBUG 10 | 11 | //#define CHECK_BUFFER 12 | 13 | class YaoFullGate; 14 | class YaoHalfGate; 15 | 16 | #ifndef FULL_GATES 17 | typedef YaoHalfGate YaoGate; 18 | #else 19 | typedef YaoFullGate YaoGate; 20 | #endif 21 | 22 | #endif /* YAO_CONFIG_H_ */ 23 | -------------------------------------------------------------------------------- /bin/README.md: -------------------------------------------------------------------------------- 1 | In binary releases, this directory constains statically linked 2 | binaries. They included code from the following projects, whose licenses 3 | are thus provided in separate files: 4 | - Boost 5 | - glibc 6 | - libsodium 7 | - MPIR 8 | - OpenSSl 9 | - NTL 10 | 11 | The binaries also include code from libstdc++ and libgcc. They have 12 | been produced using `Scripts/build.sh` and standard GCC from 13 | Devtoolset-6 on CentOS 6 and therefore satisfy the [GCC Runtime Library 14 | Exception](https://www.gnu.org/licenses/gcc-exception-3.1.en.html). 15 | -------------------------------------------------------------------------------- /doc/.gitignore: -------------------------------------------------------------------------------- 1 | instructions.csv 2 | -------------------------------------------------------------------------------- /doc/Makefile: -------------------------------------------------------------------------------- 1 | # Minimal makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | SOURCEDIR = . 8 | BUILDDIR = _build 9 | 10 | # Put it first so that "make" without argument is like "make help". 11 | help: 12 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 13 | 14 | .PHONY: help Makefile 15 | 16 | # Catch-all target: route all unknown targets to Sphinx using the new 17 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). 18 | %: Makefile 19 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) -------------------------------------------------------------------------------- /doc/_static/custom.css: -------------------------------------------------------------------------------- 1 | .wy-table-responsive table td { 2 | white-space: normal; 3 | } 4 | -------------------------------------------------------------------------------- /doc/gen-readme.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo '# Getting started' > readme.md 4 | sed -e '1 d' ../README.md >> readme.md 5 | -------------------------------------------------------------------------------- /doc/homomorphic-encryption.rst: -------------------------------------------------------------------------------- 1 | Homomorphic Encryption 2 | ---------------------- 3 | 4 | MP-SPDZ uses BGV encryption for triple generation in a number of 5 | protocols. This involves zero-knowledge proofs in some protocols and 6 | considerations about function privacy in all of them. The interface 7 | described below allows directly accessing the basic cryptographic 8 | operations in contexts where these considerations are not relevant. 9 | See ``Utils/he-example.cpp`` for some example code. 10 | 11 | 12 | Reference 13 | ~~~~~~~~~ 14 | 15 | .. doxygenclass:: FHE_Params 16 | :members: 17 | 18 | .. doxygenclass:: FHE_KeyPair 19 | :members: 20 | 21 | .. doxygenclass:: FHE_SK 22 | :members: 23 | 24 | .. doxygenclass:: FHE_PK 25 | :members: 26 | 27 | .. doxygenclass:: Plaintext 28 | :members: 29 | 30 | .. doxygenclass:: Ciphertext 31 | :members: 32 | -------------------------------------------------------------------------------- /doc/index.rst: -------------------------------------------------------------------------------- 1 | Welcome to MP-SPDZ's documentation! 2 | =================================== 3 | 4 | If you're new to MP-SPDZ, consider the following: 5 | 6 | 1. `Quickstart tutorial `_ 7 | 2. `Implemented protocols `_ 8 | 3. :ref:`troubleshooting` 9 | 4. :ref:`io` lists all the ways of getting data in and out. 10 | 11 | .. toctree:: 12 | :maxdepth: 4 13 | :caption: Contents: 14 | 15 | readme 16 | compilation 17 | Compiler 18 | instructions 19 | low-level 20 | machine-learning 21 | networking 22 | io 23 | non-linear 24 | preprocessing 25 | add-protocol 26 | homomorphic-encryption 27 | troubleshooting 28 | 29 | 30 | Indices and tables 31 | ------------------ 32 | 33 | * :ref:`genindex` 34 | * :ref:`modindex` 35 | * :ref:`search` 36 | -------------------------------------------------------------------------------- /doc/requirements.txt: -------------------------------------------------------------------------------- 1 | breathe==4.31.0 2 | sphinx-rtd-theme==0.5.2 3 | myst_parser==0.18.0 4 | -------------------------------------------------------------------------------- /docs/mPSI.md: -------------------------------------------------------------------------------- 1 | # mPSI协议 2 | 3 | **2025年3月份更新**:三方PSI效率优化,实现了一个基于OPRF和OKVS的三方PSI协议。 4 | 5 | ## 运行基于OPRF和OKVS的三方PSI协议 6 | 7 | ### 功能介绍 8 | 使用我们的PSI功能可以获得三个参与方的Set数据集的交集,并且不暴露额外的信息。 9 | 10 | ### API 11 | 默认双方的数据量是一样的,如果不一样,则先用假数据将小数据量的填充。 12 | 第i方的输入数据存储在"Player-Data/PSI/ID-Pi" 13 | 输出的交集结果存储在"Player-Data/PSI/ID-InterSet" 14 | ```python 15 | # n: number of parties 16 | mPSI(n) 17 | ``` 18 | 19 | ### 使用 20 | Scripts/PSI-Test/run_psi.sh是编译运行的脚本 21 | 默认运行的mpc文件名是:test_mpsi.mpc,如果想运行其他文件可修改脚本run_psi.sh 22 | ```shell 23 | bash Scripts/PSI-Test/run_mpsi.sh c # compile test_psi.mpc 24 | bash Scripts/PSI-Test/run_mpsi.sh x # compile virtual machine replicated-ring-party.x 25 | bash Scripts/PSI-Test/run_mpsi.sh i # run test_psi program in rss, i \in {0,1,2} 26 | ``` -------------------------------------------------------------------------------- /docs/transformer.md: -------------------------------------------------------------------------------- 1 | # Transformer和线性化ReLU层 2 | 3 | ## 更新介绍 4 | 5 | 本次更新增加了LayerNorm层,SoftMax层,Linear层以及基于这些层实现的Transformer基本模块。此外本次更新还增加了安全推理方法中常用的线性化ReLU层,该层可用于实现低通讯开销的线性化神经网络 6 | 7 | ## Transformer基本块 8 | 9 | 1. 运行MNIST-ViT.py生成测试数据,并将生成的数据直接拷贝到Player-Data中 10 | 11 | ``` 12 | cd Compiler/DL 13 | python MNIST-ViT.py 14 | cp ./Input-P0-0 ../../Player-Data/Input-P0-0 15 | ``` 16 | 17 | 2. 回到主目录,编译并运行ViT-MNIST-Test.mpc 18 | 19 | ``` 20 | cd ../../ 21 | python compile.py -R 64 ViT-MNIST-Test 22 | Scripts/ring.sh ViT-MNIST-Test 23 | ``` 24 | 25 | ## 线性化ReLU层 26 | 27 | 1. 在主目录编译并运行Linear-ReLU-Test.mpc 28 | 29 | ``` 30 | python compile.py -R 64 Linear-ReLU-Test 31 | Scripts/ring.sh Linear-ReLU-Test 32 | ``` 33 | -------------------------------------------------------------------------------- /mixed: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FudanMPL/Garnet/89af954fd61628990a0e6faa9a29d9d5e4b17667/mixed -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | gmpy2==2.1.5 2 | h5py==3.8.0 3 | matplotlib==3.5.3 4 | numpy==1.21.6 5 | opencv_python==4.7.0.72 6 | pandas==1.3.5 7 | Pillow==9.4.0 8 | scikit_image==0.19.3 9 | scikit_learn==1.2.2 10 | setuptools==63.4.1 11 | tensorflow==2.11.0 12 | torch==1.12.1 13 | torchvision==0.13.1 14 | tqdm==4.64.1 15 | scipy 16 | sympy==1.11.1 17 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup, find_packages 2 | 3 | setup( 4 | name='mp-spdz-compiler', 5 | version='0.1.0', 6 | packages=find_packages(include=['Compiler', 'Compiler.*']) 7 | ) 8 | --------------------------------------------------------------------------------