Skip to content

Commit 5c9cfe4

Browse files
authored
Refactor service protos to allow 3 service types. (#11)
The service types: * PIR-only * PNNS-only * PIR and PNNS
1 parent 99f5353 commit 5c9cfe4

File tree

6 files changed

+189
-25
lines changed

6 files changed

+189
-25
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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.api.pir.v1;
17+
18+
import "apple/swift_homomorphic_encryption/api/pir/v1/pir.proto";
19+
import "apple/swift_homomorphic_encryption/api/shared/v1/api_shared.proto";
20+
21+
// Request for server side configurations.
22+
message ConfigRequest {
23+
// List of usecases to fetch configs for.
24+
// When set to empty array, all configs will be returned.
25+
repeated string usecases = 1;
26+
}
27+
28+
// Usecase configuration.
29+
message Config {
30+
// Configuration.
31+
oneof config {
32+
// Configuration for a PIR usecase.
33+
apple.swift_homomorphic_encryption.api.pir.v1.PIRConfig pir_config = 1;
34+
}
35+
reserved 2;
36+
// Unique identifier for the configuration.
37+
bytes config_id = 3;
38+
}
39+
40+
// Server side configurations.
41+
message ConfigResponse {
42+
// usecases with associated configurations.
43+
map<string, Config> configs = 1;
44+
// Configuration & status of evaluation keys.
45+
repeated apple.swift_homomorphic_encryption.api.shared.v1.KeyStatus key_info = 2;
46+
}
47+
48+
// Container for multiple requests.
49+
message Requests {
50+
// Requests.
51+
repeated Request requests = 1;
52+
}
53+
54+
// Container for multiple responses.
55+
message Responses {
56+
// Responses.
57+
repeated Response responses = 1;
58+
}
59+
60+
// Generic request.
61+
message Request {
62+
// Usecase identifier.
63+
string usecase = 1;
64+
// Generic request.
65+
oneof request {
66+
// PIR request.
67+
apple.swift_homomorphic_encryption.api.pir.v1.PIRRequest pir_request = 2;
68+
}
69+
reserved 3;
70+
}
71+
72+
// Generic response.
73+
message Response {
74+
// Generic response.
75+
oneof response {
76+
// Response to a `PIRRequest`.
77+
apple.swift_homomorphic_encryption.api.pir.v1.PIRResponse pir_response = 1;
78+
}
79+
reserved 2;
80+
}

apple/swift_homomorphic_encryption/api/v1/api_pir.proto apple/swift_homomorphic_encryption/api/pir/v1/pir.proto

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
// limitations under the License.
1414

1515
syntax = "proto3";
16-
package apple.swift_homomorphic_encryption.api.v1;
16+
package apple.swift_homomorphic_encryption.api.pir.v1;
1717

18-
import "apple/swift_homomorphic_encryption/api/v1/api_evaluation_key.proto";
18+
import "apple/swift_homomorphic_encryption/api/shared/v1/api_shared.proto";
1919
import "apple/swift_homomorphic_encryption/pir/v1/pir.proto";
2020
import "apple/swift_homomorphic_encryption/pir/v1/pir_algorithm.proto";
2121
import "apple/swift_homomorphic_encryption/v1/he.proto";
@@ -60,13 +60,13 @@ message PIRRequest {
6060
// Encrypted query.
6161
apple.swift_homomorphic_encryption.pir.v1.EncryptedIndices query = 2;
6262
// Evaluation key metadata.
63-
EvaluationKeyMetadata evaluation_key_metadata = 3;
63+
apple.swift_homomorphic_encryption.api.shared.v1.EvaluationKeyMetadata evaluation_key_metadata = 3;
6464
// Hash of the `PIRConfig` used to construct the query.
6565
bytes configuration_hash = 4;
6666
// If set, route request to a shard with this `shard_id` instead of `shard_index`.
6767
optional string shard_id = 5;
6868
// If set, evaluation key to query with. Will override evaluation key stored server-side.
69-
optional EvaluationKey evaluation_key = 6;
69+
optional apple.swift_homomorphic_encryption.api.shared.v1.EvaluationKey evaluation_key = 6;
7070
}
7171

7272
// PIR Response.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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.api.pnns.v1;
17+
18+
import "apple/swift_homomorphic_encryption/api/pnns/v1/pnns.proto";
19+
import "apple/swift_homomorphic_encryption/api/shared/v1/api_shared.proto";
20+
21+
// Request for server side configurations.
22+
message ConfigRequest {
23+
// List of usecases to fetch configs for.
24+
// When set to empty array, all configs will be returned.
25+
repeated string usecases = 1;
26+
}
27+
28+
// Usecase configuration.
29+
message Config {
30+
reserved 1;
31+
// Configuration.
32+
oneof config {
33+
// Configuration for a PNNS usecase.
34+
apple.swift_homomorphic_encryption.api.pnns.v1.PNNSConfig pnns_config = 2;
35+
}
36+
// Unique identifier for the configuration.
37+
bytes config_id = 3;
38+
}
39+
40+
// Server side configurations.
41+
message ConfigResponse {
42+
// usecases with associated configurations.
43+
map<string, Config> configs = 1;
44+
// Configuration & status of evaluation keys.
45+
repeated apple.swift_homomorphic_encryption.api.shared.v1.KeyStatus key_info = 2;
46+
}
47+
48+
// Container for multiple requests.
49+
message Requests {
50+
// Requests.
51+
repeated Request requests = 1;
52+
}
53+
54+
// Container for multiple responses.
55+
message Responses {
56+
// Responses.
57+
repeated Response responses = 1;
58+
}
59+
60+
// Generic request.
61+
message Request {
62+
// Usecase identifier.
63+
string usecase = 1;
64+
reserved 2;
65+
// Generic request.
66+
oneof request {
67+
// PNNS request.
68+
apple.swift_homomorphic_encryption.api.pnns.v1.PNNSRequest pnns_request = 3;
69+
}
70+
}
71+
72+
// Generic response.
73+
message Response {
74+
reserved 1;
75+
// Generic response.
76+
oneof response {
77+
// Response to a `PNNSRequest`.
78+
apple.swift_homomorphic_encryption.api.pnns.v1.PNNSResponse pnns_response = 2;
79+
}
80+
}

apple/swift_homomorphic_encryption/api/v1/api_pnns.proto apple/swift_homomorphic_encryption/api/pnns/v1/pnns.proto

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
// limitations under the License.
1414

1515
syntax = "proto3";
16-
package apple.swift_homomorphic_encryption.api.v1;
16+
package apple.swift_homomorphic_encryption.api.pnns.v1;
1717

18-
import "apple/swift_homomorphic_encryption/api/v1/api_evaluation_key.proto";
18+
import "apple/swift_homomorphic_encryption/api/shared/v1/api_shared.proto";
1919
import "apple/swift_homomorphic_encryption/pnns/v1/pnns.proto";
2020
import "apple/swift_homomorphic_encryption/pnns/v1/pnns_distance_metric.proto";
2121
import "apple/swift_homomorphic_encryption/pnns/v1/pnns_matrix_packing.proto";
@@ -47,11 +47,11 @@ message PNNSRequest {
4747
// Encrypted query, one per plaintext CRT component
4848
repeated apple.swift_homomorphic_encryption.pnns.v1.SerializedCiphertextMatrix query = 2;
4949
// Key metadata
50-
EvaluationKeyMetadata evaluation_key_metadata = 3;
50+
apple.swift_homomorphic_encryption.api.shared.v1.EvaluationKeyMetadata evaluation_key_metadata = 3;
5151
// Identifier for the PNNSConfig used to construct the query
5252
bytes config_id = 4;
5353
// If set, evaluation key to query with. Will override evaluation key stored server-side
54-
optional EvaluationKey evaluation_key = 5;
54+
optional apple.swift_homomorphic_encryption.api.shared.v1.EvaluationKey evaluation_key = 5;
5555
}
5656

5757
// PNNS Shard Response

apple/swift_homomorphic_encryption/api/v1/api_evaluation_key.proto apple/swift_homomorphic_encryption/api/shared/v1/api_shared.proto

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// limitations under the License.
1414

1515
syntax = "proto3";
16-
package apple.swift_homomorphic_encryption.api.v1;
16+
package apple.swift_homomorphic_encryption.api.shared.v1;
1717

1818
import "apple/swift_homomorphic_encryption/v1/he.proto";
1919

apple/swift_homomorphic_encryption/api/v1/api.proto

+20-16
Original file line numberDiff line numberDiff line change
@@ -15,34 +15,36 @@
1515
syntax = "proto3";
1616
package apple.swift_homomorphic_encryption.api.v1;
1717

18-
import "apple/swift_homomorphic_encryption/api/v1/api_evaluation_key.proto";
19-
import "apple/swift_homomorphic_encryption/api/v1/api_pir.proto";
20-
21-
// Request for server side configurations.
22-
message ConfigRequest {
23-
// List of usecases to fetch configs for.
24-
// When set to empty array, all configs will be returned.
25-
repeated string usecases = 1;
26-
}
18+
import "apple/swift_homomorphic_encryption/api/pir/v1/pir.proto";
19+
import "apple/swift_homomorphic_encryption/api/pnns/v1/pnns.proto";
20+
import "apple/swift_homomorphic_encryption/api/shared/v1/api_shared.proto";
2721

2822
// Usecase configuration.
2923
message Config {
3024
// Configuration.
3125
oneof config {
3226
// Configuration for a PIR usecase.
33-
PIRConfig pir_config = 1;
27+
apple.swift_homomorphic_encryption.api.pir.v1.PIRConfig pir_config = 1;
28+
// Configuration for a PNNS usecase.
29+
apple.swift_homomorphic_encryption.api.pnns.v1.PNNSConfig pnns_config = 2;
3430
}
35-
reserved 2;
3631
// Unique identifier for the configuration.
3732
bytes config_id = 3;
3833
}
3934

35+
// Request for server side configurations.
36+
message ConfigRequest {
37+
// List of usecases to fetch configs for.
38+
// When set to empty array, all configs will be returned.
39+
repeated string usecases = 1;
40+
}
41+
4042
// Server side configurations.
4143
message ConfigResponse {
4244
// usecases with associated configurations.
4345
map<string, Config> configs = 1;
4446
// Configuration & status of evaluation keys.
45-
repeated KeyStatus key_info = 2;
47+
repeated apple.swift_homomorphic_encryption.api.shared.v1.KeyStatus key_info = 2;
4648
}
4749

4850
// Container for multiple requests.
@@ -64,17 +66,19 @@ message Request {
6466
// Generic request.
6567
oneof request {
6668
// PIR request.
67-
PIRRequest pir_request = 2;
69+
apple.swift_homomorphic_encryption.api.pir.v1.PIRRequest pir_request = 2;
70+
// PNNS request.
71+
apple.swift_homomorphic_encryption.api.pnns.v1.PNNSRequest pnns_request = 3;
6872
}
69-
reserved 3;
7073
}
7174

7275
// Generic response.
7376
message Response {
7477
// Generic response.
7578
oneof response {
7679
// Response to a `PIRRequest`.
77-
PIRResponse pir_response = 1;
80+
apple.swift_homomorphic_encryption.api.pir.v1.PIRResponse pir_response = 1;
81+
// Response to a `PNNSRequest`.
82+
apple.swift_homomorphic_encryption.api.pnns.v1.PNNSResponse pnns_response = 2;
7883
}
79-
reserved 2;
8084
}

0 commit comments

Comments
 (0)