Skip to content
Draft
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
4 changes: 2 additions & 2 deletions Package.resolved

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

6 changes: 3 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ let package = Package(
.product(name: "HomomorphicEncryptionProtobuf", package: "swift-homomorphic-encryption"),
.product(name: "Hummingbird", package: "hummingbird"),
.product(name: "HummingbirdCompression", package: "hummingbird-compression"),
.product(name: "PrivateInformationRetrievalProtobuf", package: "swift-homomorphic-encryption"),
.product(name: "ApplicationProtobuf", package: "swift-homomorphic-encryption"),
.product(name: "ServiceLifecycle", package: "swift-service-lifecycle"),
.product(name: "UnixSignals", package: "swift-service-lifecycle"),
],
Expand All @@ -68,7 +68,7 @@ let package = Package(
name: "ConstructDatabase",
dependencies: [
.product(name: "ArgumentParser", package: "swift-argument-parser"),
.product(name: "PrivateInformationRetrievalProtobuf", package: "swift-homomorphic-encryption"),
.product(name: "ApplicationProtobuf", package: "swift-homomorphic-encryption"),
.product(name: "SwiftProtobuf", package: "swift-protobuf"),
],
exclude: ["protobuf"],
Expand Down Expand Up @@ -101,7 +101,7 @@ let package = Package(
"PrivacyPass", "Util",
.product(name: "HomomorphicEncryptionProtobuf", package: "swift-homomorphic-encryption"),
.product(name: "HummingbirdTesting", package: "hummingbird"),
.product(name: "PrivateInformationRetrievalProtobuf", package: "swift-homomorphic-encryption"),
.product(name: "ApplicationProtobuf", package: "swift-homomorphic-encryption"),
],
swiftSettings: swiftSettings),
.testTarget(
Expand Down
4 changes: 2 additions & 2 deletions Sources/ConstructDatabase/ConstructDatabase.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 Apple Inc. and the Swift Homomorphic Encryption project authors
// Copyright 2024-2025 Apple Inc. and the Swift Homomorphic Encryption project authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -12,9 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import ApplicationProtobuf
import ArgumentParser
import Foundation
import PrivateInformationRetrievalProtobuf
import SwiftProtobuf

let discussion =
Expand Down
16 changes: 9 additions & 7 deletions Sources/PIRService/Controllers/PIRServiceController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import ApplicationProtobuf
import Foundation
import HomomorphicEncryptionProtobuf
import Hummingbird
import HummingbirdCompression
import PrivateInformationRetrievalProtobuf
import Util

struct PIRServiceController {
Expand Down Expand Up @@ -57,7 +57,7 @@ struct PIRServiceController {
func config(_ request: Request, context: AppContext) async throws -> some ResponseGenerator {
context.logger.info("Tier = \(context.userTier)")
let configRequest = try await request.decodeProto(
as: Apple_SwiftHomomorphicEncryption_Api_Pir_V1_ConfigRequest.self,
as: Apple_SwiftHomomorphicEncryption_Api_V1_ConfigRequest.self,
context: context)
let requestedUsecases = if configRequest.usecases.isEmpty {
await usecases.getAll()
Expand All @@ -77,7 +77,7 @@ struct PIRServiceController {
let existingConfigIds = configRequest.existingConfigIds.isEmpty ? Array(
repeating: Data(),
count: requestedUsecases.count) : configRequest.existingConfigIds
var configs = [String: Apple_SwiftHomomorphicEncryption_Api_Pir_V1_Config]()
var configs = [String: Apple_SwiftHomomorphicEncryption_Api_V1_Config]()
for (usecaseName, configId) in zip(requestedUsecases.keys, existingConfigIds) {
if let usecase = requestedUsecases[usecaseName] {
var config = try usecase.config(existingConfigId: Array(configId))
Expand All @@ -104,7 +104,7 @@ struct PIRServiceController {

let keyStatuses: [Apple_SwiftHomomorphicEncryption_Api_Shared_V1_KeyStatus] =
try await .init(keyStatusesSequence)
return Protobuf(Apple_SwiftHomomorphicEncryption_Api_Pir_V1_ConfigResponse.with { configResponse in
return Protobuf(Apple_SwiftHomomorphicEncryption_Api_V1_ConfigResponse.with { configResponse in
configResponse.configs = configs
configResponse.keyInfo = keyStatuses
})
Expand All @@ -114,7 +114,7 @@ struct PIRServiceController {
func queries(_ request: Request, context: AppContext) async throws -> some ResponseGenerator {
let startTime = Date.now
let requests = try await request.decodeProto(
as: Apple_SwiftHomomorphicEncryption_Api_Pir_V1_Requests.self,
as: Apple_SwiftHomomorphicEncryption_Api_V1_Requests.self,
context: context)

defer {
Expand Down Expand Up @@ -158,12 +158,14 @@ struct PIRServiceController {
throw HTTPError(.badRequest, message: "Unknown usecase: \(request.usecase)")
}
return try await usecase.process(request: request, evaluationKey: evaluationKey)
case .some(.pnnsRequest):
throw HTTPError(.badRequest, message: "Unknown request type.")
case .none:
throw HTTPError(.badRequest, message: "Unknown request type.")
}
}
let responses: [Apple_SwiftHomomorphicEncryption_Api_Pir_V1_Response] = try await .init(responsesSequence)
return Protobuf(Apple_SwiftHomomorphicEncryption_Api_Pir_V1_Responses.with { apiResponses in
let responses: [Apple_SwiftHomomorphicEncryption_Api_V1_Response] = try await .init(responsesSequence)
return Protobuf(Apple_SwiftHomomorphicEncryption_Api_V1_Responses.with { apiResponses in
apiResponses.responses = responses
})
}
Expand Down
16 changes: 8 additions & 8 deletions Sources/PIRService/Controllers/PirUsecase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import ApplicationProtobuf
import Foundation
import HomomorphicEncryption
import HomomorphicEncryptionProtobuf
import Hummingbird
import PrivateInformationRetrieval
import PrivateInformationRetrievalProtobuf
import Util

enum LoadingError: Error {
Expand Down Expand Up @@ -100,9 +100,9 @@ struct PirUsecase<PirScheme: IndexPirServer>: Usecase {
@_specialize(where PirScheme == MulPirServer<Bfv<UInt32>>)
@_specialize(where PirScheme == MulPirServer<Bfv<UInt64>>)
func process(
request: Apple_SwiftHomomorphicEncryption_Api_Pir_V1_Request,
request: Apple_SwiftHomomorphicEncryption_Api_V1_Request,
evaluationKey: Apple_SwiftHomomorphicEncryption_Api_Shared_V1_EvaluationKey) async throws
-> Apple_SwiftHomomorphicEncryption_Api_Pir_V1_Response
-> Apple_SwiftHomomorphicEncryption_Api_V1_Response
{
let pirRequest = request.pirRequest
guard !pirRequest.hasShardID else {
Expand All @@ -112,12 +112,12 @@ struct PirUsecase<PirScheme: IndexPirServer>: Usecase {
let query: KeywordPirServer<PirScheme>.Query = try pirRequest.query.native(context: context)
let evaluationKey: EvaluationKey<Scheme> = try evaluationKey.evaluationKey.native(context: context)
let response = try shard.computeResponse(to: query, using: evaluationKey)
return try Apple_SwiftHomomorphicEncryption_Api_Pir_V1_Response.with { apiResponse in
return try Apple_SwiftHomomorphicEncryption_Api_V1_Response.with { apiResponse in
apiResponse.pirResponse = try response.proto()
}
}

func config() throws -> Apple_SwiftHomomorphicEncryption_Api_Pir_V1_Config {
func config() throws -> Apple_SwiftHomomorphicEncryption_Api_V1_Config {
var pirConfig = Apple_SwiftHomomorphicEncryption_Api_Pir_V1_PIRConfig()
pirConfig.encryptionParameters = try context.encryptionParameters.proto()
guard let firstShard = shards.first else {
Expand Down Expand Up @@ -146,7 +146,7 @@ struct PirUsecase<PirScheme: IndexPirServer>: Usecase {
pirConfig.shardConfigs = []
}

return try Apple_SwiftHomomorphicEncryption_Api_Pir_V1_Config.with { config in
return try Apple_SwiftHomomorphicEncryption_Api_V1_Config.with { config in
config.pirConfig = pirConfig
config.configID = try pirConfig.sha256()
}
Expand All @@ -159,14 +159,14 @@ struct PirUsecase<PirScheme: IndexPirServer>: Usecase {
@_specialize(where PirScheme == MulPirServer<Bfv<UInt32>>)
@_specialize(where PirScheme == MulPirServer<Bfv<UInt64>>)
func processOprf(request: Apple_SwiftHomomorphicEncryption_Api_Pir_V1_OPRFRequest) async throws ->
Apple_SwiftHomomorphicEncryption_Api_Pir_V1_Response
Apple_SwiftHomomorphicEncryption_Api_V1_Response
{
guard let symmetricPirConfig else {
throw SymmetricPirError.symmetricPirNotConfigured
}
let oprfResponse = try OprfServer(symmetricPirConfig: symmetricPirConfig).computeResponse(
query: request.native())
return Apple_SwiftHomomorphicEncryption_Api_Pir_V1_Response.with { apiResponse in
return Apple_SwiftHomomorphicEncryption_Api_V1_Response.with { apiResponse in
apiResponse.oprfResponse = oprfResponse.proto()
}
}
Expand Down
16 changes: 8 additions & 8 deletions Sources/PIRService/Controllers/Usecase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,31 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import ApplicationProtobuf
import HomomorphicEncryptionProtobuf
import PrivateInformationRetrievalProtobuf
import Util

protocol Usecase: Sendable {
/// Returns the configuration.
///
/// Note: may use features that are not compatible with older platforms.
/// ``PrivateInformationRetrievalProtobuf/Apple_SwiftHomomorphicEncryption_Api_Pir_V1_Config/makeCompatible(with:)``
/// ``ApplicationProtobuf/Apple_SwiftHomomorphicEncryption_Api_V1_Config/makeCompatible(with:)``
/// can be used to make the configuration compatible with older platforms.
func config() throws -> Apple_SwiftHomomorphicEncryption_Api_Pir_V1_Config
func config() throws -> Apple_SwiftHomomorphicEncryption_Api_V1_Config
func evaluationKeyConfig() throws -> Apple_SwiftHomomorphicEncryption_V1_EvaluationKeyConfig
func process(
request: Apple_SwiftHomomorphicEncryption_Api_Pir_V1_Request,
request: Apple_SwiftHomomorphicEncryption_Api_V1_Request,
evaluationKey: Apple_SwiftHomomorphicEncryption_Api_Shared_V1_EvaluationKey) async throws
-> Apple_SwiftHomomorphicEncryption_Api_Pir_V1_Response
-> Apple_SwiftHomomorphicEncryption_Api_V1_Response
func processOprf(request: Apple_SwiftHomomorphicEncryption_Api_Pir_V1_OPRFRequest) async throws
-> Apple_SwiftHomomorphicEncryption_Api_Pir_V1_Response
-> Apple_SwiftHomomorphicEncryption_Api_V1_Response
}

extension Usecase {
func config(existingConfigId: [UInt8]) throws -> Apple_SwiftHomomorphicEncryption_Api_Pir_V1_Config {
func config(existingConfigId: [UInt8]) throws -> Apple_SwiftHomomorphicEncryption_Api_V1_Config {
let config = try config()
if Array(config.configID) == existingConfigId {
return Apple_SwiftHomomorphicEncryption_Api_Pir_V1_Config.with { apiConfig in
return Apple_SwiftHomomorphicEncryption_Api_V1_Config.with { apiConfig in
apiConfig.reuseExistingConfig = true
}
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/PIRService/Extensions/PirConfig+compatible.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import ApplicationProtobuf
import Hummingbird
import PrivateInformationRetrievalProtobuf
import Util

extension Platform {
Expand All @@ -40,7 +40,7 @@ extension Platform {
}
}

public extension Apple_SwiftHomomorphicEncryption_Api_Pir_V1_Config {
public extension Apple_SwiftHomomorphicEncryption_Api_V1_Config {
/// Makes the configuration compatible with the given platform.
/// - Parameter platform: Device platform.
mutating func makeCompatible(with platform: Platform) throws {
Expand Down
8 changes: 4 additions & 4 deletions Sources/PIRServiceTesting/PIRClient+KeyRotation.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 Apple Inc. and the Swift Homomorphic Encryption project authors
// Copyright 2024-2025 Apple Inc. and the Swift Homomorphic Encryption project authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -12,22 +12,22 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import ApplicationProtobuf
import Foundation
import HomomorphicEncryption
import PrivateInformationRetrieval
import PrivateInformationRetrievalProtobuf
import SwiftProtobuf

extension PIRClient {
mutating func fetchKeyStatus(for usecase: String) async throws
-> Apple_SwiftHomomorphicEncryption_Api_Shared_V1_KeyStatus
{
let configRequest = Apple_SwiftHomomorphicEncryption_Api_Pir_V1_ConfigRequest.with { configRequest in
let configRequest = Apple_SwiftHomomorphicEncryption_Api_V1_ConfigRequest.with { configRequest in
configRequest.usecases = [usecase]
configRequest.existingConfigIds = [configCache[usecase]?.configurationId ?? Data()]
}

let configResponse: Apple_SwiftHomomorphicEncryption_Api_Pir_V1_ConfigResponse = try await post(
let configResponse: Apple_SwiftHomomorphicEncryption_Api_V1_ConfigResponse = try await post(
path: "/config",
body: configRequest)
guard let config = configResponse.configs[usecase] else {
Expand Down
14 changes: 7 additions & 7 deletions Sources/PIRServiceTesting/PIRClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import ApplicationProtobuf
import Foundation
import HomomorphicEncryption
import HTTPTypes
import HummingbirdTesting
import PrivacyPass
import PrivateInformationRetrieval
import PrivateInformationRetrievalProtobuf
import SwiftProtobuf
import Util

Expand Down Expand Up @@ -152,16 +152,16 @@ public struct PIRClient<PIRClient: IndexPirClient> {
}
}

let requests = Apple_SwiftHomomorphicEncryption_Api_Pir_V1_Requests.with { requests in
let requests = Apple_SwiftHomomorphicEncryption_Api_V1_Requests.with { requests in
requests.requests = pirRequests.map { pirRequest in
Apple_SwiftHomomorphicEncryption_Api_Pir_V1_Request.with { request in
Apple_SwiftHomomorphicEncryption_Api_V1_Request.with { request in
request.usecase = usecase
request.pirRequest = pirRequest
}
}
}

let responses: Apple_SwiftHomomorphicEncryption_Api_Pir_V1_Responses = try await post(
let responses: Apple_SwiftHomomorphicEncryption_Api_V1_Responses = try await post(
path: "/queries",
body: requests)

Expand Down Expand Up @@ -203,15 +203,15 @@ public struct PIRClient<PIRClient: IndexPirClient> {
let oprfQueryContexts: [OprfQueryContext] = try keywords.map { keyword in
try oprfClient.queryContext(at: keyword)
}
let requests = Apple_SwiftHomomorphicEncryption_Api_Pir_V1_Requests.with { requests in
let requests = Apple_SwiftHomomorphicEncryption_Api_V1_Requests.with { requests in
requests.requests = oprfQueryContexts.map { queryContext in
Apple_SwiftHomomorphicEncryption_Api_Pir_V1_Request.with { request in
Apple_SwiftHomomorphicEncryption_Api_V1_Request.with { request in
request.usecase = usecase
request.oprfRequest = queryContext.query.proto()
}
}
}
let responses: Apple_SwiftHomomorphicEncryption_Api_Pir_V1_Responses = try await post(
let responses: Apple_SwiftHomomorphicEncryption_Api_V1_Responses = try await post(
path: "/queries",
body: requests)
let parsedOprfResponses: [OprfClient.ParsedOprfOutput] = try zip(responses.responses, oprfQueryContexts)
Expand Down
4 changes: 2 additions & 2 deletions Sources/PIRServiceTesting/PIRConfig+ShardConfig.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 Apple Inc. and the Swift Homomorphic Encryption project authors
// Copyright 2024-2025 Apple Inc. and the Swift Homomorphic Encryption project authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import ApplicationProtobuf
import PrivateInformationRetrieval
import PrivateInformationRetrievalProtobuf
import Util

public extension Apple_SwiftHomomorphicEncryption_Api_Pir_V1_PIRConfig {
Expand Down
Loading