Skip to content
Merged
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
3 changes: 1 addition & 2 deletions .spi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ version: 1
builder:
configs:
- documentation_targets:
- ApplicationProtobuf
- HomomorphicEncryption
- HomomorphicEncryptionProtobuf
- PIRGenerateDatabase
Expand All @@ -10,7 +11,5 @@ builder:
- PNNSGenerateDatabase
- PNNSProcessDatabase
- PrivateInformationRetrieval
- PrivateInformationRetrievalProtobuf
- PrivateNearestNeighborSearch
- PrivateNearestNeighborSearchProtobuf
swift_version: 6.0
2 changes: 1 addition & 1 deletion Package.resolved

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

48 changes: 6 additions & 42 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,9 @@ let package = Package(
.library(
name: "PrivateInformationRetrieval",
targets: ["PrivateInformationRetrieval"]),
.library(
name: "PrivateInformationRetrievalProtobuf",
targets: ["PrivateInformationRetrievalProtobuf"]),
.library(
name: "PrivateNearestNeighborSearch",
targets: ["PrivateNearestNeighborSearch"]),
.library(
name: "PrivateNearestNeighborSearchProtobuf",
targets: ["PrivateNearestNeighborSearchProtobuf"]),
.library(name: "ApplicationProtobuf", targets: ["ApplicationProtobuf"]),
.library(name: "_TestUtilities", targets: ["_TestUtilities"]),
.executable(name: "PIRGenerateDatabase", targets: ["PIRGenerateDatabase"]),
Expand Down Expand Up @@ -109,14 +103,6 @@ let package = Package(
dependencies: ["HomomorphicEncryption",
.product(name: "Numerics", package: "swift-numerics")],
swiftSettings: librarySettings),
.target(
name: "PrivateInformationRetrievalProtobuf",
dependencies: ["PrivateInformationRetrieval",
"HomomorphicEncryption",
"HomomorphicEncryptionProtobuf",
.product(name: "SwiftProtobuf", package: "swift-protobuf")],
exclude: ["generated/README.md", "protobuf_module_mappings.txtpb"],
swiftSettings: librarySettings),
.target(
name: "PrivateNearestNeighborSearch",
dependencies: [
Expand All @@ -125,14 +111,6 @@ let package = Package(
"_HomomorphicEncryptionExtras",
],
swiftSettings: librarySettings),
.target(
name: "PrivateNearestNeighborSearchProtobuf",
dependencies: ["PrivateNearestNeighborSearch",
"HomomorphicEncryption",
"HomomorphicEncryptionProtobuf",
.product(name: "SwiftProtobuf", package: "swift-protobuf")],
exclude: ["generated/README.md", "protobuf_module_mappings.txtpb"],
swiftSettings: librarySettings),
.target(
name: "ApplicationProtobuf",
dependencies: ["HomomorphicEncryptionProtobuf",
Expand All @@ -156,15 +134,15 @@ let package = Package(
dependencies: [
.product(name: "ArgumentParser", package: "swift-argument-parser"),
"HomomorphicEncryption",
"PrivateInformationRetrievalProtobuf",
"ApplicationProtobuf",
],
swiftSettings: executableSettings),
.executableTarget(
name: "PIRProcessDatabase",
dependencies: [
.product(name: "ArgumentParser", package: "swift-argument-parser"),
"HomomorphicEncryptionProtobuf",
"PrivateInformationRetrievalProtobuf",
"ApplicationProtobuf",
"HomomorphicEncryption",
.product(name: "Logging", package: "swift-log"),
],
Expand All @@ -174,23 +152,23 @@ let package = Package(
dependencies: [
.product(name: "ArgumentParser", package: "swift-argument-parser"),
"HomomorphicEncryption",
"PrivateInformationRetrievalProtobuf",
"ApplicationProtobuf",
],
swiftSettings: executableSettings),
.executableTarget(
name: "PNNSGenerateDatabase",
dependencies: [
.product(name: "ArgumentParser", package: "swift-argument-parser"),
"HomomorphicEncryption",
"PrivateNearestNeighborSearchProtobuf",
"ApplicationProtobuf",
],
swiftSettings: executableSettings),
.executableTarget(
name: "PNNSProcessDatabase",
dependencies: [
.product(name: "ArgumentParser", package: "swift-argument-parser"),
"HomomorphicEncryptionProtobuf",
"PrivateNearestNeighborSearchProtobuf",
"ApplicationProtobuf",
"HomomorphicEncryption",
.product(name: "Logging", package: "swift-log"),
],
Expand Down Expand Up @@ -229,24 +207,11 @@ let package = Package(
"PrivateInformationRetrieval", "_TestUtilities",
.product(name: "Numerics", package: "swift-numerics"),
], swiftSettings: executableSettings),
.testTarget(
name: "PrivateInformationRetrievalProtobufTests",
dependencies: [
"PrivateInformationRetrieval",
"PrivateInformationRetrievalProtobuf",
"_TestUtilities",
], swiftSettings: executableSettings),
.testTarget(
name: "PrivateNearestNeighborSearchTests",
dependencies: [
"PrivateNearestNeighborSearch", "HomomorphicEncryption", "_TestUtilities",
], swiftSettings: executableSettings),
.testTarget(
name: "PrivateNearestNeighborSearchProtobufTests",
dependencies: [
"PrivateNearestNeighborSearch",
"PrivateNearestNeighborSearchProtobuf",
], swiftSettings: executableSettings),
.testTarget(
name: "ApplicationProtobufTests",
dependencies: [
Expand Down Expand Up @@ -282,9 +247,8 @@ if enableBenchmarking {
"HomomorphicEncryption",
"HomomorphicEncryptionProtobuf",
"PrivateInformationRetrieval",
"PrivateInformationRetrievalProtobuf",
"PrivateNearestNeighborSearch",
"PrivateNearestNeighborSearchProtobuf",
"ApplicationProtobuf",
],
swiftSettings: benchmarkSettings),
.executableTarget(
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ Swift Homomorphic Encryption is a collection of libraries and executables.
For more information, refer to documentation for the libraries:
* [HomomorphicEncryptionProtobuf](https://swiftpackageindex.com/apple/swift-homomorphic-encryption/main/documentation/homomorphicencryptionprotobuf)
* [HomomorphicEncryption](https://swiftpackageindex.com/apple/swift-homomorphic-encryption/main/documentation/homomorphicencryption)
* [PrivateInformationRetrievalProtobuf](https://swiftpackageindex.com/apple/swift-homomorphic-encryption/main/documentation/privateinformationretrievalprotobuf)
* [ApplicationProtobuf](https://swiftpackageindex.com/apple/swift-homomorphic-encryption/main/documentation/applicationprotobuf)
* [PrivateInformationRetrieval](https://swiftpackageindex.com/apple/swift-homomorphic-encryption/main/documentation/privateinformationretrieval)
* [PrivateNearestNeighborSearchProtobuf](https://swiftpackageindex.com/apple/swift-homomorphic-encryption/main/documentation/privatenearestneighborsearchprotobuf)
* [PrivateNearestNeighborSearch](https://swiftpackageindex.com/apple/swift-homomorphic-encryption/main/documentation/privatenearestneighborsearch)

and executables:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ Swift Homomorphic Encryption is a collection of libraries and executables implem
For more information, refer to documentation for the libraries:
* [HomomorphicEncryptionProtobuf](https://swiftpackageindex.com/apple/swift-homomorphic-encryption/main/documentation/homomorphicencryptionprotobuf)
* [HomomorphicEncryption](https://swiftpackageindex.com/apple/swift-homomorphic-encryption/main/documentation/homomorphicencryption)
* [PrivateInformationRetrievalProtobuf](https://swiftpackageindex.com/apple/swift-homomorphic-encryption/main/documentation/privateinformationretrievalprotobuf)
* [ApplicationProtobuf](https://swiftpackageindex.com/apple/swift-homomorphic-encryption/main/documentation/applicationprotobuf)
* [PrivateInformationRetrieval](https://swiftpackageindex.com/apple/swift-homomorphic-encryption/main/documentation/privateinformationretrieval)
* [PrivateNearestNeighborSearchProtobuf](https://swiftpackageindex.com/apple/swift-homomorphic-encryption/main/documentation/privatenearestneighborsearchprotobuf)
* [PrivateNearestNeighborSearch](https://swiftpackageindex.com/apple/swift-homomorphic-encryption/main/documentation/privatenearestneighborsearch)

and executables:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ PIRGenerateDatabase \

This will generate a database of 100 rows, with keywords 0 to 99, and each value repeating the keyword for 10 to 20 bytes.

The database is a serialized [Apple_SwiftHomomorphicEncryption_Pir_V1_KeywordDatabase](https://swiftpackageindex.com/apple/swift-homomorphic-encryption/main/documentation/privateinformationretrievalprotobuf/apple_swifthomomorphicencryption_pir_v1_keyworddatabase).
The database is a serialized [Apple_SwiftHomomorphicEncryption_Pir_V1_KeywordDatabase](https://swiftpackageindex.com/apple/swift-homomorphic-encryption/main/documentation/applicationprotobuf/apple_swifthomomorphicencryption_pir_v1_keyworddatabase).
For readability, the `.txtpb` extension ensures the output database will be saved in protocol buffer text format.

> Note: For a more compact format, use the `.binpb` extension to save the database in protocol buffer binary format.
Expand Down
2 changes: 1 addition & 1 deletion Sources/PIRGenerateDatabase/main.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 ArgumentParser
import Foundation
import HomomorphicEncryption
import PrivateInformationRetrieval
import PrivateInformationRetrievalProtobuf

enum ValueTypeArguments: String, CaseIterable, ExpressibleByArgument {
case random
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ There are four required parameters:
1. `rlweParameters` is one of the [PredefinedRlweParameters](https://swiftpackageindex.com/apple/swift-homomorphic-encryption/main/documentation/homomorphicencryption/predefinedrlweparameters),
e.g., `n_4096_logq_27_28_28_logt_5`.
2. `inputDatabase` is the path to the unprocessed input database. It must be a
serialized [Apple_SwiftHomomorphicEncryption_Pir_V1_KeywordDatabase](https://swiftpackageindex.com/apple/swift-homomorphic-encryption/main/documentation/privateinformationretrievalprotobuf/apple_swifthomomorphicencryption_pir_v1_keyworddatabase).
serialized [Apple_SwiftHomomorphicEncryption_Pir_V1_KeywordDatabase](https://swiftpackageindex.com/apple/swift-homomorphic-encryption/main/documentation/applicationprotobuf/apple_swifthomomorphicencryption_pir_v1_keyworddatabase).

> Note: The [PIRGenerateDatabase](https://swiftpackageindex.com/apple/swift-homomorphic-encryption/main/documentation/pirgeneratedatabase) binary can be used to generate a sample database.

Expand Down
5 changes: 2 additions & 3 deletions Sources/PIRProcessDatabase/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import ApplicationProtobuf
import ArgumentParser
import Crypto
import Foundation
import HomomorphicEncryption
import HomomorphicEncryptionProtobuf
import Logging
import PrivateInformationRetrieval
import PrivateInformationRetrievalProtobuf

/// The different table sizes that can be used for the PIR database.
enum TableSizeOption: Codable, Equatable, Hashable {
Expand Down Expand Up @@ -561,8 +561,7 @@ extension ProcessKeywordDatabase.ShardValidationResult {
descriptionDict["evaluation key size"] = try sizeString(
byteCount: evaluationKey.size(),
count: evaluationKey.config.keyCount,
label: "keys"
)
label: "keys")
descriptionDict["response size"] = try sizeString(byteCount: response.size(),
count: response.ciphertexts.flatMap(\.self).count,
label: "ciphertexts")
Expand Down
2 changes: 1 addition & 1 deletion Sources/PIRShardDatabase/ShardDatabase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import ApplicationProtobuf
import ArgumentParser
import HomomorphicEncryption
import PrivateInformationRetrieval
import PrivateInformationRetrievalProtobuf

extension KeywordDatabaseShard {
func save(to path: String) throws {
Expand Down
2 changes: 1 addition & 1 deletion Sources/PNNSGenerateDatabase/GenerateDatabase.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 ArgumentParser
import Foundation
import HomomorphicEncryption
import PrivateNearestNeighborSearch
import PrivateNearestNeighborSearchProtobuf

enum VectorTypeArguments: String, CaseIterable, ExpressibleByArgument {
/// Each vector's entry is uniform random from `[-1.0, 1.0]`
Expand Down
19 changes: 2 additions & 17 deletions Sources/PNNSProcessDatabase/ProcessDatabase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//// Copyright 2024 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.
//// You may obtain a copy of the License at
////
//// http://www.apache.org/licenses/LICENSE-2.0
////
//// Unless required by applicable law or agreed to in writing, software
//// distributed under the License is distributed on an "AS IS" BASIS,
//// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//// See the License for the specific language governing permissions and
//// limitations under the License.
//
import ApplicationProtobuf
import ArgumentParser
import Foundation
import HomomorphicEncryption
import Logging
import PrivateNearestNeighborSearch
import PrivateNearestNeighborSearchProtobuf

/// Creates a new `Database` from a given path.
/// - Parameter path: The path to the `Database` file.
Expand Down Expand Up @@ -306,8 +292,7 @@ extension ValidationResult {
descriptionDict["evaluation key size"] = try sizeString(
byteCount: evaluationKey.size(),
count: evaluationKey.config.keyCount,
label: "keys"
)
label: "keys")

let responseCount: Int = response.ciphertextMatrices.map { matrix in matrix.ciphertexts.count }.sum()
descriptionDict["response size"] = try sizeString(byteCount: response.size(), count: responseCount,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ To encode as fast as possible, one could have multiple nodes that shard slices o
nodes will collect the rows from the sharding nodes. Once the whole dataset has been divided into shards, each node
holding a completed shard worth of rows can start processing them. Each node will upload the processed shard & the
resulting PIR parameters to shared storage. A post-processing job can merge all the PIR parameters to construct a
[PIRConfig](https://swiftpackageindex.com/apple/swift-homomorphic-encryption/main/documentation/privateinformationretrievalprotobuf/apple_swifthomomorphicencryption_api_v1_pirconfig)
[PIRConfig](https://swiftpackageindex.com/apple/swift-homomorphic-encryption/main/documentation/applicationprotobuf/apple_swifthomomorphicencryption_api_v1_pirconfig)
protobuf message that contains a shared evaluation key configuration and configuration for every shard.

## Sharding function
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Supported values are:

##### Configuration size
Generally, increasing the `shardCount` will yield faster server runtime.
However, since the client needs to know information about each shard, increasing `shardCount` also increases the size of the [PIR configuration](https://swiftpackageindex.com/apple/swift-homomorphic-encryption/main/documentation/privateinformationretrievalprotobuf/apple_swifthomomorphicencryption_api_pir_v1_pirconfig).
However, since the client needs to know information about each shard, increasing `shardCount` also increases the size of the [PIR configuration](https://swiftpackageindex.com/apple/swift-homomorphic-encryption/main/documentation/applicationprotobuf/apple_swifthomomorphicencryption_api_pir_v1_pirconfig).
One way to reduce the PIR configuration size is to process each shard with the same configuration (see <doc:ReusingPirParameters>).
Then, the PIR configuration will be highly compressible, yielding a smaller configuration size when transmitting over a network (that supports compression).

Expand Down
Loading
Loading