Skip to content

Commit 25e8161

Browse files
authored
Add protos for PrivateNearestNeighborsSearch (#8)
1 parent ad851b0 commit 25e8161

7 files changed

+235
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright 2024 Apple Inc. and the Swift Homomorphic Encryption project authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
syntax = "proto3";
16+
package apple.swift_homomorphic_encryption.pnns.v1;
17+
18+
import "apple/swift_homomorphic_encryption/pnns/v1/pnns_matrix_packing.proto";
19+
import "apple/swift_homomorphic_encryption/v1/he.proto";
20+
21+
// Stores a matrix of encrypted values in a serialized ciphertext for use in linear algebra
22+
// operations
23+
message SerializedCiphertextMatrix {
24+
// Number of data rows stored in the ciphertext.
25+
uint32 num_rows = 1;
26+
// Number of data columns stored in the ciphertext.
27+
uint32 num_columns = 2;
28+
// Stores the encrypted data.
29+
repeated apple.swift_homomorphic_encryption.v1.SerializedCiphertext ciphertexts = 3;
30+
// Packing algorithm for the plaintext data.
31+
MatrixPacking packing = 4;
32+
}
33+
34+
// Serialized plaintext matrix
35+
message SerializedPlaintextMatrix {
36+
// Number of rows in the data encoded in the plaintext matrix.
37+
uint32 num_rows = 1;
38+
// Number of columns in the data encoded in the plaintext matrix.
39+
uint32 num_columns = 2;
40+
// Encoded values.
41+
repeated apple.swift_homomorphic_encryption.v1.SerializedPlaintext plaintexts = 3;
42+
// Plaintext packing.
43+
MatrixPacking packing = 4;
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright 2024 Apple Inc. and the Swift Homomorphic Encryption project authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
syntax = "proto3";
16+
package apple.swift_homomorphic_encryption.pnns.v1;
17+
18+
import "apple/swift_homomorphic_encryption/pnns/v1/pnns_distance_metric.proto";
19+
import "apple/swift_homomorphic_encryption/pnns/v1/pnns_matrix_packing.proto";
20+
import "apple/swift_homomorphic_encryption/v1/he.proto";
21+
22+
// The client configuration.
23+
message ClientConfig {
24+
// Encryption parameters.
25+
apple.swift_homomorphic_encryption.v1.EncryptionParameters encryption_parameters = 1;
26+
// Factor by which to scale floating-point entries before rounding to integers.
27+
uint64 scaling_factor = 2;
28+
// Packing for the query.
29+
MatrixPacking query_packing = 3;
30+
// Number of entries in each vector.
31+
uint32 vector_dimension = 4;
32+
// Galois elements required for nearest neighbors computation.
33+
repeated uint32 galois_elements = 5;
34+
// Metric for distances between vectors.
35+
DistanceMetric distance_metric = 6;
36+
// For plaintext CRT, the list of extra plaintext moduli.
37+
// The first plaintext modulus will be the one in `encryption_parameters`.
38+
repeated uint64 extra_plaintext_moduli = 7;
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright 2024 Apple Inc. and the Swift Homomorphic Encryption project authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
syntax = "proto3";
16+
package apple.swift_homomorphic_encryption.pnns.v1;
17+
18+
// Row in a private nearest neighbors search database.
19+
message DatabaseRow {
20+
// Unique identifier for the database entry.
21+
uint64 entry_id = 1;
22+
// Metadata associated with the entry.
23+
bytes entry_metadata = 2;
24+
// Vector for use in nearest neighbors computation.
25+
repeated float vector = 3;
26+
}
27+
28+
// A private nearest neighbors search database.
29+
message Database {
30+
// Rows in the database.
31+
repeated DatabaseRow rows = 1;
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2024 Apple Inc. and the Swift Homomorphic Encryption project authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
syntax = "proto3";
16+
package apple.swift_homomorphic_encryption.pnns.v1;
17+
18+
// Metric for distances between vectors.
19+
enum DistanceMetric {
20+
// Cosine similarity.
21+
DISTANCE_METRIC_COSINE_SIMILARITY = 0;
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Copyright 2024 Apple Inc. and the Swift Homomorphic Encryption project authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
syntax = "proto3";
16+
package apple.swift_homomorphic_encryption.pnns.v1;
17+
18+
// Pre-computed values for matrix-vector multiplication using baby-step, giant-step algorithm.
19+
// See Section 6.3 of <https://eprint.iacr.org/2018/244.pdf>.
20+
message BabyStepGiantStep {
21+
// Dimension of the vector; "D" in the reference.
22+
uint32 vector_dimension = 1;
23+
// Baby step; "g" in the reference.
24+
uint32 baby_step = 2;
25+
// Giant step; "h" in the reference.
26+
uint32 giant_step = 3;
27+
}
28+
29+
// Different algorithms for packing a matrix of scalar values into plaintexts / ciphertexts.
30+
message MatrixPacking {
31+
// Different packing formats.
32+
oneof plaintext_packing_type {
33+
// Dense row packing.
34+
MatrixPackingDenseRow dense_row = 1;
35+
36+
/// Packs the values using a generalized diagonal packing.
37+
///
38+
/// Includes modifications for the baby-step, giant-step algorithm from Section 6.3 of
39+
/// <https://eprint.iacr.org/2018/244.pdf>.
40+
MatrixPackingDiagonal diagonal = 2;
41+
42+
/// As many rows of data are packed sequentially into each SIMD plaintext
43+
/// row as possible, such that no data row is split across multiple SIMD rows, and
44+
/// each data row is zero-padded to the next power of two length.
45+
/// The rows in the final plaintext are repeated as many times as possible within the plaintext,
46+
/// with the constraint that either all or none of the entries stored within the last plaintext
47+
/// row are repeated.
48+
MatrixPackingDenseColumn dense_column = 3;
49+
}
50+
}
51+
52+
// As many rows of data are packed sequentially into each SIMD row as possible,
53+
// such that no data row is split across multiple SIMD rows, and
54+
// each data row is zero-padded to the next power of two length.
55+
// The rows in the final plaintext/ciphertext are repeated as many times as possible within the plaintext/ciphertext,
56+
// with the constraint that either all or none of the entries stored within the last plaintext/ciphertext
57+
// row are repeated.
58+
message MatrixPackingDenseRow {}
59+
60+
// Packs the values using a generalized diagonal packing.
61+
message MatrixPackingDiagonal {
62+
reserved 1;
63+
// Diagonals are rotated according to the baby-step, giant-step algorithm from Section 6.3 of <https://eprint.iacr.org/2018/244.pdf>.
64+
BabyStepGiantStep baby_step_giant_step = 2;
65+
}
66+
67+
// As many columns of data are packed sequentially into each SIMD row as possible, such that no SIMD row
68+
// contains data from multiple columns.
69+
message MatrixPackingDenseColumn {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2024 Apple Inc. and the Swift Homomorphic Encryption project authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
syntax = "proto3";
16+
package apple.swift_homomorphic_encryption.pnns.v1;
17+
18+
import "apple/swift_homomorphic_encryption/pnns/v1/pnns_client_config.proto";
19+
import "apple/swift_homomorphic_encryption/pnns/v1/pnns_matrix_packing.proto";
20+
21+
// The server configuration.
22+
message ServerConfig {
23+
// Configuration shared with the client.
24+
ClientConfig client_config = 1;
25+
// Packing for the plaintext database.
26+
MatrixPacking database_packing = 2;
27+
reserved 3, 4;
28+
}

buf.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@ lint:
2626
ignore_only:
2727
ENUM_ZERO_VALUE_SUFFIX:
2828
- apple/swift_homomorphic_encryption/pir/v1/pir_algorithm.proto
29+
- apple/swift_homomorphic_encryption/pnns/v1/pnns_distance_metric.proto
2930
- apple/swift_homomorphic_encryption/v1/error_stddev.proto

0 commit comments

Comments
 (0)