├── .github └── ISSUE_TEMPLATE │ ├── bug_report.md │ ├── feature_request.md │ ├── general-question.md │ └── unexpected-benchmark.md ├── .gitignore ├── .gitmodules ├── .readthedocs.yaml ├── 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 ├── CHANGELOG.md ├── CONFIG ├── Compiler ├── GC │ ├── __init__.py │ ├── instructions.py │ ├── program.py │ └── types.py ├── __init__.py ├── allocator.py ├── circuit.py ├── circuit_oram.py ├── comparison.py ├── compilerLib.py ├── config.py ├── decision_tree.py ├── dijkstra.py ├── exceptions.py ├── floatingpoint.py ├── graph.py ├── gs.py ├── instructions.py ├── instructions_base.py ├── library.py ├── ml.py ├── mpc_math.py ├── non_linear.py ├── oram.py ├── papers.py ├── path_oblivious_heap.py ├── path_oram.py ├── permutation.py ├── program.py ├── sorting.py ├── sqrt_oram.py ├── tools.py ├── types.py └── util.py ├── Dockerfile ├── ECDSA ├── CurveElement.cpp ├── CurveElement.h ├── EcdsaOptions.h ├── Fake-ECDSA.cpp ├── P256Element.cpp ├── P256Element.h ├── README.md ├── atlas-ecdsa-party.cpp ├── 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 ├── rep4-ecdsa-party.cpp ├── semi-ecdsa-party.cpp ├── shamir-ecdsa-party.cpp ├── sign.hpp └── sy-rep-ecdsa-party.cpp ├── ExternalIO ├── Client.h ├── Client.hpp ├── README.md ├── bankers-bonus-client.cpp ├── bankers-bonus-client.py ├── client.py ├── domains.py └── personal-client-example.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 ├── 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 ├── AstraSecret.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 ├── Rep4Prep.cpp ├── Rep4Prep.h ├── 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 ├── License.txt ├── Machines ├── Atlas.hpp ├── BMR │ ├── bmr-program-party.cpp │ ├── bmr-program-tparty.cpp │ ├── mal-rep-bmr-party.cpp │ ├── mal-shamir-bmr-party.cpp │ ├── real-bmr-party.cpp │ ├── rep-bmr-party.cpp │ ├── semi-bmr-party.cpp │ └── shamir-bmr-party.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 ├── Shamir.hpp ├── Tinier.cpp ├── TripleMachine.cpp ├── astra-party.cpp ├── astra-prep-party.cpp ├── atlas-party.cpp ├── brain-party.cpp ├── ccd-party.cpp ├── chaigear-party.cpp ├── cowgear-offline.cpp ├── cowgear-party.cpp ├── dealer-ring-party.cpp ├── emulate.cpp ├── export-atlas.cpp ├── export-cowgear.cpp ├── export-dealer.cpp ├── export-hemi.cpp ├── export-rep4-ring.cpp ├── export-ring.cpp ├── export-semi2k.cpp ├── export-sy-rep-ring.cpp ├── h-files.h ├── hemi-offline.cpp ├── hemi-party.cpp ├── highgear-party.cpp ├── lowgear-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 ├── maximal.hpp ├── minimal.hpp ├── no-party.cpp ├── ps-rep-bin-party.cpp ├── ps-rep-field-party.cpp ├── ps-rep-ring-party.cpp ├── rep4-ring-party.cpp ├── replicated-bin-party.cpp ├── replicated-field-party.cpp ├── replicated-ring-party.cpp ├── semi-bin-party.cpp ├── semi-offline.cpp ├── semi-party.cpp ├── semi2k-offline.cpp ├── semi2k-party.cpp ├── shamir-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 ├── trio-party.cpp ├── trio-prep-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.cpp ├── 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 ├── 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 ├── EdabitBuffer.h ├── ExternalClients.cpp ├── ExternalClients.h ├── FieldMachine.h ├── FieldMachine.hpp ├── FixInput.cpp ├── FixInput.h ├── FloatInput.cpp ├── FloatInput.h ├── FunctionArgument.cpp ├── FunctionArgument.h ├── HonestMajorityMachine.cpp ├── HonestMajorityMachine.h ├── Input.h ├── Input.hpp ├── InputTuple.h ├── Instruction.cpp ├── Instruction.h ├── Instruction.hpp ├── IntInput.h ├── IntInput.hpp ├── Machine.h ├── Machine.hpp ├── 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 ├── PrepBuffer.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 ├── ThreadJob.h ├── ThreadQueue.cpp ├── ThreadQueue.h ├── ThreadQueues.cpp ├── ThreadQueues.h ├── TruncPrTuple.cpp ├── TruncPrTuple.h ├── config.h └── instructions.h ├── Programs └── Source │ ├── adult.mpc │ ├── aes.mpc │ ├── aes_circuit.mpc │ ├── alex.mpc │ ├── bankers_bonus.mpc │ ├── bench-dt.mpc │ ├── benchmark_conv.mpc │ ├── benchmark_mobilenet.mpc │ ├── benchmark_net.mpc │ ├── benchmark_priority_queue.mpc │ ├── benchmark_secureNN.mpc │ ├── benchmark_sops_fixed_length.mpc │ ├── benchmark_sops_fixed_num_sops.mpc │ ├── bio.mpc │ ├── blink.mpc │ ├── breast_logistic.mpc │ ├── breast_tree.mpc │ ├── diabetes.mpc │ ├── dijkstra_example.mpc │ ├── easy_adult.mpc │ ├── export-a2b.py │ ├── export-b2a.py │ ├── export-msort.py │ ├── export-sort.py │ ├── export-trunc.py │ ├── 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_avgpool.mpc │ ├── keras_mnist_lenet_predict.mpc │ ├── l2h_comparison.mpc │ ├── l2h_multiplication.mpc │ ├── logreg.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 │ ├── multinode_example_main.py │ ├── multinode_example_worker.py │ ├── oram_tutorial.mpc │ ├── personal_client_example.py │ ├── prep_aes.mpc │ ├── prf_leg.mpc │ ├── prf_mimc.mpc │ ├── regression.mpc │ ├── spect.mpc │ ├── test_args.mpc │ ├── test_dot.mpc │ ├── test_flow_optimization.mpc │ ├── test_gc.mpc │ ├── test_path_oblivious_heap.mpc │ ├── test_permute.mpc │ ├── test_sbitfix.mpc │ ├── test_sbitint.mpc │ ├── test_thread_mul.mpc │ ├── tf.mpc │ ├── torch_alex_test.mpc │ ├── torch_cifar_alex.mpc │ ├── torch_cifar_lenet.mpc │ ├── torch_cifar_lenet_pretrain.mpc │ ├── torch_densenet.py │ ├── torch_mnist_dense.mpc │ ├── torch_mnist_dense_pretrain.mpc │ ├── torch_mnist_dense_test.mpc │ ├── torch_mnist_lenet.mpc │ ├── torch_mnist_lenet_avgpool.mpc │ ├── torch_mnist_lenet_predict.mpc │ ├── torch_regression_predict.mpc │ ├── torch_resnet.py │ ├── torch_squeeze.py │ ├── torch_vgg.py │ ├── tpmpc_tutorial.mpc │ ├── tutorial.mpc │ └── vickrey.mpc ├── Protocols ├── Astra.h ├── Astra.hpp ├── AstraInput.h ├── AstraInput.hpp ├── AstraMC.h ├── AstraMC.hpp ├── AstraPrep.h ├── AstraPrep.hpp ├── AstraShare.h ├── Atlas.h ├── Atlas.hpp ├── AtlasPrep.h ├── AtlasShare.h ├── Beaver.h ├── Beaver.hpp ├── BrainPrep.h ├── BrainPrep.hpp ├── BrainShare.h ├── BufferScope.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 ├── DummyMatrixPrep.h ├── FakeInput.h ├── FakeMC.h ├── FakePrep.h ├── FakeProtocol.h ├── FakeShare.h ├── FakeShare.hpp ├── 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 ├── 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 ├── MatrixFile.h ├── NoLivePrep.h ├── NoProtocol.h ├── NoShare.h ├── Opener.h ├── PostSacriRepFieldShare.h ├── PostSacriRepRingShare.h ├── PostSacrifice.h ├── PostSacrifice.hpp ├── ProtocolSet.h ├── ProtocolSetup.h ├── Rep3Share.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 ├── SecureShuffle.h ├── SecureShuffle.hpp ├── Semi.h ├── Semi2kShare.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 ├── ShamirOptions.cpp ├── ShamirOptions.h ├── ShamirShare.h ├── Share.h ├── Share.hpp ├── ShareInterface.cpp ├── ShareInterface.h ├── ShareMatrix.h ├── ShareVector.h ├── ShareVector.hpp ├── ShuffleSacrifice.h ├── ShuffleSacrifice.hpp ├── 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 ├── SpdzWiseRep3Shuffler.h ├── SpdzWiseRep3Shuffler.hpp ├── SpdzWiseRing.h ├── SpdzWiseRing.hpp ├── SpdzWiseRingPrep.h ├── SpdzWiseRingShare.h ├── SpdzWiseShare.h ├── SpdzWiseShare.hpp ├── SquarePrep.h ├── TemiPrep.h ├── TemiPrep.hpp ├── TemiShare.h ├── Trio.h ├── Trio.hpp ├── TrioInput.h ├── TrioInput.hpp ├── TrioMC.h ├── TrioShare.h ├── config.h ├── dabit.h ├── edabit.h ├── fake-stuff.h ├── fake-stuff.hpp └── mac_key.hpp ├── README.md ├── Scripts ├── astra-common.sh ├── astra-online.sh ├── astra-prep.sh ├── astra.sh ├── atlas.sh ├── bmr-program-run-remote.sh ├── bmr-program-run.sh ├── brain.sh ├── build.sh ├── ccd.sh ├── chaigear.sh ├── compile-emulate.py ├── compile-for-emulation.sh ├── compile-run.py ├── cowgear.sh ├── dealer-ring.sh ├── decompile.py ├── direct_compilation_example.py ├── emulate-append.sh ├── emulate.sh ├── fake-spdz-real-bmr.sh ├── fixed-rep-to-float.py ├── fixed-rep-to-raw.py ├── generate-cert.sh ├── get-brew.sh ├── hemi.sh ├── highgear.sh ├── list-field-protocols.sh ├── list-he-protocols.sh ├── list-protocols.sh ├── list-ring-protocols.sh ├── lowgear.sh ├── mal-ccd.sh ├── mal-rep-bin.sh ├── mal-rep-bmr.sh ├── mal-rep-field.sh ├── mal-rep-ring.sh ├── mal-shamir-bmr.sh ├── mal-shamir.sh ├── mama.sh ├── mascot.sh ├── memory-usage.py ├── prep-usage.py ├── process-tf.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.sh ├── run-common.sh ├── run-online.sh ├── semi-bin.sh ├── semi-bmr.sh ├── semi.sh ├── semi2k.sh ├── setup-clients.sh ├── setup-online.sh ├── setup-ssl.sh ├── shamir-bmr.sh ├── shamir.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 ├── torch_cifar_alex_import.py ├── torch_mnist_dense_import.py ├── torch_mnist_lenet_import.py ├── trio-online.sh ├── trio-prep.sh ├── trio.sh └── yao.sh ├── Tools ├── BitVector.cpp ├── BitVector.h ├── Buffer.cpp ├── Buffer.h ├── Bundle.h ├── CheckVector.h ├── CodeLocations.cpp ├── CodeLocations.h ├── Commit.cpp ├── Commit.h ├── Coordinator.cpp ├── Coordinator.h ├── DiskVector.cpp ├── DiskVector.h ├── DoubleRange.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 ├── NamedStats.cpp ├── NamedStats.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-ni.cpp ├── aes.cpp ├── aes.h ├── avx_memcpy.h ├── benchmarking.cpp ├── benchmarking.h ├── callgrind.h ├── cpu_support.h ├── ezOptionParser-MIT-LICENSE ├── ezOptionParser.h ├── files.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 ├── ranges.h ├── time-func.cpp └── time-func.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 ├── export-a2b.cpp ├── export-b2a.cpp ├── export-msort.cpp ├── export-sort.cpp ├── export-trunc.cpp ├── galois-degree.cpp ├── gc-emulate.cpp ├── gen_input_f2n.cpp ├── gen_input_fp.cpp ├── he-example.cpp ├── hyper.cpp ├── l2h-example.cpp ├── mixed-example.cpp ├── ot-offline.cpp ├── pairwise-offline.cpp ├── paper-example.cpp ├── prime.cpp ├── protocol-tutorial.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 ├── SimpleOT-license.txt ├── SimplestOT_C-license.txt ├── boost-license.txt ├── cryptoTools-license.txt ├── glibc-license.txt ├── gmp-license.txt ├── libOTe-license.txt ├── libsodium-license.txt ├── ntl-license.txt ├── openssl-license.txt ├── simde-license.txt └── sse2neon-license.txt ├── compile.py ├── doc ├── .gitignore ├── Compiler.rst ├── Doxyfile ├── Makefile ├── _static │ └── custom.css ├── add-instruction.rst ├── add-protocol.rst ├── compilation.rst ├── conf.py ├── ecdsa.md ├── function-export.rst ├── gen-instructions.py ├── gen-readme.sh ├── homomorphic-encryption.rst ├── index.rst ├── instructions.rst ├── io.rst ├── journey.rst ├── low-level.rst ├── lowest-level.rst ├── machine-learning.rst ├── ml-quickstart.rst ├── multinode.rst ├── navigating-c++.rst ├── networking.rst ├── non-linear.rst ├── optimization.rst ├── poh-graph.png ├── preprocessing.rst ├── requirements.txt ├── runtime-options.rst ├── troubleshooting.rst └── utils.rst └── setup.py /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Compilation and or execution command lines 15 | 16 | **Expected behavior** 17 | A clear and concise description of what you expected to happen. 18 | 19 | **Error message** 20 | Full Python backtrace or virtual machine outputs 21 | 22 | **MP-SPDZ version** 23 | Version or commit you are using 24 | 25 | **Additional context** 26 | Add any other context about the problem here. 27 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/general-question.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: General question 3 | about: Any questions not related to a bug or a missing feature 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Relevant documentation** 11 | Which section in the [documentation](https://mp-spdz.readthedocs.io) would you expect your question to be answered? Or is there a missing section? 12 | 13 | **The question** 14 | Please don't be too brief and explain your thinking process. One-line questions are often hard to answer precisely. 15 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/unexpected-benchmark.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Unexpected benchmarking result 3 | about: Some aspects are unexpectedly slow or fast 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the result** 11 | Why is the result unexpected? 12 | 13 | **To reproduce** 14 | High-level code as well as compilation and execution command lines 15 | 16 | **Outputs** 17 | Virtual machine outputs using `--verbose` 18 | 19 | **MP-SPDZ version** 20 | Version or commit you are using 21 | 22 | **Additional context** 23 | Add any other context about the problem here. 24 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "SimpleOT"] 2 | path = deps/SimpleOT 3 | url = https://github.com/mkskeller/SimpleOT 4 | [submodule "Programs/Circuits"] 5 | path = Programs/Circuits 6 | url = https://github.com/mkskeller/bristol-fashion 7 | [submodule "simde"] 8 | path = deps/simde 9 | url = https://github.com/simd-everywhere/simde 10 | [submodule "deps/libOTe"] 11 | path = deps/libOTe 12 | url = https://github.com/mkskeller/softspoken-implementation 13 | [submodule "deps/SimplestOT_C"] 14 | path = deps/SimplestOT_C 15 | url = https://github.com/mkskeller/SimplestOT_C 16 | [submodule "deps/sse2neon"] 17 | path = deps/sse2neon 18 | url = https://github.com/DLTcollab/sse2neon 19 | -------------------------------------------------------------------------------- /BMR/AndJob.h: -------------------------------------------------------------------------------- 1 | /* 2 | * AndJob.h 3 | * 4 | */ 5 | 6 | #ifndef BMR_ANDJOB_H_ 7 | #define BMR_ANDJOB_H_ 8 | 9 | #include "GC/Secret.h" 10 | #include "Register.h" 11 | #include "GarbledGate.h" 12 | 13 | #include 14 | using namespace std; 15 | 16 | class AndJob 17 | { 18 | StackedVector< GC::Secret >* S; 19 | const vector* args; 20 | 21 | public: 22 | vector gates; 23 | size_t start, end; 24 | gate_id_t gate_id; 25 | 26 | AndJob() : S(0), args(0), start(0), end(0), gate_id(0) {} 27 | 28 | void reset(StackedVector >& S, const vector& args, 29 | size_t start, gate_id_t gate_id, size_t n_gates, int n_parties) 30 | { 31 | this->S = &S; 32 | this->args = &args; 33 | this->start = start; 34 | this->end = start; 35 | this->gate_id = gate_id; 36 | if (gates.size() < n_gates) 37 | gates.resize(n_gates, {n_parties}); 38 | } 39 | 40 | int run(); 41 | }; 42 | 43 | #endif /* BMR_ANDJOB_H_ */ 44 | -------------------------------------------------------------------------------- /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/Gate.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __GATE_H__ 3 | #define __GATE_H__ 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "Key.h" 10 | #include "common.h" 11 | 12 | #define NO_LAYER (-1) 13 | 14 | class Gate { 15 | public: 16 | wire_id_t _left; 17 | wire_id_t _right; 18 | wire_id_t _out; 19 | Function _func; 20 | 21 | int _layer; 22 | 23 | Gate() : _left(-1), _right(-1), _out(-1), _layer(-1) {} 24 | 25 | inline void init(wire_id_t left, wire_id_t right, wire_id_t out,std::string func) { 26 | _left = left; 27 | _right = right; 28 | _out = out; 29 | _func = func; 30 | _layer = NO_LAYER; 31 | } 32 | inline uint8_t func(uint8_t left, uint8_t right) { 33 | return _func[2*left+right]; 34 | } 35 | 36 | void print(int id) { 37 | printf ("gate %d: l:%lu, r:%lu, o:%lu, func:%d%d%d%d\n", id, _left, _right, _out, _func[0], _func[1], _func[2], _func[3] ); 38 | } 39 | 40 | }; 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /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/common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * common.h 3 | * 4 | */ 5 | 6 | #ifndef CIRCUIT_INC_COMMON_H_ 7 | #define CIRCUIT_INC_COMMON_H_ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | using namespace std; 15 | 16 | #include "Tools/CheckVector.h" 17 | 18 | typedef unsigned long wire_id_t; 19 | typedef unsigned long gate_id_t; 20 | typedef unsigned int party_id_t; 21 | 22 | class Function { 23 | bool rep[4]; 24 | int shift(int i) { return 4 * (3 - i); } 25 | public: 26 | Function() { memset(rep, 0, sizeof(rep)); } 27 | Function(std::string& func) 28 | { 29 | for (int i = 0; i < 4; i++) 30 | if (func[i] != '0') 31 | rep[i] = 1; 32 | else 33 | rep[i] = 0; 34 | } 35 | Function(int int_rep) 36 | { 37 | for (int i = 0; i < 4; i++) 38 | rep[i] = (int_rep << shift(i)) & 1; 39 | } 40 | uint8_t operator[](int i) { return rep[i]; } 41 | bool call(bool left, bool right) { return rep[2 * left + right]; } 42 | }; 43 | 44 | #endif /* CIRCUIT_INC_COMMON_H_ */ 45 | -------------------------------------------------------------------------------- /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/GC/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/data61/MP-SPDZ/9f2a641a9427fa01380b262402424798d097c789/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/__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/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 | KeySetup> key; 19 | string prefix = PREP_DIR "ECDSA/"; 20 | mkdir_p(prefix.c_str()); 21 | write_online_setup(prefix, P256Element::Scalar::pr()); 22 | PRNG G; 23 | G.ReSeed(); 24 | generate_mac_keys>(key, 2, prefix, G); 25 | make_mult_triples>(key, 2, 1000, false, prefix, G); 26 | make_inverse>(key, 2, 1000, false, prefix, G); 27 | P256Element::finish(); 28 | } 29 | -------------------------------------------------------------------------------- /ECDSA/atlas-ecdsa-party.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * atlas-ecdsa-party.cpp 3 | * 4 | */ 5 | 6 | #define NO_MIXED_CIRCUITS 7 | 8 | #include "Machines/Atlas.hpp" 9 | 10 | #include "hm-ecdsa-party.hpp" 11 | 12 | int main(int argc, const char** argv) 13 | { 14 | ez::ezOptionParser opt; 15 | ShamirOptions(opt, argc, argv); 16 | run(argc, argv); 17 | } 18 | -------------------------------------------------------------------------------- /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/rep4-ecdsa-party.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * rep4-ecsda-party.cpp 3 | * 4 | */ 5 | 6 | #include "Machines/Rep4.hpp" 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/Hemi.hpp" 10 | #include "Protocols/SemiMC.hpp" 11 | #include "Protocols/SemiPrep.hpp" 12 | #include "Protocols/SemiInput.hpp" 13 | #include "Protocols/MAC_Check_Base.hpp" 14 | #include "GC/SemiSecret.hpp" 15 | #include "ot-ecdsa-party.hpp" 16 | 17 | #include 18 | 19 | int main(int argc, const char** argv) 20 | { 21 | run(argc, argv); 22 | } 23 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /ExternalIO/bankers-bonus-client.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | import sys 4 | 5 | sys.path.append('.') 6 | 7 | from client import * 8 | from domains import * 9 | 10 | client_id = int(sys.argv[1]) 11 | n_parties = int(sys.argv[2]) 12 | bonus = float(sys.argv[3]) 13 | finish = int(sys.argv[4]) 14 | 15 | client = Client(['localhost'] * n_parties, 14000, client_id) 16 | 17 | for socket in client.sockets: 18 | os = octetStream() 19 | os.store(finish) 20 | os.Send(socket) 21 | 22 | def run(x): 23 | client.send_private_inputs([x]) 24 | 25 | print('Winning client id is :', client.receive_outputs(1)[0]) 26 | 27 | # running two rounds 28 | # first for sint, then for sfix 29 | run(bonus) 30 | run(bonus * 2 ** 16) 31 | -------------------------------------------------------------------------------- /ExternalIO/personal-client-example.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | import sys, random 4 | 5 | sys.path.insert(0, 'ExternalIO') 6 | 7 | from client import * 8 | 9 | party = int(sys.argv[1]) 10 | 11 | client = Client(['localhost'], 15000 + party, 0) 12 | 13 | n = 1000 14 | 15 | if party < 2: 16 | client.send_public_inputs(random.gauss(0, 1) * 2 ** 16 for i in range(n)) 17 | 18 | x = [client.receive_plain_values() for i in range(2)] 19 | client.send_public_inputs(a + b for a, b in zip(*x)) 20 | -------------------------------------------------------------------------------- /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/Diagonalizer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Diagonalizer.h 3 | * 4 | */ 5 | 6 | #ifndef FHE_DIAGONALIZER_H_ 7 | #define FHE_DIAGONALIZER_H_ 8 | 9 | #include "Math/gfpvar.h" 10 | #include "Ciphertext.h" 11 | #include "Protocols/ShareMatrix.h" 12 | 13 | class Diagonalizer 14 | { 15 | const FFT_Data& FTD; 16 | 17 | size_t n_rows, n_cols; 18 | 19 | public: 20 | typedef AddableVector> MatrixVector; 21 | 22 | vector ciphertexts; 23 | 24 | Diagonalizer(const MatrixVector& matrices, 25 | const FFT_Data& FTD, const FHE_PK& pk); 26 | 27 | Plaintext_ get_plaintext(const MatrixVector& matrices, 28 | int left_col, int right_col); 29 | 30 | MatrixVector decrypt(const vector&, int n_matrices, FHE_SK& sk); 31 | 32 | MatrixVector dediag(const vector>& plaintexts, 33 | int n_matrices); 34 | }; 35 | 36 | #endif /* FHE_DIAGONALIZER_H_ */ 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 | Ring::Ring(int m) : 6 | mm(0), phim(0) 7 | { 8 | if (m != 0) 9 | init(*this, m); 10 | } 11 | 12 | void Ring::pack(octetStream& o) const 13 | { 14 | o.store(mm); 15 | if (((mm - 1) & mm) != 0) 16 | { 17 | o.store(phim); 18 | o.store(pi); 19 | o.store(pi_inv); 20 | o.store(poly); 21 | } 22 | } 23 | 24 | void Ring::unpack(octetStream& o) 25 | { 26 | o.get(mm); 27 | if (((mm - 1) & mm) != 0) 28 | { 29 | o.get(phim); 30 | o.get(pi); 31 | o.get(pi_inv); 32 | o.get(poly); 33 | } 34 | else if (mm != 0) 35 | init(*this, mm); 36 | } 37 | 38 | bool Ring::operator !=(const Ring& other) const 39 | { 40 | if (mm != other.mm or phim != other.phim or pi != other.pi 41 | or pi_inv != other.pi_inv or poly != other.poly) 42 | return true; 43 | else 44 | return false; 45 | } 46 | -------------------------------------------------------------------------------- /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/Reshare.h: -------------------------------------------------------------------------------- 1 | #ifndef _Reshare 2 | #define _Reshare 3 | 4 | /* The procedure for the Reshare protocol 5 | * Input is a ciphertext cm and a flag NewCiphertext 6 | * Output is a Ring_Element and possibly a ciphertext cc 7 | */ 8 | 9 | #include "FHE/Ciphertext.h" 10 | #include "Networking/Player.h" 11 | #include "FHEOffline/EncCommit.h" 12 | 13 | template class DistDecrypt; 14 | 15 | template 16 | void Reshare(Plaintext& m,Ciphertext& cc, 17 | const Ciphertext& cm,bool NewCiphertext, 18 | const Player& P,EncCommitBase& EC, 19 | const FHE_PK& pk,const FHE_SK& share); 20 | 21 | template 22 | void Reshare(Plaintext& m,Ciphertext& cc, 23 | const Ciphertext& cm,bool NewCiphertext, 24 | const Player& P,EncCommitBase& EC, 25 | const FHE_PK& pk,DistDecrypt& dd); 26 | 27 | #endif 28 | 29 | -------------------------------------------------------------------------------- /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, MachineBase&, int plaintext_length, int); 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/Access.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Access.h 3 | * 4 | */ 5 | 6 | #ifndef GC_ACCESS_H_ 7 | #define GC_ACCESS_H_ 8 | 9 | #include "Clear.h" 10 | 11 | namespace GC 12 | { 13 | 14 | template 15 | class ReadAccess 16 | { 17 | public: 18 | T& dest; 19 | const Clear address; 20 | const int length; 21 | 22 | ReadAccess(T& dest, Clear address, int length, size_t& complexity) : 23 | dest(dest), address(address), length(length) 24 | { 25 | complexity += length; 26 | } 27 | }; 28 | 29 | template 30 | class WriteAccess 31 | { 32 | public: 33 | const T& source; 34 | const Clear address; 35 | 36 | WriteAccess(Clear address, const T& source) : 37 | source(source), address(address) {} 38 | }; 39 | 40 | struct ClearWriteAccess 41 | { 42 | const Clear address, value; 43 | ClearWriteAccess(Clear address, Clear value) : address(address), value(value) {} 44 | }; 45 | 46 | } /* namespace GC */ 47 | 48 | #endif /* GC_ACCESS_H_ */ 49 | -------------------------------------------------------------------------------- /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/AtlasSecret.h: -------------------------------------------------------------------------------- 1 | /* 2 | * AtlasSecret.h 3 | * 4 | */ 5 | 6 | #ifndef GC_ATLASSECRET_H_ 7 | #define GC_ATLASSECRET_H_ 8 | 9 | #include "TinySecret.h" 10 | #include "AtlasShare.h" 11 | 12 | namespace GC 13 | { 14 | 15 | class AtlasSecret : public VectorSecret 16 | { 17 | typedef AtlasSecret This; 18 | typedef VectorSecret super; 19 | 20 | public: 21 | typedef TinyMC MC; 22 | typedef MC MAC_Check; 23 | typedef VectorProtocol Protocol; 24 | typedef VectorInput Input; 25 | typedef CcdPrep LivePrep; 26 | 27 | static string type_short() 28 | { 29 | return "atlas"; 30 | } 31 | 32 | static MC* new_mc(typename super::mac_key_type); 33 | 34 | AtlasSecret() 35 | { 36 | } 37 | 38 | template 39 | AtlasSecret(const T& other) : 40 | super(other) 41 | { 42 | } 43 | }; 44 | 45 | } 46 | 47 | #endif /* GC_ATLASSECRET_H_ */ 48 | -------------------------------------------------------------------------------- /GC/BitAdder.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BitAdder.h 3 | * 4 | */ 5 | 6 | #ifndef GC_BITADDER_H_ 7 | #define GC_BITADDER_H_ 8 | 9 | #include 10 | using namespace std; 11 | 12 | class BitAdder 13 | { 14 | public: 15 | template 16 | void add(vector>& res, const vector>>& summands, 17 | SubProcessor& proc, int length, ThreadQueues* queues = 0, 18 | int player = -1); 19 | 20 | template 21 | void add(vector>& res, const vector>>& summands, 22 | size_t begin, size_t end, SubProcessor& proc, int length, 23 | int input_begin = -1, const void* supply = 0); 24 | 25 | template 26 | void multi_add(vector>& res, const vector>>& summands, 27 | size_t begin, size_t end, SubProcessor& proc, int length, 28 | int input_begin); 29 | }; 30 | 31 | #endif /* GC_BITADDER_H_ */ 32 | -------------------------------------------------------------------------------- /GC/BitPrepFiles.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BitPrepFiles.h 3 | * 4 | */ 5 | 6 | #ifndef GC_BITPREPFILES_H_ 7 | #define GC_BITPREPFILES_H_ 8 | 9 | #include "ShiftableTripleBuffer.h" 10 | #include "Processor/Data_Files.h" 11 | 12 | namespace GC 13 | { 14 | 15 | template 16 | class BitPrepFiles : public ShiftableTripleBuffer, public Sub_Data_Files 17 | { 18 | public: 19 | BitPrepFiles(const Names& N, const string& prep_data_dir, 20 | DataPositions& usage, int thread_num = -1) : 21 | Sub_Data_Files(N, prep_data_dir, usage, thread_num) 22 | { 23 | } 24 | 25 | array get_triple_no_count(int n_bits) 26 | { 27 | return ShiftableTripleBuffer::get_triple_no_count(n_bits); 28 | } 29 | 30 | void get(Dtype type, T* data) 31 | { 32 | Sub_Data_Files::get(type, data); 33 | } 34 | }; 35 | 36 | } 37 | 38 | #endif /* GC_BITPREPFILES_H_ */ 39 | -------------------------------------------------------------------------------- /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/Rep4Prep.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Rep4Prep.cpp 3 | * 4 | */ 5 | 6 | #include "Rep4Prep.h" 7 | 8 | #include "Protocols/Rep4.hpp" 9 | #include "Protocols/Rep4Input.hpp" 10 | #include "Protocols/Replicated.hpp" 11 | #include "Protocols/ReplicatedPrep.hpp" 12 | 13 | namespace GC 14 | { 15 | 16 | Rep4Prep::Rep4Prep(DataPositions& usage, int) : 17 | BufferPrep(usage) 18 | { 19 | } 20 | 21 | void Rep4Prep::set_protocol(Rep4Secret::Protocol& protocol) 22 | { 23 | this->P = &protocol.P; 24 | } 25 | 26 | void Rep4Prep::buffer_bits() 27 | { 28 | assert(P); 29 | Rep4 proto(*P); 30 | for (int i = 0; i < OnlineOptions::singleton.batch_size; i++) 31 | this->bits.push_back(proto.get_random() & 1); 32 | } 33 | 34 | } /* namespace GC */ 35 | -------------------------------------------------------------------------------- /GC/Rep4Prep.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Rep4Prep.h 3 | * 4 | */ 5 | 6 | #ifndef GC_REP4PREP_H_ 7 | #define GC_REP4PREP_H_ 8 | 9 | #include "Rep4Secret.h" 10 | #include "PersonalPrep.h" 11 | #include "Protocols/ReplicatedPrep.h" 12 | 13 | namespace GC 14 | { 15 | 16 | class Rep4Prep : public BufferPrep 17 | { 18 | public: 19 | Rep4Prep(DataPositions& usage, int _ = -1); 20 | 21 | void set_protocol(Rep4Secret::Protocol& protocol); 22 | 23 | void buffer_bits(); 24 | }; 25 | 26 | } /* namespace GC */ 27 | 28 | #endif /* GC_REP4PREP_H_ */ 29 | -------------------------------------------------------------------------------- /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 | #ifdef DEBUG_YAO 24 | cout << "untaint from " << tainted << endl; 25 | #endif 26 | bool was_tainted = tainted; 27 | tainted = false; 28 | if (was_tainted) 29 | throw needs_cleaning(); 30 | else 31 | taint(); 32 | } 33 | void taint() 34 | { 35 | tainted = true; 36 | } 37 | 38 | bool is_tainted() 39 | { 40 | return tainted; 41 | } 42 | }; 43 | 44 | } /* namespace GC */ 45 | 46 | #endif /* GC_RUNTIMEBRANCHING_H_ */ 47 | -------------------------------------------------------------------------------- /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 | void prepare_mul(const SemiSecret& x, const SemiSecret& y, int n = -1); 28 | }; 29 | 30 | } /* namespace GC */ 31 | 32 | #endif /* GC_SEMI_H_ */ 33 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 "Protocols/Atlas.hpp" 14 | 15 | #include "Shamir.hpp" 16 | 17 | #endif /* MACHINES_ATLAS_HPP_ */ 18 | -------------------------------------------------------------------------------- /Machines/BMR/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/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/BMR/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/BMR/mal-shamir-bmr-party.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * mal-shamir-bmr-party.cpp 3 | * 4 | */ 5 | 6 | #include "BMR/RealProgramParty.hpp" 7 | #include "Machines/Shamir.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/BMR/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/BMR/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/BMR/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/BMR/shamir-bmr-party.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * shamir-bmr-party.cpp 3 | * 4 | */ 5 | 6 | #include "BMR/RealProgramParty.hpp" 7 | #include "Machines/Shamir.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/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 "GC/Rep4Prep.h" 11 | #include "Protocols/Rep4Share2k.h" 12 | #include "Protocols/Rep4Prep.h" 13 | #include "Protocols/Rep4.hpp" 14 | #include "Protocols/Rep4MC.hpp" 15 | #include "Protocols/Rep4Input.hpp" 16 | #include "Protocols/Rep4Prep.hpp" 17 | 18 | #endif /* MACHINES_REP4_HPP_ */ 19 | -------------------------------------------------------------------------------- /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 | 9 | template class Machine>, Share>; 10 | -------------------------------------------------------------------------------- /Machines/SPDZ.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDZ.hpp 3 | * 4 | */ 5 | 6 | #ifndef MACHINES_SPDZ_HPP_ 7 | #define MACHINES_SPDZ_HPP_ 8 | 9 | #include "Protocols/MAC_Check.h" 10 | #include "Protocols/SPDZ.h" 11 | 12 | #include "Processor/Data_Files.hpp" 13 | #include "Processor/Instruction.hpp" 14 | #include "Processor/Machine.hpp" 15 | #include "Processor/FieldMachine.hpp" 16 | 17 | #include "Protocols/MAC_Check.hpp" 18 | #include "Protocols/fake-stuff.hpp" 19 | #include "Protocols/Beaver.hpp" 20 | #include "Protocols/Share.hpp" 21 | #include "Protocols/ReplicatedPrep.hpp" 22 | #include "Protocols/Spdz2kPrep.hpp" 23 | 24 | #include "GC/TinierSecret.h" 25 | #include "GC/TinyMC.h" 26 | #include "GC/VectorInput.h" 27 | #include "GC/VectorProtocol.h" 28 | 29 | #include "GC/ShareParty.h" 30 | #include "GC/Secret.hpp" 31 | #include "GC/ShareSecret.h" 32 | #include "GC/TinierSharePrep.h" 33 | #include "GC/CcdPrep.h" 34 | 35 | #include "GC/VectorProtocol.hpp" 36 | 37 | #include "Math/gfp.hpp" 38 | 39 | #endif /* MACHINES_SPDZ_HPP_ */ 40 | -------------------------------------------------------------------------------- /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/SemiPrep.h" 10 | 11 | #include "Processor/Data_Files.hpp" 12 | #include "Processor/Instruction.hpp" 13 | #include "Processor/Machine.hpp" 14 | #include "Protocols/MascotPrep.hpp" 15 | #include "Protocols/SemiPrep.hpp" 16 | #include "Protocols/SemiInput.hpp" 17 | #include "Protocols/MAC_Check_Base.hpp" 18 | #include "Protocols/MAC_Check.hpp" 19 | #include "Protocols/SemiMC.hpp" 20 | #include "Protocols/Beaver.hpp" 21 | #include "Protocols/MalRepRingPrep.hpp" 22 | #include "GC/SemiSecret.hpp" 23 | -------------------------------------------------------------------------------- /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/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 | #include "Protocols/Share.hpp" 18 | 19 | //template class GC::ShareParty>; 20 | template class GC::CcdPrep>; 21 | template class Preprocessing>; 22 | template class GC::TinierSharePrep>; 23 | template class GC::ShareSecret>; 24 | template class TripleShuffleSacrifice>; 25 | -------------------------------------------------------------------------------- /Machines/astra-party.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * astra-party.cpp 3 | * 4 | */ 5 | 6 | #include "Protocols/AstraShare.h" 7 | #include "GC/AstraSecret.h" 8 | 9 | #include "Processor/Machine.hpp" 10 | #include "Processor/RingMachine.hpp" 11 | #include "Protocols/AstraInput.hpp" 12 | #include "Protocols/AstraPrep.hpp" 13 | #include "Protocols/AstraMC.hpp" 14 | #include "Protocols/Astra.hpp" 15 | #include "GC/ShareSecret.hpp" 16 | 17 | int main(int argc, const char** argv) 18 | { 19 | HonestMajorityRingMachine(argc, argv, 2); 20 | } 21 | -------------------------------------------------------------------------------- /Machines/astra-prep-party.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * astra-prep-party.cpp 3 | * 4 | */ 5 | 6 | #include "Protocols/AstraShare.h" 7 | #include "GC/AstraSecret.h" 8 | 9 | #include "Processor/Machine.hpp" 10 | #include "Processor/RingMachine.hpp" 11 | #include "Protocols/ReplicatedMC.hpp" 12 | #include "Protocols/AstraInput.hpp" 13 | #include "Protocols/AstraPrep.hpp" 14 | #include "Protocols/Astra.hpp" 15 | #include "Protocols/Trio.hpp" 16 | #include "GC/ShareSecret.hpp" 17 | 18 | int main(int argc, const char** argv) 19 | { 20 | HonestMajorityRingMachine(argc, argv); 21 | } 22 | -------------------------------------------------------------------------------- /Machines/atlas-party.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * atlas-party.cpp 3 | * 4 | */ 5 | 6 | #include "Atlas.hpp" 7 | 8 | int main(int argc, const char** argv) 9 | { 10 | ShamirMachineSpec(argc, argv); 11 | } 12 | -------------------------------------------------------------------------------- /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/Shamir.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/dealer-ring-party.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * dealer-ring-party.cpp 3 | * 4 | */ 5 | 6 | #include "Protocols/DealerShare.h" 7 | #include "Protocols/DealerInput.h" 8 | #include "Protocols/Dealer.h" 9 | 10 | #include "Processor/RingMachine.hpp" 11 | #include "Processor/Machine.hpp" 12 | #include "Protocols/Replicated.hpp" 13 | #include "Protocols/DealerPrep.hpp" 14 | #include "Protocols/DealerInput.hpp" 15 | #include "Protocols/DealerMC.hpp" 16 | #include "Protocols/DealerMatrixPrep.hpp" 17 | #include "Protocols/Beaver.hpp" 18 | #include "Protocols/SemiInput.hpp" 19 | #include "Protocols/MAC_Check_Base.hpp" 20 | #include "Protocols/ReplicatedPrep.hpp" 21 | #include "Protocols/MalRepRingPrep.hpp" 22 | #include "Protocols/SemiMC.hpp" 23 | #include "GC/DealerPrep.h" 24 | #include "GC/SemiPrep.h" 25 | #include "GC/SemiSecret.hpp" 26 | 27 | int main(int argc, const char** argv) 28 | { 29 | HonestMajorityRingMachine(argc, argv, 0); 30 | } 31 | -------------------------------------------------------------------------------- /Machines/export-atlas.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * export-vm.cpp 3 | * 4 | */ 5 | 6 | #include "maximal.hpp" 7 | 8 | template class Machine>>; 9 | -------------------------------------------------------------------------------- /Machines/export-cowgear.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * export-vm.cpp 3 | * 4 | */ 5 | 6 | #include "maximal.hpp" 7 | 8 | template class Machine>>; 9 | -------------------------------------------------------------------------------- /Machines/export-dealer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * export-vm.cpp 3 | * 4 | */ 5 | 6 | #include "maximal.hpp" 7 | 8 | template class Machine>>; 9 | -------------------------------------------------------------------------------- /Machines/export-hemi.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * export-vm.cpp 3 | * 4 | */ 5 | 6 | #include "maximal.hpp" 7 | 8 | template class Machine>>; 9 | -------------------------------------------------------------------------------- /Machines/export-rep4-ring.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * export-vm.cpp 3 | * 4 | */ 5 | 6 | #include "maximal.hpp" 7 | 8 | template class Machine>; 9 | -------------------------------------------------------------------------------- /Machines/export-ring.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * export-vm.cpp 3 | * 4 | */ 5 | 6 | #include "maximal.hpp" 7 | 8 | template class Machine>; 9 | -------------------------------------------------------------------------------- /Machines/export-semi2k.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * export-vm.cpp 3 | * 4 | */ 5 | 6 | #include "maximal.hpp" 7 | 8 | template class Machine>; 9 | -------------------------------------------------------------------------------- /Machines/export-sy-rep-ring.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * export-vm.cpp 3 | * 4 | */ 5 | 6 | #include "maximal.hpp" 7 | 8 | template class Machine>; 9 | -------------------------------------------------------------------------------- /Machines/hemi-offline.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "GC/TinierSecret.h" 3 | #include "GC/Semi.h" 4 | #include "GC/SemiPrep.h" 5 | #include "Protocols/HemiShare.h" 6 | 7 | #include "Semi.hpp" 8 | #include "Math/gfp.hpp" 9 | #include "Processor/FieldMachine.hpp" 10 | #include "Processor/OfflineMachine.hpp" 11 | #include "Protocols/MascotPrep.hpp" 12 | #include "Protocols/HemiPrep.hpp" 13 | 14 | int main(int argc, const char** argv) 15 | { 16 | ez::ezOptionParser opt; 17 | DishonestMajorityFieldMachine>(argc, argv, opt); 19 | } 20 | -------------------------------------------------------------------------------- /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-shamir-offline.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * mal-shamir-offline.cpp 3 | * 4 | */ 5 | 6 | #include 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/Shamir.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 "Protocols/MaliciousShamirShare.h" 7 | #include "Protocols/ShamirOptions.h" 8 | #include "Machines/MalRep.hpp" 9 | 10 | #include "Shamir.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/minimal.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * minimal.hpp 3 | * 4 | */ 5 | 6 | // minimal header file to make all C++ code compile 7 | // but not produce all templated code in binary 8 | // use maximal.hpp for that 9 | 10 | // please report if otherwise 11 | 12 | #ifndef MACHINES_MINIMAL_HPP_ 13 | #define MACHINES_MINIMAL_HPP_ 14 | 15 | #include "h-files.h" 16 | 17 | // some h files depend on hpp files 18 | 19 | #include "GC/Secret.hpp" 20 | #include "GC/SemiSecret.hpp" 21 | #include "Protocols/DealerMC.hpp" 22 | #include "Protocols/MAC_Check.hpp" 23 | #include "Protocols/MaliciousRepMC.hpp" 24 | #include "Protocols/ShamirMC.hpp" 25 | 26 | #endif /* MACHINES_MINIMAL_HPP_ */ 27 | -------------------------------------------------------------------------------- /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 "Processor/OnlineOptions.hpp" 11 | #include "Protocols/Replicated.hpp" 12 | #include "Protocols/MalRepRingPrep.hpp" 13 | #include "Protocols/ReplicatedPrep.hpp" 14 | #include "Protocols/MAC_Check_Base.hpp" 15 | #include "Math/gfp.hpp" 16 | #include "Math/Z2k.hpp" 17 | 18 | int main(int argc, const char** argv) 19 | { 20 | ez::ezOptionParser opt; 21 | OnlineOptions::singleton = {opt, argc, argv, NoShare()}; 22 | OnlineMachine machine(argc, argv, opt, OnlineOptions::singleton); 23 | OnlineOptions::singleton.finalize(opt, argc, argv); 24 | machine.start_networking(); 25 | // use primes of length 65 to 128 for arithmetic computation 26 | machine.run>, NoShare>(); 27 | } 28 | -------------------------------------------------------------------------------- /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/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 "GC/Rep4Prep.h" 14 | #include "Processor/RingOptions.h" 15 | 16 | #include "Processor/RingMachine.hpp" 17 | #include "Protocols/RepRingOnlyEdabitPrep.hpp" 18 | #include "Protocols/Rep4Input.hpp" 19 | #include "Protocols/Rep4Prep.hpp" 20 | #include "Protocols/Rep4MC.hpp" 21 | #include "Protocols/Rep4.hpp" 22 | #include "GC/BitAdder.hpp" 23 | #include "Math/Z2k.hpp" 24 | #include "Rep.hpp" 25 | 26 | int main(int argc, const char** argv) 27 | { 28 | HonestMajorityRingMachine(argc, argv, 4); 29 | } 30 | -------------------------------------------------------------------------------- /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 | #include "Protocols/Rep3Share2k.h" 7 | #include "Processor/RingOptions.h" 8 | #include "Math/Integer.h" 9 | #include "Machines/RepRing.hpp" 10 | #include "Processor/RingMachine.hpp" 11 | 12 | int main(int argc, const char** argv) 13 | { 14 | HonestMajorityRingMachine(argc, argv); 15 | } 16 | -------------------------------------------------------------------------------- /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-offline.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "GC/TinierSecret.h" 3 | #include "GC/Semi.h" 4 | #include "GC/SemiPrep.h" 5 | 6 | #include "Semi.hpp" 7 | #include "Math/gfp.hpp" 8 | #include "Processor/FieldMachine.hpp" 9 | #include "Processor/OfflineMachine.hpp" 10 | #include "Protocols/MascotPrep.hpp" 11 | 12 | int main(int argc, const char** argv) 13 | { 14 | ez::ezOptionParser opt; 15 | DishonestMajorityFieldMachine>(argc, argv, opt); 17 | } 18 | -------------------------------------------------------------------------------- /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-offline.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "GC/TinierSecret.h" 3 | #include "GC/Semi.h" 4 | #include "GC/SemiPrep.h" 5 | #include "Protocols/Semi2kShare.h" 6 | #include "Protocols/SemiPrep2k.h" 7 | #include "Math/gf2n.h" 8 | 9 | #include "Semi.hpp" 10 | #include "Math/gfp.hpp" 11 | #include "Processor/RingMachine.hpp" 12 | #include "Processor/OfflineMachine.hpp" 13 | #include "Protocols/MascotPrep.hpp" 14 | #include "Protocols/RepRingOnlyEdabitPrep.hpp" 15 | 16 | int main(int argc, const char** argv) 17 | { 18 | ez::ezOptionParser opt; 19 | DishonestMajorityRingMachine>(argc, argv, opt); 21 | } 22 | -------------------------------------------------------------------------------- /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/shamir-party.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * shamir-party.cpp 3 | * 4 | */ 5 | 6 | #include "Protocols/ShamirOptions.h" 7 | #include "Protocols/ShamirShare.h" 8 | 9 | #include "Shamir.hpp" 10 | 11 | int main(int argc, const char** argv) 12 | { 13 | ShamirMachineSpec(argc, argv); 14 | } 15 | -------------------------------------------------------------------------------- /Machines/sy-shamir-party.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * sy-shamir-party.cpp 3 | * 4 | */ 5 | 6 | #include "Protocols/SpdzWiseShare.h" 7 | #include "Protocols/MaliciousShamirShare.h" 8 | #include "Protocols/SpdzWiseMC.h" 9 | #include "Protocols/SpdzWiseInput.h" 10 | #include "Math/gfp.h" 11 | #include "Math/gf2n.h" 12 | #include "GC/CcdSecret.h" 13 | #include "GC/MaliciousCcdSecret.h" 14 | #include "GC/SemiHonestRepPrep.h" 15 | 16 | #include "Protocols/Share.hpp" 17 | #include "Protocols/SpdzWise.hpp" 18 | #include "Protocols/SpdzWisePrep.hpp" 19 | #include "Protocols/SpdzWiseInput.hpp" 20 | #include "Protocols/SpdzWiseShare.hpp" 21 | #include "Machines/Shamir.hpp" 22 | #include "Machines/MalRep.hpp" 23 | 24 | template 25 | using SpdzWiseShamirShare = SpdzWiseShare>; 26 | 27 | int main(int argc, const char** argv) 28 | { 29 | ShamirMachineSpec(argc, argv); 30 | } 31 | -------------------------------------------------------------------------------- /Machines/tiny-party.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * tiny-party.cpp 3 | * 4 | */ 5 | 6 | #include "GC/TinySecret.h" 7 | #include "GC/TinierSecret.h" 8 | #include "GC/ShareParty.h" 9 | #include "GC/TinyMC.h" 10 | #include "GC/VectorInput.h" 11 | 12 | #include "GC/ShareParty.hpp" 13 | #include "GC/ShareSecret.hpp" 14 | #include "GC/Machine.hpp" 15 | #include "GC/Processor.hpp" 16 | #include "GC/Program.hpp" 17 | #include "GC/Thread.hpp" 18 | #include "GC/ThreadMaster.hpp" 19 | #include "GC/Secret.hpp" 20 | #include "GC/TinyPrep.hpp" 21 | #include "GC/CcdPrep.hpp" 22 | #include "GC/TinierSharePrep.hpp" 23 | 24 | #include "Processor/Instruction.hpp" 25 | #include "Protocols/MAC_Check.hpp" 26 | #include "Protocols/MAC_Check_Base.hpp" 27 | #include "Protocols/Beaver.hpp" 28 | #include "Protocols/MascotPrep.hpp" 29 | #include "Protocols/Share.hpp" 30 | 31 | int main(int argc, const char** argv) 32 | { 33 | GC::simple_binary_main>(argc, argv, 1000); 34 | } 35 | -------------------------------------------------------------------------------- /Machines/trio-party.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * trio-party.cpp 3 | * 4 | */ 5 | 6 | #include "Protocols/TrioShare.h" 7 | #include "Protocols/TrioMC.h" 8 | #include "GC/AstraSecret.h" 9 | 10 | #include "Processor/Machine.hpp" 11 | #include "Processor/RingMachine.hpp" 12 | #include "Protocols/AstraInput.hpp" 13 | #include "Protocols/AstraPrep.hpp" 14 | #include "Protocols/AstraMC.hpp" 15 | #include "Protocols/Trio.hpp" 16 | #include "Protocols/TrioInput.hpp" 17 | #include "GC/ShareSecret.hpp" 18 | 19 | int main(int argc, const char** argv) 20 | { 21 | HonestMajorityRingMachine(argc, argv, 2); 22 | } 23 | -------------------------------------------------------------------------------- /Machines/trio-prep-party.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * trio-prep-party.cpp 3 | * 4 | */ 5 | 6 | #include "Protocols/TrioShare.h" 7 | #include "GC/AstraSecret.h" 8 | 9 | #include "Processor/Machine.hpp" 10 | #include "Processor/RingMachine.hpp" 11 | #include "Protocols/AstraInput.hpp" 12 | #include "Protocols/AstraPrep.hpp" 13 | #include "Protocols/AstraMC.hpp" 14 | #include "Protocols/Trio.hpp" 15 | #include "GC/ShareSecret.hpp" 16 | 17 | int main(int argc, const char** argv) 18 | { 19 | HonestMajorityRingMachine(argc, argv); 20 | } 21 | -------------------------------------------------------------------------------- /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/ValueInterface.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ValueInterface.cpp 3 | * 4 | */ 5 | 6 | #include "bigint.h" 7 | #include "ValueInterface.h" 8 | 9 | #include 10 | 11 | const false_type ValueInterface::binary; 12 | 13 | void ValueInterface::check_setup(const string& directory) 14 | { 15 | struct stat sb; 16 | if (stat(directory.c_str(), &sb) != 0) 17 | throw setup_error(directory + " does not exist"); 18 | if (not (sb.st_mode & S_IFDIR)) 19 | throw setup_error(directory + " is not a directory"); 20 | } 21 | -------------------------------------------------------------------------------- /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 | DATA_RANDOM, 21 | DATA_OPEN, 22 | N_DTYPE, 23 | }; 24 | 25 | #endif /* MATH_FIELD_TYPES_H_ */ 26 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /Networking/Sender.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Sender.h 3 | * 4 | */ 5 | 6 | #ifndef NETWORKING_SENDER_H_ 7 | #define NETWORKING_SENDER_H_ 8 | 9 | #include 10 | 11 | #include "Receiver.h" 12 | 13 | #include "Tools/octetStream.h" 14 | #include "Tools/WaitQueue.h" 15 | #include "Tools/time-func.h" 16 | 17 | template 18 | class Sender : CommunicationThread 19 | { 20 | T socket; 21 | WaitQueue in; 22 | WaitQueue out; 23 | pthread_t thread; 24 | 25 | static void* run_thread(void* sender); 26 | 27 | // prevent copying 28 | Sender(const Sender& other); 29 | 30 | void start(); 31 | void stop(); 32 | void run_with_error(); 33 | 34 | public: 35 | Timer timer; 36 | 37 | Sender(T socket, int other); 38 | ~Sender(); 39 | 40 | T get_socket() 41 | { 42 | return socket; 43 | } 44 | 45 | void request(const octetStream& os); 46 | void wait(const octetStream& os); 47 | }; 48 | 49 | #endif /* NETWORKING_SENDER_H_ */ 50 | -------------------------------------------------------------------------------- /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_bit(rows[i].get_bit(i)); 12 | os.append(0); 13 | } 14 | 15 | void BitDiagonal::unpack(octetStream& os) 16 | { 17 | *this = {}; 18 | for (int i = 0; i < N_ROWS; i++) 19 | rows[i] = RowType(os.get_bit()) << i; 20 | } 21 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | items[0] = round(x * exp2(*params)); 16 | } 17 | 18 | template<> 19 | void FixInput_::read(std::istream& in, const int* params) 20 | { 21 | #ifdef HIGH_PREC_INPUT 22 | mpf_class x; 23 | in >> x; 24 | items[0] = x << *params; 25 | #else 26 | double x; 27 | in >> x; 28 | items[0] = round(x * exp2(*params)); 29 | #endif 30 | } 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 | } 24 | -------------------------------------------------------------------------------- /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/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/OfflineMachine.h: -------------------------------------------------------------------------------- 1 | /* 2 | * DishonestMajorityOfflineMachine.h 3 | * 4 | */ 5 | 6 | #ifndef PROCESSOR_OFFLINEMACHINE_H_ 7 | #define PROCESSOR_OFFLINEMACHINE_H_ 8 | 9 | #include "OnlineMachine.h" 10 | #include "Data_Files.h" 11 | #include "BaseMachine.h" 12 | #include "Networking/CryptoPlayer.h" 13 | 14 | template 15 | class OfflineMachine : public W, BaseMachine 16 | { 17 | DataPositions usage; 18 | Names& playerNames; 19 | Player& P; 20 | 21 | template 22 | void generate(); 23 | 24 | int buffered_total(size_t required, size_t batch); 25 | 26 | public: 27 | template 28 | OfflineMachine(int argc, const char** argv, 29 | ez::ezOptionParser& opt, OnlineOptions& online_opts, V, 30 | int nplayers = 0); 31 | ~OfflineMachine(); 32 | 33 | template 34 | int run(); 35 | 36 | const Names& get_N(); 37 | }; 38 | 39 | #endif /* PROCESSOR_OFFLINEMACHINE_H_ */ 40 | -------------------------------------------------------------------------------- /Processor/Online-Thread.h: -------------------------------------------------------------------------------- 1 | #ifndef _Online_Thread 2 | #define _Online_Thread 3 | 4 | #include "Networking/Player.h" 5 | #include "Math/gf2n.h" 6 | #include "Math/Integer.h" 7 | #include "Processor/Data_Files.h" 8 | 9 | #include 10 | using namespace std; 11 | 12 | template class Machine; 13 | 14 | template 15 | class thread_info 16 | { 17 | public: 18 | 19 | int thread_num; 20 | Names* Nms; 21 | typename sgf2n::mac_key_type *alpha2i; 22 | typename sint::mac_key_type *alphapi; 23 | 24 | Machine* machine; 25 | Processor* processor; 26 | 27 | static void* Main_Func(void *ptr); 28 | 29 | static void purge_preprocessing(const Names& N, int thread_num); 30 | 31 | template 32 | static void print_usage(ostream& o, const vector& regs, 33 | const char* name); 34 | 35 | void Sub_Main_Func(); 36 | void Main_Func_With_Purge(); 37 | }; 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /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/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 | TimerWithComm sum(const string& phase); 29 | 30 | void print_breakdown(); 31 | 32 | NamedCommStats total_comm(); 33 | NamedCommStats max_comm(); 34 | }; 35 | 36 | #endif /* PROCESSOR_THREADQUEUES_H_ */ 37 | -------------------------------------------------------------------------------- /Processor/TruncPrTuple.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * TruncPrTuple.cpp 3 | * 4 | */ 5 | 6 | #include "TruncPrTuple.h" 7 | 8 | void trunc_pr_check(int k, int m, int n_bits) 9 | { 10 | if (not (m < k and 0 < m and k <= n_bits)) 11 | { 12 | stringstream ss; 13 | ss << "invalid trunc_pr parameters, need 0 < m=" << m << " < k=" << k 14 | << " <= n_bits=" << n_bits; 15 | throw Processor_Error(ss.str()); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /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/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 | trainer = decision_tree.TreeTrainer( 28 | train[1], train[0], n_levels, binary=binary, n_threads=n_threads) 29 | trainer.time = 'time' in program.args 30 | layers = trainer.train() 31 | 32 | #decision_tree.output_decision_tree(layers) 33 | 34 | #decision_tree.test_decision_tree('foo', layers, *train) 35 | -------------------------------------------------------------------------------- /Programs/Source/export-a2b.py: -------------------------------------------------------------------------------- 1 | @export 2 | def a2b(x, res): 3 | print_ln('x=%s', x.reveal()) 4 | res[:] = sbitvec(x, length=16) 5 | print_ln('res=%s', x.reveal()) 6 | 7 | a2b(sint(size=10), sbitvec.get_type(16).Array(10)) 8 | -------------------------------------------------------------------------------- /Programs/Source/export-b2a.py: -------------------------------------------------------------------------------- 1 | @export 2 | def b2a(res, x): 3 | print_ln('x=%s', x.reveal()) 4 | res[:] = sint(x[:]) 5 | print_ln('res=%s', x.reveal()) 6 | 7 | b2a(sint.Array(size=10), sbitvec.get_type(16).Array(10)) 8 | -------------------------------------------------------------------------------- /Programs/Source/export-msort.py: -------------------------------------------------------------------------------- 1 | @export 2 | def sort(x, key_indices): 3 | print_ln('x=%s', x.reveal()) 4 | print_ln('key_indices=%s', key_indices) 5 | res = x.sort(key_indices=key_indices) 6 | print_ln('res=%s', x.reveal()) 7 | 8 | sort(sint.Matrix(500, 2), regint(0, size=1)) 9 | -------------------------------------------------------------------------------- /Programs/Source/export-sort.py: -------------------------------------------------------------------------------- 1 | @export 2 | def sort(x): 3 | print_ln('x=%s', x.reveal()) 4 | res = x.sort() 5 | print_ln('res=%s', x.reveal()) 6 | 7 | sort(sint.Array(1000)) 8 | -------------------------------------------------------------------------------- /Programs/Source/export-trunc.py: -------------------------------------------------------------------------------- 1 | @export 2 | def trunc_pr(x): 3 | print_ln('x=%s', x.reveal()) 4 | res = x.round(32, 2) 5 | print_ln('res=%s', res.reveal()) 6 | return res 7 | 8 | trunc_pr(sint(0, size=1000)) 9 | -------------------------------------------------------------------------------- /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 | sbits.dynamic_array = DynamicArray 9 | 10 | bits.unit = 64 11 | 12 | from Compiler.circuit_oram import * 13 | from Compiler import circuit_oram 14 | 15 | import oram 16 | oram.n_threads = 1 17 | oram.n_threads_for_tree = 1 18 | 19 | # ORAM/array size 20 | n = 1000000 21 | 22 | # some parameters 23 | oram.max_demux_bits = 0 24 | circuit_oram.threshold = 128 25 | 26 | # Circuit ORAM 27 | oram_type = AtLeastOneRecursionPackedCircuitORAM 28 | 29 | # linear scan (no ORAM) 30 | #oram_type = LinearORAM 31 | 32 | oram = test_oram(oram_type, n, value_type=sbits, iterations=3) 33 | -------------------------------------------------------------------------------- /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/multinode_example_worker.py: -------------------------------------------------------------------------------- 1 | n_threads = int(program.args[1]) 2 | n_ops_per_thread = int(program.args[2]) 3 | worker_id = int(program.args[3]) 4 | 5 | if len(program.args) > 4: 6 | host = program.args[4] 7 | else: 8 | host = 'localhost' 9 | 10 | n_ops = n_threads * n_ops_per_thread 11 | data = sint.Array(n_ops) 12 | 13 | main = init_client_connection(host, 15000, worker_id) 14 | 15 | data.read_from_socket(main) 16 | 17 | @for_range_opt_multithread(n_threads, n_ops) 18 | def _(i): 19 | data[i] = data[i] ** 2 20 | 21 | data.write_to_socket(main) 22 | -------------------------------------------------------------------------------- /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/personal_client_example.py: -------------------------------------------------------------------------------- 1 | listen_for_clients(15000) 2 | socket = accept_client_connection(15000) 3 | 4 | n = 1000 5 | 6 | for i in range(2): 7 | x = personal.read_fix_from_socket(i, socket, n) 8 | sfix(x).write_fully_to_socket(socket) 9 | 10 | res = sum(sfix.read_from_socket(socket, n)) 11 | print_ln('%s', res.reveal()) 12 | -------------------------------------------------------------------------------- /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 | 25 | a = 1 26 | if True: 27 | if True: 28 | a = 2 29 | if True: 30 | a = 3 31 | else: 32 | a = 4 33 | crash() 34 | -------------------------------------------------------------------------------- /Programs/Source/test_sbitint.mpc: -------------------------------------------------------------------------------- 1 | program.options.merge_opens = False 2 | 3 | from Compiler.GC.types import * 4 | 5 | def test(a, b, value_type=None): 6 | try: 7 | a = a.reveal() 8 | except AttributeError: 9 | pass 10 | import inspect 11 | print_ln('%s: %s %s %s', inspect.currentframe().f_back.f_lineno, \ 12 | (a ^ cbits(b)).reveal(), a, hex(b)) 13 | 14 | si32 = sbitint.get_type(32) 15 | 16 | test(si32(3) + si32(2), 5) 17 | test(si32(3) - si32(2), 1) 18 | test(si32(3) < si32(2), 0) 19 | test(si32(3) > si32(2), 1) 20 | test(si32(2) <= si32(2), 1) 21 | test((si32(0) < si32(1)).if_else(si32(1), si32(2)) + si32(3), 4) 22 | 23 | test(si32(3) * si32(2), 6) 24 | test(3 * si32(2), 6) 25 | test(si32(3) * 2, 6) 26 | 27 | test(si32(-1), 2**32 - 1) 28 | test(si32(-1) + si32(3), 2) 29 | test(si32(-1) - si32(-2), 1) 30 | 31 | test(si32(1) * 2 * 2, 4) 32 | 33 | for i in range(3, 32): 34 | t = sbitint.get_type(i) 35 | test(t(3) + t(2), 5) 36 | 37 | test(abs(si32(-2)), 2) 38 | test(abs(si32(2)), 2) 39 | -------------------------------------------------------------------------------- /Programs/Source/test_thread_mul.mpc: -------------------------------------------------------------------------------- 1 | n = 1000000 2 | x = sint.Array(n) 3 | x.assign_vector(regint.inc(n)) 4 | 5 | @multithread(2, n) 6 | def _(base, size): 7 | x.assign_vector(x.get_vector(base, size) ** 2, base) 8 | 9 | print_ln('%s', x[2].reveal()) 10 | crash(x[2].reveal() != 4) 11 | crash(x[n - 1].reveal() != (n - 1) ** 2) 12 | -------------------------------------------------------------------------------- /Programs/Source/tf.mpc: -------------------------------------------------------------------------------- 1 | import ml 2 | import util 3 | import math 4 | import subprocess 5 | 6 | if 'trunc_pr' in program.args: 7 | program.use_trunc_pr = True 8 | if 'split' in program.args: 9 | program.use_split(3) 10 | 11 | try: 12 | n_threads = int(program.args[2]) 13 | except: 14 | n_threads = None 15 | ml.Layer.n_threads = n_threads 16 | ml.FixConv2d.use_conv2ds = True 17 | 18 | sfix.set_precision(12, 31) 19 | 20 | layers = [] 21 | named = {} 22 | 23 | exec(subprocess.check_output(['Scripts/process-tf.py', program.args[1]])) 24 | 25 | opt = ml.Optimizer() 26 | opt.set_layers_with_inputs(layers) 27 | layers[0].X.input_from(0, binary=True) 28 | for layer in layers: 29 | layer.input_from(0, binary=True) 30 | 31 | sint(0).reveal().store_in_mem(0) 32 | 33 | opt.time_layers = 'time_layers' in program.args 34 | 35 | start_timer(1) 36 | opt.forward(1, keep_intermediate=False) 37 | stop_timer(1) 38 | if isinstance(layers[-1].Y, Array): 39 | print_ln('guess %s', layers[-1].Y[0].reveal()) 40 | -------------------------------------------------------------------------------- /Protocols/AstraMC.h: -------------------------------------------------------------------------------- 1 | /* 2 | * AstraMC.h 3 | * 4 | */ 5 | 6 | #ifndef PROTOCOLS_ASTRAMC_H_ 7 | #define PROTOCOLS_ASTRAMC_H_ 8 | 9 | #include "MAC_Check_Base.h" 10 | 11 | template 12 | class AstraMC : public MAC_Check_Base 13 | { 14 | public: 15 | AstraMC(typename T::mac_key_type = {}, int = 0, int = 0) 16 | { 17 | } 18 | 19 | virtual typename T::open_type prepare_summand(const T& secret, int my_num); 20 | 21 | void exchange(const Player& P); 22 | 23 | AstraMC& get_part_MC() 24 | { 25 | return *this; 26 | } 27 | }; 28 | 29 | #endif /* PROTOCOLS_ASTRAMC_H_ */ 30 | -------------------------------------------------------------------------------- /Protocols/AstraMC.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * AstraMC.cpp 3 | * 4 | */ 5 | 6 | #include "AstraMC.h" 7 | 8 | #include "SemiMC.hpp" 9 | 10 | template 11 | typename T::open_type AstraMC::prepare_summand(const T& secret, int my_num) 12 | { 13 | if (my_num == 1) 14 | return secret.m(my_num) - secret.lambda(my_num); 15 | else 16 | return -secret.lambda(my_num); 17 | } 18 | 19 | template 20 | void AstraMC::exchange(const Player& P) 21 | { 22 | SemiMC> opener; 23 | opener.init_open(P, this->secrets.size()); 24 | int my_num = P.my_num() + 1; 25 | 26 | for (auto& secret : this->secrets) 27 | { 28 | if (P.my_num() == 1) 29 | opener.prepare_open(prepare_summand(secret, my_num)); 30 | else 31 | opener.prepare_open(prepare_summand(secret, my_num)); 32 | } 33 | 34 | opener.exchange(P); 35 | 36 | for (size_t i = 0; i < this->secrets.size(); i++) 37 | this->values.push_back(opener.finalize_open()); 38 | } 39 | -------------------------------------------------------------------------------- /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/BufferScope.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BufferScope.h 3 | * 4 | */ 5 | 6 | #ifndef PROTOCOLS_BUFFERSCOPE_H_ 7 | #define PROTOCOLS_BUFFERSCOPE_H_ 8 | 9 | template class BufferPrep; 10 | template class Preprocessing; 11 | 12 | #include "Processor/OnlineOptions.h" 13 | 14 | template 15 | class BufferScope 16 | { 17 | T& prep; 18 | int bak; 19 | 20 | public: 21 | BufferScope(T& prep, int buffer_size) : 22 | prep(prep) 23 | { 24 | bak = this->prep.buffer_size; 25 | this->prep.buffer_size = buffer_size; 26 | } 27 | 28 | ~BufferScope() 29 | { 30 | prep.buffer_size = bak; 31 | } 32 | }; 33 | 34 | #endif /* PROTOCOLS_BUFFERSCOPE_H_ */ 35 | -------------------------------------------------------------------------------- /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 | int minimum_batch() 30 | { 31 | return -1; 32 | } 33 | 34 | void buffer_triples(); 35 | }; 36 | 37 | #endif /* PROTOCOLS_DEALERMATRIXPREP_H_ */ 38 | -------------------------------------------------------------------------------- /Protocols/DummyMatrixPrep.h: -------------------------------------------------------------------------------- 1 | /* 2 | * DummyMatrixPrep.h 3 | * 4 | */ 5 | 6 | #ifndef PROTOCOLS_DUMMYMATRIXPREP_H_ 7 | #define PROTOCOLS_DUMMYMATRIXPREP_H_ 8 | 9 | #include "Processor/Data_Files.h" 10 | #include "ShareMatrix.h" 11 | 12 | class no_matrix_prep : public exception 13 | { 14 | }; 15 | 16 | template 17 | class DummyMatrixPrep : public Preprocessing> 18 | { 19 | public: 20 | DummyMatrixPrep(int, int, int, Preprocessing&, DataPositions& usage) : 21 | Preprocessing>(usage) 22 | { 23 | throw no_matrix_prep(); 24 | } 25 | }; 26 | 27 | #endif /* PROTOCOLS_DUMMYMATRIXPREP_H_ */ 28 | -------------------------------------------------------------------------------- /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/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/RepRingOnlyEdabitPrep.h: -------------------------------------------------------------------------------- 1 | /* 2 | * RepRingOnlyEdabitPrep.h 3 | * 4 | */ 5 | 6 | #ifndef PROTOCOLS_REPRINGONLYEDABITPREP_H_ 7 | #define PROTOCOLS_REPRINGONLYEDABITPREP_H_ 8 | 9 | #include "ReplicatedPrep.h" 10 | 11 | /** 12 | * edaBit generation for replicated secret sharing modulo a power of two 13 | */ 14 | template 15 | class RepRingOnlyEdabitPrep : public virtual BufferPrep 16 | { 17 | protected: 18 | void buffer_edabits(int n_bits, ThreadQueues*); 19 | 20 | public: 21 | static void edabit_sacrifice_buckets(vector>&, size_t, bool, int, 22 | SubProcessor&, int, int, const void* = 0) 23 | { 24 | throw runtime_error("no need for sacrifice"); 25 | } 26 | 27 | RepRingOnlyEdabitPrep(SubProcessor*, DataPositions& usage) : 28 | BufferPrep(usage) 29 | { 30 | } 31 | }; 32 | 33 | #endif /* PROTOCOLS_REPRINGONLYEDABITPREP_H_ */ 34 | -------------------------------------------------------------------------------- /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 | #include "ReplicatedPO.h" 7 | 8 | #include "MaliciousRepPO.hpp" 9 | 10 | template 11 | void ReplicatedPO::send(int player) 12 | { 13 | if (this->P.get_offset(player) == 2) 14 | this->P.send_to(player, this->to_send); 15 | } 16 | 17 | template 18 | void ReplicatedPO::receive() 19 | { 20 | this->P.receive_relative(1, this->to_receive[0]); 21 | } 22 | -------------------------------------------------------------------------------- /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 "Hemi.h" 10 | #include "SemiShare.h" 11 | 12 | #include 13 | using namespace std; 14 | 15 | template class SubProcessor; 16 | template class Share; 17 | class Player; 18 | 19 | /** 20 | * SPDZ protocol 21 | */ 22 | template 23 | class SPDZ : public MaybeHemi 24 | { 25 | public: 26 | SPDZ(Player& P) : MaybeHemi(P) 27 | { 28 | } 29 | 30 | int get_n_relevant_players() 31 | { 32 | return this->P.num_players(); 33 | } 34 | }; 35 | 36 | #endif /* PROTOCOLS_SPDZ_H_ */ 37 | -------------------------------------------------------------------------------- /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 | static bool bits_from_dabits(); 31 | }; 32 | 33 | #endif /* PROTOCOLS_SEMIPREP_H_ */ 34 | -------------------------------------------------------------------------------- /Protocols/ShamirOptions.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ShamirMachine.h 3 | * 4 | */ 5 | 6 | #ifndef PROTOCOLS_SHAMIROPTIONS_H_ 7 | #define PROTOCOLS_SHAMIROPTIONS_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 /* PROTOCOLS_SHAMIROPTIONS_H_ */ 38 | -------------------------------------------------------------------------------- /Protocols/ShareInterface.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ShareInterface.cpp 3 | * 4 | */ 5 | 6 | #include "ShareInterface.h" 7 | #include "GC/NoShare.h" 8 | 9 | const int ShareInterface::default_length; 10 | 11 | const false_type ShareInterface::triple_matmul; 12 | 13 | GC::NoValue ShareInterface::get_mac_key() 14 | { 15 | throw runtime_error("no MAC"); 16 | } 17 | 18 | void ShareInterface::set_mac_key(GC::NoValue) 19 | { 20 | } 21 | -------------------------------------------------------------------------------- /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 const bool homomorphic = true; 22 | 23 | static void basic_setup(Player& P); 24 | static void teardown(); 25 | 26 | SohoPrep(SubProcessor* proc, DataPositions& usage) : 27 | BufferPrep(usage), 28 | BitPrep(proc, usage), RingPrep(proc, usage), 29 | SemiHonestRingPrep(proc, usage) 30 | { 31 | } 32 | 33 | void buffer_triples(); 34 | void buffer_squares(); 35 | void buffer_bits(); 36 | }; 37 | 38 | #endif /* PROTOCOLS_SOHOPREP_H_ */ 39 | -------------------------------------------------------------------------------- /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 Beaver BasicProtocol; 25 | typedef MaybeHemi Protocol; 26 | typedef SohoPrep LivePrep; 27 | typedef DummyMatrixPrep MatrixPrep; 28 | 29 | static const bool needs_ot = false; 30 | 31 | SohoShare() 32 | { 33 | } 34 | 35 | template 36 | SohoShare(const U& other) : 37 | super(other) 38 | { 39 | } 40 | }; 41 | 42 | #endif /* PROTOCOLS_SOHOSHARE_H_ */ 43 | -------------------------------------------------------------------------------- /Protocols/SpdzWiseRing.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SpdzWiseRing.h 3 | * 4 | */ 5 | 6 | #ifndef PROTOCOLS_SPDZWISERING_H_ 7 | #define PROTOCOLS_SPDZWISERING_H_ 8 | 9 | #include "SpdzWise.h" 10 | #include "PostSacrifice.h" 11 | #include "PostSacriRepRingShare.h" 12 | 13 | /** 14 | * Three-party replicated secret sharing protocol with MAC modulo a power of two 15 | */ 16 | template 17 | class SpdzWiseRing : public SpdzWise 18 | { 19 | typedef typename T::part_type check_type; 20 | typedef PostSacriRepRingShare zero_check_type; 21 | 22 | DataPositions zero_usage; 23 | MaliciousBitOnlyRepPrep zero_prep; 24 | typename zero_check_type::MAC_Check zero_output; 25 | SubProcessor zero_proc; 26 | 27 | public: 28 | SpdzWiseRing(Player &P); 29 | 30 | void zero_check(check_type t); 31 | }; 32 | 33 | #endif /* PROTOCOLS_SPDZWISERING_H_ */ 34 | -------------------------------------------------------------------------------- /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/TrioInput.h: -------------------------------------------------------------------------------- 1 | /* 2 | * TrioInput.h 3 | * 4 | */ 5 | 6 | #ifndef PROTOCOLS_TRIOINPUT_H_ 7 | #define PROTOCOLS_TRIOINPUT_H_ 8 | 9 | #include "AstraInput.h" 10 | 11 | template 12 | class TrioInput : public AstraInput 13 | { 14 | typedef AstraInput super; 15 | 16 | public: 17 | TrioInput(SubProcessor& proc, MAC_Check_Base& MC) : 18 | super(proc, MC) 19 | { 20 | } 21 | TrioInput(SubProcessor* proc, Player& P) : 22 | super(proc, P) 23 | { 24 | } 25 | TrioInput(MAC_Check_Base& MC, Preprocessing& prep, Player& P, 26 | Trio* protocol) : 27 | super(MC, prep, P, protocol) 28 | { 29 | } 30 | 31 | T finalize_offset(int offset) final; 32 | }; 33 | 34 | #endif /* PROTOCOLS_TRIOINPUT_H_ */ 35 | -------------------------------------------------------------------------------- /Protocols/TrioInput.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * TrioInput.hpp 3 | * 4 | */ 5 | 6 | #ifndef PROTOCOLS_TRIOINPUT_HPP_ 7 | #define PROTOCOLS_TRIOINPUT_HPP_ 8 | 9 | #include "TrioInput.h" 10 | 11 | template 12 | T TrioInput::finalize_offset(int offset) 13 | { 14 | T res; 15 | if (offset == 0) 16 | { 17 | res = this->my_results.next(); 18 | res.m(-1) = this->send_os.template get_no_check() 19 | + res.neg_lambda(-1); 20 | } 21 | else 22 | { 23 | res = this->results.next(); 24 | res.m(-1) = this->recv_os.template get_no_check< 25 | typename T::open_type>(); 26 | } 27 | return res; 28 | } 29 | 30 | #endif /* PROTOCOLS_TRIOINPUT_HPP_ */ 31 | -------------------------------------------------------------------------------- /Protocols/TrioMC.h: -------------------------------------------------------------------------------- 1 | /* 2 | * TrioMC.h 3 | * 4 | */ 5 | 6 | #ifndef PROTOCOLS_TRIOMC_H_ 7 | #define PROTOCOLS_TRIOMC_H_ 8 | 9 | #include "AstraMC.h" 10 | 11 | template 12 | class TrioMC : public AstraMC 13 | { 14 | public: 15 | TrioMC(typename T::mac_key_type = {}, int = 0, int = 0) 16 | { 17 | } 18 | 19 | typename T::open_type prepare_summand(const T& secret, int my_num) 20 | { 21 | return secret[my_num - 1]; 22 | } 23 | 24 | TrioMC& get_part_MC() 25 | { 26 | return *this; 27 | } 28 | }; 29 | 30 | #endif /* PROTOCOLS_TRIOMC_H_ */ 31 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /Protocols/mac_key.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * mac_key.hpp 3 | * 4 | */ 5 | 6 | #ifndef PROTOCOLS_MAC_KEY_HPP_ 7 | #define PROTOCOLS_MAC_KEY_HPP_ 8 | 9 | #include "Networking/Player.h" 10 | #include "Math/Setup.h" 11 | 12 | #include "fake-stuff.hpp" 13 | 14 | template 15 | typename T::mac_key_type read_or_generate_mac_key(const Player& P, 16 | string directory = "") 17 | { 18 | if (directory == "") 19 | directory = get_prep_sub_dir(P.num_players()); 20 | typename T::mac_key_type res; 21 | T::read_or_generate_mac_key(directory, P, res); 22 | return res; 23 | } 24 | 25 | template 26 | void check_field_size() 27 | { 28 | if (T::length() < OnlineOptions::singleton.security_parameter) 29 | throw field_too_small(T::length(), 30 | OnlineOptions::singleton.security_parameter); 31 | } 32 | 33 | #endif /* PROTOCOLS_MAC_KEY_HPP_ */ 34 | -------------------------------------------------------------------------------- /Scripts/astra-common.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | HERE=$(cd `dirname $0`; pwd) 4 | SPDZROOT=$HERE/.. 5 | 6 | killall $PROTOCOL-party.x $PROTOCOL-prep-party.x 7 | 8 | for dir in Player-Data/3-$PROTOCOL-{{R,B}-64,2-{40,128}}; do 9 | mkdir $dir 2> /dev/null 10 | rm $dir/* 11 | for t in $(seq 0 100); do 12 | mkfifo $dir/{Protocol,Outputs}-{edaBits-,}P{0,1,2}-T$t 13 | done 14 | done 15 | 16 | export PLAYERS=3 17 | export LOG_SUFFIX=prep- 18 | 19 | . $HERE/run-common.sh 20 | 21 | screen_prefix=p 22 | run_player $PROTOCOL-prep-party.x $* & 23 | 24 | 25 | export PLAYERS=2 26 | export LOG_SUFFIX= 27 | export PORT= 28 | 29 | . $HERE/run-common.sh 30 | 31 | screen_prefix= 32 | run_player $PROTOCOL-party.x $* || exit 1 33 | -------------------------------------------------------------------------------- /Scripts/astra-online.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | HERE=$(cd `dirname $0`; pwd) 4 | SPDZROOT=$HERE/.. 5 | 6 | export PLAYERS=2 7 | 8 | . $HERE/run-common.sh 9 | 10 | run_player astra-party.x $* || exit 1 11 | -------------------------------------------------------------------------------- /Scripts/astra-prep.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | HERE=$(cd `dirname $0`; pwd) 4 | SPDZROOT=$HERE/.. 5 | 6 | rm Player-Data/3-astra-*/* 7 | 8 | export PLAYERS=3 9 | 10 | . $HERE/run-common.sh 11 | 12 | run_player astra-prep-party.x $* || exit 1 13 | -------------------------------------------------------------------------------- /Scripts/astra.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | HERE=$(cd `dirname $0`; pwd) 4 | PROTOCOL=astra 5 | 6 | . $HERE/astra-common.sh 7 | -------------------------------------------------------------------------------- /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 | echo OTE_OPTS= -DENABLE_SOFTSPOKEN_OT=ON -DBUILD_SHARED_LIBS=0 -DCMAKE_INSTALL_LIBDIR=lib $3 >> CONFIG.mine 8 | rm -R deps/libOTe/out 9 | make clean 10 | rm -R static 11 | mkdir static 12 | make -j 4 static-release || exit 1 13 | mkdir bin 14 | dest=bin/`uname`-$2 15 | rm -R $dest 16 | mv static $dest 17 | strip $dest/* 18 | } 19 | 20 | make deps/libOTe/libOTe 21 | 22 | echo AVX_OT = 0 >> CONFIG.mine 23 | build '-maes -mpclmul -DCHECK_AES -DCHECK_PCLMUL -DCHECK_AVX' amd64 -DENABLE_AVX=OFF 24 | 25 | echo AVX_OT = 1 >> CONFIG.mine 26 | build '-msse4.1 -maes -mpclmul -mavx -mavx2 -mbmi2 -madx' adx -DENABLE_AVX=ON 27 | -------------------------------------------------------------------------------- /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-emulate.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import os, sys 4 | 5 | sys.path.insert(0, os.path.dirname(sys.argv[0]) + '/..') 6 | 7 | from Compiler.compilerLib import Compiler 8 | 9 | compiler = Compiler(split_args=True) 10 | compiler.prep_compile(build=False) 11 | compiler.execute = True 12 | compiler.options.execute = 'emulate' 13 | if not compiler.options.binary: 14 | compiler.options.ring = compiler.options.ring or '64' 15 | compiler.options.keep_cisc = compiler.options.keep_cisc or '' 16 | compiler.build() 17 | prog = compiler.compile_file() 18 | compiler.local_execution() 19 | -------------------------------------------------------------------------------- /Scripts/compile-for-emulation.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | pypy3 ./compile.py -CDR 64 -K '' $* 4 | -------------------------------------------------------------------------------- /Scripts/compile-run.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import os, sys 4 | 5 | sys.path.insert(0, os.path.dirname(sys.argv[0]) + '/..') 6 | 7 | from Compiler.compilerLib import Compiler 8 | 9 | compiler = Compiler( 10 | execute=True, split_args=True, 11 | usage="usage: %prog [options] [-E] protocol filename [args] " 12 | "[-- [run-time args]]") 13 | compiler.prep_compile() 14 | prog = compiler.compile_file() 15 | 16 | if prog.options.hostfile: 17 | compiler.remote_execution() 18 | else: 19 | compiler.local_execution() 20 | -------------------------------------------------------------------------------- /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/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 | filename = 'Programs/Bytecode/%s.asm' % tapename 15 | print('Creating', filename) 16 | with open(filename, 'w') as out: 17 | for i, inst in enumerate(Tape.read_instructions(tapename)): 18 | print(inst, '#', i, file=out) 19 | -------------------------------------------------------------------------------- /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/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 | dir="$(dirname $0)" 4 | . "$dir"/run-common.sh 5 | prog=${1%.sch} 6 | prog=${prog##*/} 7 | shift 8 | mkdir logs 2> /dev/null 9 | $prefix "$dir"/../emulate.x $prog $* 2>&1 | tee logs/emulate-$prog 10 | -------------------------------------------------------------------------------- /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 | if os.path.isfile(sys.argv[1]): 18 | tapename = re.sub(r'\.bc', '', os.path.basename(sys.argv[1])) 19 | else: 20 | tapename = next(Program.read_tapes(sys.argv[1])) 21 | 22 | res = Tape.ReqNum() 23 | for inst in Tape.read_instructions(tapename): 24 | res.update(inst.get_usage()) 25 | 26 | for x in res.pretty(): 27 | print(x) 28 | -------------------------------------------------------------------------------- /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.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/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 | echo NOTE: This runs the SPDZ online phase, requiring a prior preprocessing generation with Fake-Offline.x 9 | echo See https://github.com/data61/MP-SPDZ/?tab=readme-ov-file#protocols for all protocols. 10 | 11 | run_player Player-Online.x $* || exit 1 12 | -------------------------------------------------------------------------------- /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.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 | # brew-installed OpenSSL on MacOS 4 | PATH="/opt/homebrew/opt/openssl@3/bin:$PATH" 5 | 6 | n=$1 7 | 8 | test -e Player-Data || mkdir Player-Data 9 | 10 | echo Setting up SSL for $n parties 11 | 12 | for i in `seq 0 $[n-1]`; do 13 | openssl req -newkey rsa -nodes -x509 -out Player-Data/C$i.pem -keyout Player-Data/C$i.key -subj "/CN=C$i" 14 | done 15 | 16 | c_rehash Player-Data 17 | -------------------------------------------------------------------------------- /Scripts/setup-online.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | HERE=$(cd `dirname $0`; pwd) 4 | SPDZROOT=$HERE/.. 5 | 6 | # number of players 7 | players=${1:-2} 8 | # prime field bit length 9 | bits=${2:-128} 10 | # binary field bit length, default by binary 11 | g=${3:-0} 12 | # default number of triples etc. to create 13 | default=${4:-10000} 14 | 15 | die () { 16 | echo >&2 "$@" 17 | echo >&2 "Usage: 18 | setup-online.sh [nplayers] [prime_bitlength] [gf2n_bitlength] [num_prep] 19 | Defaults: 20 | nplayers=2, prime_bitlength=128, gf2n_bitlength=40/128 (as compiled), num_prep=10000" 21 | exit 1 22 | } 23 | 24 | [ "$#" -le 4 ] || die "More than 4 arguments provided" 25 | 26 | for arg in "$@" 27 | do 28 | echo "$arg" | grep -E -q '^[0-9]+$' || die "Integer argument required, $arg provided" 29 | done 30 | 31 | $HERE/setup-ssl.sh ${players} 32 | 33 | $SPDZROOT/Fake-Offline.x ${players} -lgp ${bits} -lg2 ${g} --default ${default} 34 | 35 | -------------------------------------------------------------------------------- /Scripts/setup-ssl.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # brew-installed OpenSSL on MacOS 4 | PATH="/opt/homebrew/opt/openssl@3/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 | rm -v $ssl_dir/*.0 18 | c_rehash -v $ssl_dir 19 | -------------------------------------------------------------------------------- /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/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 -r CONFIG CONFIG.mine 5 | touch ECDSA/Fake-ECDSA.cpp 6 | 7 | make -j4 ecdsa Fake-ECDSA.x 8 | 9 | port=${PORT:-$((RANDOM%10000+10000))} 10 | 11 | run() 12 | { 13 | echo $1 14 | if ! { 15 | for j in $(seq 0 $2); do 16 | ./$1-ecdsa-party.x -pn $port -p $j 1 2>logs/ecdsa-$j & true 17 | done 18 | wait 19 | } | tee logs/ecdsa | grep "Online checking"; then 20 | exit 1 21 | fi 22 | } 23 | 24 | for i in rep mal-rep shamir mal-shamir atlas sy-rep; do 25 | run $i 2 26 | done 27 | 28 | run rep4 3 29 | 30 | for i in semi mascot; do 31 | run $i 1 32 | done 33 | 34 | ./Fake-ECDSA.x 35 | run fake-spdz 1 36 | -------------------------------------------------------------------------------- /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/tldr.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | if test `uname` = "Linux"; then 4 | flags='cat /proc/cpuinfo' 5 | elif test `uname` = Darwin; then 6 | make mac-setup 7 | make tldr 8 | else 9 | echo OS unknown 10 | exit 1 11 | fi 12 | 13 | if test "$flags"; then 14 | if $flags | grep -q adx; then 15 | cpu=adx 16 | else 17 | if test `uname -m` != x86_64; then 18 | echo Binaries are not available for `uname -m` 19 | echo Use the source distribution: https://github.com/data61/MP-SPDZ/#tldr-source-distribution 20 | exit 1 21 | fi 22 | cpu=amd64 23 | fi 24 | 25 | if ! cp -av bin/`uname`-$cpu/* .; then 26 | echo This only works with a release downloaded from https://github.com/data61/MP-SPDZ/releases 1>&2 27 | echo Make sure NOT to download a source code only file 1>&2 28 | exit 1 29 | fi 30 | fi 31 | 32 | mkdir Player-Data 2> /dev/null 33 | exit 0 34 | -------------------------------------------------------------------------------- /Scripts/trio-online.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | HERE=$(cd `dirname $0`; pwd) 4 | SPDZROOT=$HERE/.. 5 | 6 | export PLAYERS=2 7 | 8 | . $HERE/run-common.sh 9 | 10 | run_player trio-party.x $* || exit 1 11 | -------------------------------------------------------------------------------- /Scripts/trio-prep.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | HERE=$(cd `dirname $0`; pwd) 4 | SPDZROOT=$HERE/.. 5 | 6 | rm Player-Data/3-trio-*/* 7 | 8 | export PLAYERS=3 9 | 10 | . $HERE/run-common.sh 11 | 12 | run_player trio-prep-party.x $* || exit 1 13 | -------------------------------------------------------------------------------- /Scripts/trio.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | HERE=$(cd `dirname $0`; pwd) 4 | PROTOCOL=trio 5 | 6 | . $HERE/astra-common.sh 7 | -------------------------------------------------------------------------------- /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/CodeLocations.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * CodeLocations.cpp 3 | * 4 | */ 5 | 6 | #include "CodeLocations.h" 7 | #include "Processor/OnlineOptions.h" 8 | 9 | CodeLocations CodeLocations::singleton; 10 | 11 | void CodeLocations::maybe_output(const char* file, int line, 12 | const char* function) 13 | { 14 | if (OnlineOptions::singleton.code_locations) 15 | singleton.output(file, line, function); 16 | } 17 | 18 | void CodeLocations::output(const char* file, int line, 19 | const char* function) 20 | { 21 | location_type location({file, line, function}); 22 | lock.lock(); 23 | if (done.find(location) == done.end()) 24 | cerr << "first call to " << file << ":" << line << ", " << function 25 | << endl; 26 | done.insert(location); 27 | lock.unlock(); 28 | } 29 | -------------------------------------------------------------------------------- /Tools/CodeLocations.h: -------------------------------------------------------------------------------- 1 | /* 2 | * CodeLocations.h 3 | * 4 | */ 5 | 6 | #ifndef TOOLS_CODELOCATIONS_H_ 7 | #define TOOLS_CODELOCATIONS_H_ 8 | 9 | #include "Lock.h" 10 | 11 | #include 12 | #include 13 | #include 14 | using namespace std; 15 | 16 | class CodeLocations 17 | { 18 | typedef tuple location_type; 19 | 20 | static CodeLocations singleton; 21 | 22 | Lock lock; 23 | set done; 24 | 25 | public: 26 | static void maybe_output(const char* file, int line, const char* function); 27 | 28 | void output(const char* file, int line, const char* function); 29 | }; 30 | 31 | #define CODE_LOCATION CodeLocations::maybe_output(__FILE__, __LINE__, __PRETTY_FUNCTION__); 32 | 33 | #endif /* TOOLS_CODELOCATIONS_H_ */ 34 | -------------------------------------------------------------------------------- /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 | class ScopeLock 23 | { 24 | Lock& lock; 25 | 26 | public: 27 | ScopeLock(Lock& lock) : 28 | lock(lock) 29 | { 30 | lock.lock(); 31 | } 32 | 33 | ~ScopeLock() 34 | { 35 | lock.unlock(); 36 | } 37 | }; 38 | 39 | #endif /* TOOLS_LOCK_H_ */ 40 | -------------------------------------------------------------------------------- /Tools/MemoryUsage.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MemoryUsage.h 3 | * 4 | */ 5 | 6 | #ifndef TOOLS_MEMORYUSAGE_H_ 7 | #define TOOLS_MEMORYUSAGE_H_ 8 | 9 | #include 10 | using namespace std; 11 | 12 | class MemoryUsage 13 | { 14 | map usage; 15 | 16 | public: 17 | MemoryUsage& operator+=(const MemoryUsage& other) 18 | { 19 | for (auto& it : other.usage) 20 | usage[it.first] += it.second; 21 | return *this; 22 | } 23 | 24 | void update(const string& tag, size_t size) 25 | { 26 | usage[tag] = max(size, usage[tag]); 27 | } 28 | 29 | void add(const string& tag, size_t size) 30 | { 31 | usage[tag] += size; 32 | } 33 | 34 | size_t get(const string& tag) 35 | { 36 | return usage[tag]; 37 | } 38 | 39 | void print() 40 | { 41 | for (auto& it : usage) 42 | cout << it.first << " required: " << 1e-9 * it.second << " (GB)" << endl; 43 | } 44 | }; 45 | 46 | #endif /* TOOLS_MEMORYUSAGE_H_ */ 47 | -------------------------------------------------------------------------------- /Tools/NamedStats.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * NamedStats.cpp 3 | * 4 | */ 5 | 6 | #include "NamedStats.h" 7 | 8 | #include 9 | #include 10 | 11 | NamedStats& NamedStats::operator+=(const NamedStats& other) 12 | { 13 | for (auto x : other) 14 | (*this)[x.first] += x.second; 15 | return *this; 16 | } 17 | 18 | void NamedStats::print() 19 | { 20 | long sum = 0; 21 | for (auto x : *this) 22 | sum += x.second; 23 | if (sum > 0) 24 | cerr << "Detailed costs:" << endl; 25 | for (auto x : *this) 26 | { 27 | if (x.second > 0) 28 | { 29 | cerr.fill(' '); 30 | cerr << " "; 31 | cerr << setw(10) << x.second << " " << x.first << endl; 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Tools/NamedStats.h: -------------------------------------------------------------------------------- 1 | /* 2 | * NamedStats.h 3 | * 4 | */ 5 | 6 | #ifndef TOOLS_NAMEDSTATS_H_ 7 | #define TOOLS_NAMEDSTATS_H_ 8 | 9 | #include 10 | #include 11 | 12 | using namespace std; 13 | 14 | class NamedStats : public map 15 | { 16 | public: 17 | NamedStats& operator+=(const NamedStats& other); 18 | 19 | void print(); 20 | }; 21 | 22 | #endif /* TOOLS_NAMEDSTATS_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/OfflineMachineBase.h: -------------------------------------------------------------------------------- 1 | /* 2 | * OfflineMachineBase.h 3 | * 4 | */ 5 | 6 | #ifndef TOOLS_OFFLINEMACHINEBASE_H_ 7 | #define TOOLS_OFFLINEMACHINEBASE_H_ 8 | 9 | #include "Tools/ezOptionParser.h" 10 | #include "Networking/Server.h" 11 | #include "Networking/Player.h" 12 | 13 | class OfflineParams 14 | { 15 | public: 16 | bool output; 17 | int nthreads; 18 | 19 | OfflineParams() : output(false), nthreads(0) {} 20 | }; 21 | 22 | class OfflineMachineBase : virtual public OfflineParams 23 | { 24 | protected: 25 | ez::ezOptionParser opt; 26 | 27 | public: 28 | Names N; 29 | int my_num, nplayers; 30 | long long ntriples, nTriplesPerThread; 31 | 32 | OfflineMachineBase(); 33 | ~OfflineMachineBase(); 34 | 35 | void parse_options(int argc, const char** argv); 36 | void start_networking_with_server(string hostname = "localhost", int portnum = 5000); 37 | }; 38 | 39 | #endif /* TOOLS_OFFLINEMACHINEBASE_H_ */ 40 | -------------------------------------------------------------------------------- /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.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 | TimerWithComm(); 18 | TimerWithComm(const Timer& other); 19 | TimerWithComm(double time); 20 | 21 | void start(const NamedCommStats& stats = {}); 22 | void stop(const NamedCommStats& stats = {}); 23 | 24 | double mb_sent() const; 25 | size_t rounds() const; 26 | 27 | TimerWithComm operator+(const TimerWithComm& other); 28 | TimerWithComm operator-(const TimerWithComm& other); 29 | TimerWithComm& operator+=(const TimerWithComm& other); 30 | TimerWithComm& operator-=(const TimerWithComm& other); 31 | 32 | string full(); 33 | 34 | friend ostream& operator<<(ostream& os, const TimerWithComm& stats); 35 | }; 36 | 37 | #endif /* TOOLS_TIMERWITHCOMM_H_ */ 38 | -------------------------------------------------------------------------------- /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.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * benchmarking.cpp 3 | * 4 | */ 5 | 6 | #include "benchmarking.h" 7 | 8 | void insecure(string message, bool warning) 9 | { 10 | #ifdef INSECURE 11 | if (warning) 12 | cerr << "WARNING: insecure " << message << endl; 13 | #else 14 | (void)warning; 15 | string msg = "You are trying to use insecure benchmarking functionality for " 16 | + message + ".\nYou can activate this at compile time " 17 | "by adding -DINSECURE to the compiler options.\n" 18 | "Make sure to run 'make clean' as well before compiling."; 19 | cerr << msg << endl; 20 | #ifdef INSECURE_EXCEPTION 21 | throw exception(); 22 | #endif 23 | exit(1); 24 | #endif 25 | } 26 | 27 | void insecure_fake(bool warning) 28 | { 29 | #if defined(INSECURE) or defined(INSECURE_FAKE) 30 | if (warning) 31 | cerr << "WARNING: insecure preprocessing" << endl; 32 | #else 33 | (void) warning; 34 | insecure("preprocessing"); 35 | #endif 36 | } 37 | -------------------------------------------------------------------------------- /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/files.h: -------------------------------------------------------------------------------- 1 | /* 2 | * files.h 3 | * 4 | */ 5 | 6 | #ifndef TOOLS_FILES_H_ 7 | #define TOOLS_FILES_H_ 8 | 9 | #include 10 | 11 | void open_with_check(std::ifstream& stream, const std::string& filename) 12 | { 13 | stream.open(filename); 14 | if (not stream.good()) 15 | throw runtime_error("cannot open " + filename); 16 | } 17 | 18 | #endif /* TOOLS_FILES_H_ */ 19 | -------------------------------------------------------------------------------- /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 | #include "simde/simde/x86/avx2.h" 17 | #include "simde/simde/x86/clmul.h" 18 | #define SSE2NEON_SUPPRESS_WARNINGS 19 | #include "sse2neon/sse2neon.h" 20 | #endif 21 | #endif 22 | 23 | #endif /* TOOLS_INTRINSICS_H_ */ 24 | -------------------------------------------------------------------------------- /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", "Randoms", "Opens", "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 | #ifndef TOOLS_PPRINT_H_ 2 | #define TOOLS_PPRINT_H_ 3 | 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | 9 | inline void pprint_bytes(const char *label, unsigned char *bytes, int len) 10 | { 11 | cout << label << ": "; 12 | for (int j = 0; j < len; j++) 13 | cout << setfill('0') << setw(2) << hex << (int) bytes[j]; 14 | cout << dec << endl; 15 | } 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /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/gc-emulate.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * gc-emulate.cpp 3 | * 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | #include "GC/Machine.h" 10 | #include "GC/Processor.h" 11 | 12 | #include "GC/Processor.hpp" 13 | #include "GC/Machine.hpp" 14 | #include "GC/Program.hpp" 15 | #include "GC/Thread.hpp" 16 | #include "GC/ThreadMaster.hpp" 17 | #include "Processor/Machine.hpp" 18 | #include "Processor/Instruction.hpp" 19 | 20 | int main(int argc, char** argv) 21 | { 22 | if (argc < 2) 23 | exit(1); 24 | 25 | GC::Memory dynamic_memory; 26 | GC::Machine machine; 27 | GC::Processor processor(machine); 28 | GC::Program program; 29 | program.parse(string(argv[1]) + "-0"); 30 | machine.reset(program, dynamic_memory); 31 | processor.reset(program); 32 | if (argc > 2) 33 | processor.open_input_file(argv[2]); 34 | while (program.execute(processor, dynamic_memory) != GC::DONE_BREAK); 35 | } 36 | -------------------------------------------------------------------------------- /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 << abs(atoi(argv[2])), atoi(argv[2]) <= 0) << 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 : public InputterBase 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 : public InputterBase 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/YaoHalfGate.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * YaoHalfGate.cpp 3 | * 4 | */ 5 | 6 | #include "YaoHalfGate.h" 7 | #include "YaoGarbler.h" 8 | #include "YaoEvaluator.h" 9 | 10 | YaoHalfGate::YaoHalfGate(YaoGarbleWire& out, const YaoGarbleWire& left, 11 | const YaoGarbleWire& right, Function function) 12 | { 13 | for (int i = 0; i < 4; i++) 14 | assert(function[i] == Function(0x0001)[i]); 15 | Key labels[4]; 16 | Key hashes[4]; 17 | E_inputs(labels, left, right, YaoGarbler::s().get_delta().doubling(1), 18 | {}, YaoGarbler::s().counter); 19 | YaoGarbler::s().mmo.hash<4>(hashes, labels); 20 | and_garble(out, hashes, left, right, YaoGarbler::s().get_delta()); 21 | } 22 | 23 | void YaoHalfGate::eval(YaoEvalWire& out, const YaoEvalWire& left, 24 | const YaoEvalWire& right) 25 | { 26 | Key hashes[2]; 27 | Key labels[2]; 28 | eval_inputs(labels, left.key(), right.key(), YaoEvaluator::s().counter); 29 | YaoEvaluator::s().mmo.hash<2>(hashes, labels); 30 | eval(out, hashes, left, right); 31 | } 32 | -------------------------------------------------------------------------------- /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/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 include code from the following projects, whose licenses 3 | are thus provided in separate files: 4 | - Boost 5 | - glibc 6 | - libsodium 7 | - GMP 8 | - OpenSSl 9 | - NTL 10 | - SimpleOT 11 | - SimplestOT_C 12 | - libOTe 13 | - cryptoTools 14 | - simde 15 | - sse2neon 16 | 17 | The binaries also include code from libstdc++ and libgcc. They have 18 | been produced using `Scripts/build.sh` and standard GCC from 19 | Devtoolset-6 on CentOS 6 and therefore satisfy the [GCC Runtime Library 20 | Exception](https://www.gnu.org/licenses/gcc-exception-3.1.en.html). 21 | -------------------------------------------------------------------------------- /bin/libsodium-license.txt: -------------------------------------------------------------------------------- 1 | /* 2 | * ISC License 3 | * 4 | * Copyright (c) 2013-2019 5 | * Frank Denis 6 | * 7 | * Permission to use, copy, modify, and/or distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice appear in all copies. 10 | * 11 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 12 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 13 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 14 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 16 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 17 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 | */ 19 | -------------------------------------------------------------------------------- /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/ecdsa.md: -------------------------------------------------------------------------------- 1 | ../ECDSA/README.md -------------------------------------------------------------------------------- /doc/gen-readme.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo '# Getting Started' > readme.md 4 | sed -e '1 d' -e 's#(Programs/Source#(../Programs/Source#g' -e 's#(./Dockerfile#(../Dockerfile#' ../README.md >> readme.md 5 | 6 | echo '# Client Interface' > client-interface.md 7 | cat ../ExternalIO/README.md >> client-interface.md 8 | -------------------------------------------------------------------------------- /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/poh-graph.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/data61/MP-SPDZ/9f2a641a9427fa01380b262402424798d097c789/doc/poh-graph.png -------------------------------------------------------------------------------- /doc/requirements.txt: -------------------------------------------------------------------------------- 1 | requests==2.32 2 | sphinx-rtd-theme==0.5.2 3 | sphinx==4.3.2 4 | breathe==4.31.0 5 | myst_parser==0.18.0 6 | sphinxcontrib_applehelp==1.0.4 7 | sphinxcontrib-devhelp==1.0.2 8 | sphinxcontrib-htmlhelp==2.0.1 9 | sphinxcontrib-jsmath==1.0.1 10 | sphinxcontrib-qthelp==1.0.3 11 | sphinxcontrib-serializinghtml==1.1.5 12 | -------------------------------------------------------------------------------- /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 | --------------------------------------------------------------------------------