Skip to content

Commit a3c21a3

Browse files
authored
sync (#342)
1 parent b992382 commit a3c21a3

File tree

4 files changed

+23
-8
lines changed

4 files changed

+23
-8
lines changed

.bazeliskrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
USE_BAZEL_VERSION=7.5.0
1+
USE_BAZEL_VERSION=7.6.1

MODULE.bazel.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

psi/algorithm/sealpir/seal_pir.cc

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <memory.h>
1818

1919
#include <algorithm>
20+
#include <cstddef>
2021
#include <functional>
2122
#include <span>
2223
#include <utility>
@@ -1181,17 +1182,31 @@ inline vector<Ciphertext> SealPirServer::ExpandQuery(
11811182
inline void SealPirServer::MultiplyPowerOfX(const Ciphertext &encrypted,
11821183
Ciphertext &destination,
11831184
uint32_t index) const {
1184-
int N = enc_params_->poly_modulus_degree();
1185+
size_t N = enc_params_->poly_modulus_degree();
11851186
size_t coeff_mod_cnt = enc_params_->coeff_modulus().size() - 1;
11861187
size_t encrypted_cnt = encrypted.size();
11871188

11881189
destination = encrypted;
1189-
1190+
uint32_t actual_index = index % N;
1191+
// avoid exception in SEAL debug mode
11901192
for (size_t i = 0; i < encrypted_cnt; ++i) {
11911193
for (size_t j = 0; j < coeff_mod_cnt; ++j) {
1192-
seal::util::negacyclic_shift_poly_coeffmod(
1193-
encrypted.data(i) + (j * N), N, index,
1194-
enc_params_->coeff_modulus()[j], destination.data(i) + (j * N));
1194+
if (index >= N) {
1195+
// negate coefficients when index >= N
1196+
vector<uint64_t> temp_data(N);
1197+
for (size_t k = 0; k < N; ++k) {
1198+
temp_data[k] = enc_params_->coeff_modulus()[j].value() -
1199+
encrypted.data(i)[j * N + k];
1200+
}
1201+
seal::util::negacyclic_shift_poly_coeffmod(
1202+
temp_data.data(), N, actual_index, enc_params_->coeff_modulus()[j],
1203+
destination.data(i) + (j * N));
1204+
} else {
1205+
// direct shift when index < N
1206+
seal::util::negacyclic_shift_poly_coeffmod(
1207+
encrypted.data(i) + (j * N), N, actual_index,
1208+
enc_params_->coeff_modulus()[j], destination.data(i) + (j * N));
1209+
}
11951210
}
11961211
}
11971212
}

psi/utils/sync.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ auto SyncWait(const std::shared_ptr<yacl::link::Context>& lctx, F&& func,
4949
auto fut = std::async(std::launch::async, std::forward<F>(func),
5050
std::forward<Args>(args)...);
5151

52-
std::conditional_t<!std::is_void_v<R>, R, std::monostate> res;
52+
std::conditional_t<!std::is_void_v<R>, R, std::monostate> res{};
5353

5454
while (true) {
5555
if (!done) {

0 commit comments

Comments
 (0)