Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【OSCP】在 YACL 上支持基于 OT 的 Private Set Union 算法 #232

Merged
merged 5 commits into from
Mar 18, 2024
Merged

【OSCP】在 YACL 上支持基于 OT 的 Private Set Union 算法 #232

merged 5 commits into from
Mar 18, 2024

Conversation

zhangwfjh
Copy link
Contributor

Fixed #98

@Jamie-Cui Jamie-Cui self-requested a review January 23, 2024 02:41
Copy link
Member

@Jamie-Cui Jamie-Cui left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make changes to this PR accordingly~ thanks

1. remove psu namespace
2. use const reference shared_ptr in parameters
3. separate CRHash from UHF
4. remove `Serialize`
1. always use `Blake` hash function
2. add submodules and security declarations
3. change to `SecureRandBits` for OTe
1. fix `memcpy` bug
2. replace hasher by lambda
3. use hash sort as shuffle
4. rename constants
@Jamie-Cui
Copy link
Member

Thanks for you contribution, currently this PR is under security review by our team, this PR will be merged if our security team has no more concerns.

@Jamie-Cui Jamie-Cui added the WIP: security-review This PR is under security review label Jan 28, 2024
@cmh927
Copy link

cmh927 commented Feb 20, 2024

Could you explain the implementation of the function Interpolate() in yacl/crypto/primitives/psu/krtw19_psu.cc?

@zhangwfjh
Copy link
Contributor Author

zhangwfjh commented Feb 21, 2024

Could you explain the implementation of the function Interpolate() in yacl/crypto/primitives/psu/krtw19_psu.cc?

The key recursive step is the following
$$[x^k](x-x_1) \dotsm (x-x_j) = [x^{k-1}](x-x_1) \dotsm (x-x_{j-1}) - x_j \cdot [x^k](x-x_1) \dotsm (x-x_{j-1}),$$
where $[x^k] p(x)$ represents the $k$-th order coefficient $p_k$ of the polynomial $p(x)=\sum_k p_kx^k$.

@Jamie-Cui
Copy link
Member

Could you explain the implementation of the function Interpolate() in yacl/crypto/primitives/psu/krtw19_psu.cc?

The key recursive step is the following xk⋯(x−xj)=xk−1⋯(x−xj−1)−xj⋅xk⋯(x−xj−1), where [xk]p(x) represents the k-th order coefficient pk of the polynomial p(x)=∑kpkxk.

Sorry I've been away from work for some time. Can you please explain more details about the codes (or, is there any other references that you can refer your code to? If there is, we may speed up the security-review process and merge this PR). Many thanks.

Again, sorry for the delay :)

@zhangwfjh
Copy link
Contributor Author

zhangwfjh commented Mar 6, 2024

Could you explain the implementation of the function Interpolate() in yacl/crypto/primitives/psu/krtw19_psu.cc?

The key recursive step is the following xk⋯(x−xj)=xk−1⋯(x−xj−1)−xj⋅xk⋯(x−xj−1), where [xk]p(x) represents the k-th order coefficient pk of the polynomial p(x)=∑kpkxk.

Sorry I've been away from work for some time. Can you please explain more details about the codes (or, is there any other references that you can refer your code to? If there is, we may speed up the security-review process and merge this PR). Many thanks.

Again, sorry for the delay :)

The implementation is based on the following formula (w.o. optimization).
image
image

I made some minor changes to the original codes to improve readability.

// @param x The x-coordinates of the points.
// @param y The y-coordinates of the points.
// @return The interpolation polynomial L(X) such that L(x[i]) = y[i] for all i.
auto Interpolate(const std::vector<uint64_t>& x,
                 const std::vector<uint64_t>& y) {
  using Poly = std::vector<uint64_t>;
  size_t n{x.size()};
  Poly L(n);  // L(X) = sum_{i=0}^{n-1} yi * Li(X)
  for (size_t i{}; i != n; ++i) {
    Poly Li(n);       // Li(X) = num(X) / den
    uint64_t den{1};  // den = ∏_{j≠i} (xi - xj) = den<n-1>
    Poly num(n);      // num(X) = ∏_{j≠i} (X - xj) = num<n-1>(X)
    for (size_t j{}; j != n; ++j) {
      if (x[i] != x[j]) {
        den = GfMul64(den, x[i] ^ x[j]);  // den<j> = den<j-1> * (xi - xj)
        uint64_t num_km1{0};              // num<j-1>(X)[k-1]
        for (size_t k{}; k != n; ++k) {
          // num<j>(X)[k] = (num<j-1>(X) * (X - xj))[k]
          //              = (num<j-1>(X) * X)[k] - (num<j-1>(X) * xj)[k]
          //              = num<j-1>(X)[k-1] - num<j-1>(X)[k] * xj
          num_km1 = std::exchange(num[k], num_km1 ^ GfMul64(num[k], x[j]));
        }
      }
    }
    for (size_t k{}; k != n; ++k) {
      Li[k] = GfMul64(num[k], Inv64(den));
      L[k] ^= GfMul64(y[i], Li[k]);
    }
  }
  return L;
}

@Jamie-Cui Jamie-Cui removed the WIP: security-review This PR is under security review label Mar 18, 2024
@Jamie-Cui Jamie-Cui self-requested a review March 18, 2024 11:25
Copy link
Member

@Jamie-Cui Jamie-Cui left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Jamie-Cui Jamie-Cui merged commit 4779ef6 into secretflow:main Mar 18, 2024
6 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Mar 18, 2024
@zhangwfjh zhangwfjh deleted the krtw19 branch March 19, 2024 02:47
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

在 YACL 上支持基于 OT 的 Private Set Union 算法
3 participants