Skip to content

Commit

Permalink
repo-sync-2024-02-19T16:30:32+0800 (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
6fj authored Feb 19, 2024
1 parent e5f86c1 commit fa343ef
Show file tree
Hide file tree
Showing 301 changed files with 2,808 additions and 3,617 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/scorecard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,6 @@ jobs:

# Upload the results to GitHub's code scanning dashboard.
- name: "Upload to code-scanning"
uses: github/codeql-action/upload-sarif@379614612a29c9e28f31f39a59013eb8012a51f0 # v3.24.3
uses: github/codeql-action/upload-sarif@0b21cf2492b6b02c465a3e5d7c473717ad7721ba # v3.23.1
with:
sarif_file: results.sarif
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,13 @@ sender.config:
In the first terminal, run the following command

```bash
docker run -it --rm --network host --mount type=bind,source=/tmp/receiver,target=/root/receiver -w /root --cap-add=SYS_PTRACE --security-opt seccomp=unconfined --cap-add=NET_ADMIN --privileged=true secretflow-registry.cn-hangzhou.cr.aliyuncs.com/secretflow/psi-anolis8:latest bash -c "./main --config receiver/receiver.config"
docker run -it --rm --network host --mount type=bind,source=/tmp/receiver,target=/root/receiver --cap-add=SYS_PTRACE --security-opt seccomp=unconfined --cap-add=NET_ADMIN --privileged=true secretflow-registry.cn-hangzhou.cr.aliyuncs.com/secretflow/psi-anolis8:latest bash -c "./main --config receiver/receiver.config"
```

In the other terminal, run the following command simultaneously.

```bash
docker run -it --rm --network host --mount type=bind,source=/tmp/sender,target=/root/sender -w /root --cap-add=SYS_PTRACE --security-opt seccomp=unconfined --cap-add=NET_ADMIN --privileged=true secretflow-registry.cn-hangzhou.cr.aliyuncs.com/secretflow/psi-anolis8:latest bash -c "./main --config sender/sender.config"
docker run -it --rm --network host --mount type=bind,source=/tmp/sender,target=/root/sender --cap-add=SYS_PTRACE --security-opt seccomp=unconfined --cap-add=NET_ADMIN --privileged=true secretflow-registry.cn-hangzhou.cr.aliyuncs.com/secretflow/psi-anolis8:latest bash -c "./main --config sender/sender.config"
```

## Building SecretFlow PSI Library
Expand Down Expand Up @@ -155,9 +155,12 @@ docker exec -it psi-dev-$(whoami) bash
#### Linux

```sh
Install gcc>=11.2, cmake>=3.26, ninja, nasm>=2.15, python>=3.8, bazel==6.4.0, golang, xxd, lld
Install gcc>=11.2, cmake>=3.26, ninja, nasm>=2.15, python>=3.8, bazel, golang, xxd, lld
```

> **Note**<br>
Please install bazel with version in .bazelversion or use bazelisk.

### Build & UnitTest


Expand Down
5 changes: 5 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
> - `[API]` prefix for API changes.
> - `[Improvement]` prefix for implementation improvement.
## v0.2.0.dev240219

- [Feature] add ecdh logger for debug purposes.
- [API] modify repo structure.

## v0.2.0.dev240123

- [Feature] add RFC9380 25519 elligator2 hash_to_curve.
Expand Down
173 changes: 93 additions & 80 deletions bazel/patches/apsi.patch
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,88 @@ index 3b15780..5085038 100644

if(APSI_FOURQ_AMD64)
add_subdirectory(amd64)
diff --git a/common/apsi/fourq/FourQ_internal.h b/common/apsi/fourq/FourQ_internal.h
index 009bb1d..5aa9886 100644
--- a/common/apsi/fourq/FourQ_internal.h
+++ b/common/apsi/fourq/FourQ_internal.h
@@ -143,7 +143,7 @@ static __inline unsigned int is_digit_lessthan_ct(digit_t x, digit_t y)

// 64x64-bit multiplication
#define MUL128(multiplier, multiplicand, product) \
- mp_mul( \
+ fq_mp_mul( \
(digit_t *)&(multiplier), \
(digit_t *)&(multiplicand), \
(digit_t *)&(product), \
@@ -151,12 +151,12 @@ static __inline unsigned int is_digit_lessthan_ct(digit_t x, digit_t y)

// 128-bit addition, inputs < 2^127
#define ADD128(addend1, addend2, addition) \
- mp_add((digit_t *)(addend1), (digit_t *)(addend2), (digit_t *)(addition), NWORDS_FIELD);
+ fq_mp_add((digit_t *)(addend1), (digit_t *)(addend2), (digit_t *)(addition), NWORDS_FIELD);

// 128-bit addition with output carry
#define ADC128(addend1, addend2, carry, addition) \
(carry) = \
- mp_add((digit_t *)(addend1), (digit_t *)(addend2), (digit_t *)(addition), NWORDS_FIELD);
+ fq_mp_add((digit_t *)(addend1), (digit_t *)(addend2), (digit_t *)(addition), NWORDS_FIELD);

#elif (TARGET == TARGET_AMD64 && OS_TARGET == OS_WIN)

@@ -257,10 +257,10 @@ static __inline unsigned int is_digit_lessthan_ct(digit_t x, digit_t y)
bool is_zero_ct(digit_t *a, unsigned int nwords);

// Multiprecision addition, c = a+b. Returns the carry bit
-unsigned int mp_add(digit_t *a, digit_t *b, digit_t *c, unsigned int nwords);
+unsigned int fq_mp_add(digit_t *a, digit_t *b, digit_t *c, unsigned int nwords);

// Schoolbook multiprecision multiply, c = a*b
-void mp_mul(const digit_t *a, const digit_t *b, digit_t *c, const unsigned int nwords);
+void fq_mp_mul(const digit_t *a, const digit_t *b, digit_t *c, const unsigned int nwords);

// Multiprecision subtraction, c = a-b. Returns the borrow bit
#if defined(GENERIC_IMPLEMENTATION)
diff --git a/common/apsi/fourq/generic/fp.h b/common/apsi/fourq/generic/fp.h
index f475de1..e24a26a 100644
--- a/common/apsi/fourq/generic/fp.h
+++ b/common/apsi/fourq/generic/fp.h
@@ -172,7 +172,7 @@ void mod1271(felm_t a)
ADDC(borrow, a[NWORDS_FIELD - 1], (mask >> 1), borrow, a[NWORDS_FIELD - 1]);
}

-void mp_mul(const digit_t *a, const digit_t *b, digit_t *c, const unsigned int nwords)
+void fq_mp_mul(const digit_t *a, const digit_t *b, digit_t *c, const unsigned int nwords)
{ // Schoolbook multiprecision multiply, c = a*b
unsigned int i, j;
digit_t u, v, UV[2];
@@ -195,7 +195,7 @@ void mp_mul(const digit_t *a, const digit_t *b, digit_t *c, const unsigned int n
}
}

-unsigned int mp_add(digit_t *a, digit_t *b, digit_t *c, unsigned int nwords)
+unsigned int fq_mp_add(digit_t *a, digit_t *b, digit_t *c, unsigned int nwords)
{ // Multiprecision addition, c = a+b, where lng(a) = lng(b) = nwords. Returns the carry bit
unsigned int i, carry = 0;

@@ -263,13 +263,13 @@ void fpinv1271(felm_t a)
static void multiply(const digit_t *a, const digit_t *b, digit_t *c)
{ // Schoolbook multiprecision multiply, c = a*b

- mp_mul(a, b, c, NWORDS_ORDER);
+ fq_mp_mul(a, b, c, NWORDS_ORDER);
}

static unsigned int add(const digit_t *a, const digit_t *b, digit_t *c, const unsigned int nwords)
{ // Multiprecision addition, c = a+b, where lng(a) = lng(b) = nwords. Returns the carry bit

- return mp_add((digit_t *)a, (digit_t *)b, c, (unsigned int)nwords);
+ return fq_mp_add((digit_t *)a, (digit_t *)b, c, (unsigned int)nwords);
}

unsigned int subtract(const digit_t *a, const digit_t *b, digit_t *c, const unsigned int nwords)
diff --git a/common/apsi/fourq/kex.c b/common/apsi/fourq/kex.c
new file mode 100644
index 0000000..5c37c60
index 0000000..d59af6d
--- /dev/null
+++ b/common/apsi/fourq/kex.c
@@ -0,0 +1,181 @@
Expand Down Expand Up @@ -282,6 +361,19 @@ index 0000000..5c37c60
+
+ return Status;
+}
diff --git a/common/apsi/util/stopwatch.h b/common/apsi/util/stopwatch.h
index e09a53b..c5e4bab 100644
--- a/common/apsi/util/stopwatch.h
+++ b/common/apsi/util/stopwatch.h
@@ -22,7 +22,7 @@

// Measure a block
#define STOPWATCH(stopwatch, name) \
- apsi::util::StopwatchScope UNIQUE_STOPWATCH_NAME(stopwatchscope)(stopwatch, name);
+ ::apsi::util::StopwatchScope UNIQUE_STOPWATCH_NAME(stopwatchscope)(stopwatch, name);

namespace apsi {
namespace util {
diff --git a/receiver/apsi/CMakeLists.txt b/receiver/apsi/CMakeLists.txt
index afce298..7757b68 100644
--- a/receiver/apsi/CMakeLists.txt
Expand Down Expand Up @@ -355,82 +447,3 @@ index fd245d7..99e4228 100644
DESTINATION
${APSI_INCLUDES_INSTALL_DIR}/apsi
)
diff --git a/common/apsi/fourq/FourQ_internal.h b/common/apsi/fourq/FourQ_internal.h
index 009bb1d..5aa9886 100644
--- a/common/apsi/fourq/FourQ_internal.h
+++ b/common/apsi/fourq/FourQ_internal.h
@@ -143,7 +143,7 @@ static __inline unsigned int is_digit_lessthan_ct(digit_t x, digit_t y)

// 64x64-bit multiplication
#define MUL128(multiplier, multiplicand, product) \
- mp_mul( \
+ fq_mp_mul( \
(digit_t *)&(multiplier), \
(digit_t *)&(multiplicand), \
(digit_t *)&(product), \
@@ -151,12 +151,12 @@ static __inline unsigned int is_digit_lessthan_ct(digit_t x, digit_t y)

// 128-bit addition, inputs < 2^127
#define ADD128(addend1, addend2, addition) \
- mp_add((digit_t *)(addend1), (digit_t *)(addend2), (digit_t *)(addition), NWORDS_FIELD);
+ fq_mp_add((digit_t *)(addend1), (digit_t *)(addend2), (digit_t *)(addition), NWORDS_FIELD);

// 128-bit addition with output carry
#define ADC128(addend1, addend2, carry, addition) \
(carry) = \
- mp_add((digit_t *)(addend1), (digit_t *)(addend2), (digit_t *)(addition), NWORDS_FIELD);
+ fq_mp_add((digit_t *)(addend1), (digit_t *)(addend2), (digit_t *)(addition), NWORDS_FIELD);

#elif (TARGET == TARGET_AMD64 && OS_TARGET == OS_WIN)

@@ -257,10 +257,10 @@ static __inline unsigned int is_digit_lessthan_ct(digit_t x, digit_t y)
bool is_zero_ct(digit_t *a, unsigned int nwords);

// Multiprecision addition, c = a+b. Returns the carry bit
-unsigned int mp_add(digit_t *a, digit_t *b, digit_t *c, unsigned int nwords);
+unsigned int fq_mp_add(digit_t *a, digit_t *b, digit_t *c, unsigned int nwords);

// Schoolbook multiprecision multiply, c = a*b
-void mp_mul(const digit_t *a, const digit_t *b, digit_t *c, const unsigned int nwords);
+void fq_mp_mul(const digit_t *a, const digit_t *b, digit_t *c, const unsigned int nwords);

// Multiprecision subtraction, c = a-b. Returns the borrow bit
#if defined(GENERIC_IMPLEMENTATION)
diff --git a/common/apsi/fourq/generic/fp.h b/common/apsi/fourq/generic/fp.h
index f475de1..e24a26a 100644
--- a/common/apsi/fourq/generic/fp.h
+++ b/common/apsi/fourq/generic/fp.h
@@ -172,7 +172,7 @@ void mod1271(felm_t a)
ADDC(borrow, a[NWORDS_FIELD - 1], (mask >> 1), borrow, a[NWORDS_FIELD - 1]);
}

-void mp_mul(const digit_t *a, const digit_t *b, digit_t *c, const unsigned int nwords)
+void fq_mp_mul(const digit_t *a, const digit_t *b, digit_t *c, const unsigned int nwords)
{ // Schoolbook multiprecision multiply, c = a*b
unsigned int i, j;
digit_t u, v, UV[2];
@@ -195,7 +195,7 @@ void mp_mul(const digit_t *a, const digit_t *b, digit_t *c, const unsigned int n
}
}

-unsigned int mp_add(digit_t *a, digit_t *b, digit_t *c, unsigned int nwords)
+unsigned int fq_mp_add(digit_t *a, digit_t *b, digit_t *c, unsigned int nwords)
{ // Multiprecision addition, c = a+b, where lng(a) = lng(b) = nwords. Returns the carry bit
unsigned int i, carry = 0;

@@ -263,13 +263,13 @@ void fpinv1271(felm_t a)
static void multiply(const digit_t *a, const digit_t *b, digit_t *c)
{ // Schoolbook multiprecision multiply, c = a*b

- mp_mul(a, b, c, NWORDS_ORDER);
+ fq_mp_mul(a, b, c, NWORDS_ORDER);
}

static unsigned int add(const digit_t *a, const digit_t *b, digit_t *c, const unsigned int nwords)
{ // Multiprecision addition, c = a+b, where lng(a) = lng(b) = nwords. Returns the carry bit

- return mp_add((digit_t *)a, (digit_t *)b, c, (unsigned int)nwords);
+ return fq_mp_add((digit_t *)a, (digit_t *)b, c, (unsigned int)nwords);
}

unsigned int subtract(const digit_t *a, const digit_t *b, digit_t *c, const unsigned int nwords)
1 change: 0 additions & 1 deletion bazel/patches/grpc.patch
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,3 @@ index 72e1b6609e..aded52d0db 100644
#include <grpc/slice.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>

1 change: 0 additions & 1 deletion bazel/patches/ippcp.patch
Original file line number Diff line number Diff line change
Expand Up @@ -248,4 +248,3 @@ index 315d1a3..8b11c7a 100644
endif(${ARCH} MATCHES "ia32")
endif(APPLE)
endif(UNIX)

2 changes: 1 addition & 1 deletion bazel/patches/perfetto.patch
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ index 4ebb0576b..6322273b8 100644
+
#include <chrono>
#include <optional>
#include <string>
#include <string>
2 changes: 1 addition & 1 deletion bazel/sparsehash.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ cc_library(
includes = ["src"],
visibility = ["//visibility:public"],
deps = [
"@psi//psi/psi/core/vole_psi:sparsehash_config",
"@psi//psi/rr22:sparsehash_config",
],
)
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
# global variables
extlinks = {
"psi_doc_host": ("https://www.secretflow.org.cn/docs/psi/en/", "doc "),
"psi_code_host": ("https://github.com/secretflow", "code "),
"psi_code_host": ("https://github.com/secretflow/psi/", "code "),
}

html_theme = "pydata_sphinx_theme"
Expand Down
11 changes: 4 additions & 7 deletions docs/getting_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Welcome to SecretFlow PSI Library. There are multiple methods to use PSI/PIR.
* Python packages

* `SPU <https://pypi.org/project/spu/>`_ warps the library as Python bindings. You could call PSI/PIR with spu.
* `SecretFlow <https://pypi.org/project/secretflow/>`_ warps SPU further.
* `SecretFlow <https://pypi.org/project/secretflow/>`_ warps SPU further with user-friendly APIs.


* Applications
Expand Down Expand Up @@ -147,11 +147,13 @@ You need to install:
* ninja
* nasm>=2.15
* python>=3.8
* bazel==6.4.0
* bazel
* golang
* xxd
* lld

For bazel, please check version in `.bazelversion <https://github.com/secretflow/psi/blob/main/.bazelversion>`_ or use bazelisk instead.

Build & UnitTest
^^^^^^^^^^^^^^^^

Expand All @@ -172,8 +174,3 @@ Reporting an Issue
Please create an issue at `Github Issues <https://github.com/secretflow/psi/issues>`_.

We will look into issues and get back to you soon.

Frequently Asked Questions (FAQ)
--------------------------------

We will collect some popular questions from users and update this part promptly.
6 changes: 3 additions & 3 deletions docs/reference/launch_config.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ Please check psi.v2.PsiConfig and psi.v2.UbPsiConfig at **PSI v2 Configuration**
| ----- | ---- | ----------- |
| link_config | [ yacl.link.ContextDescProto](#yacllinkcontextdescproto) | Configs for network. |
| self_link_party | [ string](#string) | With link_config. |
| [**oneof**](https://developers.google.com/protocol-buffers/docs/proto3#oneof) runtime_config.legacy_psi_config | [ psi.BucketPsiConfig](#psibucketpsiconfig) | Please check at psi.proto. |
| [**oneof**](https://developers.google.com/protocol-buffers/docs/proto3#oneof) runtime_config.psi_config | [ psi.v2.PsiConfig](#psiv2psiconfig) | Please check at psi_v2.proto. |
| [**oneof**](https://developers.google.com/protocol-buffers/docs/proto3#oneof) runtime_config.ub_psi_config | [ psi.v2.UbPsiConfig](#psiv2ubpsiconfig) | Please check at psi_v2.proto. |
| [**oneof**](https://developers.google.com/protocol-buffers/docs/proto3#oneof) runtime_config.legacy_psi_config | [ BucketPsiConfig](#bucketpsiconfig) | Please check at psi.proto. |
| [**oneof**](https://developers.google.com/protocol-buffers/docs/proto3#oneof) runtime_config.psi_config | [ v2.PsiConfig](#v2psiconfig) | Please check at psi_v2.proto. |
| [**oneof**](https://developers.google.com/protocol-buffers/docs/proto3#oneof) runtime_config.ub_psi_config | [ v2.UbPsiConfig](#v2ubpsiconfig) | Please check at psi_v2.proto. |
<!-- end Fields -->
<!-- end HasFields -->
<!-- end messages -->
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/psi_v2_config.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Configs for ECDH protocol.

| Field | Type | Description |
| ----- | ---- | ----------- |
| curve | [ psi.psi.CurveType](#psipsicurvetype) | none |
| curve | [ psi.CurveType](#psicurvetype) | none |
<!-- end Fields -->
<!-- end HasFields -->

Expand Down
6 changes: 3 additions & 3 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
nbsphinx==0.9.3
sphinx==7.2.6
myst-parser==2.0.0
nbsphinx==0.8.9
sphinx==5.3.0
myst-parser==0.18.1
sphinx-intl==2.1.0
pydata-sphinx-theme
Loading

0 comments on commit fa343ef

Please sign in to comment.