├── .gitignore ├── fbpcf ├── io │ ├── api │ │ ├── test │ │ │ ├── data │ │ │ │ ├── buffered_reader_empty_file.txt │ │ │ │ ├── file_io_wrappers_read_csv_test.csv │ │ │ │ ├── local_file_reader_test_file.txt │ │ │ │ ├── file_io_wrappers_read_file_test.txt │ │ │ │ ├── expected_local_file_writer_test_file.txt │ │ │ │ ├── expected_buffered_writer_test_file.txt │ │ │ │ └── buffered_reader_test_file.txt │ │ │ └── IOUtilsTest.cpp │ │ ├── SocketReader.cpp │ │ ├── SocketWriter.cpp │ │ ├── IReaderCloser.h │ │ ├── IWriterCloser.h │ │ ├── ICloser.h │ │ ├── CloudFileWriter.cpp │ │ ├── LocalFileWriter.h │ │ ├── LocalFileReader.h │ │ ├── IWriter.h │ │ ├── FileWriter.h │ │ ├── SocketWriter.h │ │ ├── FileReader.h │ │ ├── SocketReader.h │ │ ├── FileWriter.cpp │ │ ├── IReader.h │ │ ├── FileReader.cpp │ │ ├── CloudFileWriter.h │ │ └── FileIOWrappers.h │ ├── LocalInputStream.cpp │ ├── S3InputStream.cpp │ ├── GCSInputStream.cpp │ ├── IInputStream.h │ ├── LocalInputStream.h │ ├── MockFileManager.h │ ├── cloud_util │ │ ├── IFileReader.h │ │ ├── CloudFileUtil.h │ │ ├── S3FileReader.h │ │ ├── IFileUploader.h │ │ ├── GCSFileReader.h │ │ ├── GCSFileUploader.h │ │ ├── S3FileUploader.h │ │ ├── GCSFileReader.cpp │ │ ├── S3Client.h │ │ └── S3Client.cpp │ ├── S3InputStream.h │ ├── test │ │ └── FileManagerUtilTest.cpp │ ├── GCSInputStream.h │ ├── FileManagerUtil.h │ ├── LocalFileManager.h │ ├── IFileManager.h │ └── S3FileManager.h ├── exception │ ├── ExceptionBase.cpp │ ├── AwsException.h │ ├── EmpException.h │ ├── GcpException.h │ ├── PcfException.h │ └── ExceptionBase.h ├── mpc │ ├── EmpTestUtil.cpp │ ├── test │ │ ├── test_apps │ │ │ └── millionaire │ │ │ │ ├── MillionaireApp.cpp │ │ │ │ ├── MillionaireApp.h │ │ │ │ └── MillionaireGame.h │ │ ├── QueueIOTest.cpp │ │ └── MpcAppExecutorTest.cpp │ ├── QueueIO.cpp │ ├── IMpcGame.h │ ├── EmpGame.h │ └── QueueIO.h ├── aws │ ├── test │ │ ├── AwsSdkTest.cpp │ │ └── MockS3ClientTest.cpp │ ├── AwsSdk.cpp │ ├── AwsSdk.h │ ├── S3Util.h │ └── MockS3Client.h ├── test │ └── emp │ │ └── EMPOperatorTestConfig.hpp ├── system │ ├── CpuUtil.h │ └── CpuUtil.cpp ├── mpc_std_lib │ ├── permuter │ │ ├── IPermuterFactory.h │ │ ├── DummyPermuterFactory.h │ │ └── AsWaksmanPermuterFactory.h │ ├── shuffler │ │ ├── IShufflerFactory.h │ │ ├── NonShufflerFactory.h │ │ ├── NonShuffler.h │ │ └── IShuffler.h │ ├── compactor │ │ ├── ICompactorFactory.h │ │ └── DummyCompactorFactory.h │ ├── oram │ │ ├── ISinglePointArrayGeneratorFactory.h │ │ ├── IObliviousDeltaCalculatorFactory.h │ │ ├── IDifferenceCalculatorFactory.h │ │ ├── IWriteOnlyOramFactory.h │ │ ├── encoder │ │ │ ├── OramDecoder.h │ │ │ └── OramEncoder.h │ │ ├── ObliviousDeltaCalculatorFactory.h │ │ ├── DummyObliviousDeltaCalculatorFactory.h │ │ ├── DifferenceCalculatorFactory.h │ │ ├── SinglePointArrayGeneratorFactory.h │ │ ├── DummyObliviousDeltaCalculator.h │ │ ├── IObliviousDeltaCalculator.h │ │ ├── DummySinglePointArrayGeneratorFactory.h │ │ └── DummyDifferenceCalculatorFactory.h │ ├── unified_data_process │ │ ├── adapter │ │ │ ├── IAdapterFactory.h │ │ │ └── Adapter.h │ │ └── data_processor │ │ │ ├── IDataProcessorFactory.h │ │ │ ├── test │ │ │ └── UdpEncryptionMock.h │ │ │ └── DummyDataProcessorFactory.h │ ├── util │ │ ├── secureRandomPermutation.h │ │ ├── secureRandomPermutation.cpp │ │ ├── secureSamplePublicSeed.h │ │ └── test │ │ │ └── secureRandomPermutationTest.cpp │ ├── aes_circuit │ │ ├── IAesCircuitFactory.h │ │ ├── IAesCircuitCtrFactory.h │ │ ├── AesCircuitFactory.h │ │ ├── DummyAesCircuitFactory.h │ │ ├── AesCircuitCtr_impl.h │ │ ├── AesCircuitCtrFactory.h │ │ ├── AesCircuitCtr.h │ │ └── DummyAesCircuit.h │ └── walr_multiplication │ │ └── IWalrMatrixMultiplicationFactory.h ├── engine │ ├── util │ │ ├── IPrgFactory.h │ │ ├── Masker.h │ │ ├── test │ │ │ ├── aesTestHelper.h │ │ │ ├── benchmarks │ │ │ │ └── LocalBenchmark.h │ │ │ ├── aesTestHelper.cpp │ │ │ └── aesTest.cpp │ │ ├── AesPrgFactory.h │ │ ├── util.cpp │ │ ├── Masker_impl.h │ │ └── IPrg.h │ ├── ISecretShareEngineFactory.h │ ├── tuple_generator │ │ ├── oblivious_transfer │ │ │ ├── ferret │ │ │ │ ├── IRcotExtenderFactory.h │ │ │ │ ├── IMatrixMultiplierFactory.h │ │ │ │ ├── IMultiPointCotFactory.h │ │ │ │ ├── DummyMatrixMultiplier.cpp │ │ │ │ ├── ISinglePointCotFactory.h │ │ │ │ ├── DummyRcotExtenderFactory.h │ │ │ │ ├── DummyMatrixMultiplierFactory.h │ │ │ │ ├── SinglePointCotFactory.h │ │ │ │ ├── TenLocalLinearMatrixMultiplierFactory.h │ │ │ │ ├── DummyMatrixMultiplier.h │ │ │ │ ├── TenLocalLinearMatrixMultiplier.h │ │ │ │ ├── IMatrixMultiplier.h │ │ │ │ ├── test │ │ │ │ │ └── benchmarks │ │ │ │ │ │ └── MatrixMultiplierBenchmark.cpp │ │ │ │ ├── DummySinglePointCotFactory.h │ │ │ │ ├── DummyMultiPointCotFactory.h │ │ │ │ └── RegularErrorMultiPointCotFactory.h │ │ │ ├── IBidirectionObliviousTransferFactory.h │ │ │ ├── IFlexibleRandomCorrelatedObliviousTransfer.h │ │ │ ├── IBaseObliviousTransferFactory.h │ │ │ ├── DummyBaseObliviousTransfer.cpp │ │ │ ├── NpBaseObliviousTransferFactory.h │ │ │ ├── IRandomCorrelatedObliviousTransferFactory.h │ │ │ ├── IRandomCorrelatedObliviousTransfer.h │ │ │ ├── DummyBaseObliviousTransferFactory.h │ │ │ └── DummyBidirectionObliviousTransferFactory.h │ │ ├── IArithmeticTupleGeneratorFactory.h │ │ ├── NullArithmeticTupleGeneratorFactory.h │ │ ├── DummyArithmeticTupleGenerator.h │ │ ├── NullTupleGeneratorFactory.h │ │ ├── DummyArithmeticTupleGeneratorFactory.h │ │ ├── ITupleGeneratorFactory.h │ │ ├── NullArithmeticTupleGenerator.h │ │ ├── IProductShareGeneratorFactory.h │ │ ├── DummyTupleGeneratorFactory.h │ │ └── DummyProductShareGeneratorFactory.h │ ├── communication │ │ ├── AgentMapHelper.h │ │ └── IPartyCommunicationAgentFactory.h │ └── DummySecretShareEngineFactory.h ├── primitive │ └── mac │ │ ├── IMacFactory.h │ │ ├── AesCmacFactory.h │ │ ├── S2vFactory.h │ │ ├── AesCmac.cpp │ │ ├── IMac.h │ │ ├── AesCmac.h │ │ └── S2v.cpp ├── gcp │ ├── GCSUtil.h │ └── MockGCSClient.h ├── util │ └── IMetricRecorder.h ├── scheduler │ ├── ISchedulerFactory.h │ ├── test │ │ └── benchmarks │ │ │ ├── WireKeeperBenchmark.h │ │ │ └── AllocatorBenchmark.h │ ├── PlaintextSchedulerFactory.h │ └── IAllocator.h ├── common │ ├── test │ │ ├── VectorUtilTest.cpp │ │ └── FunctionalUtilTest.cpp │ ├── FunctionalUtil.h │ └── VectorUtil.h ├── frontend │ └── test │ │ └── utilTest.cpp └── tests │ └── github │ └── cleanup.sh ├── docs ├── T.jpg ├── RCT.jpg ├── RoP.jpg ├── lift.jpg ├── pcfArch.jpg ├── privatelift.jpg ├── v2 │ ├── pcf2_architecture.png │ ├── pcf2_simple_arch.png │ └── pcf2_system_architecture_current.png └── security_reviews │ ├── NCC_Group_MetaPlatformsInc_E003028_DLOE_Report_2022-06-27_DLOE-ORAM.pdf │ └── NCC_Group_MetaPlatformsInc_FACI564_DLOE_Report_2022-02-11_DLOE-EMP-Toolkit.pdf ├── example ├── edit_distance │ ├── data_gen │ │ └── edit_distance_200_params.csv │ ├── test │ │ └── test_data │ │ │ ├── edit_distance_test_params.csv │ │ │ ├── edit_distance_test_player_2_input.csv │ │ │ ├── edit_distance_test_results.csv │ │ │ ├── edit_distance_incorrect_size_test_results.csv │ │ │ ├── edit_distance_incorrect_test_results.csv │ │ │ ├── edit_distance_test_player_1_input.csv │ │ │ └── edit_distance_incorrect_message_test_results.csv │ ├── EditDistanceApp_impl.h │ ├── Validator.h │ ├── Util.h │ └── EditDistanceCalculator.h └── millionaire │ ├── MillionaireApp.cpp │ ├── MillionaireApp.h │ ├── test │ ├── MillionaireGameTest.cpp │ └── MillionaireAppTest.cpp │ ├── MillionaireGame.h │ └── main.cpp ├── CHANGELOG.md ├── docker ├── cmake │ └── testing.cmake └── utils │ └── get_make_options.sh └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | sample 2 | -------------------------------------------------------------------------------- /fbpcf/io/api/test/data/buffered_reader_empty_file.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docs/T.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebookresearch/fbpcf/HEAD/docs/T.jpg -------------------------------------------------------------------------------- /docs/RCT.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebookresearch/fbpcf/HEAD/docs/RCT.jpg -------------------------------------------------------------------------------- /docs/RoP.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebookresearch/fbpcf/HEAD/docs/RoP.jpg -------------------------------------------------------------------------------- /docs/lift.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebookresearch/fbpcf/HEAD/docs/lift.jpg -------------------------------------------------------------------------------- /docs/pcfArch.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebookresearch/fbpcf/HEAD/docs/pcfArch.jpg -------------------------------------------------------------------------------- /docs/privatelift.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebookresearch/fbpcf/HEAD/docs/privatelift.jpg -------------------------------------------------------------------------------- /example/edit_distance/data_gen/edit_distance_200_params.csv: -------------------------------------------------------------------------------- 1 | threshold,delete_cost,insert_cost 2 | 100,35,30 3 | -------------------------------------------------------------------------------- /docs/v2/pcf2_architecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebookresearch/fbpcf/HEAD/docs/v2/pcf2_architecture.png -------------------------------------------------------------------------------- /docs/v2/pcf2_simple_arch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebookresearch/fbpcf/HEAD/docs/v2/pcf2_simple_arch.png -------------------------------------------------------------------------------- /example/edit_distance/test/test_data/edit_distance_test_params.csv: -------------------------------------------------------------------------------- 1 | threshold,delete_cost,insert_cost 2 | 100,35,30 3 | -------------------------------------------------------------------------------- /example/edit_distance/test/test_data/edit_distance_test_player_2_input.csv: -------------------------------------------------------------------------------- 1 | guess 2 | curvy 3 | grain 4 | black-and-white 5 | not-empty 6 | -------------------------------------------------------------------------------- /fbpcf/io/api/test/data/file_io_wrappers_read_csv_test.csv: -------------------------------------------------------------------------------- 1 | name,age,occupation 2 | Paul,35, Programmer 3 | ,13, 4 | 5 | Bill,,Lawyer 6 | -------------------------------------------------------------------------------- /example/edit_distance/test/test_data/edit_distance_test_results.csv: -------------------------------------------------------------------------------- 1 | distance,receiver_message 2 | 131,b 3 | 81,soft 4 | 0,hello 5 | 315, 6 | -------------------------------------------------------------------------------- /docs/v2/pcf2_system_architecture_current.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebookresearch/fbpcf/HEAD/docs/v2/pcf2_system_architecture_current.png -------------------------------------------------------------------------------- /example/edit_distance/test/test_data/edit_distance_incorrect_size_test_results.csv: -------------------------------------------------------------------------------- 1 | distance,receiver_message 2 | 131,b 3 | 81,soft 4 | 0,wrong 5 | 315, 6 | -------------------------------------------------------------------------------- /example/edit_distance/test/test_data/edit_distance_incorrect_test_results.csv: -------------------------------------------------------------------------------- 1 | distance,receiver_message 2 | 1,jello 3 | 0,jello 4 | 0,jello 5 | 0,jello 6 | -------------------------------------------------------------------------------- /fbpcf/io/api/test/data/local_file_reader_test_file.txt: -------------------------------------------------------------------------------- 1 | this is a test file 2 | it has many lines in it 3 | 4 | the quick brown fox jumped over the lazy dog 5 | -------------------------------------------------------------------------------- /example/edit_distance/test/test_data/edit_distance_test_player_1_input.csv: -------------------------------------------------------------------------------- 1 | word,sender_message 2 | temporary,box 3 | mug,soft 4 | black-and-white,hello 5 | ,empty 6 | -------------------------------------------------------------------------------- /fbpcf/io/api/test/data/file_io_wrappers_read_file_test.txt: -------------------------------------------------------------------------------- 1 | this is a test file 2 | here's the second line, please read me 3 | 4 | last line here, don't miss me ~~ 5 | -------------------------------------------------------------------------------- /example/edit_distance/test/test_data/edit_distance_incorrect_message_test_results.csv: -------------------------------------------------------------------------------- 1 | distance,receiver_message 2 | 131,b 3 | 81,soft 4 | 0,hello 5 | 315, 6 | 20,extra 7 | -------------------------------------------------------------------------------- /fbpcf/io/api/test/data/expected_local_file_writer_test_file.txt: -------------------------------------------------------------------------------- 1 | this file contains the expected text in local_file_writer_test_file.text 2 | 3 | LocalFileWriterTest writes to the above file 4 | We assert that it's contents match this file 5 | -------------------------------------------------------------------------------- /docs/security_reviews/NCC_Group_MetaPlatformsInc_E003028_DLOE_Report_2022-06-27_DLOE-ORAM.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebookresearch/fbpcf/HEAD/docs/security_reviews/NCC_Group_MetaPlatformsInc_E003028_DLOE_Report_2022-06-27_DLOE-ORAM.pdf -------------------------------------------------------------------------------- /docs/security_reviews/NCC_Group_MetaPlatformsInc_FACI564_DLOE_Report_2022-02-11_DLOE-EMP-Toolkit.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebookresearch/fbpcf/HEAD/docs/security_reviews/NCC_Group_MetaPlatformsInc_FACI564_DLOE_Report_2022-02-11_DLOE-EMP-Toolkit.pdf -------------------------------------------------------------------------------- /fbpcf/io/api/SocketReader.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | namespace fbpcf::io {} // namespace fbpcf::io 9 | -------------------------------------------------------------------------------- /fbpcf/io/api/SocketWriter.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | namespace fbpcf::io {} // namespace fbpcf::io 9 | -------------------------------------------------------------------------------- /fbpcf/exception/ExceptionBase.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include "ExceptionBase.h" 9 | 10 | namespace fbpcf { 11 | const char* ExceptionBase::what() const noexcept { 12 | return error_.c_str(); 13 | } 14 | } // namespace fbpcf 15 | -------------------------------------------------------------------------------- /fbpcf/io/LocalInputStream.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include "LocalInputStream.h" 9 | 10 | #include 11 | 12 | namespace fbpcf { 13 | std::istream& LocalInputStream::get() { 14 | return is_; 15 | } 16 | } // namespace fbpcf 17 | -------------------------------------------------------------------------------- /fbpcf/io/S3InputStream.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include "S3InputStream.h" 9 | 10 | #include 11 | 12 | namespace fbpcf { 13 | std::istream& S3InputStream::get() { 14 | return r_.GetBody(); 15 | } 16 | } // namespace fbpcf 17 | -------------------------------------------------------------------------------- /fbpcf/io/api/test/data/expected_buffered_writer_test_file.txt: -------------------------------------------------------------------------------- 1 | this file tests the buffered writer 2 | these two lines fit in one chunk 3 | but this next line is going to be much longer and will require multiple iterations of the loop to fit everything in the file 4 | this is tiny 5 | writing a small string 6 | writing a big string that will also take multiple iterations to write everything in the file so that we have comprehensive tests 7 | -------------------------------------------------------------------------------- /fbpcf/io/GCSInputStream.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include "fbpcf/io/GCSInputStream.h" 9 | 10 | #include 11 | 12 | namespace fbpcf { 13 | std::istream& GCSInputStream::get() { 14 | return s_; 15 | } 16 | } // namespace fbpcf 17 | -------------------------------------------------------------------------------- /fbpcf/io/IInputStream.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | namespace fbpcf { 13 | class IInputStream { 14 | public: 15 | virtual ~IInputStream() {} 16 | 17 | virtual std::istream& get() = 0; 18 | }; 19 | } // namespace fbpcf 20 | -------------------------------------------------------------------------------- /fbpcf/mpc/EmpTestUtil.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include "EmpTestUtil.h" 9 | 10 | namespace fbpcf::mpc { 11 | bool isTestable() { 12 | #ifndef ENABLE_RDSEED 13 | return true; 14 | #else 15 | return isDrngSupported(); 16 | #endif 17 | } 18 | } // namespace fbpcf::mpc 19 | -------------------------------------------------------------------------------- /fbpcf/aws/test/AwsSdkTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include "fbpcf/aws/AwsSdk.h" 9 | 10 | #include // @manual 11 | #include 12 | 13 | namespace fbpcf { 14 | TEST(AwsSdk, aquire) { 15 | AwsSdk::aquire(); 16 | Aws::S3::S3Client s3Client; // Expectation: no crash 17 | } 18 | } // namespace fbpcf 19 | -------------------------------------------------------------------------------- /example/millionaire/MillionaireApp.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include "folly/Random.h" 9 | 10 | #include "./MillionaireApp.h" // @manual 11 | 12 | namespace fbpcf { 13 | 14 | int MillionaireApp::getInputData() { 15 | return folly::Random::rand32(0, 1000000000); 16 | } 17 | 18 | void MillionaireApp::putOutputData(const bool&) {} 19 | } // namespace fbpcf 20 | -------------------------------------------------------------------------------- /fbpcf/test/emp/EMPOperatorTestConfig.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | namespace fbpcf { 13 | 14 | template 15 | struct EMPOperatorTestConfig { 16 | std::function op; 17 | DataType inputData; 18 | }; 19 | } // namespace fbpcf 20 | -------------------------------------------------------------------------------- /fbpcf/system/CpuUtil.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | namespace fbpcf::system { 13 | struct CpuId { 14 | uint32_t eax; 15 | uint32_t ebx; 16 | uint32_t ecx; 17 | uint32_t edx; 18 | }; 19 | 20 | CpuId getCpuId(const uint64_t& eax); 21 | bool isIntelCpu(); 22 | bool isDrngSupported(); 23 | } // namespace fbpcf::system 24 | -------------------------------------------------------------------------------- /fbpcf/mpc/test/test_apps/millionaire/MillionaireApp.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include "folly/Random.h" 9 | 10 | #include "fbpcf/mpc/test/test_apps/millionaire/MillionaireApp.h" 11 | 12 | namespace fbpcf { 13 | 14 | int MillionaireApp::getInputData() { 15 | return folly::Random::rand32(0, 1000000000); 16 | } 17 | 18 | void MillionaireApp::putOutputData(const bool&) {} 19 | } // namespace fbpcf 20 | -------------------------------------------------------------------------------- /fbpcf/exception/AwsException.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include "ExceptionBase.h" 11 | 12 | namespace fbpcf { 13 | class AwsException : public ExceptionBase { 14 | public: 15 | explicit AwsException(const std::string& error) : ExceptionBase{error} {} 16 | explicit AwsException(const std::exception& exception) 17 | : ExceptionBase{exception} {} 18 | }; 19 | } // namespace fbpcf 20 | -------------------------------------------------------------------------------- /fbpcf/exception/EmpException.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include "ExceptionBase.h" 11 | 12 | namespace fbpcf { 13 | class EmpException : public ExceptionBase { 14 | public: 15 | explicit EmpException(const std::string& error) : ExceptionBase{error} {} 16 | explicit EmpException(const std::exception& exception) 17 | : ExceptionBase{exception} {} 18 | }; 19 | } // namespace fbpcf 20 | -------------------------------------------------------------------------------- /fbpcf/exception/GcpException.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include "ExceptionBase.h" 11 | 12 | namespace fbpcf { 13 | class GcpException : public ExceptionBase { 14 | public: 15 | explicit GcpException(const std::string& error) : ExceptionBase{error} {} 16 | explicit GcpException(const std::exception& exception) 17 | : ExceptionBase{exception} {} 18 | }; 19 | } // namespace fbpcf 20 | -------------------------------------------------------------------------------- /fbpcf/exception/PcfException.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include "ExceptionBase.h" 11 | 12 | namespace fbpcf { 13 | class PcfException : public ExceptionBase { 14 | public: 15 | explicit PcfException(const std::string& error) : ExceptionBase{error} {} 16 | explicit PcfException(const std::exception& exception) 17 | : ExceptionBase{exception} {} 18 | }; 19 | } // namespace fbpcf 20 | -------------------------------------------------------------------------------- /fbpcf/mpc_std_lib/permuter/IPermuterFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include "fbpcf/mpc_std_lib/permuter/IPermuter.h" 11 | 12 | namespace fbpcf::mpc_std_lib::permuter { 13 | 14 | template 15 | class IPermuterFactory { 16 | public: 17 | virtual ~IPermuterFactory() = default; 18 | virtual std::unique_ptr> create() = 0; 19 | }; 20 | 21 | } // namespace fbpcf::mpc_std_lib::permuter 22 | -------------------------------------------------------------------------------- /fbpcf/mpc_std_lib/shuffler/IShufflerFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include "fbpcf/mpc_std_lib/shuffler/IShuffler.h" 11 | 12 | namespace fbpcf::mpc_std_lib::shuffler { 13 | 14 | template 15 | class IShufflerFactory { 16 | public: 17 | virtual ~IShufflerFactory() = default; 18 | virtual std::unique_ptr> create() = 0; 19 | }; 20 | 21 | } // namespace fbpcf::mpc_std_lib::shuffler 22 | -------------------------------------------------------------------------------- /fbpcf/io/LocalInputStream.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | 13 | #include "IInputStream.h" 14 | 15 | namespace fbpcf { 16 | class LocalInputStream : public IInputStream { 17 | public: 18 | explicit LocalInputStream(std::ifstream is) : is_{std::move(is)} {} 19 | 20 | std::istream& get() override; 21 | 22 | private: 23 | std::ifstream is_; 24 | }; 25 | } // namespace fbpcf 26 | -------------------------------------------------------------------------------- /fbpcf/io/MockFileManager.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include "IFileManager.h" 13 | 14 | namespace fbpcf { 15 | class MockFileManager : public IFileManager { 16 | public: 17 | MOCK_METHOD1(read, std::string(const std::string& fileName)); 18 | 19 | MOCK_METHOD2( 20 | write, 21 | void(const std::string& fileName, const std::string& data)); 22 | }; 23 | } // namespace fbpcf 24 | -------------------------------------------------------------------------------- /fbpcf/io/api/IReaderCloser.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include "fbpcf/io/api/ICloser.h" 11 | #include "fbpcf/io/api/IReader.h" 12 | 13 | namespace fbpcf::io { 14 | 15 | /* 16 | * Defines a class that reads data from an 17 | * underlying medium and closes it. 18 | */ 19 | class IReaderCloser : public IReader, public ICloser { 20 | public: 21 | virtual ~IReaderCloser() = default; 22 | }; 23 | 24 | } // namespace fbpcf::io 25 | -------------------------------------------------------------------------------- /fbpcf/io/api/IWriterCloser.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include "fbpcf/io/api/ICloser.h" 11 | #include "fbpcf/io/api/IWriter.h" 12 | 13 | namespace fbpcf::io { 14 | 15 | /* 16 | * Defines a class that writes data to an 17 | * underlying medium and closes it. 18 | */ 19 | class IWriterCloser : public IWriter, public ICloser { 20 | public: 21 | virtual ~IWriterCloser() = default; 22 | }; 23 | 24 | } // namespace fbpcf::io 25 | -------------------------------------------------------------------------------- /fbpcf/io/api/test/data/buffered_reader_test_file.txt: -------------------------------------------------------------------------------- 1 | this is a simple first line 2 | this is a second line that is intended to be longer than a line that can fit in a single buffer 3 | this is a third line that should take at least three iterations of the buffer so that we can properly check the iterative functionality 4 | 5 | we also test a blank line and 6 | a line that will include a newline 7 | 8 | finally, we want to test a really long block of 9 | text, that will take 3 or 4 chunks, but this time 10 | using the read API instead of the readLine API to 11 | make sure that we have adequate test coverage. the 12 | total size of this paragraph is 242 bytes. 13 | -------------------------------------------------------------------------------- /fbpcf/mpc_std_lib/compactor/ICompactorFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include "fbpcf/mpc_std_lib/compactor/ICompactor.h" 11 | 12 | namespace fbpcf::mpc_std_lib::compactor { 13 | 14 | template 15 | class ICompactorFactory { 16 | public: 17 | virtual ~ICompactorFactory() = default; 18 | virtual std::unique_ptr> create() = 0; 19 | }; 20 | 21 | } // namespace fbpcf::mpc_std_lib::compactor 22 | -------------------------------------------------------------------------------- /fbpcf/io/cloud_util/IFileReader.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | namespace fbpcf::cloudio { 13 | 14 | class IFileReader { 15 | public: 16 | virtual ~IFileReader() {} 17 | virtual std::string readBytes( 18 | const std::string& fileName, 19 | std::size_t start, 20 | std::size_t end) = 0; 21 | virtual size_t getFileContentLength(const std::string& fileName) = 0; 22 | }; 23 | 24 | } // namespace fbpcf::cloudio 25 | -------------------------------------------------------------------------------- /fbpcf/io/api/ICloser.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | namespace fbpcf::io { 11 | 12 | /* 13 | * Defines a class that uses an underlying 14 | * medium and must close it to free up the allocated 15 | * resources. 16 | */ 17 | class ICloser { 18 | public: 19 | /* 20 | * close() returns 0 if it succeeds, and -1 21 | * in the case of an error. 22 | */ 23 | virtual int close() = 0; 24 | virtual ~ICloser() = default; 25 | }; 26 | 27 | } // namespace fbpcf::io 28 | -------------------------------------------------------------------------------- /fbpcf/aws/AwsSdk.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include "AwsSdk.h" 9 | 10 | #include 11 | 12 | #include 13 | 14 | namespace fbpcf { 15 | folly::Singleton awsSdkSingleton{}; 16 | std::shared_ptr AwsSdk::aquire() { 17 | return awsSdkSingleton.try_get(); 18 | } 19 | 20 | AwsSdk::AwsSdk() { 21 | Aws::InitAPI(options_); 22 | } 23 | 24 | AwsSdk::~AwsSdk() { 25 | Aws::ShutdownAPI(options_); 26 | } 27 | } // namespace fbpcf 28 | -------------------------------------------------------------------------------- /fbpcf/engine/util/IPrgFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | #include 10 | #include 11 | 12 | #include "fbpcf/engine/util/IPrg.h" 13 | 14 | namespace fbpcf::engine::util { 15 | 16 | /** 17 | * prg factory API, create a seeded prg with a given seed 18 | */ 19 | class IPrgFactory { 20 | public: 21 | virtual ~IPrgFactory() = default; 22 | virtual std::unique_ptr create(__m128i seed) const = 0; 23 | }; 24 | 25 | } // namespace fbpcf::engine::util 26 | -------------------------------------------------------------------------------- /fbpcf/engine/util/Masker.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | #include "fbpcf/engine/util/util.h" 13 | 14 | namespace fbpcf::engine::util { 15 | 16 | template 17 | class Masker { 18 | public: 19 | static T mask(T src, __m128i key); 20 | static T unmask(__m128i key, bool choice, T correction0, T correction1); 21 | }; 22 | 23 | } // namespace fbpcf::engine::util 24 | 25 | #include "fbpcf/engine/util/Masker_impl.h" 26 | -------------------------------------------------------------------------------- /fbpcf/mpc_std_lib/oram/ISinglePointArrayGeneratorFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include "fbpcf/mpc_std_lib/oram/ISinglePointArrayGenerator.h" 12 | 13 | namespace fbpcf::mpc_std_lib::oram { 14 | 15 | class ISinglePointArrayGeneratorFactory { 16 | public: 17 | virtual ~ISinglePointArrayGeneratorFactory() = default; 18 | 19 | virtual std::unique_ptr create() = 0; 20 | }; 21 | 22 | } // namespace fbpcf::mpc_std_lib::oram 23 | -------------------------------------------------------------------------------- /fbpcf/mpc_std_lib/unified_data_process/adapter/IAdapterFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include "fbpcf/mpc_std_lib/unified_data_process/adapter/IAdapter.h" 13 | 14 | namespace fbpcf::mpc_std_lib::unified_data_process::adapter { 15 | 16 | class IAdapterFactory { 17 | public: 18 | virtual ~IAdapterFactory() = default; 19 | virtual std::unique_ptr create() = 0; 20 | }; 21 | 22 | } // namespace fbpcf::mpc_std_lib::unified_data_process::adapter 23 | -------------------------------------------------------------------------------- /fbpcf/primitive/mac/IMacFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | #include 10 | #include "fbpcf/primitive/mac/IMac.h" 11 | 12 | namespace fbpcf::primitive::mac { 13 | 14 | /** 15 | * MAC factory API, create a MAC generator with a given key 16 | */ 17 | class IMacFactory { 18 | public: 19 | virtual ~IMacFactory() = default; 20 | virtual std::unique_ptr create( 21 | const std::vector& macKey) const = 0; 22 | }; 23 | 24 | } // namespace fbpcf::primitive::mac 25 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change log 2 | All notable changes to this project will be documented in this file. 3 | 4 | ## [2.1.0] - 2022-06-30 5 | - Each socket connection and socket connection factory now need a dedicated name. 6 | - The traffic on each socket connection will be monitored separately. 7 | 8 | 9 | ## [2.0.0] - 2022-05-05 10 | - New features and APIs are explained in the README 11 | - Removed dependence on EMP-toolkit 12 | 13 | ## [1.0.0] - 2022-03-29 14 | - Official release of the v1 version of this repository. 15 | - This version only exposes APIs that depend on the emp-toolkit 16 | and not on the newly built MPC engine. 17 | - Newer APIs that do not depend on emp are still in a pre-release stage. 18 | -------------------------------------------------------------------------------- /fbpcf/io/S3InputStream.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include // @manual 13 | 14 | #include "IInputStream.h" 15 | 16 | namespace fbpcf { 17 | class S3InputStream : public IInputStream { 18 | public: 19 | explicit S3InputStream(Aws::S3::Model::GetObjectResult r) 20 | : r_{std::move(r)} {} 21 | 22 | std::istream& get() override; 23 | 24 | private: 25 | Aws::S3::Model::GetObjectResult r_; 26 | }; 27 | } // namespace fbpcf 28 | -------------------------------------------------------------------------------- /fbpcf/exception/ExceptionBase.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | 13 | namespace fbpcf { 14 | class ExceptionBase : public std::exception { 15 | public: 16 | explicit ExceptionBase(const std::string& error) : error_{error} {} 17 | explicit ExceptionBase(const std::exception& exception) 18 | : error_{exception.what()} {} 19 | 20 | const char* what() const noexcept override; 21 | 22 | protected: 23 | std::string error_; 24 | }; 25 | } // namespace fbpcf 26 | -------------------------------------------------------------------------------- /fbpcf/aws/AwsSdk.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include 13 | 14 | #include 15 | 16 | namespace fbpcf { 17 | namespace { 18 | struct SingletonTag {}; 19 | } // namespace 20 | 21 | struct AwsSdk { 22 | ~AwsSdk(); 23 | static std::shared_ptr aquire(); 24 | 25 | private: 26 | AwsSdk(); 27 | 28 | private: 29 | Aws::SDKOptions options_; 30 | 31 | friend class folly::Singleton; 32 | }; 33 | } // namespace fbpcf 34 | -------------------------------------------------------------------------------- /fbpcf/io/test/FileManagerUtilTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include 9 | 10 | #include "fbpcf/io/FileManagerUtil.h" 11 | 12 | namespace fbpcf::io { 13 | TEST(FileManagerUtilTest, TestGetS3FileType) { 14 | auto type = 15 | getFileType("https://bucket-name.s3.Region.amazonaws.com/key-name"); 16 | EXPECT_EQ(FileType::S3, type); 17 | } 18 | 19 | TEST(FileManagerUtilTest, TestGetLocalFileType) { 20 | auto type = getFileType("/root/local"); 21 | EXPECT_EQ(FileType::Local, type); 22 | } 23 | } // namespace fbpcf::io 24 | -------------------------------------------------------------------------------- /fbpcf/io/GCSInputStream.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include // @manual 11 | #include 12 | 13 | #include "fbpcf/io/IInputStream.h" 14 | namespace gcs = ::google::cloud::storage; 15 | namespace fbpcf { 16 | class GCSInputStream : public IInputStream { 17 | public: 18 | explicit GCSInputStream(gcs::ObjectReadStream&& s) : s_{std::move(s)} {} 19 | 20 | std::istream& get() override; 21 | 22 | private: 23 | gcs::ObjectReadStream s_; 24 | }; 25 | } // namespace fbpcf 26 | -------------------------------------------------------------------------------- /fbpcf/aws/test/MockS3ClientTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include "fbpcf/aws/MockS3Client.h" 9 | #include "fbpcf/aws/AwsSdk.h" 10 | 11 | #include // @manual 12 | #include 13 | #include 14 | 15 | using testing::_; 16 | 17 | namespace fbpcf { 18 | TEST(MockS3Client, TestMockedClient) { 19 | AwsSdk::aquire(); 20 | MockS3Client client; 21 | 22 | Aws::S3::Model::GetObjectRequest request; 23 | EXPECT_CALL(client, GetObject(_)).Times(1); 24 | client.GetObject(request); 25 | } 26 | } // namespace fbpcf 27 | -------------------------------------------------------------------------------- /fbpcf/engine/ISecretShareEngineFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include "fbpcf/engine/ISecretShareEngine.h" 15 | 16 | namespace fbpcf::engine { 17 | 18 | /** 19 | * This factory creates secret share MPC engine 20 | */ 21 | class ISecretShareEngineFactory { 22 | public: 23 | virtual ~ISecretShareEngineFactory() = default; 24 | 25 | virtual std::unique_ptr create() = 0; 26 | }; 27 | 28 | } // namespace fbpcf::engine 29 | -------------------------------------------------------------------------------- /fbpcf/mpc_std_lib/oram/IObliviousDeltaCalculatorFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include "fbpcf/engine/communication/IPartyCommunicationAgent.h" 12 | #include "fbpcf/mpc_std_lib/oram/IObliviousDeltaCalculator.h" 13 | 14 | namespace fbpcf::mpc_std_lib::oram { 15 | 16 | class IObliviousDeltaCalculatorFactory { 17 | public: 18 | virtual ~IObliviousDeltaCalculatorFactory() = default; 19 | 20 | virtual std::unique_ptr create() = 0; 21 | }; 22 | 23 | } // namespace fbpcf::mpc_std_lib::oram 24 | -------------------------------------------------------------------------------- /docker/cmake/testing.cmake: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # 3 | # This source code is licensed under the MIT license found in the 4 | # LICENSE file in the root directory of this source tree. 5 | 6 | include(FetchContent) 7 | FetchContent_Declare( 8 | googletest 9 | URL https://github.com/google/googletest/archive/609281088cfefc76f9d0ce82e1ff6c30cc3591e5.zip 10 | ) 11 | FetchContent_MakeAvailable(googletest) 12 | 13 | enable_testing() 14 | 15 | # GCP Testing 16 | add_executable( 17 | gcp_test 18 | "fbpcf/gcp/test/GCSUtilTest.cpp" 19 | ) 20 | target_link_libraries( 21 | gcp_test 22 | fbpcf 23 | gtest_main 24 | ) 25 | include(GoogleTest) 26 | gtest_discover_tests(gcp_test) 27 | install(TARGETS gcp_test DESTINATION test) 28 | -------------------------------------------------------------------------------- /fbpcf/mpc_std_lib/shuffler/NonShufflerFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include "fbpcf/mpc_std_lib/shuffler/IShufflerFactory.h" 11 | #include "fbpcf/mpc_std_lib/shuffler/NonShuffler.h" 12 | 13 | namespace fbpcf::mpc_std_lib::shuffler::insecure { 14 | 15 | template 16 | class NonShufflerFactory final : public IShufflerFactory { 17 | public: 18 | std::unique_ptr> create() override { 19 | return std::make_unique>(); 20 | } 21 | }; 22 | 23 | } // namespace fbpcf::mpc_std_lib::shuffler::insecure 24 | -------------------------------------------------------------------------------- /fbpcf/mpc_std_lib/oram/IDifferenceCalculatorFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include "fbpcf/engine/communication/IPartyCommunicationAgent.h" 12 | #include "fbpcf/mpc_std_lib/oram/IDifferenceCalculator.h" 13 | 14 | namespace fbpcf::mpc_std_lib::oram { 15 | 16 | template 17 | class IDifferenceCalculatorFactory { 18 | public: 19 | virtual ~IDifferenceCalculatorFactory() = default; 20 | 21 | virtual std::unique_ptr> create() = 0; 22 | }; 23 | 24 | } // namespace fbpcf::mpc_std_lib::oram 25 | -------------------------------------------------------------------------------- /fbpcf/mpc_std_lib/util/secureRandomPermutation.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include "fbpcf/engine/util/IPrg.h" 11 | 12 | namespace fbpcf::mpc_std_lib::util { 13 | 14 | const uint32_t RANDOM_PERMUTATION_SECURITY_BITS = 128; 15 | 16 | /** 17 | *This method generates a random indexes permutation in range [0, size - 1]. 18 | *This method required a prg to generate secure random bytes. 19 | */ 20 | 21 | std::vector secureRandomPermutation( 22 | uint32_t size, 23 | engine::util::IPrg& prg); 24 | 25 | } // namespace fbpcf::mpc_std_lib::util 26 | -------------------------------------------------------------------------------- /fbpcf/primitive/mac/AesCmacFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | #include "fbpcf/primitive/mac/AesCmac.h" 10 | #include "fbpcf/primitive/mac/IMacFactory.h" 11 | 12 | namespace fbpcf::primitive::mac { 13 | 14 | /** 15 | * An AesCmac factory for creating 128-bit AesCmac. 16 | */ 17 | class AesCmacFactory final : public IMacFactory { 18 | public: 19 | std::unique_ptr create( 20 | const std::vector& macKey) const override { 21 | return std::make_unique(macKey); 22 | } 23 | }; 24 | 25 | } // namespace fbpcf::primitive::mac 26 | -------------------------------------------------------------------------------- /fbpcf/engine/util/test/aesTestHelper.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | #include 10 | #include "fbpcf/engine/util/aes.h" 11 | 12 | namespace fbpcf::engine::util { 13 | 14 | class AesTestHelper final : public Aes { 15 | public: 16 | explicit AesTestHelper(__m128i key) : Aes(key), key_(key) {} 17 | 18 | /** 19 | * Switch the cipher to decryption mode 20 | */ 21 | void switchToDecrypt(); 22 | 23 | void decryptInPlace(std::vector<__m128i>& ciphertext) const; 24 | 25 | private: 26 | __m128i key_; 27 | }; 28 | 29 | } // namespace fbpcf::engine::util 30 | -------------------------------------------------------------------------------- /fbpcf/mpc_std_lib/unified_data_process/data_processor/IDataProcessorFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include "fbpcf/mpc_std_lib/unified_data_process/data_processor/IDataProcessor.h" 12 | 13 | namespace fbpcf::mpc_std_lib::unified_data_process::data_processor { 14 | 15 | template 16 | class IDataProcessorFactory { 17 | public: 18 | virtual ~IDataProcessorFactory() = default; 19 | virtual std::unique_ptr> create() = 0; 20 | }; 21 | 22 | } // namespace fbpcf::mpc_std_lib::unified_data_process::data_processor 23 | -------------------------------------------------------------------------------- /fbpcf/gcp/GCSUtil.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #include // @manual=fbsource//third-party/google-cloud-cpp/google/cloud/storage:google_cloud_cpp_storage 15 | 16 | namespace fbpcf::gcp { 17 | struct GCSClientOption {}; 18 | 19 | struct GCSObjectReference { 20 | std::string bucket; 21 | std::string key; 22 | }; 23 | 24 | GCSObjectReference uriToObjectReference(std::string url); 25 | std::unique_ptr createGCSClient(); 26 | } // namespace fbpcf::gcp 27 | -------------------------------------------------------------------------------- /fbpcf/io/api/CloudFileWriter.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include "fbpcf/io/api/CloudFileWriter.h" 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | namespace fbpcf::io { 15 | 16 | int CloudFileWriter::close() { 17 | if (isClosed_) { 18 | return 0; 19 | } 20 | isClosed_ = true; 21 | return cloudFileUploader_->complete(); 22 | } 23 | 24 | size_t CloudFileWriter::write(std::vector& buf) { 25 | return cloudFileUploader_->upload(buf); 26 | } 27 | 28 | CloudFileWriter::~CloudFileWriter() { 29 | close(); 30 | } 31 | } // namespace fbpcf::io 32 | -------------------------------------------------------------------------------- /fbpcf/mpc_std_lib/shuffler/NonShuffler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include "fbpcf/mpc_std_lib/shuffler/IShuffler.h" 11 | 12 | namespace fbpcf::mpc_std_lib::shuffler::insecure { 13 | 14 | /** 15 | * This shuffler doesn't do anything but simply output the input. It is only 16 | *meant to be used as a placeholder in tests. 17 | **/ 18 | template 19 | class NonShuffler final : public IShuffler { 20 | public: 21 | T shuffle(const T& src, uint32_t /*size*/) const override { 22 | return src; 23 | } 24 | }; 25 | 26 | } // namespace fbpcf::mpc_std_lib::shuffler::insecure 27 | -------------------------------------------------------------------------------- /fbpcf/mpc_std_lib/aes_circuit/IAesCircuitFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include "fbpcf/mpc_std_lib/aes_circuit/IAesCircuit.h" 12 | 13 | namespace fbpcf::mpc_std_lib::aes_circuit { 14 | 15 | template 16 | class IAesCircuitFactory { 17 | public: 18 | virtual ~IAesCircuitFactory() = default; 19 | virtual std::unique_ptr> create() = 0; 20 | 21 | enum CircuitType { 22 | Dummy, 23 | Secure, 24 | }; 25 | 26 | virtual CircuitType getCircuitType() const = 0; 27 | }; 28 | 29 | } // namespace fbpcf::mpc_std_lib::aes_circuit 30 | -------------------------------------------------------------------------------- /fbpcf/mpc/QueueIO.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include "QueueIO.h" 9 | 10 | namespace fbpcf { 11 | void QueueIO::send_data_internal(const void* data, int64_t len) { 12 | outQueue_->withWLock([&data, len](auto& locked) { 13 | for (auto i = 0; i < len; i++) { 14 | locked.push(*((char*)data + i)); 15 | } 16 | }); 17 | } 18 | 19 | void QueueIO::recv_data_internal(void* data, int64_t len) { 20 | for (auto i = 0; i < len; i++) { 21 | while (inQueue_->rlock()->empty()) { 22 | } 23 | *((char*)data + i) = inQueue_->rlock()->front(); 24 | inQueue_->wlock()->pop(); 25 | } 26 | } 27 | } // namespace fbpcf 28 | -------------------------------------------------------------------------------- /fbpcf/primitive/mac/S2vFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | #include "fbpcf/primitive/mac/AesCmac.h" 10 | #include "fbpcf/primitive/mac/IMacFactory.h" 11 | #include "fbpcf/primitive/mac/S2v.h" 12 | 13 | namespace fbpcf::primitive::mac { 14 | 15 | /** 16 | * An AesCmac factory for creating 128-bit AesCmac. 17 | */ 18 | class S2vFactory final : public IMacFactory { 19 | public: 20 | std::unique_ptr create( 21 | const std::vector& macKey) const override { 22 | return std::make_unique(std::make_unique(macKey)); 23 | } 24 | }; 25 | 26 | } // namespace fbpcf::primitive::mac 27 | -------------------------------------------------------------------------------- /example/millionaire/MillionaireApp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include "./MillionaireGame.h" // @manual 13 | #include "fbpcf/mpc/EmpApp.h" 14 | 15 | namespace fbpcf { 16 | class MillionaireApp : public EmpApp, int, bool> { 17 | public: 18 | MillionaireApp(Party party, const std::string& serverIp, uint16_t port) 19 | : EmpApp, int, bool>{party, serverIp, port} {} 20 | 21 | protected: 22 | int getInputData() override; 23 | void putOutputData(const bool& output) override; 24 | }; 25 | } // namespace fbpcf 26 | -------------------------------------------------------------------------------- /fbpcf/engine/tuple_generator/oblivious_transfer/ferret/IRcotExtenderFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include "fbpcf/engine/communication/IPartyCommunicationAgent.h" 13 | #include "fbpcf/engine/tuple_generator/oblivious_transfer/ferret/IRcotExtender.h" 14 | 15 | namespace fbpcf::engine::tuple_generator::oblivious_transfer::ferret { 16 | 17 | class IRcotExtenderFactory { 18 | public: 19 | virtual ~IRcotExtenderFactory() = default; 20 | virtual std::unique_ptr create() = 0; 21 | }; 22 | 23 | } // namespace 24 | // fbpcf::engine::tuple_generator::oblivious_transfer::ferret 25 | -------------------------------------------------------------------------------- /fbpcf/engine/tuple_generator/oblivious_transfer/ferret/IMatrixMultiplierFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include "fbpcf/engine/communication/IPartyCommunicationAgent.h" 13 | #include "fbpcf/engine/tuple_generator/oblivious_transfer/ferret/IMatrixMultiplier.h" 14 | 15 | namespace fbpcf::engine::tuple_generator::oblivious_transfer::ferret { 16 | 17 | class IMatrixMultiplierFactory { 18 | public: 19 | virtual ~IMatrixMultiplierFactory() = default; 20 | virtual std::unique_ptr create() = 0; 21 | }; 22 | 23 | } // namespace 24 | // fbpcf::engine::tuple_generator::oblivious_transfer::ferret 25 | -------------------------------------------------------------------------------- /fbpcf/io/FileManagerUtil.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | 13 | #include "IFileManager.h" 14 | #include "IInputStream.h" 15 | 16 | namespace fbpcf::io { 17 | enum class FileType { Local, S3 }; 18 | 19 | std::unique_ptr getInputStream(const std::string& fileName); 20 | 21 | std::string read(const std::string& fileName); 22 | 23 | void write(const std::string& fileName, const std::string& data); 24 | 25 | FileType getFileType(const std::string& fileName); 26 | 27 | std::unique_ptr getFileManager( 28 | const std::string& fileName); 29 | } // namespace fbpcf::io 30 | -------------------------------------------------------------------------------- /fbpcf/engine/util/AesPrgFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | #include "fbpcf/engine/util/AesPrg.h" 10 | #include "fbpcf/engine/util/IPrgFactory.h" 11 | 12 | namespace fbpcf::engine::util { 13 | 14 | /** 15 | * an aes prg factory, always creates aes-based prg. 16 | */ 17 | class AesPrgFactory final : public IPrgFactory { 18 | public: 19 | explicit AesPrgFactory(int bufferSize = 1024) : bufferSize_(bufferSize) {} 20 | 21 | std::unique_ptr create(__m128i seed) const override { 22 | return std::make_unique(seed, bufferSize_); 23 | } 24 | 25 | private: 26 | int bufferSize_; 27 | }; 28 | 29 | } // namespace fbpcf::engine::util 30 | -------------------------------------------------------------------------------- /fbpcf/mpc_std_lib/oram/IWriteOnlyOramFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include "fbpcf/mpc_std_lib/oram/IWriteOnlyOram.h" 12 | 13 | namespace fbpcf::mpc_std_lib::oram { 14 | 15 | template 16 | class IWriteOnlyOramFactory { 17 | public: 18 | virtual ~IWriteOnlyOramFactory() = default; 19 | 20 | virtual std::unique_ptr> create(size_t size) = 0; 21 | 22 | /** 23 | * Get maximum batch size that can be used without running out of memory. 24 | */ 25 | virtual uint32_t getMaxBatchSize(size_t size, uint8_t concurrency) = 0; 26 | }; 27 | 28 | } // namespace fbpcf::mpc_std_lib::oram 29 | -------------------------------------------------------------------------------- /fbpcf/mpc/test/test_apps/millionaire/MillionaireApp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include "fbpcf/mpc/EmpApp.h" 13 | #include "fbpcf/mpc/test/test_apps/millionaire/MillionaireGame.h" 14 | 15 | namespace fbpcf { 16 | class MillionaireApp : public EmpApp, int, bool> { 17 | public: 18 | MillionaireApp(Party party, const std::string& serverIp, uint16_t port) 19 | : EmpApp, int, bool>{party, serverIp, port} {} 20 | 21 | protected: 22 | int getInputData() override; 23 | void putOutputData(const bool& output) override; 24 | }; 25 | } // namespace fbpcf 26 | -------------------------------------------------------------------------------- /fbpcf/util/IMetricRecorder.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | namespace fbpcf::util { 13 | /** 14 | * Different components could have different implementation of this recorder. 15 | * The only function of this interface is to allow metric collector to pull 16 | * metrics regardless of the actual implementation. The implementation of 17 | * this object needs to be thread-safe. 18 | */ 19 | 20 | class IMetricRecorder { 21 | public: 22 | virtual ~IMetricRecorder() = default; 23 | // return a map of metric name and values. 24 | virtual folly::dynamic getMetrics() const = 0; 25 | }; 26 | 27 | } // namespace fbpcf::util 28 | -------------------------------------------------------------------------------- /fbpcf/mpc_std_lib/aes_circuit/IAesCircuitCtrFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include "fbpcf/mpc_std_lib/aes_circuit/IAesCircuitCtr.h" 12 | #include "fbpcf/mpc_std_lib/aes_circuit/IAesCircuitFactory.h" 13 | 14 | namespace fbpcf::mpc_std_lib::aes_circuit { 15 | 16 | template 17 | class IAesCircuitCtrFactory { 18 | public: 19 | virtual ~IAesCircuitCtrFactory() = default; 20 | 21 | virtual std::unique_ptr> create() = 0; 22 | 23 | virtual typename IAesCircuitFactory::CircuitType getCircuitType() 24 | const = 0; 25 | }; 26 | 27 | } // namespace fbpcf::mpc_std_lib::aes_circuit 28 | -------------------------------------------------------------------------------- /fbpcf/scheduler/ISchedulerFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include "fbpcf/scheduler/IScheduler.h" 11 | #include "fbpcf/util/MetricCollector.h" 12 | 13 | namespace fbpcf::scheduler { 14 | 15 | template 16 | class ISchedulerFactory { 17 | public: 18 | explicit ISchedulerFactory( 19 | std::shared_ptr metricCollector) 20 | : metricCollector_(metricCollector) {} 21 | virtual ~ISchedulerFactory() = default; 22 | 23 | virtual std::unique_ptr create() = 0; 24 | 25 | protected: 26 | std::shared_ptr metricCollector_; 27 | }; 28 | 29 | } // namespace fbpcf::scheduler 30 | -------------------------------------------------------------------------------- /fbpcf/engine/tuple_generator/IArithmeticTupleGeneratorFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | #include 10 | 11 | #include "fbpcf/engine/tuple_generator/IArithmeticTupleGenerator.h" 12 | 13 | namespace fbpcf::engine::tuple_generator { 14 | 15 | /** 16 | * This is the API for an arithmetic tuple generator that generates integer 17 | * tuples. 18 | */ 19 | 20 | class IArithmeticTupleGeneratorFactory { 21 | public: 22 | virtual ~IArithmeticTupleGeneratorFactory() = default; 23 | 24 | /** 25 | * Create a tuple generator with all party. 26 | */ 27 | virtual std::unique_ptr create() = 0; 28 | }; 29 | 30 | } // namespace fbpcf::engine::tuple_generator 31 | -------------------------------------------------------------------------------- /fbpcf/io/cloud_util/CloudFileUtil.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include 9 | #include 10 | #include "fbpcf/io/cloud_util/IFileReader.h" 11 | #include "fbpcf/io/cloud_util/IFileUploader.h" 12 | 13 | namespace fbpcf::cloudio { 14 | enum class CloudFileType { S3, GCS, UNKNOWN }; 15 | 16 | CloudFileType getCloudFileType(const std::string& filePath); 17 | std::unique_ptr getCloudFileReader(const std::string& filePath); 18 | std::unique_ptr getCloudFileUploader( 19 | const std::string& filePath); 20 | std::string getCloudProviderString(const std::string& filePath); 21 | std::string getCloudStorageServiceString(const std::string& filePath); 22 | } // namespace fbpcf::cloudio 23 | -------------------------------------------------------------------------------- /fbpcf/engine/tuple_generator/oblivious_transfer/ferret/IMultiPointCotFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include "fbpcf/engine/communication/IPartyCommunicationAgent.h" 13 | #include "fbpcf/engine/tuple_generator/oblivious_transfer/ferret/IMultiPointCot.h" 14 | 15 | namespace fbpcf::engine::tuple_generator::oblivious_transfer::ferret { 16 | 17 | class IMultiPointCotFactory { 18 | public: 19 | virtual ~IMultiPointCotFactory() = default; 20 | virtual std::unique_ptr create( 21 | std::unique_ptr& agent) = 0; 22 | }; 23 | 24 | } // namespace 25 | // fbpcf::engine::tuple_generator::oblivious_transfer::ferret 26 | -------------------------------------------------------------------------------- /fbpcf/io/LocalFileManager.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include "IFileManager.h" 13 | 14 | namespace fbpcf { 15 | class LocalFileManager : public IFileManager { 16 | public: 17 | std::unique_ptr getInputStream( 18 | const std::string& fileName) override; 19 | 20 | std::string read(const std::string& fileName) override; 21 | 22 | void write(const std::string& fileName, const std::string& data) override; 23 | 24 | void copy(const std::string& sourceFile, const std::string& destination) 25 | override; 26 | 27 | std::string 28 | readBytes(const std::string& fileName, std::size_t start, std::size_t end); 29 | }; 30 | } // namespace fbpcf 31 | -------------------------------------------------------------------------------- /fbpcf/mpc/test/QueueIOTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | #include "fbpcf/mpc/QueueIO.h" 16 | 17 | namespace fbpcf { 18 | TEST(QueueIOTest, ReadAndWrite) { 19 | auto queueA = std::make_shared>>(); 20 | auto queueB = std::make_shared>>(); 21 | 22 | QueueIO ioA{queueA, queueB}; 23 | QueueIO ioB{queueB, queueA}; 24 | 25 | std::array a{"abc"}; 26 | ioA.send_data(a.data(), 4); 27 | 28 | std::array b; 29 | ioB.recv_data(b.data(), 4); 30 | 31 | EXPECT_EQ(a, b); 32 | } 33 | } // namespace fbpcf 34 | -------------------------------------------------------------------------------- /fbpcf/engine/tuple_generator/oblivious_transfer/ferret/DummyMatrixMultiplier.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include "fbpcf/engine/tuple_generator/oblivious_transfer/ferret/DummyMatrixMultiplier.h" 9 | 10 | namespace fbpcf::engine::tuple_generator::oblivious_transfer::ferret::insecure { 11 | 12 | std::vector<__m128i> DummyMatrixMultiplier::multiplyWithRandomMatrix( 13 | __m128i /*seed*/, 14 | int64_t rstLength, 15 | const std::vector<__m128i>& src) const { 16 | std::vector<__m128i> rst(rstLength); 17 | for (int i = 0; i < rstLength; i++) { 18 | rst[i] = src[i % src.size()]; 19 | } 20 | return rst; 21 | } 22 | 23 | } // namespace 24 | // fbpcf::engine::tuple_generator::oblivious_transfer::ferret::insecure 25 | -------------------------------------------------------------------------------- /fbpcf/engine/tuple_generator/oblivious_transfer/ferret/ISinglePointCotFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include "fbpcf/engine/communication/IPartyCommunicationAgent.h" 13 | #include "fbpcf/engine/tuple_generator/oblivious_transfer/ferret/ISinglePointCot.h" 14 | 15 | namespace fbpcf::engine::tuple_generator::oblivious_transfer::ferret { 16 | 17 | class ISinglePointCotFactory { 18 | public: 19 | virtual ~ISinglePointCotFactory() = default; 20 | virtual std::unique_ptr create( 21 | std::unique_ptr& agent) = 0; 22 | }; 23 | 24 | } // namespace 25 | // fbpcf::engine::tuple_generator::oblivious_transfer::ferret 26 | -------------------------------------------------------------------------------- /fbpcf/common/test/VectorUtilTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #include 13 | 14 | #include "fbpcf/common/VectorUtil.h" 15 | 16 | namespace fbpcf::vector { 17 | TEST(FunctionalUtilTest, TestVectorAdd) { 18 | std::vector v1{1, 2, 3}; 19 | std::vector v2{4, 5, 6}; 20 | std::vector expectedOutput{5, 7, 9}; 21 | 22 | auto output = Add(v1, v2); 23 | EXPECT_EQ(expectedOutput, output); 24 | } 25 | 26 | TEST(FunctionalUtilTest, TestVectorAddWithException) { 27 | std::vector v1{1}; 28 | std::vector v2{2, 3}; 29 | 30 | EXPECT_THROW(Add(v1, v2), std::invalid_argument); 31 | } 32 | } // namespace fbpcf::vector 33 | -------------------------------------------------------------------------------- /fbpcf/mpc/IMpcGame.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include "fbpcf/perf/PerfUtil.h" 13 | 14 | namespace fbpcf { 15 | template 16 | class IMpcGame { 17 | public: 18 | virtual ~IMpcGame() {} 19 | 20 | OutputDataType perfPlay(const InputDataType& inputData) { 21 | auto decorator = fbpcf::perf::decorate( 22 | "IMpcGame::perfPlay", 23 | static_cast< 24 | std::function>( 25 | &IMpcGame::play)); 26 | return decorator(this, inputData); 27 | } 28 | 29 | virtual OutputDataType play(const InputDataType& inputData) = 0; 30 | }; 31 | } // namespace fbpcf 32 | -------------------------------------------------------------------------------- /fbpcf/io/cloud_util/S3FileReader.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include // @manual 13 | #include "fbpcf/io/cloud_util/IFileReader.h" 14 | 15 | namespace fbpcf::cloudio { 16 | 17 | class S3FileReader : public IFileReader { 18 | public: 19 | explicit S3FileReader(std::shared_ptr client) 20 | : s3Client_{client} {} 21 | 22 | std::string readBytes( 23 | const std::string& filePath, 24 | std::size_t start, 25 | std::size_t end) override; 26 | 27 | size_t getFileContentLength(const std::string& filePath) override; 28 | 29 | private: 30 | std::shared_ptr s3Client_; 31 | }; 32 | 33 | } // namespace fbpcf::cloudio 34 | -------------------------------------------------------------------------------- /fbpcf/engine/util/test/benchmarks/LocalBenchmark.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | namespace fbpcf::engine::util { 13 | 14 | /** 15 | * A parent class for local benchmarks that don't need to measure network use. 16 | */ 17 | class LocalBenchmark { 18 | public: 19 | virtual ~LocalBenchmark() = default; 20 | 21 | void runBenchmark(unsigned int n) { 22 | BENCHMARK_SUSPEND { 23 | setup(); 24 | } 25 | 26 | run(n); 27 | 28 | BENCHMARK_SUSPEND { 29 | teardown(); 30 | } 31 | } 32 | 33 | protected: 34 | virtual void setup() {} 35 | virtual void teardown() {} 36 | virtual void run(unsigned int n) = 0; 37 | }; 38 | 39 | } // namespace fbpcf::engine::util 40 | -------------------------------------------------------------------------------- /fbpcf/mpc_std_lib/aes_circuit/AesCircuitFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include "fbpcf/mpc_std_lib/aes_circuit/AesCircuit.h" 11 | #include "fbpcf/mpc_std_lib/aes_circuit/IAesCircuitFactory.h" 12 | 13 | namespace fbpcf::mpc_std_lib::aes_circuit { 14 | 15 | template 16 | class AesCircuitFactory : IAesCircuitFactory { 17 | public: 18 | std::unique_ptr> create() override { 19 | return std::make_unique>(); 20 | } 21 | 22 | typename IAesCircuitFactory::CircuitType getCircuitType() 23 | const override { 24 | return IAesCircuitFactory::CircuitType::Secure; 25 | } 26 | }; 27 | 28 | } // namespace fbpcf::mpc_std_lib::aes_circuit 29 | -------------------------------------------------------------------------------- /fbpcf/frontend/test/utilTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include 9 | #include 10 | 11 | #include "fbpcf/frontend/util.h" 12 | 13 | namespace fbpcf::frontend { 14 | 15 | TEST(TypeIndicatorTest, testIntegerTypes) { 16 | const int width = 31; 17 | EXPECT_EQ(width, Signed::width); 18 | EXPECT_EQ(width, Unsigned::width); 19 | 20 | EXPECT_TRUE(IsSigned>::value); 21 | EXPECT_FALSE(IsSigned>::value); 22 | 23 | EXPECT_TRUE(IsBatch>>::value); 24 | EXPECT_TRUE(IsBatch>>::value); 25 | 26 | EXPECT_FALSE(IsBatch>::value); 27 | EXPECT_FALSE(IsBatch>::value); 28 | } 29 | 30 | } // namespace fbpcf::frontend 31 | -------------------------------------------------------------------------------- /fbpcf/io/api/LocalFileWriter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include "fbpcf/io/api/IWriterCloser.h" 16 | 17 | namespace fbpcf::io { 18 | 19 | /* 20 | This class is the API for writing a file to local 21 | storage. It must be on disk and cannot be a file in 22 | cloud storage. 23 | */ 24 | class LocalFileWriter : public IWriterCloser { 25 | public: 26 | explicit LocalFileWriter(std::string filePath); 27 | 28 | int close() override; 29 | size_t write(std::vector& buf) override; 30 | ~LocalFileWriter() override; 31 | 32 | private: 33 | std::unique_ptr outputStream_; 34 | bool isClosed_; 35 | }; 36 | 37 | } // namespace fbpcf::io 38 | -------------------------------------------------------------------------------- /fbpcf/io/cloud_util/IFileUploader.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | #include 10 | #include 11 | 12 | namespace fbpcf::cloudio { 13 | 14 | class IFileUploader { 15 | public: 16 | virtual ~IFileUploader() {} 17 | 18 | // Initilize the upload. In multipart upload, the first step is usually 19 | // initiate a multipart upload, and it will return an upload ID which is 20 | // needed in following uploads. 21 | virtual void init() = 0; 22 | 23 | // Upload the buf to cloud 24 | virtual int upload(std::vector& buf) = 0; 25 | 26 | // Complete the upload. The cloud (e.g. S3) creates the object by 27 | // concatenating the parts in ascending order based on the part number. 28 | virtual int complete() = 0; 29 | }; 30 | 31 | } // namespace fbpcf::cloudio 32 | -------------------------------------------------------------------------------- /fbpcf/engine/tuple_generator/NullArithmeticTupleGeneratorFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | #include 10 | 11 | #include "fbpcf/engine/tuple_generator/IArithmeticTupleGeneratorFactory.h" 12 | #include "fbpcf/engine/tuple_generator/NullArithmeticTupleGenerator.h" 13 | 14 | namespace fbpcf::engine::tuple_generator { 15 | 16 | /** 17 | * This factory creates null tuple generators 18 | */ 19 | 20 | class NullArithmeticTupleGeneratorFactory final 21 | : public IArithmeticTupleGeneratorFactory { 22 | public: 23 | /** 24 | * Create a null tuple generator; 25 | */ 26 | std::unique_ptr create() override { 27 | return std::make_unique(); 28 | } 29 | }; 30 | 31 | } // namespace fbpcf::engine::tuple_generator 32 | -------------------------------------------------------------------------------- /fbpcf/mpc_std_lib/aes_circuit/DummyAesCircuitFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include "fbpcf/mpc_std_lib/aes_circuit/DummyAesCircuit.h" 11 | #include "fbpcf/mpc_std_lib/aes_circuit/IAesCircuitFactory.h" 12 | 13 | namespace fbpcf::mpc_std_lib::aes_circuit::insecure { 14 | 15 | template 16 | class DummyAesCircuitFactory : public IAesCircuitFactory { 17 | public: 18 | std::unique_ptr> create() override { 19 | return std::make_unique>(); 20 | } 21 | 22 | typename IAesCircuitFactory::CircuitType getCircuitType() 23 | const override { 24 | return IAesCircuitFactory::CircuitType::Dummy; 25 | } 26 | }; 27 | 28 | } // namespace fbpcf::mpc_std_lib::aes_circuit::insecure 29 | -------------------------------------------------------------------------------- /fbpcf/engine/tuple_generator/oblivious_transfer/ferret/DummyRcotExtenderFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include "fbpcf/engine/communication/IPartyCommunicationAgent.h" 13 | #include "fbpcf/engine/tuple_generator/oblivious_transfer/ferret/DummyRcotExtender.h" 14 | #include "fbpcf/engine/tuple_generator/oblivious_transfer/ferret/IRcotExtenderFactory.h" 15 | 16 | namespace fbpcf::engine::tuple_generator::oblivious_transfer::ferret::insecure { 17 | 18 | class DummyRcotExtenderFactory final : public IRcotExtenderFactory { 19 | public: 20 | std::unique_ptr create() override { 21 | return std::make_unique(); 22 | } 23 | }; 24 | 25 | } // namespace 26 | // fbpcf::engine::tuple_generator::oblivious_transfer::ferret::insecure 27 | -------------------------------------------------------------------------------- /fbpcf/primitive/mac/AesCmac.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include "fbpcf/primitive/mac/AesCmac.h" 9 | #include 10 | namespace fbpcf::primitive::mac { 11 | 12 | __m128i AesCmac::getMacM128i(const std::vector& text) const { 13 | const std::vector cmac = getMac128(text); 14 | return engine::util::buildM128i(cmac); 15 | } 16 | 17 | std::vector AesCmac::getMac128( 18 | const std::vector& text) const { 19 | std::vector cmac(16); 20 | size_t mactlen; 21 | CMAC_Init(ctx_, macKey_.data(), 16, EVP_aes_128_cbc(), nullptr); 22 | CMAC_Update(ctx_, text.data(), sizeof(unsigned char) * text.size()); 23 | CMAC_Final(ctx_, cmac.data(), &mactlen); 24 | return cmac; 25 | } 26 | } // namespace fbpcf::primitive::mac 27 | -------------------------------------------------------------------------------- /fbpcf/io/cloud_util/GCSFileReader.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include // @manual 11 | 12 | #include 13 | #include 14 | #include "fbpcf/io/cloud_util/IFileReader.h" 15 | 16 | namespace fbpcf::cloudio { 17 | class GCSFileReader : public IFileReader { 18 | public: 19 | explicit GCSFileReader(std::shared_ptr client) 20 | : GCSClient_{std::move(client)} {} 21 | 22 | std::string readBytes( 23 | const std::string& filePath, 24 | std::size_t start, 25 | std::size_t end) override; 26 | 27 | size_t getFileContentLength(const std::string& filePath) override; 28 | 29 | private: 30 | std::shared_ptr GCSClient_; 31 | }; 32 | 33 | } // namespace fbpcf::cloudio 34 | -------------------------------------------------------------------------------- /fbpcf/io/api/LocalFileReader.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include "fbpcf/io/api/IReaderCloser.h" 16 | 17 | namespace fbpcf::io { 18 | 19 | /* 20 | This class is the API for reading a file from local 21 | storage. It must be on disk and cannot be a file in 22 | cloud storage. 23 | */ 24 | class LocalFileReader : public IReaderCloser { 25 | public: 26 | explicit LocalFileReader(std::string filePath); 27 | 28 | int close() override; 29 | size_t read(std::vector& buf) override; 30 | bool eof() override; 31 | ~LocalFileReader() override; 32 | 33 | private: 34 | std::unique_ptr inputStream_; 35 | bool isClosed_; 36 | }; 37 | 38 | } // namespace fbpcf::io 39 | -------------------------------------------------------------------------------- /fbpcf/io/IFileManager.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #include "IInputStream.h" 15 | 16 | namespace fbpcf { 17 | class IFileManager { 18 | public: 19 | virtual ~IFileManager() {} 20 | 21 | virtual std::unique_ptr getInputStream( 22 | const std::string& fileName) = 0; 23 | 24 | virtual std::string read(const std::string& fileName) = 0; 25 | 26 | virtual void write(const std::string& fileName, const std::string& data) = 0; 27 | 28 | virtual void copy( 29 | const std::string& sourceFile, 30 | const std::string& destination) = 0; 31 | 32 | virtual std::string readBytes( 33 | const std::string& fileName, 34 | std::size_t start, 35 | std::size_t end) = 0; 36 | }; 37 | } // namespace fbpcf 38 | -------------------------------------------------------------------------------- /fbpcf/engine/tuple_generator/oblivious_transfer/ferret/DummyMatrixMultiplierFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include "fbpcf/engine/communication/IPartyCommunicationAgent.h" 13 | #include "fbpcf/engine/tuple_generator/oblivious_transfer/ferret/DummyMatrixMultiplier.h" 14 | #include "fbpcf/engine/tuple_generator/oblivious_transfer/ferret/IMatrixMultiplierFactory.h" 15 | 16 | namespace fbpcf::engine::tuple_generator::oblivious_transfer::ferret::insecure { 17 | 18 | class DummyMatrixMultiplierFactory final : public IMatrixMultiplierFactory { 19 | public: 20 | std::unique_ptr create() override { 21 | return std::make_unique(); 22 | } 23 | }; 24 | 25 | } // namespace 26 | // fbpcf::engine::tuple_generator::oblivious_transfer::ferret::insecure 27 | -------------------------------------------------------------------------------- /fbpcf/mpc_std_lib/walr_multiplication/IWalrMatrixMultiplicationFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include "fbpcf/mpc_std_lib/walr_multiplication/IWalrMatrixMultiplication.h" 11 | #include "fbpcf/util/MetricCollector.h" 12 | 13 | namespace fbpcf::mpc_std_lib::walr { 14 | 15 | template 16 | class IWalrMatrixMultiplicationFactory { 17 | public: 18 | explicit IWalrMatrixMultiplicationFactory( 19 | std::shared_ptr metricCollector) 20 | : metricCollector_(metricCollector) {} 21 | virtual ~IWalrMatrixMultiplicationFactory() = default; 22 | virtual std::unique_ptr> create() = 0; 23 | 24 | protected: 25 | std::shared_ptr metricCollector_; 26 | }; 27 | 28 | } // namespace fbpcf::mpc_std_lib::walr 29 | -------------------------------------------------------------------------------- /fbpcf/engine/tuple_generator/oblivious_transfer/IBidirectionObliviousTransferFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | #include "fbpcf/engine/communication/IPartyCommunicationAgent.h" 10 | #include "fbpcf/engine/tuple_generator/oblivious_transfer/IBidirectionObliviousTransfer.h" 11 | 12 | namespace fbpcf::engine::tuple_generator::oblivious_transfer { 13 | 14 | class IBidirectionObliviousTransferFactory { 15 | public: 16 | virtual ~IBidirectionObliviousTransferFactory() = default; 17 | 18 | /** 19 | * Create an oblivious transfer with a particular party. 20 | * Some implementation may need party id to decide parties' roles in the 21 | * underlying protocol. 22 | */ 23 | virtual std::unique_ptr create(int id) = 0; 24 | }; 25 | 26 | } // namespace fbpcf::engine::tuple_generator::oblivious_transfer 27 | -------------------------------------------------------------------------------- /fbpcf/io/api/IWriter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | namespace fbpcf::io { 15 | 16 | /* 17 | * Defines a class that writes data to 18 | * an underlying medium. 19 | */ 20 | class IWriter { 21 | public: 22 | /* 23 | * write() returns the number of bytes it 24 | * was able to write, or -1 if there was 25 | * an error. It attempts to write the first 26 | * n bytes of the entire provided buffer. 27 | */ 28 | virtual size_t write(std::vector& buf) = 0; 29 | 30 | /* 31 | * returns the path of the file being written to 32 | */ 33 | std::string& getFilePath() { 34 | return filepath_; 35 | } 36 | 37 | virtual ~IWriter() = default; 38 | 39 | protected: 40 | std::string filepath_; 41 | }; 42 | 43 | } // namespace fbpcf::io 44 | -------------------------------------------------------------------------------- /fbpcf/io/api/FileWriter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include "fbpcf/io/api/IWriterCloser.h" 14 | 15 | namespace fbpcf::io { 16 | 17 | /* 18 | This class is the API for writing a file to any 19 | storage, local or cloud. It can be in any supported 20 | cloud provider or a file on disk. Internally, this 21 | class will create a LocalFileWriter or CloudFileWriter 22 | depending on what file path is provided. 23 | */ 24 | class FileWriter : public IWriterCloser { 25 | public: 26 | explicit FileWriter(std::string filePath); 27 | 28 | int close() override; 29 | size_t write(std::vector& buf) override; 30 | ~FileWriter() override; 31 | 32 | private: 33 | std::unique_ptr childWriter_; 34 | }; 35 | 36 | } // namespace fbpcf::io 37 | -------------------------------------------------------------------------------- /fbpcf/engine/tuple_generator/DummyArithmeticTupleGenerator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | #include "fbpcf/engine/tuple_generator/IArithmeticTupleGenerator.h" 10 | 11 | namespace fbpcf::engine::tuple_generator::insecure { 12 | 13 | /** 14 | A dummy integer tuple generator, always generate tuple (0, 0,0 ) 15 | */ 16 | class DummyArithmeticTupleGenerator final : public IArithmeticTupleGenerator { 17 | public: 18 | std::vector getIntegerTuple(uint32_t size) override { 19 | std::vector result; 20 | for (size_t i = 0; i < size; i++) { 21 | result.push_back(IntegerTuple(0, 0, 0)); 22 | } 23 | return result; 24 | } 25 | 26 | std::pair getTrafficStatistics() const override { 27 | return {0, 0}; 28 | } 29 | }; 30 | 31 | } // namespace fbpcf::engine::tuple_generator::insecure 32 | -------------------------------------------------------------------------------- /fbpcf/engine/tuple_generator/NullTupleGeneratorFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | #include "fbpcf/engine/tuple_generator/ITupleGeneratorFactory.h" 10 | #include "fbpcf/engine/tuple_generator/NullTupleGenerator.h" 11 | 12 | namespace fbpcf::engine::tuple_generator { 13 | 14 | /** 15 | * This factory creates null tuple generators 16 | */ 17 | 18 | class NullTupleGeneratorFactory final : public ITupleGeneratorFactory { 19 | public: 20 | explicit NullTupleGeneratorFactory( 21 | std::shared_ptr metricCollector) 22 | : ITupleGeneratorFactory(metricCollector) {} 23 | /** 24 | * Create a null tuple generator; 25 | */ 26 | std::unique_ptr create() override { 27 | return std::make_unique(); 28 | } 29 | }; 30 | 31 | } // namespace fbpcf::engine::tuple_generator 32 | -------------------------------------------------------------------------------- /fbpcf/engine/tuple_generator/DummyArithmeticTupleGeneratorFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | #include 10 | 11 | #include "fbpcf/engine/tuple_generator/DummyArithmeticTupleGenerator.h" 12 | #include "fbpcf/engine/tuple_generator/IArithmeticTupleGeneratorFactory.h" 13 | #include "fbpcf/engine/util/IPrgFactory.h" 14 | 15 | namespace fbpcf::engine::tuple_generator::insecure { 16 | 17 | /** 18 | * This factory creates dummy tuple generators 19 | */ 20 | 21 | class DummyArithmeticTupleGeneratorFactory final 22 | : public IArithmeticTupleGeneratorFactory { 23 | public: 24 | /** 25 | * Create a dummy tuple generator; 26 | */ 27 | std::unique_ptr create() override { 28 | return std::make_unique(); 29 | } 30 | }; 31 | 32 | } // namespace fbpcf::engine::tuple_generator::insecure 33 | -------------------------------------------------------------------------------- /fbpcf/engine/tuple_generator/oblivious_transfer/IFlexibleRandomCorrelatedObliviousTransfer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include "fbpcf/engine/communication/IPartyCommunicationAgent.h" 11 | #include "fbpcf/engine/tuple_generator/oblivious_transfer/IRandomCorrelatedObliviousTransfer.h" 12 | 13 | namespace fbpcf::engine::tuple_generator::oblivious_transfer { 14 | 15 | /** 16 | * A flexible RCOT allows to extract the communication it uses before destroy 17 | */ 18 | 19 | class IFlexibleRandomCorrelatedObliviousTransfer 20 | : public IRandomCorrelatedObliviousTransfer { 21 | public: 22 | virtual ~IFlexibleRandomCorrelatedObliviousTransfer() = default; 23 | 24 | virtual std::unique_ptr 25 | extractCommunicationAgent() = 0; 26 | }; 27 | 28 | } // namespace fbpcf::engine::tuple_generator::oblivious_transfer 29 | -------------------------------------------------------------------------------- /fbpcf/io/api/SocketWriter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #include "fbpcf/io/api/IWriterCloser.h" 15 | 16 | namespace fbpcf::io { 17 | 18 | /* 19 | This class is the API for writing data to a network 20 | socket. It is constructed with a socket file descriptor. 21 | */ 22 | class SocketWriter : public IWriterCloser { 23 | public: 24 | /* 25 | * Creates a SocketWriter to write to the given 26 | * file descriptor. 27 | */ 28 | SocketWriter(FILE* socket); 29 | 30 | /* 31 | * Creates a SocketReader to write to 32 | * the provided SSL/TLS connection object. 33 | */ 34 | SocketWriter(SSL* ssl); 35 | 36 | int close() override; 37 | size_t write(std::vector& buf) override; 38 | ~SocketWriter() override; 39 | }; 40 | 41 | } // namespace fbpcf::io 42 | -------------------------------------------------------------------------------- /example/millionaire/test/MillionaireGameTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | #include "../MillionaireGame.h" // @manual 14 | #include "fbpcf/mpc/EmpTestUtil.h" 15 | #include "fbpcf/system/CpuUtil.h" 16 | 17 | namespace fbpcf { 18 | TEST(MillionaireGame, AliceIsRicher) { 19 | if (!mpc::isTestable()) { 20 | GTEST_SKIP(); 21 | } 22 | 23 | auto res = mpc::test, int, bool>(2, 1); 24 | EXPECT_EQ(true, res.first); 25 | EXPECT_EQ(true, res.second); 26 | } 27 | 28 | TEST(MillionaireGame, BobIsRicher) { 29 | if (!system::isDrngSupported()) { 30 | GTEST_SKIP(); 31 | } 32 | 33 | auto res = mpc::test, int, bool>(1, 2); 34 | EXPECT_EQ(false, res.first); 35 | EXPECT_EQ(false, res.second); 36 | } 37 | } // namespace fbpcf 38 | -------------------------------------------------------------------------------- /fbpcf/engine/tuple_generator/oblivious_transfer/IBaseObliviousTransferFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | #include "fbpcf/engine/communication/IPartyCommunicationAgent.h" 10 | #include "fbpcf/engine/tuple_generator/oblivious_transfer/IBaseObliviousTransfer.h" 11 | 12 | namespace fbpcf::engine::tuple_generator::oblivious_transfer { 13 | 14 | /** 15 | * Create a base oblivious transfer with a particular party. 16 | * Some implementation may need party id to decide parties' roles in the 17 | * underlying protocol. 18 | */ 19 | class IBaseObliviousTransferFactory { 20 | public: 21 | virtual ~IBaseObliviousTransferFactory() = default; 22 | 23 | virtual std::unique_ptr create( 24 | std::unique_ptr agent) = 0; 25 | }; 26 | 27 | } // namespace fbpcf::engine::tuple_generator::oblivious_transfer 28 | -------------------------------------------------------------------------------- /fbpcf/engine/tuple_generator/oblivious_transfer/ferret/SinglePointCotFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | 13 | #include "fbpcf/engine/tuple_generator/oblivious_transfer/ferret/ISinglePointCotFactory.h" 14 | #include "fbpcf/engine/tuple_generator/oblivious_transfer/ferret/SinglePointCot.h" 15 | #include "fbpcf/engine/util/IPrgFactory.h" 16 | 17 | namespace fbpcf::engine::tuple_generator::oblivious_transfer::ferret { 18 | 19 | class SinglePointCotFactory final : public ISinglePointCotFactory { 20 | public: 21 | std::unique_ptr create( 22 | std::unique_ptr& agent) 23 | override { 24 | return std::make_unique(agent); 25 | } 26 | }; 27 | 28 | } // namespace 29 | // fbpcf::engine::tuple_generator::oblivious_transfer::ferret 30 | -------------------------------------------------------------------------------- /fbpcf/io/api/FileReader.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include "fbpcf/io/api/IReaderCloser.h" 14 | 15 | namespace fbpcf::io { 16 | 17 | /* 18 | This class is the API for reading a file from any 19 | storage, local or cloud. It can be in any supported 20 | cloud provider or a file on disk. Internally, this 21 | class will create a LocalFileReader or CloudFileReader 22 | depending on what file path is provided. 23 | */ 24 | class FileReader : public IReaderCloser { 25 | public: 26 | explicit FileReader(std::string filePath); 27 | 28 | int close() override; 29 | size_t read(std::vector& buf) override; 30 | bool eof() override; 31 | ~FileReader() override; 32 | 33 | private: 34 | std::unique_ptr childReader_; 35 | }; 36 | 37 | } // namespace fbpcf::io 38 | -------------------------------------------------------------------------------- /fbpcf/scheduler/test/benchmarks/WireKeeperBenchmark.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include "fbpcf/scheduler/WireKeeper.h" 13 | 14 | const bool unsafe = true; 15 | 16 | namespace fbpcf::scheduler { 17 | 18 | #define BENCHMARK_WIREKEEPER \ 19 | folly::BenchmarkSuspender braces; \ 20 | auto wireKeeper = WireKeeper::createWithVectorArena(); \ 21 | std::vector> wireIds; \ 22 | for (auto i = 0; i < n; i++) { \ 23 | wireIds.push_back(wireKeeper->allocateBooleanValue()); \ 24 | } \ 25 | braces.dismiss(); \ 26 | while (n--) 27 | 28 | } // namespace fbpcf::scheduler 29 | -------------------------------------------------------------------------------- /fbpcf/io/api/SocketReader.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | #include 10 | #include 11 | #include 12 | 13 | #include "fbpcf/io/api/IReaderCloser.h" 14 | 15 | namespace fbpcf::io { 16 | 17 | /* 18 | This class is the API for reading data from network 19 | socket. It is constructed with a socket file descriptor. 20 | */ 21 | class SocketReader : public IReaderCloser { 22 | public: 23 | /* 24 | * Creates a SocketReader to read from the given 25 | * file descriptor. 26 | */ 27 | SocketReader(FILE* socket); 28 | 29 | /* 30 | * Creates a SocketReader to read from 31 | * the provided SSL/TLS connection object. 32 | */ 33 | SocketReader(SSL* ssl); 34 | 35 | int close() override; 36 | size_t read(std::vector& buf) override; 37 | bool eof() override; 38 | ~SocketReader() override; 39 | }; 40 | 41 | } // namespace fbpcf::io 42 | -------------------------------------------------------------------------------- /fbpcf/common/FunctionalUtil.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | namespace fbpcf::functional { 18 | template 19 | std::vector map( 20 | const std::vector& input, 21 | const std::function& f) { 22 | std::vector output; 23 | std::transform(input.begin(), input.end(), std::back_inserter(output), f); 24 | return output; 25 | } 26 | 27 | template 28 | T reduce( 29 | const std::vector& input, 30 | const std::function& f) { 31 | if (input.size() == 0) { 32 | throw std::invalid_argument("Can't reduce empty vector."); 33 | } 34 | 35 | return std::accumulate(++input.begin(), input.end(), input[0], f); 36 | } 37 | } // namespace fbpcf::functional 38 | -------------------------------------------------------------------------------- /fbpcf/engine/tuple_generator/oblivious_transfer/ferret/TenLocalLinearMatrixMultiplierFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include "fbpcf/engine/communication/IPartyCommunicationAgent.h" 13 | #include "fbpcf/engine/tuple_generator/oblivious_transfer/ferret/IMatrixMultiplierFactory.h" 14 | #include "fbpcf/engine/tuple_generator/oblivious_transfer/ferret/TenLocalLinearMatrixMultiplier.h" 15 | #include "fbpcf/engine/util/AesPrgFactory.h" 16 | 17 | namespace fbpcf::engine::tuple_generator::oblivious_transfer::ferret { 18 | 19 | class TenLocalLinearMatrixMultiplierFactory final 20 | : public IMatrixMultiplierFactory { 21 | public: 22 | std::unique_ptr create() override { 23 | return std::make_unique(); 24 | } 25 | }; 26 | 27 | } // namespace 28 | // fbpcf::engine::tuple_generator::oblivious_transfer::ferret 29 | -------------------------------------------------------------------------------- /fbpcf/io/api/FileWriter.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include "fbpcf/io/api/FileWriter.h" 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include "fbpcf/io/api/CloudFileWriter.h" 14 | #include "fbpcf/io/api/IOUtils.h" 15 | #include "fbpcf/io/api/LocalFileWriter.h" 16 | 17 | namespace fbpcf::io { 18 | FileWriter::FileWriter(std::string filePath) { 19 | if (IOUtils::isCloudFile(filePath)) { 20 | childWriter_ = std::make_unique(filePath); 21 | } else { 22 | childWriter_ = std::make_unique(filePath); 23 | } 24 | 25 | filepath_ = filePath; 26 | } 27 | 28 | FileWriter::~FileWriter() { 29 | close(); 30 | } 31 | 32 | size_t FileWriter::write(std::vector& buf) { 33 | return childWriter_->write(buf); 34 | } 35 | 36 | int FileWriter::close() { 37 | return childWriter_->close(); 38 | } 39 | } // namespace fbpcf::io 40 | -------------------------------------------------------------------------------- /fbpcf/mpc_std_lib/permuter/DummyPermuterFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include "fbpcf/mpc_std_lib/permuter/DummyPermuter.h" 11 | #include "fbpcf/mpc_std_lib/permuter/IPermuterFactory.h" 12 | 13 | namespace fbpcf::mpc_std_lib::permuter::insecure { 14 | 15 | template 16 | class DummyPermuterFactory final 17 | : public IPermuterFactory< 18 | typename util::SecBatchType::type> { 19 | public: 20 | DummyPermuterFactory(int myId, int partnerId) 21 | : myId_(myId), partnerId_(partnerId) {} 22 | 23 | std::unique_ptr::type>> 24 | create() override { 25 | return std::make_unique>(myId_, partnerId_); 26 | } 27 | 28 | private: 29 | int myId_; 30 | int partnerId_; 31 | }; 32 | 33 | } // namespace fbpcf::mpc_std_lib::permuter::insecure 34 | -------------------------------------------------------------------------------- /fbpcf/engine/tuple_generator/oblivious_transfer/ferret/DummyMatrixMultiplier.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include "fbpcf/engine/tuple_generator/oblivious_transfer/ferret/IMatrixMultiplier.h" 11 | 12 | namespace fbpcf::engine::tuple_generator::oblivious_transfer::ferret::insecure { 13 | 14 | /** 15 | * This is merely a dummy calculator - it won't actually generate any random 16 | * matrix for multiplication.Instead, it will only repeat the input to reach the 17 | * expected output length. 18 | */ 19 | class DummyMatrixMultiplier final : public IMatrixMultiplier { 20 | public: 21 | /** 22 | * @inherit doc 23 | */ 24 | std::vector<__m128i> multiplyWithRandomMatrix( 25 | __m128i seed, 26 | int64_t rstLength, 27 | const std::vector<__m128i>& src) const override; 28 | }; 29 | 30 | } // namespace 31 | // fbpcf::engine::tuple_generator::oblivious_transfer::ferret::insecure 32 | -------------------------------------------------------------------------------- /fbpcf/mpc/EmpGame.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | #include "IMpcGame.h" 16 | 17 | namespace fbpcf { 18 | enum class Party { Alice = emp::ALICE, Bob = emp::BOB }; 19 | enum class Visibility { 20 | Public = emp::PUBLIC, 21 | Alice = emp::ALICE, 22 | Bob = emp::BOB, 23 | Xor = emp::XOR, 24 | }; 25 | 26 | template 27 | class EmpGame : public IMpcGame { 28 | public: 29 | EmpGame(std::unique_ptr ioChannel, Party party) 30 | : party_{party}, ioChannel_{std::move(ioChannel)} { 31 | emp::setup_semi_honest(ioChannel_.get(), static_cast(party)); 32 | } 33 | 34 | protected: 35 | Party party_; 36 | 37 | private: 38 | std::unique_ptr ioChannel_; 39 | }; 40 | } // namespace fbpcf 41 | -------------------------------------------------------------------------------- /fbpcf/mpc_std_lib/permuter/AsWaksmanPermuterFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include "fbpcf/mpc_std_lib/permuter/AsWaksmanPermuter.h" 11 | #include "fbpcf/mpc_std_lib/permuter/IPermuterFactory.h" 12 | 13 | namespace fbpcf::mpc_std_lib::permuter { 14 | 15 | template 16 | class AsWaksmanPermuterFactory final 17 | : public IPermuterFactory< 18 | typename util::SecBatchType::type> { 19 | public: 20 | AsWaksmanPermuterFactory(int myId, int partnerId) 21 | : myId_(myId), partnerId_(partnerId) {} 22 | 23 | std::unique_ptr::type>> 24 | create() override { 25 | return std::make_unique>( 26 | myId_, partnerId_); 27 | } 28 | 29 | private: 30 | int myId_; 31 | int partnerId_; 32 | }; 33 | 34 | } // namespace fbpcf::mpc_std_lib::permuter 35 | -------------------------------------------------------------------------------- /example/millionaire/MillionaireGame.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include 9 | 10 | #include "fbpcf/mpc/EmpGame.h" 11 | #include "folly/logging/xlog.h" 12 | 13 | namespace fbpcf { 14 | // define the classic millionaire game 15 | template 16 | class MillionaireGame : public EmpGame { 17 | public: 18 | MillionaireGame(std::unique_ptr io, Party party) 19 | : EmpGame(std::move(io), party) {} 20 | 21 | bool play(const int& number) override { 22 | emp::Integer a{64, number, emp::ALICE}; 23 | emp::Integer b{64, number, emp::BOB}; 24 | 25 | XLOGF(INFO, "I have money: {}", number); 26 | auto result = (a > b).reveal(); 27 | if (result) { 28 | XLOG(INFO) << "Alice is richer!"; 29 | } else { 30 | XLOG(INFO) << "Bob is richer!"; 31 | } 32 | 33 | return result; 34 | } 35 | }; 36 | } // namespace fbpcf 37 | -------------------------------------------------------------------------------- /fbpcf/engine/tuple_generator/ITupleGeneratorFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | #include 10 | 11 | #include "fbpcf/engine/tuple_generator/ITupleGenerator.h" 12 | #include "fbpcf/util/MetricCollector.h" 13 | 14 | namespace fbpcf::engine::tuple_generator { 15 | 16 | /** 17 | * This is the API for a tuple generator that generates tuples. 18 | */ 19 | 20 | class ITupleGeneratorFactory { 21 | public: 22 | explicit ITupleGeneratorFactory( 23 | std::shared_ptr metricCollector) 24 | : metricCollector_(metricCollector) {} 25 | virtual ~ITupleGeneratorFactory() = default; 26 | 27 | /** 28 | * Create a tuple generator with all party. 29 | */ 30 | virtual std::unique_ptr create() = 0; 31 | 32 | protected: 33 | std::shared_ptr metricCollector_; 34 | }; 35 | 36 | } // namespace fbpcf::engine::tuple_generator 37 | -------------------------------------------------------------------------------- /fbpcf/engine/tuple_generator/NullArithmeticTupleGenerator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | #include "fbpcf/engine/tuple_generator/IArithmeticTupleGenerator.h" 10 | 11 | namespace fbpcf::engine::tuple_generator { 12 | 13 | /** 14 | A null integer tuple generator, throws exception when the secret share engine 15 | tries to generate integer tuples with this generator 16 | */ 17 | class NullArithmeticTupleGenerator final : public IArithmeticTupleGenerator { 18 | public: 19 | std::vector getIntegerTuple(uint32_t size) override { 20 | if (size == 0) { 21 | return std::vector(); 22 | } 23 | throw std::runtime_error( 24 | "The secret share engine is not configured with integer tuple generator."); 25 | } 26 | 27 | std::pair getTrafficStatistics() const override { 28 | return {0, 0}; 29 | } 30 | }; 31 | 32 | } // namespace fbpcf::engine::tuple_generator 33 | -------------------------------------------------------------------------------- /fbpcf/tests/github/cleanup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright (c) Meta Platforms, Inc. and affiliates. 3 | # 4 | # This source code is licensed under the MIT license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | # Usage:Remove ECS tasks and aggregation outputs in S3 bucket 8 | set -e 9 | 10 | E2E_CLUSTER_NAME="onedocker-cluster-fbpcf-e2e-workflow" 11 | LIFT_OUTPUT_PATH="s3://fbpcf-e2e-github-workflow/lift/outputs" 12 | ATTRIBUTION_OUTPUT_PATH="s3://fbpcf-e2e-github-workflow/attribution/outputs" 13 | 14 | # Remove ECS tasks 15 | RUNNING_TASKS=$(aws ecs list-tasks --cluster "$E2E_CLUSTER_NAME" --desired-status RUNNING --region us-west-2 | grep -E "task/" | sed -E "s/.*task\/(.*)\"/\1/" | sed -z 's/\n/ /g') 16 | IFS=', ' read -r -a array <<< "$RUNNING_TASKS" 17 | for task in "${array[@]}" 18 | do 19 | aws ecs stop-task --cluster "${E2E_CLUSTER_NAME}" --task "${task}" --region us-west-2 > /dev/null 20 | echo "Task:${task} is stopped" 21 | done 22 | 23 | # Remove all the outputs from previous run 24 | aws s3 rm --recursive "$LIFT_OUTPUT_PATH" 25 | aws s3 rm --recursive "$ATTRIBUTION_OUTPUT_PATH" 26 | -------------------------------------------------------------------------------- /fbpcf/mpc_std_lib/aes_circuit/AesCircuitCtr_impl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include "fbpcf/mpc_std_lib/aes_circuit/AesCircuitCtr.h" 12 | 13 | namespace fbpcf::mpc_std_lib::aes_circuit { 14 | 15 | template 16 | std::vector AesCircuitCtr::encrypt_impl( 17 | const std::vector& plaintext, 18 | const std::vector& expandedEncKey, 19 | const std::vector& mask) const { 20 | size_t blockNo = plaintext.size() / 128; 21 | std::vector encryptedMask = 22 | AesCircuit_->encrypt(mask, expandedEncKey); 23 | std::vector rst; 24 | rst.reserve(blockNo * 128); 25 | for (int i = 0; i < blockNo; ++i) { 26 | for (int j = 0; j < 128; ++j) { 27 | rst.push_back(plaintext[i * 128 + j] ^ encryptedMask[i * 128 + j]); 28 | } 29 | } 30 | return rst; 31 | } 32 | } // namespace fbpcf::mpc_std_lib::aes_circuit 33 | -------------------------------------------------------------------------------- /fbpcf/io/api/IReader.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | namespace fbpcf::io { 15 | 16 | /* 17 | * Defines a class that reads data from an 18 | * underlying medium. 19 | */ 20 | class IReader { 21 | public: 22 | /* 23 | * read() returns the number of bytes it was 24 | * able to read, or -1 if error. It fills 25 | * the provided buffer with the data that was 26 | * read 27 | */ 28 | virtual size_t read(std::vector& buf) = 0; 29 | /* 30 | * eof() returns whether there is any more 31 | * data left in the file 32 | */ 33 | virtual bool eof() = 0; 34 | 35 | /* 36 | * returns the path of the file being read 37 | */ 38 | std::string& getFilePath() { 39 | return filepath_; 40 | } 41 | 42 | virtual ~IReader() = default; 43 | 44 | protected: 45 | std::string filepath_; 46 | }; 47 | 48 | } // namespace fbpcf::io 49 | -------------------------------------------------------------------------------- /fbpcf/mpc_std_lib/aes_circuit/AesCircuitCtrFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include "fbpcf/mpc_std_lib/aes_circuit/AesCircuit.h" 11 | #include "fbpcf/mpc_std_lib/aes_circuit/AesCircuitCtr.h" 12 | #include "fbpcf/mpc_std_lib/aes_circuit/IAesCircuitCtrFactory.h" 13 | #include "fbpcf/mpc_std_lib/aes_circuit/IAesCircuitFactory.h" 14 | 15 | namespace fbpcf::mpc_std_lib::aes_circuit { 16 | 17 | template 18 | class AesCircuitCtrFactory : IAesCircuitCtrFactory { 19 | public: 20 | std::unique_ptr> create() override { 21 | return std::make_unique>( 22 | std::make_unique>()); 23 | } 24 | 25 | typename IAesCircuitFactory::CircuitType getCircuitType() 26 | const override { 27 | return IAesCircuitFactory::CircuitType::Secure; 28 | } 29 | }; 30 | 31 | } // namespace fbpcf::mpc_std_lib::aes_circuit 32 | -------------------------------------------------------------------------------- /fbpcf/primitive/mac/IMac.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include "fbpcf/engine/util/util.h" 15 | 16 | namespace fbpcf::primitive::mac { 17 | 18 | class IMac { 19 | public: 20 | virtual ~IMac() = default; 21 | 22 | /** 23 | * Generate 128-bit MAC for the input text 24 | * @param text the data on which the MAC is calculated. 25 | * @return a MAC with 128 bits as a __m128i 26 | */ 27 | virtual __m128i getMacM128i(const std::vector& text) const = 0; 28 | 29 | /** 30 | * Generate 128-bit MAC for the input text 31 | * @param text the data on which the MAC is calculated. 32 | * @return a MAC with 16 bytes as an unsigned char vector 33 | */ 34 | virtual std::vector getMac128( 35 | const std::vector& text) const = 0; 36 | }; 37 | 38 | } // namespace fbpcf::primitive::mac 39 | -------------------------------------------------------------------------------- /fbpcf/mpc/test/test_apps/millionaire/MillionaireGame.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include "fbpcf/mpc/EmpGame.h" 13 | #include "folly/logging/xlog.h" 14 | 15 | namespace fbpcf { 16 | // define the classic millionaire game 17 | template 18 | class MillionaireGame : public EmpGame { 19 | public: 20 | MillionaireGame(std::unique_ptr io, Party party) 21 | : EmpGame(std::move(io), party) {} 22 | 23 | bool play(const int& number) override { 24 | emp::Integer a{64, number, emp::ALICE}; 25 | emp::Integer b{64, number, emp::BOB}; 26 | 27 | XLOGF(INFO, "I have money: {}", number); 28 | auto result = (a > b).reveal(); 29 | if (result) { 30 | XLOG(INFO) << "Alice is richer!"; 31 | } else { 32 | XLOG(INFO) << "Bob is richer!"; 33 | } 34 | 35 | return result; 36 | } 37 | }; 38 | } // namespace fbpcf 39 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Meta Platforms, Inc. and affiliates. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /example/edit_distance/EditDistanceApp_impl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include "./EditDistanceApp.h" // @manual 12 | 13 | namespace fbpcf::edit_distance { 14 | 15 | template 16 | void EditDistanceApp::run() { 17 | auto scheduler = fbpcf::scheduler::getLazySchedulerFactoryWithRealEngine( 18 | myRole_, *communicationAgentFactory_) 19 | ->create(); 20 | 21 | XLOG(INFO, "Scheduler created successfully"); 22 | auto editDistanceGame = 23 | EditDistanceGame(myRole_, std::move(scheduler)); 24 | 25 | EditDistanceInputReader inputReader(dataFilePath_, paramsFilePath_); 26 | 27 | std::string output = editDistanceGame.play(std::move(inputReader)); 28 | 29 | XLOG(INFO) << "Writing results..."; 30 | fbpcf::io::FileIOWrappers::writeFile(outFilePath_, output); 31 | } 32 | } // namespace fbpcf::edit_distance 33 | -------------------------------------------------------------------------------- /fbpcf/io/api/FileReader.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include "fbpcf/io/api/FileReader.h" 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include "fbpcf/io/api/CloudFileReader.h" 14 | #include "fbpcf/io/api/LocalFileReader.h" 15 | 16 | #include "IOUtils.h" 17 | 18 | namespace fbpcf::io { 19 | FileReader::FileReader(std::string filePath) { 20 | if (IOUtils::isCloudFile(filePath)) { 21 | childReader_ = std::make_unique(filePath); 22 | } else { 23 | childReader_ = std::make_unique(filePath); 24 | } 25 | 26 | filepath_ = filePath; 27 | } 28 | 29 | FileReader::~FileReader() { 30 | close(); 31 | } 32 | 33 | size_t FileReader::read(std::vector& buf) { 34 | return childReader_->read(buf); 35 | } 36 | 37 | bool FileReader::eof() { 38 | return childReader_->eof(); 39 | } 40 | 41 | int FileReader::close() { 42 | return childReader_->close(); 43 | } 44 | } // namespace fbpcf::io 45 | -------------------------------------------------------------------------------- /example/edit_distance/Validator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | #include "./EditDistanceResults.h" // @manual 13 | 14 | namespace fbpcf::edit_distance { 15 | 16 | class Validator { 17 | public: 18 | enum { 19 | SUCCESS = 0, 20 | SIZE_MISMATCH = 1, 21 | RESULT_MISMATCH = 2, 22 | }; 23 | 24 | explicit Validator( 25 | std::vector& outputSharePaths, 26 | std::string expectedOutputPath) 27 | : outputPaths_(outputSharePaths), 28 | expectedOutputPath_(expectedOutputPath) {} 29 | 30 | int validate(); 31 | 32 | private: 33 | void appendOutputLine( 34 | const std::vector& header, 35 | const std::vector& parts); 36 | 37 | std::vector outputPaths_; 38 | std::string expectedOutputPath_; 39 | 40 | EditDistanceResults actualResults_; 41 | EditDistanceResults expectedResults_; 42 | }; 43 | 44 | } // namespace fbpcf::edit_distance 45 | -------------------------------------------------------------------------------- /fbpcf/engine/util/util.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include "fbpcf/engine/util/util.h" 9 | 10 | namespace fbpcf::engine::util { 11 | 12 | Expander::Expander(int64_t index) 13 | : cipher0_(_mm_set_epi64x(0, (uint64_t)index << 1)), 14 | cipher1_(_mm_set_epi64x(1 + ((uint64_t)index << 1), 0)) {} 15 | 16 | std::vector<__m128i> Expander::expand(std::vector<__m128i>&& src) const { 17 | // expand n __m128i variable to 2n __m128i variable with two ciphers 18 | assert(!std::empty(src)); 19 | std::vector<__m128i> tmp = src; 20 | cipher0_.encryptInPlace(tmp); 21 | std::vector<__m128i> rst(src.size() * 2); 22 | for (size_t i = 0; i < src.size(); i++) { 23 | rst[2 * i] = _mm_xor_si128(tmp.at(i), src.at(i)); 24 | rst[2 * i + 1] = src.at(i); 25 | } 26 | cipher1_.encryptInPlace(src); 27 | for (size_t i = 0; i < src.size(); i++) { 28 | rst[2 * i + 1] = _mm_xor_si128(src.at(i), rst.at(2 * i + 1)); 29 | } 30 | return rst; 31 | } 32 | 33 | } // namespace fbpcf::engine::util 34 | -------------------------------------------------------------------------------- /fbpcf/engine/tuple_generator/IProductShareGeneratorFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | #include 10 | 11 | #include "fbpcf/engine/communication/IPartyCommunicationAgent.h" 12 | #include "fbpcf/engine/tuple_generator/IProductShareGenerator.h" 13 | 14 | namespace fbpcf::engine::tuple_generator { 15 | 16 | /** 17 | * This is the API for an object that generates product shares. namely, a party 18 | * holds bits a1, b1 and the other party holds bits a2, b2. This object will 19 | * generate the shares of a1&b2 ^ a2&b1 for the two parties 20 | */ 21 | class IProductShareGeneratorFactory { 22 | public: 23 | virtual ~IProductShareGeneratorFactory() = default; 24 | 25 | /** 26 | * Create a product generator with a particular party. 27 | * Some implementation may need party id to decide parties' roles in the 28 | * underlying protocol. 29 | */ 30 | virtual std::unique_ptr create(int id) = 0; 31 | }; 32 | 33 | } // namespace fbpcf::engine::tuple_generator 34 | -------------------------------------------------------------------------------- /fbpcf/engine/util/Masker_impl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | #include 13 | #include "fbpcf/engine/util/util.h" 14 | 15 | namespace fbpcf::engine::util { 16 | 17 | template <> 18 | class Masker { 19 | public: 20 | static bool mask(bool src, __m128i key) { 21 | return src ^ getLsb(key); 22 | } 23 | static bool 24 | unmask(__m128i key, bool choice, bool correction0, bool correction1) { 25 | return getLsb(key) ^ (correction0 ^ choice * (correction0 ^ correction1)); 26 | } 27 | }; 28 | 29 | template <> 30 | class Masker { 31 | public: 32 | static uint64_t mask(uint64_t src, __m128i key) { 33 | return src - getLast64Bits(key); 34 | } 35 | static uint64_t 36 | unmask(__m128i key, bool choice, uint64_t correction0, uint64_t correction1) { 37 | return getLast64Bits(key) + 38 | (correction0 + choice * (correction1 - correction0)); 39 | } 40 | }; 41 | } // namespace fbpcf::engine::util 42 | -------------------------------------------------------------------------------- /fbpcf/engine/tuple_generator/oblivious_transfer/ferret/TenLocalLinearMatrixMultiplier.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include "fbpcf/engine/tuple_generator/oblivious_transfer/ferret/IMatrixMultiplier.h" 11 | #include "fbpcf/engine/util/IPrgFactory.h" 12 | 13 | namespace fbpcf::engine::tuple_generator::oblivious_transfer::ferret { 14 | 15 | /** 16 | * This lpn calculator uses a built-in 10 local linear code generator. 17 | * With a given seed, exactly 10 items from src (potentially with duplication) 18 | * are selected to compose 1 result item. 19 | */ 20 | class TenLocalLinearMatrixMultiplier final : public IMatrixMultiplier { 21 | public: 22 | TenLocalLinearMatrixMultiplier() {} 23 | 24 | /** 25 | * @inherit doc 26 | */ 27 | std::vector<__m128i> multiplyWithRandomMatrix( 28 | __m128i seed, 29 | int64_t rstLength, 30 | const std::vector<__m128i>& src) const override; 31 | }; 32 | 33 | } // namespace 34 | // fbpcf::engine::tuple_generator::oblivious_transfer::ferret 35 | -------------------------------------------------------------------------------- /fbpcf/scheduler/PlaintextSchedulerFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include "fbpcf/scheduler/IScheduler.h" 11 | #include "fbpcf/scheduler/ISchedulerFactory.h" 12 | #include "fbpcf/scheduler/PlaintextScheduler.h" 13 | #include "fbpcf/scheduler/WireKeeper.h" 14 | 15 | namespace fbpcf::scheduler { 16 | 17 | template 18 | class PlaintextSchedulerFactory final : public ISchedulerFactory { 19 | public: 20 | PlaintextSchedulerFactory() 21 | : ISchedulerFactory( 22 | std::make_shared( 23 | "plaintext_scheduler")) {} 24 | 25 | PlaintextSchedulerFactory( 26 | std::shared_ptr metricCollector) 27 | : ISchedulerFactory(metricCollector) {} 28 | std::unique_ptr create() override { 29 | return std::make_unique( 30 | WireKeeper::createWithVectorArena()); 31 | } 32 | }; 33 | 34 | } // namespace fbpcf::scheduler 35 | -------------------------------------------------------------------------------- /fbpcf/mpc_std_lib/oram/encoder/OramDecoder.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include "fbpcf/mpc_std_lib/oram/encoder/OramMappingConfig.h" 11 | #include "folly/String.h" 12 | 13 | namespace fbpcf::mpc_std_lib::oram { 14 | 15 | class OramDecoder { 16 | public: 17 | /* 18 | * Reconstructs an object that can perform the reverse mapping from ORAM 19 | * bucket indexes to the original values that were encoded. 20 | */ 21 | explicit OramDecoder(std::unique_ptr config); 22 | 23 | /* 24 | * Retrieves the original encoded values given the ORAM index and the 25 | * previously saved mapping config. An empty vector indicates that the index 26 | * corersponds to a filtered out value. 27 | */ 28 | std::vector> decodeORAMIndexes( 29 | const std::vector& oramIndexes); 30 | 31 | private: 32 | std::unordered_map> 33 | oramIndexToBreakdownMapping_{}; 34 | }; 35 | } // namespace fbpcf::mpc_std_lib::oram 36 | -------------------------------------------------------------------------------- /fbpcf/mpc_std_lib/util/secureRandomPermutation.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include "fbpcf/mpc_std_lib/util/secureRandomPermutation.h" 9 | 10 | namespace fbpcf::mpc_std_lib::util { 11 | std::vector secureRandomPermutation( 12 | uint32_t size, 13 | engine::util::IPrg& prg) { 14 | std::vector rst(size); 15 | for (size_t i = 0; i < size; i++) { 16 | rst[i] = i; 17 | } 18 | 19 | BN_CTX* ctx = BN_CTX_new(); 20 | if (ctx == nullptr) { 21 | throw std::runtime_error( 22 | "BN_CTX initialization failed: " + std::to_string(ERR_get_error())); 23 | } 24 | 25 | for (size_t i = size; i > 1; i--) { 26 | // Max permutation size + 128 bit security parameter 27 | auto randomBytes = prg.getRandomBytes( 28 | sizeof(uint32_t) + RANDOM_PERMUTATION_SECURITY_BITS / 8); 29 | auto position = engine::util::mod(randomBytes, i, ctx); 30 | std::swap(rst[position], rst[i - 1]); 31 | } 32 | BN_CTX_free(ctx); 33 | return rst; 34 | } 35 | } // namespace fbpcf::mpc_std_lib::util 36 | -------------------------------------------------------------------------------- /fbpcf/io/cloud_util/GCSFileUploader.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | 13 | #include // @manual 14 | #include "fbpcf/io/cloud_util/IFileUploader.h" 15 | 16 | namespace fbpcf::cloudio { 17 | class GCSFileUploader : public IFileUploader { 18 | public: 19 | explicit GCSFileUploader( 20 | std::shared_ptr gcsClient, 21 | const std::string& filePath) 22 | : gcsClient_{std::move(gcsClient)}, filePath_{filePath} { 23 | init(); 24 | } 25 | int upload(std::vector& buf) override; 26 | int complete() override; 27 | 28 | private: 29 | void init() override; 30 | google::cloud::Status abortUpload(std::string session_id); 31 | std::shared_ptr gcsClient_; 32 | const std::string filePath_; 33 | std::size_t partNumber_ = 1; 34 | std::string sessionId_; 35 | 36 | google::cloud::storage::ObjectWriteStream stream_; 37 | }; 38 | 39 | } // namespace fbpcf::cloudio 40 | -------------------------------------------------------------------------------- /fbpcf/io/cloud_util/S3FileUploader.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include // @manual 11 | #include // @manual 12 | #include 13 | #include "fbpcf/io/cloud_util/IFileUploader.h" 14 | 15 | namespace fbpcf::cloudio { 16 | 17 | class S3FileUploader : public IFileUploader { 18 | public: 19 | explicit S3FileUploader( 20 | std::shared_ptr s3Client, 21 | const std::string& filePath) 22 | : s3Client_{std::move(s3Client)}, filePath_{filePath} { 23 | init(); 24 | } 25 | int upload(std::vector& buf) override; 26 | int complete() override; 27 | 28 | private: 29 | void init() override; 30 | void abortUpload(); 31 | std::shared_ptr s3Client_; 32 | const std::string filePath_; 33 | std::string bucket_; 34 | std::string key_; 35 | std::string uploadId_; 36 | std::size_t partNumber_ = 1; 37 | Aws::Vector completedParts_; 38 | }; 39 | 40 | } // namespace fbpcf::cloudio 41 | -------------------------------------------------------------------------------- /example/millionaire/test/MillionaireAppTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include 9 | 10 | #include 11 | 12 | #include "folly/Random.h" 13 | 14 | #include "../MillionaireApp.h" // @manual 15 | 16 | namespace fbpcf { 17 | 18 | class MillionaireAppTest : public ::testing::Test { 19 | protected: 20 | void SetUp() override { 21 | port_ = 5000 + folly::Random::rand32() % 1000; 22 | } 23 | 24 | static void runGame(Party party, const std::string& serverIp, uint16_t port) { 25 | MillionaireApp(party, serverIp, port).run(); 26 | } 27 | 28 | protected: 29 | uint16_t port_; 30 | }; 31 | 32 | // The purpose of this test case is to ensure there is no exception to run 33 | // MillionaireApp. Correctness test is coverred in MillionaireGameTest. 34 | TEST_F(MillionaireAppTest, TestNoException) { 35 | auto futureAlice = std::async(runGame, Party::Alice, "", port_); 36 | auto futureBob = std::async(runGame, Party::Bob, "127.0.0.1", port_); 37 | 38 | futureAlice.wait(); 39 | futureBob.wait(); 40 | } 41 | } // namespace fbpcf 42 | -------------------------------------------------------------------------------- /fbpcf/mpc_std_lib/aes_circuit/AesCircuitCtr.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | #include "fbpcf/mpc_std_lib/aes_circuit/IAesCircuit.h" 13 | #include "fbpcf/mpc_std_lib/aes_circuit/IAesCircuitCtr.h" 14 | 15 | namespace fbpcf::mpc_std_lib::aes_circuit { 16 | 17 | /* 18 | * This is the implementation of AES circuit in Counter mode 19 | */ 20 | template 21 | class AesCircuitCtr final : public IAesCircuitCtr { 22 | public: 23 | explicit AesCircuitCtr(std::unique_ptr> AesCircuit) 24 | : AesCircuit_{std::move(AesCircuit)} {} 25 | 26 | private: 27 | virtual std::vector encrypt_impl( 28 | const std::vector& plaintext, 29 | const std::vector& expandedEncKey, 30 | const std::vector& mask) const override; 31 | 32 | std::unique_ptr> AesCircuit_; 33 | }; 34 | 35 | } // namespace fbpcf::mpc_std_lib::aes_circuit 36 | 37 | #include "fbpcf/mpc_std_lib/aes_circuit/AesCircuitCtr_impl.h" 38 | -------------------------------------------------------------------------------- /fbpcf/engine/communication/AgentMapHelper.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | 13 | #include "fbpcf/engine/communication/IPartyCommunicationAgent.h" 14 | #include "fbpcf/engine/communication/IPartyCommunicationAgentFactory.h" 15 | 16 | namespace fbpcf::engine::communication { 17 | 18 | /** 19 | * Create an agent map for party with 'myId' with entries for all the other 20 | * parties. 21 | */ 22 | inline std::map> getAgentMap( 23 | int numberOfParties, 24 | int myId, 25 | IPartyCommunicationAgentFactory& agentFactory) { 26 | std::map> 27 | agentMap; 28 | for (int i = 0; i < numberOfParties; i++) { 29 | if (i != myId) { 30 | agentMap.emplace( 31 | i, 32 | agentFactory.create( 33 | i, "secret_share_engine_traffic_to_party " + std::to_string(i))); 34 | } 35 | } 36 | return agentMap; 37 | } 38 | 39 | } // namespace fbpcf::engine::communication 40 | -------------------------------------------------------------------------------- /fbpcf/mpc_std_lib/oram/ObliviousDeltaCalculatorFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include "fbpcf/engine/communication/IPartyCommunicationAgentFactory.h" 12 | #include "fbpcf/mpc_std_lib/oram/IObliviousDeltaCalculatorFactory.h" 13 | #include "fbpcf/mpc_std_lib/oram/ObliviousDeltaCalculator.h" 14 | 15 | namespace fbpcf::mpc_std_lib::oram { 16 | 17 | template 18 | class ObliviousDeltaCalculatorFactory final 19 | : public IObliviousDeltaCalculatorFactory { 20 | public: 21 | ObliviousDeltaCalculatorFactory( 22 | bool amIParty0, 23 | int32_t party0Id, 24 | int32_t party1Id) 25 | : amIParty0_(amIParty0), party0Id_(party0Id), party1Id_(party1Id) {} 26 | 27 | std::unique_ptr create() override { 28 | return std::make_unique>( 29 | amIParty0_, party0Id_, party1Id_); 30 | } 31 | 32 | private: 33 | bool amIParty0_; 34 | int32_t party0Id_; 35 | int32_t party1Id_; 36 | }; 37 | 38 | } // namespace fbpcf::mpc_std_lib::oram 39 | -------------------------------------------------------------------------------- /fbpcf/io/api/CloudFileWriter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | #include 10 | #include 11 | #include 12 | 13 | #include "fbpcf/io/api/IWriterCloser.h" 14 | #include "fbpcf/io/cloud_util/CloudFileUtil.h" 15 | #include "fbpcf/io/cloud_util/IFileUploader.h" 16 | 17 | namespace fbpcf::io { 18 | 19 | /* 20 | This class is the API for writing a file to cloud 21 | storage. It can be in any supported cloud provider, but 22 | cannot be a local file. 23 | */ 24 | class CloudFileWriter : public IWriterCloser { 25 | public: 26 | explicit CloudFileWriter(const std::string& filePath) : filePath_{filePath} { 27 | cloudFileUploader_ = fbpcf::cloudio::getCloudFileUploader(filePath_); 28 | isClosed_ = false; 29 | filepath_ = filePath; 30 | } 31 | 32 | int close() override; 33 | size_t write(std::vector& buf) override; 34 | ~CloudFileWriter() override; 35 | 36 | private: 37 | const std::string filePath_; 38 | std::unique_ptr cloudFileUploader_; 39 | bool isClosed_; 40 | }; 41 | 42 | } // namespace fbpcf::io 43 | -------------------------------------------------------------------------------- /fbpcf/engine/util/test/aesTestHelper.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include "fbpcf/engine/util/test/aesTestHelper.h" 9 | #include 10 | 11 | namespace fbpcf::engine::util { 12 | 13 | void AesTestHelper::switchToDecrypt() { 14 | // convert the encryption key to the decryption key 15 | roundKey_ = Aes::expandDecryptionKey(key_); 16 | } 17 | 18 | void AesTestHelper::decryptInPlace(std::vector<__m128i>& ciphertext) const { 19 | // Using naked pointer for best performance. This is very hot code. 20 | uint32_t size = ciphertext.size(); 21 | auto dataPointer = ciphertext.data(); 22 | for (unsigned int i = 0; i < size; ++i) { 23 | dataPointer[i] = _mm_xor_si128(dataPointer[i], roundKey_.at(0)); 24 | } 25 | for (unsigned int j = 1; j < kRound; ++j) { 26 | for (unsigned int i = 0; i < size; ++i) { 27 | dataPointer[i] = _mm_aesdec_si128(dataPointer[i], roundKey_.at(j)); 28 | } 29 | } 30 | for (unsigned int i = 0; i < size; ++i) 31 | dataPointer[i] = _mm_aesdeclast_si128(dataPointer[i], roundKey_.at(kRound)); 32 | } 33 | 34 | } // namespace fbpcf::engine::util 35 | -------------------------------------------------------------------------------- /fbpcf/mpc_std_lib/shuffler/IShuffler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include "fbpcf/mpc_std_lib/util/util.h" 11 | 12 | namespace fbpcf::mpc_std_lib::shuffler { 13 | 14 | /* 15 | * A shuffler will shuffle a number of values, and output them in 16 | * a shuffled order. 17 | * Our shuffler is decoupled from the concrete types. As long as a type can 18 | * perform certain operations/has certain helper functions that depends on 19 | * concrete implementation (the user may need to implement this method), it 20 | * should be supported by our shuffler. 21 | */ 22 | /** 23 | * This type T corresponds to a set of values, e.g. std::vector 24 | */ 25 | template 26 | class IShuffler { 27 | public: 28 | virtual ~IShuffler() = default; 29 | 30 | /** 31 | * shuffle a batch of secret values. 32 | * @param src the batch of values to shuffle 33 | * @param size the size of the batch 34 | * @return the shuffled values in batch 35 | */ 36 | virtual T shuffle(const T& src, uint32_t size) const = 0; 37 | }; 38 | 39 | } // namespace fbpcf::mpc_std_lib::shuffler 40 | -------------------------------------------------------------------------------- /fbpcf/mpc_std_lib/unified_data_process/data_processor/test/UdpEncryptionMock.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | #include "fbpcf/mpc_std_lib/unified_data_process/data_processor/IUdpEncryption.h" 13 | 14 | namespace fbpcf::mpc_std_lib::unified_data_process::data_processor { 15 | 16 | using namespace ::testing; 17 | 18 | class UdpEncryptionMock final : public IUdpEncryption { 19 | public: 20 | MOCK_METHOD(void, prepareToProcessMyData, (size_t)); 21 | 22 | MOCK_METHOD( 23 | void, 24 | processMyData, 25 | (const std::vector>&, 26 | const std::vector& indexes)); 27 | 28 | MOCK_METHOD(std::vector<__m128i>, getExpandedKey, ()); 29 | 30 | MOCK_METHOD( 31 | void, 32 | prepareToProcessPeerData, 33 | (size_t, const std::vector&)); 34 | 35 | MOCK_METHOD(void, processPeerData, (size_t)); 36 | 37 | MOCK_METHOD(EncryptionResults, getProcessedData, ()); 38 | }; 39 | 40 | } // namespace fbpcf::mpc_std_lib::unified_data_process::data_processor 41 | -------------------------------------------------------------------------------- /fbpcf/engine/tuple_generator/oblivious_transfer/DummyBaseObliviousTransfer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include "fbpcf/engine/tuple_generator/oblivious_transfer/DummyBaseObliviousTransfer.h" 9 | 10 | namespace fbpcf::engine::tuple_generator::oblivious_transfer::insecure { 11 | 12 | std::pair, std::vector<__m128i>> 13 | DummyBaseObliviousTransfer::send( 14 | size_t size) { // this is a dummy implementation 15 | std::vector<__m128i> m0(size); 16 | std::vector<__m128i> m1(size); 17 | for (size_t i = 0; i < size; i++) { 18 | m0[i] = _mm_set_epi64x(i, 0); 19 | m1[i] = _mm_set_epi64x(i, 1); 20 | } 21 | return {std::move(m0), std::move(m1)}; 22 | } 23 | 24 | std::vector<__m128i> DummyBaseObliviousTransfer::receive( 25 | const std::vector& choice) { 26 | // this is a dummy implementation 27 | std::vector<__m128i> m(choice.size()); 28 | for (size_t i = 0; i < choice.size(); i++) { 29 | m[i] = _mm_set_epi64x(i, choice.at(i)); 30 | } 31 | return m; 32 | } 33 | 34 | } // namespace 35 | // fbpcf::engine::tuple_generator::oblivious_transfer::insecure 36 | -------------------------------------------------------------------------------- /fbpcf/engine/tuple_generator/oblivious_transfer/NpBaseObliviousTransferFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | #include "fbpcf/engine/communication/IPartyCommunicationAgent.h" 10 | #include "fbpcf/engine/tuple_generator/oblivious_transfer/IBaseObliviousTransferFactory.h" 11 | #include "fbpcf/engine/tuple_generator/oblivious_transfer/NpBaseObliviousTransfer.h" 12 | 13 | namespace fbpcf::engine::tuple_generator::oblivious_transfer { 14 | 15 | /** 16 | * Create a base oblivious transfer with a particular party. 17 | * Some implementation may need party id to decide parties' roles in the 18 | * underlying protocol. 19 | */ 20 | class NpBaseObliviousTransferFactory final 21 | : public IBaseObliviousTransferFactory { 22 | public: 23 | explicit NpBaseObliviousTransferFactory() {} 24 | 25 | std::unique_ptr create( 26 | std::unique_ptr agent) override { 27 | return std::make_unique(std::move(agent)); 28 | } 29 | }; 30 | 31 | } // namespace fbpcf::engine::tuple_generator::oblivious_transfer 32 | -------------------------------------------------------------------------------- /fbpcf/common/VectorUtil.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | namespace fbpcf::vector { 18 | template 19 | std::vector apply( 20 | const std::vector& a, 21 | const std::vector& b, 22 | std::function f) { 23 | if (a.size() != b.size()) { 24 | throw std::invalid_argument("Size doesn't match."); 25 | } 26 | 27 | std::vector res; 28 | res.reserve(a.size()); 29 | 30 | for (int64_t i = 0; i < a.size(); i++) { 31 | res.push_back(f(a[i], b[i])); 32 | } 33 | 34 | return res; 35 | } 36 | 37 | template 38 | std::vector Add(const std::vector& a, const std::vector& b) { 39 | return apply(a, b, [](const T& x, const T& y) { return x + y; }); 40 | } 41 | 42 | template 43 | std::vector Xor(const std::vector& a, const std::vector& b) { 44 | return apply(a, b, [](const T& x, const T& y) { return x ^ y; }); 45 | } 46 | } // namespace fbpcf::vector 47 | -------------------------------------------------------------------------------- /fbpcf/common/test/FunctionalUtilTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include "fbpcf/common/FunctionalUtil.h" 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | namespace fbpcf::functional { 17 | TEST(FunctionalUtilTest, TestMap) { 18 | std::vector input{1, 2, 3}; 19 | std::vector expectedOutput{"1", "2", "3"}; 20 | 21 | auto output = map( 22 | input, [](const auto& x) { return std::to_string(x); }); 23 | EXPECT_EQ(expectedOutput, output); 24 | } 25 | 26 | TEST(FunctionalUtilTest, TestReduce) { 27 | std::vector input{1, 2, 3}; 28 | int expectedOutput = 6; 29 | 30 | auto output = 31 | reduce(input, [](const auto& x, const auto& y) { return x + y; }); 32 | EXPECT_EQ(expectedOutput, output); 33 | } 34 | 35 | TEST(FunctionalUtilTest, TestReduceWithException) { 36 | std::vector input; 37 | 38 | EXPECT_THROW( 39 | reduce(input, [](const auto& x, const auto& y) { return x + y; }), 40 | std::invalid_argument); 41 | } 42 | } // namespace fbpcf::functional 43 | -------------------------------------------------------------------------------- /fbpcf/engine/tuple_generator/DummyTupleGeneratorFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | #include 10 | 11 | #include "fbpcf/engine/tuple_generator/DummyTupleGenerator.h" 12 | #include "fbpcf/engine/tuple_generator/ITupleGeneratorFactory.h" 13 | #include "fbpcf/engine/util/IPrgFactory.h" 14 | 15 | namespace fbpcf::engine::tuple_generator::insecure { 16 | 17 | /** 18 | * This factory creates dummy tuple generators 19 | */ 20 | 21 | class DummyTupleGeneratorFactory final : public ITupleGeneratorFactory { 22 | public: 23 | explicit DummyTupleGeneratorFactory( 24 | std::shared_ptr metricCollector) 25 | : ITupleGeneratorFactory(metricCollector) {} 26 | /** 27 | * Create a dummy tuple generator; 28 | */ 29 | std::unique_ptr create() override { 30 | auto recorder = std::make_shared(); 31 | metricCollector_->addNewRecorder("tuple_generator", recorder); 32 | return std::make_unique(recorder); 33 | } 34 | }; 35 | 36 | } // namespace fbpcf::engine::tuple_generator::insecure 37 | -------------------------------------------------------------------------------- /fbpcf/engine/util/test/aesTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include "fbpcf/engine/util/test/aesTestHelper.h" 13 | 14 | namespace fbpcf::engine::util { 15 | 16 | TEST(aesTest, testEncryptionAndDecryption) { 17 | std::random_device rd; 18 | std::mt19937_64 e(rd()); 19 | std::uniform_int_distribution dist(0, 0xFFFFFFFF); 20 | 21 | __m128i key = _mm_set_epi32(dist(e), dist(e), dist(e), dist(e)); 22 | AesTestHelper cipher(key); 23 | 24 | std::vector<__m128i> plaintext(16); 25 | for (int i = 0; i < 16; i++) { 26 | plaintext[i] = _mm_set_epi32(dist(e), dist(e), dist(e), dist(e)); 27 | } 28 | auto duplicate = plaintext; 29 | 30 | cipher.encryptInPlace(duplicate); 31 | cipher.switchToDecrypt(); 32 | cipher.decryptInPlace(duplicate); 33 | 34 | for (int i = 0; i < 16; i++) { 35 | EXPECT_TRUE(_mm_testz_si128( 36 | _mm_xor_si128(duplicate[i], plaintext[i]), 37 | _mm_xor_si128(duplicate[i], plaintext[i]))); 38 | } 39 | } 40 | 41 | } // namespace fbpcf::engine::util 42 | -------------------------------------------------------------------------------- /fbpcf/mpc_std_lib/util/secureSamplePublicSeed.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | 13 | #include "fbpcf/engine/communication/IPartyCommunicationAgent.h" 14 | #include "fbpcf/engine/util/util.h" 15 | 16 | namespace fbpcf::mpc_std_lib::util { 17 | 18 | /** 19 | * This method generates a public random seed for two parties. The detailed 20 | protocol is noted below: 21 | * 1. party 1 and party 2 sample a random string s1 and s2 respectively. 22 | * 2. party 1 computes hash(s1||r) and share the hash with party 2. r is a random 23 | * string as well. 24 | * 3. party 2 shares s2 with party 1. 25 | * 4. party 1 shares s1 and r with party 2. 26 | * 5. party 2 verifies s1 and r against the hash received before. 27 | * 6. the two parties outputs (s1 xor s2). 28 | * As long as s1 is truly random or s2 is truly random, s1 xor s2 will be true 29 | random string as well 30 | */ 31 | 32 | __m128i secureSamplePublicSeed( 33 | bool amISendingFirst, 34 | engine::communication::IPartyCommunicationAgent& agent); 35 | 36 | } // namespace fbpcf::mpc_std_lib::util 37 | -------------------------------------------------------------------------------- /fbpcf/engine/tuple_generator/oblivious_transfer/IRandomCorrelatedObliviousTransferFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include "fbpcf/engine/communication/IPartyCommunicationAgent.h" 14 | #include "fbpcf/engine/tuple_generator/oblivious_transfer/IRandomCorrelatedObliviousTransfer.h" 15 | 16 | namespace fbpcf::engine::tuple_generator::oblivious_transfer { 17 | 18 | class IRandomCorrelatedObliviousTransferFactory { 19 | public: 20 | virtual ~IRandomCorrelatedObliviousTransferFactory() = default; 21 | 22 | /** 23 | * Construct sender 24 | */ 25 | virtual std::unique_ptr create( 26 | __m128i delta, 27 | std::unique_ptr agent) = 0; 28 | 29 | /** 30 | * Construct receiver 31 | */ 32 | virtual std::unique_ptr create( 33 | std::unique_ptr agent) = 0; 34 | }; 35 | 36 | } // namespace fbpcf::engine::tuple_generator::oblivious_transfer 37 | -------------------------------------------------------------------------------- /fbpcf/mpc_std_lib/oram/DummyObliviousDeltaCalculatorFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include "fbpcf/engine/communication/IPartyCommunicationAgentFactory.h" 12 | #include "fbpcf/mpc_std_lib/oram/DummyObliviousDeltaCalculator.h" 13 | #include "fbpcf/mpc_std_lib/oram/IObliviousDeltaCalculatorFactory.h" 14 | 15 | namespace fbpcf::mpc_std_lib::oram::insecure { 16 | 17 | class DummyObliviousDeltaCalculatorFactory final 18 | : public IObliviousDeltaCalculatorFactory { 19 | public: 20 | DummyObliviousDeltaCalculatorFactory( 21 | int32_t peerId, 22 | engine::communication::IPartyCommunicationAgentFactory& factory) 23 | : peerId_(peerId), factory_(factory) {} 24 | 25 | std::unique_ptr create() override { 26 | return std::make_unique( 27 | factory_.create(peerId_, "dummy_oblivious_delta_calculator_traffic")); 28 | } 29 | 30 | private: 31 | int32_t peerId_; 32 | engine::communication::IPartyCommunicationAgentFactory& factory_; 33 | }; 34 | 35 | } // namespace fbpcf::mpc_std_lib::oram::insecure 36 | -------------------------------------------------------------------------------- /fbpcf/mpc_std_lib/oram/DifferenceCalculatorFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include "fbpcf/engine/communication/IPartyCommunicationAgentFactory.h" 12 | #include "fbpcf/mpc_std_lib/oram/DifferenceCalculator.h" 13 | #include "fbpcf/mpc_std_lib/oram/IDifferenceCalculatorFactory.h" 14 | 15 | namespace fbpcf::mpc_std_lib::oram { 16 | 17 | template 18 | class DifferenceCalculatorFactory final 19 | : public IDifferenceCalculatorFactory { 20 | public: 21 | DifferenceCalculatorFactory( 22 | bool amIParty0, 23 | int32_t party0Id, 24 | int32_t party1Id) 25 | : amIParty0_(amIParty0), party0Id_(party0Id), party1Id_(party1Id) {} 26 | 27 | std::unique_ptr> create() override { 28 | return std::make_unique< 29 | DifferenceCalculator>( 30 | amIParty0_, party0Id_, party1Id_); 31 | } 32 | 33 | private: 34 | bool amIParty0_; 35 | int32_t party0Id_; 36 | int32_t party1Id_; 37 | }; 38 | 39 | } // namespace fbpcf::mpc_std_lib::oram 40 | -------------------------------------------------------------------------------- /fbpcf/engine/tuple_generator/DummyProductShareGeneratorFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | #include 10 | 11 | #include "fbpcf/engine/communication/IPartyCommunicationAgentFactory.h" 12 | #include "fbpcf/engine/tuple_generator/DummyProductShareGenerator.h" 13 | #include "fbpcf/engine/tuple_generator/IProductShareGeneratorFactory.h" 14 | 15 | namespace fbpcf::engine::tuple_generator::insecure { 16 | 17 | /** 18 | * This object always generates Dummy product share generators 19 | */ 20 | class DummyProductShareGeneratorFactory final 21 | : public IProductShareGeneratorFactory { 22 | public: 23 | explicit DummyProductShareGeneratorFactory( 24 | communication::IPartyCommunicationAgentFactory& factory) 25 | : factory_(factory) {} 26 | 27 | std::unique_ptr create(int id) override { 28 | return std::make_unique( 29 | factory_.create(id, "dummy_product_generator_traffic")); 30 | } 31 | 32 | private: 33 | communication::IPartyCommunicationAgentFactory& factory_; 34 | }; 35 | 36 | } // namespace fbpcf::engine::tuple_generator::insecure 37 | -------------------------------------------------------------------------------- /fbpcf/mpc/QueueIO.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | #include "folly/Synchronized.h" 16 | 17 | namespace fbpcf { 18 | class QueueIO : public emp::IOChannel { 19 | public: 20 | QueueIO( 21 | const std::shared_ptr>> inQueue, 22 | const std::shared_ptr>> outQueue) 23 | : inQueue_{inQueue}, outQueue_{outQueue} {} 24 | 25 | void send_data_internal(const void* data, int64_t len); 26 | void recv_data_internal(void* data, int64_t len); 27 | 28 | /* This is a design issue in EMP. flush() is not part of IOChannel interface, 29 | * but it's coupled in implementation. EMP should either defines it in 30 | * IOChannel, or the implementation shouldn't assume flush() is in the 31 | * implementation. */ 32 | void flush() {} 33 | 34 | private: 35 | const std::shared_ptr>> inQueue_; 36 | const std::shared_ptr>> outQueue_; 37 | }; 38 | } // namespace fbpcf 39 | -------------------------------------------------------------------------------- /fbpcf/engine/tuple_generator/oblivious_transfer/IRandomCorrelatedObliviousTransfer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | #include 10 | #include 11 | #include 12 | #include "fbpcf/engine/util/util.h" 13 | 14 | namespace fbpcf::engine::tuple_generator::oblivious_transfer { 15 | 16 | /** 17 | * The Random Correlated Oblivious Transfer API. 18 | * This object works as a wrap to hide all the details about the underlying RCOT 19 | * extender. 20 | */ 21 | 22 | class IRandomCorrelatedObliviousTransfer { 23 | public: 24 | virtual ~IRandomCorrelatedObliviousTransfer() = default; 25 | 26 | /** 27 | * Run a number of random correlated OT. 28 | * @param size: number of RCOT results to generate 29 | * @return : the output from RCOT. 30 | */ 31 | virtual std::vector<__m128i> rcot(int64_t size) = 0; 32 | 33 | /** 34 | * Get the total amount of traffic transmitted. 35 | * @return a pair of (sent, received) data in bytes. 36 | */ 37 | virtual std::pair getTrafficStatistics() const = 0; 38 | }; 39 | 40 | } // namespace fbpcf::engine::tuple_generator::oblivious_transfer 41 | -------------------------------------------------------------------------------- /fbpcf/engine/tuple_generator/oblivious_transfer/DummyBaseObliviousTransferFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | #include "fbpcf/engine/communication/IPartyCommunicationAgent.h" 10 | #include "fbpcf/engine/tuple_generator/oblivious_transfer/DummyBaseObliviousTransfer.h" 11 | #include "fbpcf/engine/tuple_generator/oblivious_transfer/IBaseObliviousTransferFactory.h" 12 | 13 | namespace fbpcf::engine::tuple_generator::oblivious_transfer::insecure { 14 | 15 | /** 16 | * Create a base oblivious transfer with a particular party. 17 | * Some implementation may need party id to decide parties' roles in the 18 | * underlying protocol. 19 | */ 20 | class DummyBaseObliviousTransferFactory final 21 | : public IBaseObliviousTransferFactory { 22 | public: 23 | explicit DummyBaseObliviousTransferFactory() {} 24 | 25 | std::unique_ptr create( 26 | std::unique_ptr agent) override { 27 | return std::make_unique(std::move(agent)); 28 | } 29 | }; 30 | 31 | } // namespace 32 | // fbpcf::engine::tuple_generator::oblivious_transfer::insecure 33 | -------------------------------------------------------------------------------- /fbpcf/mpc_std_lib/aes_circuit/DummyAesCircuit.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include "fbpcf/mpc_std_lib/aes_circuit/IAesCircuit.h" 11 | 12 | namespace fbpcf::mpc_std_lib::aes_circuit::insecure { 13 | 14 | /* 15 | * This is merely a placeholder that basically does nothing other than input 16 | * validation. This object is only meant to be used for test purpose. When 17 | * testing, the corresponding encryption/decryption process should also do 18 | * nothing to make the final result correct. 19 | */ 20 | template 21 | class DummyAesCircuit final : public IAesCircuit { 22 | private: 23 | std::vector encrypt_impl( 24 | const std::vector& plaintext, 25 | const std::vector& /* expandedEncKey */) const override { 26 | return plaintext; 27 | } 28 | 29 | /** 30 | * @inherit doc 31 | */ 32 | std::vector decrypt_impl( 33 | const std::vector& ciphertext, 34 | const std::vector& /* expandedDecKey */) const override { 35 | return ciphertext; 36 | } 37 | }; 38 | 39 | } // namespace fbpcf::mpc_std_lib::aes_circuit::insecure 40 | -------------------------------------------------------------------------------- /docker/utils/get_make_options.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright (c) Meta Platforms, Inc. and affiliates. 3 | # 4 | # This source code is licensed under the MIT license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | BYTES_PER_MEGABYTE=1000000 8 | 9 | # We need up to 2000 MB (less than 2GB) per thread. 10 | MAX_THREAD_MEMORY_IN_BYTES=$((2000 * BYTES_PER_MEGABYTE)) 11 | 12 | # The functionality below calculates the number of bytes of memory available by getting the number 13 | # Of physical pages available, multiplying it by the page size (in bytes) and dividing that by the 14 | # number of bytes per thread that we want available to give us the maximum number of threads 15 | MAX_THREADS=$(($(getconf _PHYS_PAGES) * $(getconf PAGE_SIZE) / MAX_THREAD_MEMORY_IN_BYTES)) 16 | 17 | # Get the number of possible threads by pulling the online processors 18 | EFFECTIVE_THREADS=$(getconf _NPROCESSORS_ONLN) 19 | 20 | # Use the lesser of the maximum allowed threads by memory or available processors 21 | export MAKE_JOBS=$((MAX_THREADS < EFFECTIVE_THREADS ? MAX_THREADS : EFFECTIVE_THREADS)) 22 | 23 | # Set the maximum load average on the CPU as 9/10ths of the available cores 24 | # This ensures that we don't saturate the CPU with processes that are greater 25 | # than the cores available 26 | export MAKE_MAX_LOAD=$((EFFECTIVE_THREADS * 9 / 10)) 27 | -------------------------------------------------------------------------------- /fbpcf/io/api/FileIOWrappers.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | namespace fbpcf::io { 15 | 16 | // This class provides wrappers to the raw APIs to 17 | // do common operations like upload an entire file or 18 | // retrieve an entire file. 19 | class FileIOWrappers { 20 | public: 21 | static std::string readFile(const std::string& srcPath); 22 | static void writeFile( 23 | const std::string& destPath, 24 | const std::string& content); 25 | static void transferFileInParts( 26 | const std::string& srcPath, 27 | const std::string& destPath); 28 | 29 | // Reads a csv from the given file, calling the given function for each line 30 | // Returns true on success, false on failure 31 | static bool readCsv( 32 | const std::string& srcPath, 33 | std::function& header, 35 | const std::vector& parts)> readLine, 36 | std::function&)> processHeader = 37 | [](auto) {}); 38 | }; 39 | 40 | } // namespace fbpcf::io 41 | -------------------------------------------------------------------------------- /fbpcf/primitive/mac/AesCmac.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include "fbpcf/engine/util/aes.h" 17 | #include "fbpcf/primitive/mac/IMac.h" 18 | 19 | namespace fbpcf::primitive::mac { 20 | 21 | class AesCmac final : public IMac { 22 | public: 23 | /** 24 | * Create a AesCmac that has an initial key and can generate 128-bit Mac for 25 | * arbitrary inputs. 26 | */ 27 | explicit AesCmac(const std::vector& macKey) : macKey_(macKey) { 28 | ctx_ = CMAC_CTX_new(); 29 | } 30 | 31 | ~AesCmac() { 32 | CMAC_CTX_free(ctx_); 33 | } 34 | 35 | /** 36 | * @inherit doc 37 | */ 38 | std::vector getMac128( 39 | const std::vector& text) const override; 40 | 41 | /** 42 | * @inherit doc 43 | */ 44 | __m128i getMacM128i(const std::vector& text) const override; 45 | 46 | private: 47 | std::vector macKey_; 48 | CMAC_CTX* ctx_; 49 | }; 50 | 51 | } // namespace fbpcf::primitive::mac 52 | -------------------------------------------------------------------------------- /fbpcf/aws/S3Util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #include // @manual 15 | 16 | namespace fbpcf::aws { 17 | // referencee of environment variables: 18 | // https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-envvars.html 19 | struct S3ClientOption { 20 | // AWS_DEFAULT_REGION 21 | std::optional region; 22 | // AWS_ACCESS_KEY_ID 23 | std::optional accessKeyId; 24 | // AWS_SECRET_ACCESS_KEY 25 | std::optional secretKey; 26 | // AWS_PROXY_HOST 27 | std::optional proxyHost; 28 | // AWS_PROXY_PORT 29 | std::optional proxyPort; 30 | // AWS_PROXY_SCHEME 31 | std::optional proxyScheme; 32 | // AWS_PROXY_CERT_PATH 33 | std::optional proxySSLCertPath; 34 | }; 35 | 36 | struct S3ObjectReference { 37 | std::string region; 38 | std::string bucket; 39 | std::string key; 40 | }; 41 | 42 | S3ObjectReference uriToObjectReference(std::string url); 43 | std::unique_ptr createS3Client(const S3ClientOption& option); 44 | } // namespace fbpcf::aws 45 | -------------------------------------------------------------------------------- /fbpcf/engine/tuple_generator/oblivious_transfer/ferret/IMatrixMultiplier.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | #include 10 | #include 11 | 12 | namespace fbpcf::engine::tuple_generator::oblivious_transfer::ferret { 13 | 14 | /** 15 | * This object is to hide the complicated matrix multiplication, which is 16 | * necessary to meet the requirements of LPN assumption, from the caller. The 17 | * matrix is generated via a code generator. See details at 18 | * https://eprint.iacr.org/2020/924.pdf 19 | */ 20 | class IMatrixMultiplier { 21 | public: 22 | virtual ~IMatrixMultiplier() = default; 23 | 24 | /** 25 | * multiply the src with a randomly generated matrix with seed 26 | * @param seed the seed to generate the matrix 27 | * @param rstLength the length of the result vector 28 | * @param src the vector for matrix multiplication 29 | * @return the product 30 | */ 31 | virtual std::vector<__m128i> multiplyWithRandomMatrix( 32 | __m128i seed, 33 | int64_t dstLength, 34 | const std::vector<__m128i>& src) const = 0; 35 | }; 36 | 37 | } // namespace 38 | // fbpcf::engine::tuple_generator::oblivious_transfer::ferret 39 | -------------------------------------------------------------------------------- /fbpcf/io/S3FileManager.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include // @manual 13 | #include 14 | 15 | #include "IFileManager.h" 16 | #include "IInputStream.h" 17 | 18 | namespace fbpcf { 19 | class S3FileManager : public IFileManager { 20 | public: 21 | explicit S3FileManager(std::unique_ptr client) 22 | : s3Client_{std::move(client)} {} 23 | 24 | std::unique_ptr getInputStream( 25 | const std::string& fileName) override; 26 | 27 | std::string 28 | readBytes(const std::string& fileName, std::size_t start, std::size_t end); 29 | std::string read(const std::string& fileName) override; 30 | 31 | void write(const std::string& fileName, const std::string& data) override; 32 | 33 | void copy(const std::string& sourceFile, const std::string& destination) 34 | override; 35 | 36 | void writeDataStream( 37 | const std::string& fileName, 38 | std::shared_ptr>> 39 | dataStream); 40 | 41 | private: 42 | std::unique_ptr s3Client_; 43 | }; 44 | } // namespace fbpcf 45 | -------------------------------------------------------------------------------- /example/edit_distance/Util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include "fbpcf/frontend/mpcGame.h" 12 | 13 | namespace fbpcf::edit_distance { 14 | /** 15 | * Share integer, with width number of bits, from sender to receiver. The 16 | * integer is revealed in plaintext to the receiver. 17 | */ 18 | template 19 | uint64_t shareIntFrom(const int myRole, uint64_t input) { 20 | // Sender shares input 21 | typename fbpcf::frontend::MpcGame< 22 | schedulerId>::template SecUnsignedInt 23 | secInput{input, sender}; 24 | // Reveal to receiver 25 | uint64_t output = secInput.openToParty(receiver).getValue(); 26 | return (myRole == sender) ? input : output; 27 | } 28 | 29 | template 30 | T createPublicBatchConstant(O ele, size_t size) { 31 | std::vector copies(size, ele); 32 | return T(copies); 33 | } 34 | 35 | template 36 | T createSecretBatchConstant(O ele, size_t size, int partyId) { 37 | std::vector copies(size, ele); 38 | return T(copies, partyId); 39 | } 40 | 41 | } // namespace fbpcf::edit_distance 42 | -------------------------------------------------------------------------------- /fbpcf/engine/DummySecretShareEngineFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | #include "fbpcf/engine/DummySecretShareEngine.h" 10 | #include "fbpcf/engine/ISecretShareEngineFactory.h" 11 | #include "fbpcf/engine/communication/IPartyCommunicationAgentFactory.h" 12 | 13 | namespace fbpcf::engine { 14 | 15 | class DummySecretShareEngineFactory final : public ISecretShareEngineFactory { 16 | public: 17 | explicit DummySecretShareEngineFactory(int myId) : myId_(myId) {} 18 | 19 | std::unique_ptr create() override { 20 | return std::make_unique(myId_); 21 | } 22 | 23 | private: 24 | int myId_; 25 | }; 26 | 27 | /** 28 | * This API is used in test only. 29 | */ 30 | inline std::unique_ptr getDummyEngineFactory( 31 | int myId, 32 | [[maybe_unused]] int numberOfParty, 33 | [[maybe_unused]] communication::IPartyCommunicationAgentFactory& 34 | communicationAgentFactory, 35 | [[maybe_unused]] std::shared_ptr 36 | metricCollector) { 37 | return std::make_unique(myId); 38 | } 39 | 40 | } // namespace fbpcf::engine 41 | -------------------------------------------------------------------------------- /fbpcf/engine/util/IPrg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | #include 13 | #include "fbpcf/engine/util/util.h" 14 | 15 | namespace fbpcf::engine::util { 16 | 17 | class IPrg { 18 | public: 19 | virtual ~IPrg() = default; 20 | 21 | __m128i getRandomM128i() { 22 | auto randomBytes = getRandomBytes(16); 23 | assert(randomBytes.size() == 16); 24 | return buildM128i(randomBytes); 25 | } 26 | 27 | virtual std::vector getRandomBits(uint32_t size) = 0; 28 | 29 | /** 30 | * Generate random bytes from async buffer 31 | * @param size the number of random bytes being generated 32 | * @return each element in the vector is a random byte 33 | */ 34 | virtual std::vector getRandomBytes(uint32_t size) = 0; 35 | 36 | /** 37 | * Generate random unsigned 64 bit integers from random bytes 38 | * @param size the number of random unsigned 64 bit integers being generated 39 | * @return each element in the vector is a random unsigned 64 bit integer 40 | */ 41 | virtual std::vector getRandomUInt64(uint32_t size) = 0; 42 | }; 43 | 44 | } // namespace fbpcf::engine::util 45 | -------------------------------------------------------------------------------- /fbpcf/mpc_std_lib/util/test/secureRandomPermutationTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include "fbpcf/mpc_std_lib/util/secureRandomPermutation.h" 9 | 10 | #include 11 | #include 12 | #include "fbpcf/engine/util/AesPrgFactory.h" 13 | #include "fbpcf/engine/util/util.h" 14 | #include "fbpcf/test/TestHelper.h" 15 | 16 | namespace fbpcf::mpc_std_lib::util { 17 | void permutationTest(engine::util::IPrg& prg) { 18 | std::random_device rd; 19 | std::mt19937_64 e(rd()); 20 | std::uniform_int_distribution dist(1, 0xFFF); 21 | uint32_t size = dist(e); 22 | const std::vector& permutation = secureRandomPermutation(size, prg); 23 | EXPECT_EQ(size, permutation.size()); 24 | for (uint32_t i = 0; i < size; i++) { 25 | EXPECT_TRUE( 26 | std::find(permutation.begin(), permutation.end(), i) != 27 | permutation.end()); 28 | } 29 | } 30 | 31 | TEST(permutationTest, testPermutationWithAesPrg) { 32 | auto prgFactory = std::make_unique(); 33 | auto prg = prgFactory->create(engine::util::getRandomM128iFromSystemNoise()); 34 | permutationTest(*prg); 35 | } 36 | 37 | } // namespace fbpcf::mpc_std_lib::util 38 | -------------------------------------------------------------------------------- /fbpcf/mpc_std_lib/compactor/DummyCompactorFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include "fbpcf/mpc_std_lib/compactor/DummyCompactor.h" 11 | #include "fbpcf/mpc_std_lib/compactor/ICompactorFactory.h" 12 | 13 | namespace fbpcf::mpc_std_lib::compactor::insecure { 14 | 15 | template 16 | class DummyCompactorFactory final 17 | : public ICompactorFactory< 18 | typename util::SecBatchType::type, 19 | typename util::SecBatchType::type> { 20 | public: 21 | using SecBatchType = typename util::SecBatchType::type; 22 | using SecBatchLabelType = 23 | typename util::SecBatchType::type; 24 | explicit DummyCompactorFactory(int myId, int partnerId) 25 | : myId_(myId), partnerId_(partnerId) {} 26 | 27 | std::unique_ptr> create() 28 | override { 29 | return std::make_unique>( 30 | myId_, partnerId_); 31 | } 32 | 33 | private: 34 | int myId_; 35 | int partnerId_; 36 | }; 37 | 38 | } // namespace fbpcf::mpc_std_lib::compactor::insecure 39 | -------------------------------------------------------------------------------- /fbpcf/engine/tuple_generator/oblivious_transfer/DummyBidirectionObliviousTransferFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | #include 10 | 11 | #include "fbpcf/engine/communication/IPartyCommunicationAgentFactory.h" 12 | #include "fbpcf/engine/tuple_generator/oblivious_transfer/DummyBidirectionObliviousTransfer.h" 13 | #include "fbpcf/engine/tuple_generator/oblivious_transfer/IBidirectionObliviousTransferFactory.h" 14 | 15 | namespace fbpcf::engine::tuple_generator::oblivious_transfer::insecure { 16 | 17 | class DummyBidirectionObliviousTransferFactory final 18 | : public IBidirectionObliviousTransferFactory { 19 | public: 20 | explicit DummyBidirectionObliviousTransferFactory( 21 | communication::IPartyCommunicationAgentFactory& factory) 22 | : factory_(factory) {} 23 | 24 | std::unique_ptr create(int id) override { 25 | return std::make_unique( 26 | factory_.create(id, "dummy_bidirection_ot_traffic")); 27 | } 28 | 29 | private: 30 | communication::IPartyCommunicationAgentFactory& factory_; 31 | }; 32 | 33 | } // namespace 34 | // fbpcf::engine::tuple_generator::oblivious_transfer::insecure 35 | -------------------------------------------------------------------------------- /fbpcf/engine/tuple_generator/oblivious_transfer/ferret/test/benchmarks/MatrixMultiplierBenchmark.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include 9 | #include 10 | 11 | #include "fbpcf/engine/tuple_generator/oblivious_transfer/ferret/test/benchmarks/MatrixMultiplierBenchmark.h" 12 | 13 | namespace fbpcf::engine::tuple_generator::oblivious_transfer::ferret { 14 | 15 | void MatrixMultiplierBenchmark::setup( 16 | std::unique_ptr factory, 17 | int64_t rstLength, 18 | int64_t srcLength) { 19 | std::random_device rd; 20 | std::mt19937_64 e(rd()); 21 | std::uniform_int_distribution dist(0, 0xFFFFFFFF); 22 | 23 | multiplier_ = factory->create(); 24 | rstLength_ = rstLength; 25 | // for benchmark, the concrete value doesn't matter; 26 | seed_ = _mm_set_epi64x(dist(e), dist(e)); 27 | src_ = std::vector<__m128i>(srcLength); 28 | for (auto& item : src_) { 29 | item = _mm_set_epi64x(dist(e), dist(e)); 30 | } 31 | } 32 | 33 | std::vector<__m128i> MatrixMultiplierBenchmark::benchmark() const { 34 | return multiplier_->multiplyWithRandomMatrix(seed_, rstLength_, src_); 35 | } 36 | 37 | } // namespace 38 | // fbpcf::engine::tuple_generator::oblivious_transfer::ferret 39 | -------------------------------------------------------------------------------- /fbpcf/engine/tuple_generator/oblivious_transfer/ferret/DummySinglePointCotFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include "fbpcf/engine/tuple_generator/oblivious_transfer/ferret/DummySinglePointCot.h" 13 | #include "fbpcf/engine/tuple_generator/oblivious_transfer/ferret/ISinglePointCotFactory.h" 14 | #include "fbpcf/engine/util/IPrgFactory.h" 15 | #include "fbpcf/engine/util/util.h" 16 | 17 | namespace fbpcf::engine::tuple_generator::oblivious_transfer::ferret::insecure { 18 | 19 | class DummySinglePointCotFactory final : public ISinglePointCotFactory { 20 | public: 21 | explicit DummySinglePointCotFactory( 22 | std::unique_ptr prgFactory) 23 | : prgFactory_(std::move(prgFactory)) {} 24 | 25 | std::unique_ptr create( 26 | std::unique_ptr& agent) 27 | override { 28 | return std::make_unique( 29 | agent, prgFactory_->create(util::getRandomM128iFromSystemNoise())); 30 | } 31 | 32 | private: 33 | std::unique_ptr prgFactory_; 34 | }; 35 | 36 | } // namespace 37 | // fbpcf::engine::tuple_generator::oblivious_transfer::ferret::insecure 38 | -------------------------------------------------------------------------------- /fbpcf/scheduler/test/benchmarks/AllocatorBenchmark.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include "fbpcf/scheduler/UnorderedMapAllocator.h" 13 | #include "fbpcf/scheduler/VectorArenaAllocator.h" 14 | 15 | namespace fbpcf::scheduler { 16 | 17 | const bool unsafe = true; 18 | 19 | template 20 | inline void benchmarkAllocate(std::unique_ptr> allocator, int n) { 21 | while (n--) { 22 | allocator->allocate(n); 23 | } 24 | } 25 | 26 | template 27 | inline void benchmarkFree(std::unique_ptr> allocator, int n) { 28 | uint64_t ref; 29 | BENCHMARK_SUSPEND { 30 | auto count = n; 31 | while (count--) { 32 | ref = allocator->allocate(count); 33 | } 34 | } 35 | 36 | while (n--) { 37 | allocator->free(ref--); 38 | } 39 | } 40 | 41 | template 42 | inline void benchmarkGet(std::unique_ptr> allocator, int n) { 43 | uint64_t ref; 44 | BENCHMARK_SUSPEND { 45 | auto count = n; 46 | while (count--) { 47 | ref = allocator->allocate(count); 48 | } 49 | } 50 | 51 | while (n--) { 52 | allocator->get(ref--); 53 | } 54 | } 55 | 56 | } // namespace fbpcf::scheduler 57 | -------------------------------------------------------------------------------- /fbpcf/engine/tuple_generator/oblivious_transfer/ferret/DummyMultiPointCotFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | 13 | #include "fbpcf/engine/tuple_generator/oblivious_transfer/ferret/DummyMultiPointCot.h" 14 | #include "fbpcf/engine/tuple_generator/oblivious_transfer/ferret/IMultiPointCotFactory.h" 15 | #include "fbpcf/engine/util/IPrgFactory.h" 16 | #include "fbpcf/engine/util/util.h" 17 | 18 | namespace fbpcf::engine::tuple_generator::oblivious_transfer::ferret::insecure { 19 | 20 | class DummyMultiPointCotFactory final : public IMultiPointCotFactory { 21 | public: 22 | explicit DummyMultiPointCotFactory( 23 | std::unique_ptr prgFactory) 24 | : prgFactory_(std::move(prgFactory)) {} 25 | 26 | std::unique_ptr create( 27 | std::unique_ptr& agent) 28 | override { 29 | return std::make_unique( 30 | agent, prgFactory_->create(util::getRandomM128iFromSystemNoise())); 31 | } 32 | 33 | private: 34 | std::unique_ptr prgFactory_; 35 | }; 36 | 37 | } // namespace 38 | // fbpcf::engine::tuple_generator::oblivious_transfer::ferret::insecure 39 | -------------------------------------------------------------------------------- /fbpcf/mpc_std_lib/oram/SinglePointArrayGeneratorFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include "fbpcf/engine/communication/IPartyCommunicationAgentFactory.h" 12 | #include "fbpcf/mpc_std_lib/oram/IObliviousDeltaCalculatorFactory.h" 13 | #include "fbpcf/mpc_std_lib/oram/ISinglePointArrayGeneratorFactory.h" 14 | #include "fbpcf/mpc_std_lib/oram/SinglePointArrayGenerator.h" 15 | 16 | namespace fbpcf::mpc_std_lib::oram { 17 | 18 | class SinglePointArrayGeneratorFactory final 19 | : public ISinglePointArrayGeneratorFactory { 20 | public: 21 | SinglePointArrayGeneratorFactory( 22 | bool firstShare, 23 | std::unique_ptr 24 | obliviousCalculatrFactory) 25 | : firstShare_(firstShare), 26 | obliviousCalculatrFactory_(std::move(obliviousCalculatrFactory)) {} 27 | 28 | std::unique_ptr create() override { 29 | return std::make_unique( 30 | firstShare_, obliviousCalculatrFactory_->create()); 31 | } 32 | 33 | private: 34 | bool firstShare_; 35 | std::unique_ptr obliviousCalculatrFactory_; 36 | }; 37 | 38 | } // namespace fbpcf::mpc_std_lib::oram 39 | -------------------------------------------------------------------------------- /example/millionaire/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include 9 | 10 | #include 11 | 12 | #include "folly/init/Init.h" 13 | #include "folly/logging/xlog.h" 14 | 15 | #include "./MillionaireApp.h" // @manual 16 | #include "fbpcf/exception/ExceptionBase.h" 17 | 18 | DEFINE_int32(role, 1, "1 = Alice, 2 = Bob"); 19 | DEFINE_string(server_ip, "", "Server's IP address"); 20 | DEFINE_int32(port, 5000, "Server's port"); 21 | 22 | int main(int argc, char* argv[]) { 23 | folly::init(&argc, &argv); 24 | gflags::ParseCommandLineFlags(&argc, &argv, true); 25 | 26 | XLOGF(INFO, "Role: {}", FLAGS_role); 27 | XLOGF(INFO, "Server IP: {}", FLAGS_server_ip); 28 | XLOGF(INFO, "Port: {}", FLAGS_port); 29 | 30 | XLOG(INFO) << "Start Millionaire Game..."; 31 | 32 | auto role = static_cast(FLAGS_role); 33 | 34 | try { 35 | fbpcf::MillionaireApp(role, FLAGS_server_ip, FLAGS_port).run(); 36 | } catch (const fbpcf::ExceptionBase& e) { 37 | XLOGF(ERR, "Some error occured: {}", e.what()); 38 | return 1; 39 | } catch (const std::exception& e) { 40 | XLOGF(ERR, "Some unknown error occured: {}", e.what()); 41 | return -1; 42 | } 43 | 44 | XLOG(INFO) << "Millionaire Game is completed."; 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /fbpcf/aws/MockS3Client.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include // @manual 11 | #include // @manual 12 | #include // @manual 13 | #include 14 | 15 | namespace fbpcf { 16 | class MockS3Client : public Aws::S3::S3Client { 17 | public: 18 | MOCK_CONST_METHOD1( 19 | GetObject, 20 | Aws::S3::Model::GetObjectOutcome( 21 | const Aws::S3::Model::GetObjectRequest& request)); 22 | 23 | MOCK_CONST_METHOD1( 24 | PutObject, 25 | Aws::S3::Model::PutObjectOutcome( 26 | const Aws::S3::Model::PutObjectRequest& request)); 27 | 28 | MOCK_METHOD( 29 | Aws::S3::Model::CreateMultipartUploadOutcome, 30 | CreateMultipartUpload, 31 | (const Aws::S3::Model::CreateMultipartUploadRequest&), 32 | (const)); 33 | 34 | MOCK_METHOD( 35 | Aws::S3::Model::UploadPartOutcome, 36 | UploadPart, 37 | (const Aws::S3::Model::UploadPartRequest&), 38 | (const)); 39 | 40 | MOCK_METHOD( 41 | Aws::S3::Model::CompleteMultipartUploadOutcome, 42 | CompleteMultipartUpload, 43 | (const Aws::S3::Model::CompleteMultipartUploadRequest&), 44 | (const)); 45 | }; 46 | } // namespace fbpcf 47 | -------------------------------------------------------------------------------- /fbpcf/mpc_std_lib/oram/DummyObliviousDeltaCalculator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include "fbpcf/engine/communication/IPartyCommunicationAgent.h" 12 | #include "fbpcf/mpc_std_lib/oram/IObliviousDeltaCalculator.h" 13 | 14 | namespace fbpcf::mpc_std_lib::oram::insecure { 15 | 16 | /** 17 | * A dummy implementation of oblivious delta calculator 18 | */ 19 | class DummyObliviousDeltaCalculator final : public IObliviousDeltaCalculator { 20 | public: 21 | explicit DummyObliviousDeltaCalculator( 22 | std::unique_ptr agent) 23 | : agent_(std::move(agent)) {} 24 | 25 | /** 26 | * @inherit doc 27 | */ 28 | std::tuple, std::vector, std::vector> 29 | calculateDelta( 30 | const std::vector<__m128i>& delta0Shares, 31 | const std::vector<__m128i>& delta1Shares, 32 | const std::vector& alphaShares) const override; 33 | 34 | std::pair getTrafficStatistics() const override { 35 | return agent_->getTrafficStatistics(); 36 | } 37 | 38 | private: 39 | std::unique_ptr agent_; 40 | }; 41 | 42 | } // namespace fbpcf::mpc_std_lib::oram::insecure 43 | -------------------------------------------------------------------------------- /fbpcf/system/CpuUtil.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include "CpuUtil.h" 9 | 10 | #include 11 | 12 | namespace fbpcf::system { 13 | // reference: https://bduvenhage.me/rng/2019/04/06/the-intel-drng.html 14 | CpuId getCpuId(const uint64_t& eax) { 15 | CpuId info; 16 | #ifdef __aarch64__ 17 | std::memset(&info, 0, sizeof(info)); 18 | #else 19 | asm volatile("cpuid" 20 | : "=a"(info.eax), "=b"(info.ebx), "=c"(info.ecx), "=d"(info.edx) 21 | : "a"(eax), "c"(0)); 22 | #endif 23 | 24 | return info; 25 | } 26 | 27 | bool isIntelCpu() { 28 | auto info = getCpuId(0); 29 | return !( 30 | std::memcmp((char*)&info.ebx, "Genu", 4) || 31 | std::memcmp((char*)&info.ecx, "ntel", 4) || 32 | std::memcmp((char*)&info.edx, "ineI", 4)); 33 | } 34 | 35 | bool isDrngSupported() { 36 | bool rdrandSupported = false; 37 | bool rdseedSupported = false; 38 | 39 | if (isIntelCpu()) { 40 | auto info = getCpuId(1); 41 | if ((info.ecx & 0x40000000) == 0x40000000) { 42 | rdrandSupported = true; 43 | } 44 | 45 | info = getCpuId(7); 46 | if ((info.ebx & 0x40000) == 0x40000) { 47 | rdseedSupported = true; 48 | } 49 | } 50 | 51 | return rdrandSupported && rdseedSupported; 52 | } 53 | } // namespace fbpcf::system 54 | -------------------------------------------------------------------------------- /fbpcf/io/cloud_util/GCSFileReader.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include "fbpcf/io/cloud_util/GCSFileReader.h" 9 | #include 10 | #include // @manual 11 | #include "fbpcf/exception/GcpException.h" 12 | 13 | namespace fbpcf::cloudio { 14 | 15 | std::string GCSFileReader::readBytes( 16 | const std::string& filePath, 17 | std::size_t start, 18 | std::size_t end) { 19 | const auto& ref = fbpcf::gcp::uriToObjectReference(filePath); 20 | 21 | auto outcome = GCSClient_->ReadObject( 22 | ref.bucket, ref.key, google::cloud::storage::ReadRange(start, end)); 23 | if (!outcome.status().ok()) { 24 | throw GcpException{outcome.status().message()}; 25 | } 26 | std::stringstream ss; 27 | ss << outcome.rdbuf(); 28 | return ss.str(); 29 | } 30 | 31 | size_t GCSFileReader::getFileContentLength(const std::string& filePath) { 32 | const auto& ref = fbpcf::gcp::uriToObjectReference(filePath); 33 | auto outcome = GCSClient_->GetObjectMetadata(ref.bucket, ref.key); 34 | if (!outcome) { 35 | throw GcpException{ 36 | "Error getting object metadata for object " + ref.key + 37 | " Reason: " + outcome.status().message()}; 38 | } 39 | return outcome->size(); 40 | } 41 | 42 | } // namespace fbpcf::cloudio 43 | -------------------------------------------------------------------------------- /fbpcf/mpc_std_lib/oram/IObliviousDeltaCalculator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | 13 | namespace fbpcf::mpc_std_lib::oram { 14 | 15 | /** 16 | * an oblivious delta calculator obliviously choose between two secret-shared 17 | * secrets and compute the lsbs of the shared secrets. 18 | */ 19 | class IObliviousDeltaCalculator { 20 | public: 21 | virtual ~IObliviousDeltaCalculator() = default; 22 | 23 | /** 24 | * This object operates in batches. 25 | * Compute mux(alpha, delta1, delta0) and lsb(delta0) xor alpha xor 1 and 26 | * lsb(delta1) xor alpha. 27 | * @param delta0Shares this party’s shares of delta0 28 | * @param delta1Shares this party’s shares of delta1 29 | * @param alphaShares this party’s shares of alpha 30 | * @return a batch of delta, a batch of delta_t0 and a batch of delta_t1 31 | */ 32 | virtual std::tuple, std::vector, std::vector> 33 | calculateDelta( 34 | const std::vector<__m128i>& delta0Shares, 35 | const std::vector<__m128i>& delta1Shares, 36 | const std::vector& alphaShares) const = 0; 37 | 38 | virtual std::pair getTrafficStatistics() const = 0; 39 | }; 40 | 41 | } // namespace fbpcf::mpc_std_lib::oram 42 | -------------------------------------------------------------------------------- /fbpcf/scheduler/IAllocator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | 13 | /** 14 | * An instance of this class provides operations for allocating and freeing 15 | * memory. 16 | */ 17 | namespace fbpcf::scheduler { 18 | 19 | template 20 | class IAllocator { 21 | public: 22 | virtual ~IAllocator() = default; 23 | 24 | /* Allocate a value of type T and return an ID reference to it. 25 | * This method invalidates any references returned by get or 26 | * getWritableReference 27 | */ 28 | virtual uint64_t allocate(T&& value) = 0; 29 | 30 | // Free the object with the given ID reference. 31 | virtual void free(uint64_t id) = 0; 32 | 33 | // Get the value with given ID reference. 34 | virtual const T& get(uint64_t id) const = 0; 35 | 36 | // Same as above, but returns a non-const T. 37 | virtual T& getWritableReference(uint64_t id) = 0; 38 | 39 | // Does this allocator throw errors when accessing unallocated/freed memory 40 | // locations? 41 | virtual bool isSafe() const = 0; 42 | 43 | protected: 44 | std::string errorMessageCannotFindItem(uint64_t id) const { 45 | return std::string("Can't find item with ID " + std::to_string(id) + "!"); 46 | } 47 | }; 48 | 49 | } // namespace fbpcf::scheduler 50 | -------------------------------------------------------------------------------- /fbpcf/engine/communication/IPartyCommunicationAgentFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | #include 10 | 11 | #include 12 | #include "fbpcf/engine/communication/IPartyCommunicationAgent.h" 13 | #include "fbpcf/util/MetricCollector.h" 14 | 15 | namespace fbpcf::engine::communication { 16 | 17 | /** 18 | * An communication factory API 19 | */ 20 | class IPartyCommunicationAgentFactory { 21 | public: 22 | explicit IPartyCommunicationAgentFactory(std::string name) 23 | : metricCollector_(std::make_shared(name)) { 24 | } 25 | 26 | explicit IPartyCommunicationAgentFactory( 27 | std::shared_ptr metricCollector) 28 | : metricCollector_(metricCollector) {} 29 | 30 | virtual ~IPartyCommunicationAgentFactory() = default; 31 | 32 | /** 33 | * create an agent that talks to a certain party. 34 | */ 35 | virtual std::unique_ptr create( 36 | int id, 37 | std::string name) = 0; 38 | 39 | std::shared_ptr getMetricsCollector() const { 40 | return metricCollector_; 41 | } 42 | 43 | protected: 44 | std::shared_ptr metricCollector_; 45 | }; 46 | 47 | } // namespace fbpcf::engine::communication 48 | -------------------------------------------------------------------------------- /fbpcf/gcp/MockGCSClient.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include // @manual=fbsource//third-party/google-cloud-cpp/google/cloud/storage:google_cloud_cpp_storage 12 | #include // @manual=fbsource//third-party/google-cloud-cpp/google/cloud/storage:google_cloud_cpp_storage 13 | #include // @manual=fbsource//third-party/google-cloud-cpp/google/cloud/storage:google_cloud_cpp_storage 14 | #include // @manual=fbsource//third-party/google-cloud-cpp/google/cloud/storage:google_cloud_cpp_storage 15 | 16 | namespace gcs = ::google::cloud::storage; 17 | 18 | namespace fbpcf { 19 | class MockGCSClient : public gcs::Client { 20 | public: 21 | MOCK_METHOD( 22 | gcs::ObjectReadStream, 23 | ReadObject, 24 | (const std::string, const std::string, const gcs::ReadRange)); 25 | 26 | MOCK_METHOD( 27 | gcs::ObjectWriteStream, 28 | WriteObject, 29 | (const std::string, const std::string)); 30 | 31 | MOCK_METHOD( 32 | google::cloud::StatusOr, 33 | UploadFile, 34 | (const std::string, const std::string, const std::string)); 35 | }; 36 | } // namespace fbpcf 37 | -------------------------------------------------------------------------------- /fbpcf/mpc_std_lib/oram/DummySinglePointArrayGeneratorFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include "fbpcf/engine/communication/IPartyCommunicationAgentFactory.h" 12 | #include "fbpcf/mpc_std_lib/oram/DummySinglePointArrayGenerator.h" 13 | #include "fbpcf/mpc_std_lib/oram/ISinglePointArrayGeneratorFactory.h" 14 | 15 | namespace fbpcf::mpc_std_lib::oram::insecure { 16 | 17 | class DummySinglePointArrayGeneratorFactory final 18 | : public ISinglePointArrayGeneratorFactory { 19 | public: 20 | DummySinglePointArrayGeneratorFactory( 21 | bool thisPartyToSetIndicator, 22 | int32_t peerId, 23 | engine::communication::IPartyCommunicationAgentFactory& factory) 24 | : thisPartyToSetIndicator_(thisPartyToSetIndicator), 25 | peerId_(peerId), 26 | factory_(factory) {} 27 | 28 | std::unique_ptr create() override { 29 | return std::make_unique( 30 | thisPartyToSetIndicator_, 31 | factory_.create(peerId_, "dummy_single_point_array_generator_traffic")); 32 | } 33 | 34 | private: 35 | bool thisPartyToSetIndicator_; 36 | int32_t peerId_; 37 | engine::communication::IPartyCommunicationAgentFactory& factory_; 38 | }; 39 | 40 | } // namespace fbpcf::mpc_std_lib::oram::insecure 41 | -------------------------------------------------------------------------------- /fbpcf/io/cloud_util/S3Client.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include // @manual 13 | #include // @manual 14 | #include "fbpcf/aws/S3Util.h" 15 | 16 | namespace fbpcf::cloudio { 17 | 18 | class S3ClientFactory { 19 | public: 20 | S3ClientFactory() {} 21 | virtual ~S3ClientFactory() {} 22 | virtual std::shared_ptr createS3Client( 23 | const fbpcf::aws::S3ClientOption& option) { 24 | return fbpcf::aws::createS3Client(option); 25 | } 26 | }; 27 | 28 | class S3Client { 29 | private: 30 | explicit S3Client(const fbpcf::aws::S3ClientOption& option) { 31 | awsS3Client_ = s3ClientFactory_->createS3Client(option); 32 | } 33 | 34 | public: 35 | static std::shared_ptr getInstance( 36 | const fbpcf::aws::S3ClientOption& option); 37 | 38 | std::shared_ptr getS3Client() { 39 | return awsS3Client_; 40 | } 41 | 42 | static void setS3ClientFactory(std::shared_ptr factory) { 43 | s3ClientFactory_ = factory; 44 | } 45 | 46 | private: 47 | std::shared_ptr awsS3Client_; 48 | static inline std::shared_ptr s3ClientFactory_ = 49 | std::make_shared(); 50 | }; 51 | 52 | } // namespace fbpcf::cloudio 53 | -------------------------------------------------------------------------------- /fbpcf/io/api/test/IOUtilsTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include "fbpcf/io/api/IOUtils.h" 9 | #include 10 | #include 11 | 12 | namespace fbpcf::io { 13 | 14 | TEST(IOUtilsTest, testIsCloudFile) { 15 | bool ans = 16 | IOUtils::isCloudFile("https://random_bucket.us-west-2.amazonaws.com"); 17 | EXPECT_EQ(ans, true); 18 | 19 | ans = IOUtils::isCloudFile("/random/local/file"); 20 | EXPECT_EQ(ans, false); 21 | } 22 | 23 | TEST(IOUtilsTest, testGetDefaultWriterChunkSizeForFile) { 24 | auto cloudResult = IOUtils::getDefaultWriterChunkSizeForFile( 25 | "https://random_bucket.us-west-2.amazonaws.com"); 26 | EXPECT_EQ(cloudResult, kCloudBufferedWriterChunkSize); 27 | 28 | auto localResult = 29 | IOUtils::getDefaultWriterChunkSizeForFile("/random/local/file"); 30 | EXPECT_EQ(localResult, kLocalBufferedWriterChunkSize); 31 | } 32 | 33 | TEST(IOUtilsTest, testGetDefaultReaderChunkSizeForFile) { 34 | auto cloudResult = IOUtils::getDefaultReaderChunkSizeForFile( 35 | "https://random_bucket.us-west-2.amazonaws.com"); 36 | EXPECT_EQ(cloudResult, kCloudBufferedReaderChunkSize); 37 | 38 | auto localResult = 39 | IOUtils::getDefaultReaderChunkSizeForFile("/random/local/file"); 40 | EXPECT_EQ(localResult, kLocalBufferedReaderChunkSize); 41 | } 42 | 43 | } // namespace fbpcf::io 44 | -------------------------------------------------------------------------------- /fbpcf/io/cloud_util/S3Client.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include "fbpcf/io/cloud_util/S3Client.h" 9 | 10 | #include // @manual 11 | #include // @manual 12 | 13 | #include 14 | #include 15 | 16 | namespace fbpcf::cloudio { 17 | std::shared_ptr S3Client::getInstance( 18 | const fbpcf::aws::S3ClientOption& option) { 19 | /* Due to previous problems, we create a Singleton instance of the S3Client, 20 | * but there's a catch: we need a distinct S3Client for each region, or we 21 | * run into other issues. For that reason, we store this map from string to 22 | * S3Client with the assumption that the keys are region names. Since region 23 | * is optional, we also allow for a default empty string region. 24 | */ 25 | static folly::Synchronized< 26 | folly::F14FastMap>> 27 | m; 28 | 29 | std::string defaultStr{}; 30 | auto region = option.region.value_or(defaultStr); 31 | 32 | return m.withWLock([&](auto& clientMap) { 33 | if (clientMap.find(region) == clientMap.end()) { 34 | std::shared_ptr ptr{new S3Client{option}}; 35 | clientMap[region] = ptr; 36 | } 37 | 38 | return clientMap.at(region); 39 | }); 40 | } 41 | } // namespace fbpcf::cloudio 42 | -------------------------------------------------------------------------------- /fbpcf/primitive/mac/S2v.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include "fbpcf/primitive/mac/S2v.h" 9 | namespace fbpcf::primitive::mac { 10 | 11 | __m128i S2v::getMacM128i(const std::vector& text) const { 12 | const std::vector cmac = getMac128(text); 13 | return engine::util::buildM128i(cmac); 14 | } 15 | 16 | std::vector S2v::getMac128( 17 | const std::vector& text) const { 18 | __m128i rb = _mm_set_epi64x(0, rb_nonce); 19 | std::vector textCopy(text); 20 | std::vector initialBlock(16); 21 | 22 | __m128i initalMac = mac_->getMacM128i(initialBlock); 23 | 24 | // dbl 25 | bool msb = engine::util::getMsb(initalMac); 26 | engine::util::lShiftByBitsInPlace(initalMac, 1); 27 | if (msb) { 28 | initalMac = _mm_xor_si128(initalMac, rb); 29 | } 30 | _mm_storeu_si128((__m128i*)initialBlock.data(), initalMac); 31 | 32 | // pad 33 | if (textCopy.size() < 16) { 34 | textCopy.push_back(0x80); 35 | while (textCopy.size() < 16) { 36 | textCopy.push_back(0x00); 37 | } 38 | } 39 | 40 | // xor or xorend 41 | for (size_t i = 0; i < 16; ++i) { 42 | textCopy.at(textCopy.size() - 1 - i) ^= initialBlock.at(15 - i); 43 | } 44 | 45 | return mac_->getMac128(textCopy); 46 | } 47 | 48 | } // namespace fbpcf::primitive::mac 49 | -------------------------------------------------------------------------------- /example/edit_distance/EditDistanceCalculator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include "./InputProcessor.h" // @manual 9 | #include "./MPCTypes.h" // @manual 10 | #include "./Util.h" // @manual 11 | 12 | #pragma once 13 | 14 | namespace fbpcf::edit_distance { 15 | 16 | template 17 | class EditDistanceCalculator { 18 | public: 19 | explicit EditDistanceCalculator( 20 | int myRole, 21 | InputProcessor&& inputProcessor) 22 | : myRole_{myRole}, inputProcessor_(inputProcessor) { 23 | calculateEditDistances(); 24 | calculateMessages(); 25 | } 26 | 27 | const InputProcessor& getInputProcessor() const { 28 | return inputProcessor_; 29 | } 30 | 31 | const SecString& getReceiverMessages() const { 32 | return receiverMessages_; 33 | } 34 | 35 | const Sec32Int getEditDistances() const { 36 | return editDistances_; 37 | } 38 | 39 | std::string toJson() const; 40 | 41 | private: 42 | void calculateEditDistances(); 43 | void calculateMessages(); 44 | 45 | int myRole_; 46 | InputProcessor inputProcessor_; 47 | 48 | SecString receiverMessages_; 49 | Sec32Int editDistances_; 50 | }; 51 | 52 | } // namespace fbpcf::edit_distance 53 | 54 | #include "./EditDistanceCalculator_impl.h" // @manual 55 | -------------------------------------------------------------------------------- /fbpcf/mpc_std_lib/oram/encoder/OramEncoder.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | #include "folly/String.h" 13 | 14 | #include "fbpcf/mpc_std_lib/oram/encoder/IFilter.h" 15 | #include "fbpcf/mpc_std_lib/oram/encoder/IOramEncoder.h" 16 | 17 | namespace fbpcf::mpc_std_lib::oram { 18 | 19 | class OramEncoder : public IOramEncoder { 20 | public: 21 | explicit OramEncoder( 22 | std::unique_ptr>> filters) 23 | : filters_{std::move(filters)} {} 24 | 25 | std::vector generateORAMIndexes( 26 | const std::vector>& tuples) override; 27 | 28 | std::unique_ptr exportMappingConfig() const override; 29 | 30 | uint32_t getOramSize() const override { 31 | return currentIndex_; 32 | } 33 | 34 | private: 35 | std::unique_ptr>> filters_; 36 | 37 | uint32_t filteredValuesIndex_ = 0; 38 | bool wasAnyRowFiltered_ = false; 39 | uint32_t currentIndex_ = 0; 40 | std::unordered_map breakdownMapping_{}; 41 | 42 | std::string convertBreakdownsToKey( 43 | const std::vector& breakdownValues) const { 44 | return folly::join(",", breakdownValues); 45 | } 46 | }; 47 | 48 | } // namespace fbpcf::mpc_std_lib::oram 49 | -------------------------------------------------------------------------------- /fbpcf/engine/tuple_generator/oblivious_transfer/ferret/RegularErrorMultiPointCotFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include "fbpcf/engine/tuple_generator/oblivious_transfer/ferret/IMultiPointCotFactory.h" 13 | #include "fbpcf/engine/tuple_generator/oblivious_transfer/ferret/ISinglePointCotFactory.h" 14 | #include "fbpcf/engine/tuple_generator/oblivious_transfer/ferret/RegularErrorMultiPointCot.h" 15 | #include "fbpcf/engine/util/IPrgFactory.h" 16 | #include "fbpcf/engine/util/util.h" 17 | 18 | namespace fbpcf::engine::tuple_generator::oblivious_transfer::ferret { 19 | 20 | class RegularErrorMultiPointCotFactory final : public IMultiPointCotFactory { 21 | public: 22 | explicit RegularErrorMultiPointCotFactory( 23 | std::unique_ptr singlePointCotFactory) 24 | : singlePointCotFactory_(std::move(singlePointCotFactory)) {} 25 | 26 | std::unique_ptr create( 27 | std::unique_ptr& agent) 28 | override { 29 | return std::make_unique( 30 | singlePointCotFactory_->create(agent)); 31 | } 32 | 33 | private: 34 | std::unique_ptr singlePointCotFactory_; 35 | }; 36 | 37 | } // namespace 38 | // fbpcf::engine::tuple_generator::oblivious_transfer::ferret 39 | -------------------------------------------------------------------------------- /fbpcf/mpc_std_lib/oram/DummyDifferenceCalculatorFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include "fbpcf/engine/communication/IPartyCommunicationAgentFactory.h" 12 | #include "fbpcf/mpc_std_lib/oram/DummyDifferenceCalculator.h" 13 | #include "fbpcf/mpc_std_lib/oram/IDifferenceCalculatorFactory.h" 14 | 15 | namespace fbpcf::mpc_std_lib::oram::insecure { 16 | 17 | template 18 | class DummyDifferenceCalculatorFactory final 19 | : public IDifferenceCalculatorFactory { 20 | public: 21 | DummyDifferenceCalculatorFactory( 22 | bool thisPartyToSetDifference, 23 | int32_t peerId, 24 | engine::communication::IPartyCommunicationAgentFactory& factory) 25 | : thisPartyToSetDifference_(thisPartyToSetDifference), 26 | peerId_(peerId), 27 | factory_(factory) {} 28 | 29 | std::unique_ptr> create() override { 30 | return std::make_unique>( 31 | thisPartyToSetDifference_, 32 | factory_.create(peerId_, "dummy_difference_calculator_traffic")); 33 | } 34 | 35 | private: 36 | bool thisPartyToSetDifference_; 37 | int32_t peerId_; 38 | engine::communication::IPartyCommunicationAgentFactory& factory_; 39 | }; 40 | 41 | } // namespace fbpcf::mpc_std_lib::oram::insecure 42 | -------------------------------------------------------------------------------- /fbpcf/mpc/test/MpcAppExecutorTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | #include "folly/Random.h" 14 | 15 | #include "fbpcf/mpc/MpcAppExecutor.h" 16 | #include "fbpcf/mpc/test/test_apps/millionaire/MillionaireApp.h" 17 | 18 | namespace fbpcf { 19 | class MpcAppExecutorTest : public ::testing::Test { 20 | protected: 21 | void SetUp() override { 22 | port_ = 5000 + folly::Random::rand32() % 1000; 23 | } 24 | 25 | static void 26 | executeApps(Party party, const std::string& serverIp, uint16_t port) { 27 | constexpr int32_t kNumOfTask = 10; 28 | constexpr int32_t kConcurrency = 4; 29 | std::vector> apps; 30 | 31 | for (auto i = 0; i < kNumOfTask; i++) { 32 | apps.push_back(std::make_unique( 33 | party, serverIp, port + i % kConcurrency)); 34 | } 35 | 36 | MpcAppExecutor executor{kConcurrency}; 37 | executor.execute(apps); 38 | } 39 | 40 | protected: 41 | uint16_t port_; 42 | }; 43 | 44 | TEST_F(MpcAppExecutorTest, TestConcurrency) { 45 | auto futureAlice = std::async(executeApps, Party::Alice, "", port_); 46 | auto futureBob = std::async(executeApps, Party::Bob, "127.0.0.1", port_); 47 | 48 | futureAlice.wait(); 49 | futureBob.wait(); 50 | } 51 | } // namespace fbpcf 52 | -------------------------------------------------------------------------------- /fbpcf/mpc_std_lib/unified_data_process/adapter/Adapter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include "fbpcf/frontend/BitString.h" 11 | #include "fbpcf/mpc_std_lib/shuffler/IShuffler.h" 12 | #include "fbpcf/mpc_std_lib/unified_data_process/adapter/IAdapter.h" 13 | 14 | namespace fbpcf::mpc_std_lib::unified_data_process::adapter { 15 | 16 | template 17 | class Adapter final : public IAdapter { 18 | using SecBit = frontend::Bit; 19 | using PubBit = frontend::Bit; 20 | using SecString = frontend::BitString; 21 | 22 | public: 23 | Adapter( 24 | bool amIParty0, 25 | int32_t party0Id, 26 | int32_t party1Id, 27 | std::unique_ptr> shuffler) 28 | : amIParty0_(amIParty0), 29 | party0Id_(party0Id), 30 | party1Id_(party1Id), 31 | shuffler_(std::move(shuffler)) {} 32 | 33 | std::vector adapt_impl( 34 | const std::vector& unionMap) const override; 35 | 36 | private: 37 | bool amIParty0_; 38 | int32_t party0Id_; 39 | int32_t party1Id_; 40 | std::unique_ptr> shuffler_; 41 | }; 42 | 43 | } // namespace fbpcf::mpc_std_lib::unified_data_process::adapter 44 | 45 | #include "fbpcf/mpc_std_lib/unified_data_process/adapter/Adapter_impl.h" 46 | -------------------------------------------------------------------------------- /fbpcf/mpc_std_lib/unified_data_process/data_processor/DummyDataProcessorFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include "fbpcf/engine/communication/IPartyCommunicationAgentFactory.h" 12 | #include "fbpcf/mpc_std_lib/unified_data_process/data_processor/DummyDataProcessor.h" 13 | #include "fbpcf/mpc_std_lib/unified_data_process/data_processor/IDataProcessorFactory.h" 14 | 15 | namespace fbpcf::mpc_std_lib::unified_data_process::data_processor::insecure { 16 | 17 | template 18 | class DummyDataProcessorFactory final 19 | : public IDataProcessorFactory { 20 | public: 21 | DummyDataProcessorFactory( 22 | int32_t myId, 23 | int32_t partnerId, 24 | engine::communication::IPartyCommunicationAgentFactory& agentFactory) 25 | : myId_(myId), partnerId_(partnerId), agentFactory_(agentFactory) {} 26 | 27 | std::unique_ptr> create() { 28 | return std::make_unique>( 29 | myId_, 30 | partnerId_, 31 | agentFactory_.create(partnerId_, "dummy_data_processor_traffic")); 32 | } 33 | 34 | private: 35 | int32_t myId_; 36 | int32_t partnerId_; 37 | engine::communication::IPartyCommunicationAgentFactory& agentFactory_; 38 | }; 39 | 40 | } // namespace 41 | // fbpcf::mpc_std_lib::unified_data_process::data_processor::insecure 42 | --------------------------------------------------------------------------------