7 Star 37 Fork 9

BaseBit.ai / XSCE

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
Clone or Download
contribute
Sync branch
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README
Apache-2.0

中文

XSCE

XDP stack is listed below including PCT technologies layer which provides sandbox, TEE, FL and MPC components to support a variety of algorithms and applications. XSCE is the MPC framework component integrated in XDP platform.

XSCE (XDP Secure Computing Engine) is a unified MPC framework providing most frequently used algorithms and can be easily integrated by application software.

For current phase, XSCE provide PSI&PIR algorithms to open source, and more algorithms will come soon in the next few months.

build options

  • build

The XSCE has been tested on Linux. There is one dependency on libOTe. The lowest dependencies of build and run environment: Ubuntu 20, c++ 17, cmake 3.20, python3, instruction set: aes sse2 sse3 ssse3 sse4.1 sse4.2 avx avx2 avx256 avx512f pclmul bmi2 adx mmx.
The XSCE can be built as:

./build.py libote spdz xsce  

./build.py libote command will build libOTe library and xsce will use the library in ./third_party/libOTe_libs, otherwise xsce will use the library in the default directory which is /usr/local.
./build.py spdz command will build MP-SPDZ library and xsce will use the library in ./lib, otherwise xsce will use the library in the default directory which is /usr/local. The libraries are libtoolkits.a, libcommon.a, libPSI.a, libPIR.a and libMP-SPDZ.a, will be located in the ./lib directory, and the main executable with examples is pir/psi/arithmetic and is located in the build directory, eg build/bin/pir, build/bin/psi, build/bin/arithmetic.

  • install

After build the XSCE, the libraries and headers for secondary developing can be installed as following:

./build.py install   install the headers and libs to the default path: /usr/local
or 
./build.py install=/xx/yy install the headers and libs to the configuration path: /xx/yy
  • docker

The XSCE provides docker file. Executing the following commands can build a compiled and installed xsce environment, the libraries and header files will be located in /usr/local.

./build.py docker=images

After build the docker images, you can run the docker and git clone the source code, then build the examples in the docker by ./build.py xsce.

By default, sudo is not used. If installation requires sudo access, then add sudo. See ./build.py help for full details.

example

  • psi example

After building project, use the following command in the project root directory to run psi example:

build/bin/psi
  • pir example

After building project, use the following command in the project root directory to run pir example:

build/bin/pir
or
1. server party: build/bin/pir -r 0
2. client party: build/bin/pir -r 1
  • arithmetic example

After building project, first create the test folder, then copy the executable program and circuits into it.

mkdir test_dir
cp -rf XSCE_PATH/build/bin/arithmetic XSCE_PATH/src/arithmetic/Programs test_dir/

In addition, if you want to run 3-party algorithms, you may need to set up ssl for security as we use honest majority protocol(Shamir), then copy the certificates and keys into the test directory.

cd XSCE_PATH/third_party/MP-SPDZ
./Scripts/setup-ssl.sh [<number of parties> <ssl_dir>]
If it failed for `c_rehash: command not found`, change workdirectory to <ssl_dir> and execute shell command `for file in *.pem; do ln -s "$file" "$(openssl x509 -hash -noout -in "$file")".0; done` for instead.  
mkdir test_dir/Player-Data
cp XSCE_PATH/third_party/MP-SPDZ/ssl_dir/* test_dir/Player-Data/
cd test_dir

Finally, use the following command in the project root directory to run arithmetic example(e.g., 2-party addition):

1. party0: ./arithmetic -c 2 -r 0 -p 127.0.0.1:7878 add2
2. party1: ./arithmetic -c 2 -r 1 -p 127.0.0.1:7878 add2
  • logistic regression example

After building project, copy the mp-spdz circuits to root directory.

cp -rf XSCE_PATH/src/arithmetic/Programs XSCE_PATH/

Finally, use the following command in the project root directory to run logistic regression example:

1. party0: build/bin/lr  -r 0 -alg 1
2. party1: build/bin/lr  -r 1 -alg 1

Algorithms design

  • PSI

PSI algorithm is implemented according to IACR paper “Private Set Intersection in the Internet Setting From Lightweight Oblivious PRF”: https://eprint.iacr.org/2020/729

  • PIR

PIR algorithm is implemented as below: Input/output: client party uses single or multiple ids to query and get result from server, server party uses multiple string data for client to query each of which contains id field value.

1. client uses ids to run psi algorithm with server, and get the server indexes of matched ids in server party.
2. server encrypts each string data with random keys which are oprf values  generated in PSI algorithm(for intersection elements, their oprf values are the same) and send them to client.
3. client uses local oprf values of matched elements to decrypt ciphertext data to plaintext string data. 
  • Arithmetic

The arithmetic algorithm is implemented based on MP-SPDZ, the circuits have been compiled and optimized. And XSCE implements a C++ wrapper of the SPDZ high-level interface, which can be used to do computation involving the adding, multiplying, etc. The following algorithms are supported:

  • 2-party addition(a+b)
  • 2-party multiplication(a*b)
  • 2-party comparison(a<b)
  • 2-party median-value(Given two arrays, to find the median-value)
  • 2-party variance(Given two arrays, to compute the variance)
  • 2-party inner product(Given two arrays, to compute the inner product)
  • 3-party addition(a+b+c)
  • 3-party multiplication(a*b*c)
  • 3-party median-value(Given three arrays, to find the median-value)
  • 3-party variance(Given three arrays, to compute the variance)

The 2-party algorithms are as follows:

  • EXPORT_SYM int runAdd2(SPDZAlg *spdzalg); //2-party addition
  • EXPORT_SYM int runMul2(SPDZAlg *spdzalg); //2-party multiplication
  • EXPORT_SYM int runCmp2(SPDZAlg *spdzalg); //2-party comparison
  • EXPORT_SYM int runVar2(SPDZAlg *spdzalg); //2-party variance
  • EXPORT_SYM int runMid2(SPDZAlg *spdzalg); //2-party median-value
  • EXPORT_SYM int runInnerProd2(SPDZAlg *spdzAlg); //2-party inner-product

The 3-party algorithms are as follows:

  • EXPORT_SYM int runAdd3(SPDZAlg *spdzalg); //3-party addition

  • EXPORT_SYM int runMul3(SPDZAlg *spdzalg); //3-party multiplication

  • EXPORT_SYM int runVar3(SPDZAlg *spdzalg); //3-party variance

  • EXPORT_SYM int runMid3(SPDZAlg *spdzalg); //3-party median-value

  • logistic regression (vertical mode)

Logistic regression (vertical mode) algorithm is implemented as below:

Input/output:
1. training data: server provide sample data including label value and feature value, client provide correspondent sample data only including feature value(should be aligned with server);
2. traning parameters: iteration number, traning batch size, learning rate.
  1. based on gradient descent algorithm, client needs to use server label value to update its model parameters which is implemented MP-SPDZ to run a inner product calculation;
  2. when training is over,server and client save their model result to specified file.

More algorithms will be supported soon.

License

This project has been placed in the public domain and/or apache2.0 license.

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

About

基于MPC技术的隐私计算框架,提供各种常用算法。 expand collapse
C++ and 4 more languages
Apache-2.0
Cancel

Releases

No release

Contributors

All

Activities

Load More
can not load any more
C++
1
https://gitee.com/basebit-ai/XSCE.git
git@gitee.com:basebit-ai/XSCE.git
basebit-ai
XSCE
XSCE
master

Search