Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 122 additions & 0 deletions MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

187 changes: 187 additions & 0 deletions psi/algorithm/inspire/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
# Copyright 2026 The secretflow authors.

load("//bazel:psi.bzl", "psi_cc_binary", "psi_cc_library", "psi_cc_test")

package(default_visibility = ["//visibility:public"])

X86_64_COMPATIBLE = ["@platforms//cpu:x86_64"]

psi_cc_library(
name = "types",
hdrs = ["types.h"],
target_compatible_with = X86_64_COMPATIBLE,
)

psi_cc_library(
name = "params",
hdrs = ["params.h"],
target_compatible_with = X86_64_COMPATIBLE,
deps = ["//psi/algorithm/ypir:params"],
)

psi_cc_library(
name = "serialize",
srcs = ["serialize.cc"],
hdrs = ["serialize.h"],
target_compatible_with = X86_64_COMPATIBLE,
deps = [
":types",
"@yacl//yacl/base:buffer",
"@yacl//yacl/base:byte_container_view",
"@yacl//yacl/base:exception",
],
)

psi_cc_library(
name = "internal_primitives",
srcs = ["internal_primitives.cc"],
hdrs = ["internal_primitives.h"],
target_compatible_with = X86_64_COMPATIBLE,
deps = [
"//psi/algorithm/ypir:legacy_ypir_impl",
"//psi/algorithm/ypir:params",
"//psi/algorithm/ypir:ypir_internal_params",
"@yacl//yacl/base:exception",
],
)

psi_cc_library(
name = "internal",
srcs = ["internal.cc"],
hdrs = ["internal.h"],
target_compatible_with = X86_64_COMPATIBLE,
deps = [
":types",
"//psi/algorithm/ypir:legacy_ypir_impl",
"//psi/algorithm/ypir:params",
"//psi/algorithm/ypir:util",
"//psi/algorithm/ypir:ypir_internal_params",
"@yacl//yacl/base:exception",
],
)

psi_cc_library(
name = "large_record_he",
srcs = ["large_record_he.cc"],
hdrs = ["large_record_he.h"],
target_compatible_with = X86_64_COMPATIBLE,
deps = [
"@hexl",
],
)

psi_cc_library(
name = "large_record",
srcs = ["large_record.cc"],
hdrs = ["large_record.h"],
target_compatible_with = X86_64_COMPATIBLE,
deps = [
":internal_primitives",
":large_record_he",
":types",
"//psi/algorithm/ypir:legacy_ypir_impl",
"//psi/algorithm/ypir:ypir_internal_params",
"@hexl",
"@yacl//yacl/base:exception",
],
)

psi_cc_library(
name = "client",
srcs = ["client.cc"],
hdrs = ["client.h"],
target_compatible_with = X86_64_COMPATIBLE,
deps = [
":internal",
":params",
":serialize",
":types",
"//psi/algorithm/pir_interface:index_pir",
"//psi/algorithm/pir_interface:pir_db",
"//psi/algorithm/ypir:ypir_internal_params",
"@yacl//yacl/base:buffer",
"@yacl//yacl/base:byte_container_view",
"@yacl//yacl/base:exception",
],
)

psi_cc_library(
name = "server",
srcs = ["server.cc"],
hdrs = ["server.h"],
target_compatible_with = X86_64_COMPATIBLE,
deps = [
":internal",
":params",
":serialize",
":types",
"//psi/algorithm/pir_interface:pir_db",
"//psi/algorithm/ypir:ypir_internal_params",
"@yacl//yacl/base:buffer",
"@yacl//yacl/base:byte_container_view",
"@yacl//yacl/base:exception",
],
)

psi_cc_library(
name = "entry",
srcs = ["entry.cc"],
hdrs = ["entry.h"],
target_compatible_with = X86_64_COMPATIBLE,
deps = [
":client",
":params",
":server",
"//psi/algorithm/pir_interface:pir_db",
"@abseil-cpp//absl/strings",
"@yacl//yacl/base:buffer",
"@yacl//yacl/base:byte_container_view",
"@yacl//yacl/base:exception",
"@yacl//yacl/link:context",
],
)

psi_cc_binary(
name = "inspire_flow_smoke",
srcs = ["inspire_flow_smoke.cc"],
linkstatic = True,
target_compatible_with = X86_64_COMPATIBLE,
deps = [
":internal",
":params",
"//psi/algorithm/ypir:ypir_internal_params",
],
)

psi_cc_test(
name = "inspire_flow_test",
srcs = ["inspire_flow_smoke.cc"],
target_compatible_with = X86_64_COMPATIBLE,
deps = [
":internal",
":params",
"//psi/algorithm/ypir:ypir_internal_params",
],
)

psi_cc_binary(
name = "large_record_flow_smoke",
srcs = ["large_record_flow_smoke.cc"],
linkstatic = True,
target_compatible_with = X86_64_COMPATIBLE,
deps = [
":large_record",
":types",
],
)

psi_cc_binary(
name = "large_record_full_test",
srcs = ["large_record_full_test.cc"],
linkstatic = True,
target_compatible_with = X86_64_COMPATIBLE,
deps = [
":large_record",
":types",
],
)
61 changes: 61 additions & 0 deletions psi/algorithm/inspire/client.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#include "psi/algorithm/inspire/client.h"

#include <string>
#include <utility>

#include "yacl/base/exception.h"

#include "psi/algorithm/inspire/serialize.h"
#include "psi/algorithm/ypir/ypir_internal_params.h"

namespace psi::inspire {

InspireClient::InspireClient(InspireParameters params)
: params_(std::move(params)),
context_(std::make_unique<psi::ypir::internal::ypir::Context>(
psi::ypir::internal::ypir::CreateContext(params_))) {
YACL_ENFORCE(params_.mode == psi::ypir::YpirMode::kDoublepir);
}

yacl::Buffer InspireClient::GeneratePksBuffer() const {
return yacl::Buffer();
}

std::string InspireClient::GeneratePksString() const { return {}; }

InspireQuery InspireClient::GenerateQuery(uint64_t raw_idx) const {
YACL_ENFORCE_LT(raw_idx, params_.NumItems());
return internal::GenerateQuery(raw_idx, params_, client_secrets_, *context_);
}

yacl::Buffer InspireClient::GenerateQueryBuffer(uint64_t raw_idx) const {
return SerializeQuery(GenerateQuery(raw_idx));
}

yacl::Buffer InspireClient::GenerateIndexQuery(uint64_t raw_idx) const {
return GenerateQueryBuffer(raw_idx);
}

std::string InspireClient::GenerateIndexQueryStr(uint64_t raw_idx) const {
auto buffer = GenerateQueryBuffer(raw_idx);
return std::string(static_cast<std::string_view>(buffer));
}

std::vector<uint8_t> InspireClient::DecodeResponse(
const InspireResponse& response, uint64_t raw_idx) const {
YACL_ENFORCE_LT(raw_idx, params_.NumItems());
return internal::RecoverResponse(response, params_, client_secrets_,
*context_);
}

std::vector<uint8_t> InspireClient::DecodeResponseBuffer(
const yacl::ByteContainerView& response_buffer, uint64_t raw_idx) const {
return DecodeResponse(DeserializeResponse(response_buffer), raw_idx);
}

std::vector<uint8_t> InspireClient::DecodeIndexResponse(
const yacl::ByteContainerView& response_buffer, uint64_t raw_idx) const {
return DecodeResponseBuffer(response_buffer, raw_idx);
}

} // namespace psi::inspire
Loading
Loading