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_
0 commit comments