Skip to content

Commit 24b4be2

Browse files
schoppmpdpf-team-bot
authored andcommitted
Add interface for two-party key generation protocol
PiperOrigin-RevId: 533501605
1 parent b20bc9d commit 24b4be2

File tree

5 files changed

+336
-0
lines changed

5 files changed

+336
-0
lines changed

dpf/key_generation_protocol/BUILD

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Copyright 2023 Google LLC
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+
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
16+
load("@rules_cc//cc:defs.bzl", "cc_library")
17+
load("@rules_proto//proto:defs.bzl", "proto_library")
18+
19+
package(
20+
default_visibility = ["//visibility:public"],
21+
)
22+
23+
cc_library(
24+
name = "key_generation_protocol",
25+
srcs = ["key_generation_protocol.cc"],
26+
hdrs = ["key_generation_protocol.h"],
27+
deps = [
28+
":key_generation_protocol_cc_proto",
29+
"//dpf:distributed_point_function",
30+
"//dpf:distributed_point_function_cc_proto",
31+
"//dpf:status_macros",
32+
"@com_google_absl//absl/memory",
33+
"@com_google_absl//absl/numeric:int128",
34+
"@com_google_absl//absl/status",
35+
"@com_google_absl//absl/status:statusor",
36+
],
37+
)
38+
39+
cc_test(
40+
name = "key_generation_protocol_test",
41+
srcs = ["key_generation_protocol_test.cc"],
42+
deps = [
43+
":key_generation_protocol",
44+
"//dpf:distributed_point_function_cc_proto",
45+
"//dpf/internal:status_matchers",
46+
"@com_github_google_googletest//:gtest_main",
47+
],
48+
)
49+
50+
cc_proto_library(
51+
name = "key_generation_protocol_cc_proto",
52+
deps = [":key_generation_protocol_proto"],
53+
)
54+
55+
proto_library(
56+
name = "key_generation_protocol_proto",
57+
srcs = ["key_generation_protocol.proto"],
58+
deps = ["//dpf:distributed_point_function_proto"],
59+
)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright 2023 Google LLC
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+
#include "dpf/key_generation_protocol/key_generation_protocol.h"
16+
17+
#include "absl/memory/memory.h"
18+
#include "absl/status/status.h"
19+
#include "dpf/distributed_point_function.h"
20+
#include "dpf/status_macros.h"
21+
22+
namespace distributed_point_functions {
23+
24+
KeyGenerationProtocol::KeyGenerationProtocol(
25+
std::unique_ptr<DistributedPointFunction> dpf, int party)
26+
: dpf_(std::move(dpf)), party_(party) {}
27+
28+
absl::StatusOr<std::unique_ptr<KeyGenerationProtocol>>
29+
KeyGenerationProtocol::Create(absl::Span<const DpfParameters> parameters,
30+
int party) {
31+
if (party != 0 && party != 1) {
32+
return absl::InvalidArgumentError("`party` must be 0 or 1");
33+
}
34+
DPF_ASSIGN_OR_RETURN(auto dpf,
35+
DistributedPointFunction::CreateIncremental(parameters));
36+
return absl::WrapUnique(new KeyGenerationProtocol(std::move(dpf), party));
37+
}
38+
39+
} // namespace distributed_point_functions
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
/*
2+
* Copyright 2023 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#ifndef DISTRIBUTED_POINT_FUNCTIONS_DPF_KEY_GENERATION_PROTOCOL_KEY_GENERATION_PROTOCOL_H_
18+
#define DISTRIBUTED_POINT_FUNCTIONS_DPF_KEY_GENERATION_PROTOCOL_KEY_GENERATION_PROTOCOL_H_
19+
20+
#include <memory>
21+
22+
#include "absl/numeric/int128.h"
23+
#include "absl/status/statusor.h"
24+
#include "dpf/distributed_point_function.h"
25+
#include "dpf/distributed_point_function.pb.h"
26+
#include "dpf/key_generation_protocol/key_generation_protocol.pb.h"
27+
28+
namespace distributed_point_functions {
29+
30+
// A two-party protocol for generating a DPF key.
31+
// For each level of the DPF evaluation tree, the following messages are
32+
// exchanged between the parties. We refer to the corresponding lines in
33+
// Algorithm 8 of https://eprint.iacr.org/2022/866.pdf.
34+
//
35+
// 1. Perform two parallel OTs to obtain shares of s_{CW} (Step 5)
36+
// 2. Exchange shares of s_{CW}, t^L_{CW}, and t^R_{CW} (Step 5)
37+
// 3. Perform two parallel OTs to obtain shares of W_{CW} (Step 11)
38+
// 4. Exchange shares of W_{CW}.
39+
//
40+
// These steps correspond to the following functions in this class:
41+
//
42+
// 1a. ComputeSeedCorrectionOtReceiverMessage
43+
// 1b. ComputeSeedCorrectionOtSenderMessage
44+
// 2. ComputeSeedCorrectionShare
45+
// 3a. ComputeValueCorrectionOtReceiverMessage
46+
// 3b. ComputeValueCorrectionOtSenderMessage
47+
// 4. ComputeValueCorrectionShare
48+
//
49+
// Each of these methods takes the other party's message from the previous
50+
// round, as well as a ProtocolState message containing the party's local state.
51+
// It updates the state and returns the computed message or a Status indicating
52+
// any errors.
53+
//
54+
// NOTE: We may want to compute the value correction first, as done in
55+
// DistributedPointFunction::GenerateIncremental.
56+
class KeyGenerationProtocol {
57+
public:
58+
struct ProtocolState {
59+
int tree_level;
60+
// Add more local state variables here.
61+
};
62+
63+
// Creates a new instance of the key generation protocol for a DPF with the
64+
// given parameters. Party must be 0 or 1.
65+
static absl::StatusOr<std::unique_ptr<KeyGenerationProtocol>> Create(
66+
absl::Span<const DpfParameters> parameters, int party);
67+
68+
// Create ProtocolState given shares of alphas and betas. Arguments are given
69+
// as Spans to allow batching.
70+
absl::StatusOr<ProtocolState> Initialize(
71+
absl::Span<const absl::uint128> alpha_shares,
72+
absl::Span<const std::vector<Value>> beta_shares) const;
73+
74+
// Receiver OT message for the MUX in Step 5. Just takes the state as input.
75+
absl::StatusOr<SeedCorrectionOtReceiverMessage>
76+
ComputeSeedCorrectionOtReceiverMessage(ProtocolState& state) const;
77+
78+
// Computes the sender OT message given the receiver message and the state.
79+
absl::StatusOr<SeedCorrectionOtSenderMessage>
80+
ComputeSeedCorrectionOtSenderMessage(
81+
const SeedCorrectionOtReceiverMessage& seed_ot_receiver_message,
82+
ProtocolState& state) const;
83+
84+
// Computes the share of the seed correction word given the sender OT message
85+
// and the state.
86+
absl::StatusOr<SeedCorrectionShare> ComputeSeedCorrectionOtShare(
87+
const SeedCorrectionOtSenderMessage& seed_ot_sender_message,
88+
ProtocolState& state) const;
89+
90+
// Updates the state with the other party's seed correction share.
91+
absl::Status ApplySeedCorrectionShare(
92+
const SeedCorrectionShare& seed_correction_share,
93+
ProtocolState& state) const;
94+
95+
// Computes the OT receiver message for the MUX gate in Step 11 given the
96+
// state.
97+
absl::StatusOr<ValueCorrectionOtReceiverMessage>
98+
ComputeValueCorrectionOtReceiverMessage(ProtocolState& state) const;
99+
100+
// Computes the OT sender message in Step 11 given the receiver message and
101+
// the state.
102+
absl::StatusOr<ValueCorrectionOtSenderMessage>
103+
ComputeValueCorrectionOtSenderMessage(
104+
const ValueCorrectionOtReceiverMessage& value_ot_receiver_message,
105+
ProtocolState& state) const;
106+
107+
// Computes the value correction share given the OT sender message and the
108+
// state.
109+
absl::StatusOr<ValueCorrectionShare> ComputeValueCorrectionOtShare(
110+
const ValueCorrectionOtSenderMessage& value_ot_sender_message,
111+
ProtocolState& state) const;
112+
113+
// Updates the state with the other party's value correction share.
114+
absl::Status ApplyValueCorrectionShare(
115+
const ValueCorrectionShare& value_correction_share,
116+
ProtocolState& state) const;
117+
118+
// Finalizes the protocol after all tree levels have been computed and returns
119+
// the generated DpfKey.
120+
absl::StatusOr<DpfKey> Finalize(ProtocolState& state) const;
121+
122+
private:
123+
explicit KeyGenerationProtocol(std::unique_ptr<DistributedPointFunction> dpf,
124+
int party);
125+
126+
std::unique_ptr<DistributedPointFunction> dpf_;
127+
int party_;
128+
};
129+
130+
} // namespace distributed_point_functions
131+
132+
#endif // DISTRIBUTED_POINT_FUNCTIONS_DPF_KEY_GENERATION_PROTOCOL_KEY_GENERATION_PROTOCOL_H_
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright 2023 Google LLC
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+
17+
package distributed_point_functions;
18+
19+
import "dpf/distributed_point_function.proto";
20+
21+
// For faster allocations of sub-messages.
22+
option cc_enable_arenas = true;
23+
24+
message SeedCorrectionOtSenderMessage {
25+
repeated Block masked_message_one = 1;
26+
repeated Block masked_message_two = 2;
27+
}
28+
29+
message SeedCorrectionOtReceiverMessage {
30+
repeated bool choice_bit_mask = 1;
31+
}
32+
33+
message SeedCorrectionShare {
34+
repeated Block seed = 1;
35+
repeated bool control_bit_left = 2;
36+
repeated bool control_bit_right = 3;
37+
}
38+
39+
message ValueCorrectionOtSenderMessage {
40+
repeated Value masked_message_one = 1;
41+
repeated Value masked_message_two = 2;
42+
}
43+
44+
message ValueCorrectionOtReceiverMessage {
45+
repeated bool choice_bit_mask = 1;
46+
}
47+
48+
message ValueCorrectionShare {
49+
repeated Value value = 1;
50+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Copyright 2023 Google LLC
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+
#include "dpf/key_generation_protocol/key_generation_protocol.h"
16+
17+
#include "dpf/distributed_point_function.pb.h"
18+
#include "dpf/internal/status_matchers.h"
19+
#include "gmock/gmock.h"
20+
#include "gtest/gtest.h"
21+
22+
namespace distributed_point_functions {
23+
namespace {
24+
25+
using dpf_internal::IsOkAndHolds;
26+
using dpf_internal::StatusIs;
27+
using ::testing::HasSubstr;
28+
using ::testing::NotNull;
29+
30+
class KeyGenerationProtocolTest : public testing::Test {
31+
protected:
32+
void SetUp() override {
33+
parameters_.resize(2);
34+
parameters_[0].set_log_domain_size(5);
35+
parameters_[0].mutable_value_type()->mutable_integer()->set_bitsize(64);
36+
parameters_[1].set_log_domain_size(10);
37+
parameters_[1].mutable_value_type()->mutable_integer()->set_bitsize(64);
38+
}
39+
std::vector<DpfParameters> parameters_;
40+
};
41+
42+
TEST_F(KeyGenerationProtocolTest, CreateSucceeds) {
43+
constexpr int party = 0;
44+
45+
EXPECT_THAT(KeyGenerationProtocol::Create(parameters_, party),
46+
IsOkAndHolds(NotNull()));
47+
}
48+
49+
TEST_F(KeyGenerationProtocolTest, CreateFailsIfPartyIsNot0Or1) {
50+
constexpr int party = 2;
51+
52+
EXPECT_THAT(KeyGenerationProtocol::Create(parameters_, party),
53+
StatusIs(absl::StatusCode::kInvalidArgument, HasSubstr("party")));
54+
}
55+
} // namespace
56+
} // namespace distributed_point_functions

0 commit comments

Comments
 (0)